|
|
#!/bin/bash # --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: bin/sde-build-tools # Copyright (C) 2006 - 2015 The OpenSDE Project # Copyright (C) 2004 - 2006 The T2 SDE Project # Copyright (C) 1998 - 2003 Clifford Wolf # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END ---
#Description: Builds tools, wrappers and caches needed for a build
[ -n "$SDEROOT" ] || export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
. "$SDEROOT/lib/libsde.in"
create_usage() { local progname=${0##*/}
cat <<EOT Usage: ${progname//-/ } [--config <config>] [-<stagelevel>] [--cleanup] EOT }
shortopts='0123456789c:' longopts='help,config:,cfg:,cleanup' options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" ) if [ $? -ne 0 ]; then create_usage exit -1 fi
# load new arguments list eval set -- "$options"
config=default stagelevel=9 cleanup=0
while [ $# -gt 0 ]; do case "$1" in --help) create_usage exit 0 ;; --cleanup) cleanup=1 ;; -c|--cfg|--config) config="$2" shift ;; -[0-9]) stagelevel=${1#-} ;; --) shift break ;; *) echo_abort 1 "Unknown argument '$1', aborting." esac shift done
cd "$SDEROOT"
. lib/functions.in . lib/parse-config
# all our work here goes to the same location, $TOOLSDIR # TOOLSDIR="build/$SDECFG_ID/TOOLCHAIN/$toolsdir" var_remove PATH ":" $base/$TOOLSDIR/bin var_remove PATH ":" $base/$TOOLSDIR/wrapper
mkdir -p tmp mkdir -p $TOOLSDIR/bin mkdir -p $TOOLSDIR/wrapper
case $arch_machine in powerpc64|sparc64|x86_64|mips64) mkdir -p $TOOLSDIR/lib64 if [ ! -L $TOOLSDIR/lib ]; then ln -sf lib64 $TOOLSDIR/lib fi ;; *) mkdir -p $TOOLSDIR/lib ;; esac
if [ $toolsdir = tools.cross ]; then mkdir -p $TOOLSDIR/{var/adm,etc,share,include} [ -L $TOOLSDIR/usr ] || ln -s . $TOOLSDIR/usr [ -L $TOOLSDIR/sbin ] || ln -s bin $TOOLSDIR/sbin [ -L $TOOLSDIR/var/adm/logs ] || ln -s ../../../../var/adm/logs \ $TOOLSDIR/var/adm/logs mkdir -p build/$SDECFG_ID/var/adm/logs fi
x="$( bin/find config/$config/. package/. scripts/. \ lib/. architecture/. target/. \( ! -name '*.cache' ! \ -name '*.patch*' ! -name '.*' ! -name 'svn-commit.tmp' \ \( \! -name '*.conf' -o -name 'pkg*.conf' \) \) -a -type f \ -newer $TOOLSDIR/.lastupdate \ -printf 'Found new/updated file: %p\n' 2> /dev/null )"
if [ "$x" ] ; then echo_header Found $( echo "$x" | wc -l ) new/updated \ files in source tree: echo "$x" | head -n 3 | sed 's,/\./,/,g' | while read y ; do echo_status $y ; done [ "$( echo "$x" | tail -n +4 )" ] && echo_status "** list truncated to save space on the terminal **"
if [ "$SDEDEBUG_TOOLS_SKIP" = 1 ]; then echo_error "Found \$SDEDEBUG_TOOLS_SKIP ..." else rm -f $TOOLSDIR/.lastupdate
if echo "$x" | grep -qv " config/$config/package" ; then echo_header Re-running configuration: while read -r line ; do echo_status "$line" done < <( ./scripts/Config -cfg $config -oldconfig ) fi fi fi
if [ $cleanup = 1 ] ; then echo_header "Removing old stuff in $toolsdir/ directory ..."
rm -f $TOOLSDIR/wrapper/*
rm -f $TOOLSDIR/bin/getdu rm -f $TOOLSDIR/bin/getfiles rm -f $TOOLSDIR/bin/fl_wrparse rm -f $TOOLSDIR/bin/fl_stparse
rm -f $TOOLSDIR/lib/fl_wrapper.so rm -f $TOOLSDIR/lib/parse-config rm -f $TOOLSDIR/lib/parse-config-fixarch rm -f $TOOLSDIR/.lastupdate fi
if [ ! -f $TOOLSDIR/.lastupdate ] ; then
echo_header "Building tools in build/.../TOOLCHAIN/$toolsdir:"
# CC, CXX, F77 and KCC Wrapper # wrappers="cmd_wrapper" ; wrappervars= echo_status "Building $toolsdir/wrapper/cmd_wrapper." $BUILDCC -Wall -O2 src/tools-source/cmd_wrapper.c \ -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \ -o $TOOLSDIR/wrapper/tmp.$$ || exit 1 mv $TOOLSDIR/wrapper/tmp.$$ \ $TOOLSDIR/wrapper/cmd_wrapper # build_wrapper() { local x="$( echo ${1//,/ } )" y z wrappervars="$wrappervars $x" while shift ; [ $# != 0 ] do wrappers="$wrappers $1" tmp=`mktemp -p $TOOLSDIR/wrapper` { echo '#!/bin/bash'
for y in $x ; do echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && " echo "export CMD_WRAPPER_DEBUG=1" done
for y in $x ; do echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && " echo "export CMD_WRAPPER_BYPASS=1" done
z=; echo -n 'export CMD_WRAPPER_APPEND_PO="' for y in $x; do echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" " done ; echo '"'
z=; echo -n 'export CMD_WRAPPER_OTHERS="' for y in $x; do echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":" done ; echo '"'
z=; echo -n 'export CMD_WRAPPER_INSERT="' for y in $x; do echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" " done ; echo '"'
z=; echo -n 'export CMD_WRAPPER_REMOVE="' for y in $x; do echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" " done ; echo '"'
z=; echo -n 'export CMD_WRAPPER_APPEND="' for y in $x; do echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" " done ; echo '"'
z=; echo -n 'export CMD_WRAPPER_FILTER="' for y in $x; do echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|" done ; echo '"'
echo 'exec cmd_wrapper $( basename $0 ) "$@"' } > $tmp chmod +rx $tmp mv $tmp "$TOOLSDIR/wrapper/$1" done } # while read script ; do . $script done < <( bin/find package/. lib/*/. \ $( get_reverted `get_expanded target/%/. $targetchain` ) -name 'wrappers.in' ) # echo_status "Building $toolsdir/wrapper/strip_wrapper." cp src/tools-source/strip_wrapper.sh $TOOLSDIR/wrapper/strip_wrapper chmod +x $TOOLSDIR/wrapper/strip_wrapper wrappers="$wrappers strip_wrapper" # for x in strip $arch_target-strip ; do [ $crossnative = cross -a $x = strip ] && continue if [ -x "`type -p $x`" ] ; then ln -sf strip_wrapper \ $TOOLSDIR/wrapper/$x wrappers="$wrappers $x" fi done # if [ "$toolsdir" = "tools.chroot" ]; then echo_status "Building $toolsdir/wrapper/{uname,arch}."
sed -e "s,@@ARCH_MACHINE@@,$arch_machine,g" \ src/tools-source/uname_wrapper.in.sh > $TOOLSDIR/wrapper/uname sed -e "s,@@ARCH@@,$( echo $arch | arch2uname ),g" \ src/tools-source/arch_wrapper.in.sh > $TOOLSDIR/wrapper/arch
chmod +x $TOOLSDIR/wrapper/{uname,arch} wrappers="$wrappers uname arch" fi # echo_status "Building $toolsdir/wrapper/install_wrapper." cp src/tools-source/install_wrapper.sh $TOOLSDIR/wrapper/install_wrapper chmod +x $TOOLSDIR/wrapper/install_wrapper ln -sf install_wrapper $TOOLSDIR/wrapper/install ln -sf install_wrapper $TOOLSDIR/wrapper/cp ln -sf install_wrapper $TOOLSDIR/wrapper/ln ln -sf install_wrapper $TOOLSDIR/wrapper/mv wrappers="$wrappers install_wrapper install cp ln mv" # for x in $( ls $TOOLSDIR/wrapper/ ) do z=0 for y in $wrappers ; do [ "$x" = "$y" ] && z=1 done if [ "$z" = 0 ] ; then rm -f $TOOLSDIR/wrapper/$x fi done
# Various small tools # for x in getdu getfiles fl_wrparse fl_stparse ; do echo_status "Building $toolsdir/bin/$x." $BUILDCC -Wall -O2 src/tools-source/$x.c \ -o $TOOLSDIR/bin/$x.$$ || exit 1 mv $TOOLSDIR/bin/$x.$$ \ $TOOLSDIR/bin/$x done
# Flist Wrapper Library # if [ "$SDECFG_FLIST" = "flwrapper" ] ; then FLWRAPPER_LIBC=$(ls -1 \ "$xroot"/lib*/{*/,}libc[.-]* 2> /dev/null | grep -v '\.a$' | grep '\.so' | sort -V | head -n1 ) if [ ! -f "$FLWRAPPER_LIBC" ]; then abort 'Unable to detect /lib/libc.* for flwrapper' fi echo_status "Building $toolsdir/lib/fl_wrapper.so ($FLWRAPPER_LIBC)."
if ! atstage native; then FLWRAPPER_BASEDIR="$base" else FLWRAPPER_BASEDIR= fi
make -s -C src/tools-source/fl_wrapper LIB="$PWD/$TOOLSDIR/lib/fl_wrapper.so" \ CC="$BUILDCC" LIBC="${FLWRAPPER_LIBC##*/}" BASE="$FLWRAPPER_BASEDIR" \ || exit 1
echo_status "Testing $toolsdir/lib/fl_wrapper.so." if ! sh -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$SDECFG_ID/` `TOOLCHAIN/$toolsdir/lib/fl_wrapper.so\" date ; ` `exit \$?" >/dev/null 2>&1 then echo_error "Detected a problem with the flist" \ "wrapper lib on your system." echo_error "Please specify another flist-creation" \ "system in your build configuration." rm -f $TOOLSDIR/lib/fl_wrapper.so echo ; exit 1 fi fi
# Create Parse-Config Collection # prio_find() { local name="$1"; shift local mode="$1"; shift
wrapper() { if [ "$mode" = "preserve" ]; then grep -n ^ else sed -e "s|^|$mode:|" fi }
bin/find "$@" -type f '(' -name "$name" -o -name "$name-[0-9]" ')' | wrapper | sed -e "s|^.*/$name\$|5:\0|" -e "s|^.*/$name-\(.\)\$|\1\:\0|" -e 's|/\./|/|' }
echo_status "Creating $toolsdir/lib/parse-config." ( prio_find parse-config 0 architecture/$arch/. lib/*/. package/. | grep -v lib/output prio_find parse-config preserve $( get_reverted `get_expanded target/%/. $targetchain` ) ) | sort -n -t: | sed -e 's|^....|\. |' > $TOOLSDIR/lib/parse-config.$$ mv $TOOLSDIR/lib/parse-config.$$ \ $TOOLSDIR/lib/parse-config
( prio_find parse-config-fixarch 0 architecture/$arch/. lib/*/. package/. | grep -v lib/output prio_find parse-config-fixarch preserve $( get_reverted `get_expanded target/%/. $targetchain` ) ) | sort -n -t: | sed -e 's|^....|\. |' > $TOOLSDIR/lib/parse-config-fixarch.$$ mv $TOOLSDIR/lib/parse-config-fixarch.$$ \ $TOOLSDIR/lib/parse-config-fixarch
# Create pkg_*_{pre,post}.conf files #
echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf" rm -f $TOOLSDIR/lib/pkg_*_{pre,post}.conf for y in `echo architecture/$arch/pkg_*_{pre,post}.conf`; do if [ -f $y ]; then echo " . $y" >> $TOOLSDIR/lib/${y##*/} fi done
if atstage rebuild; then for x in /var/adm/packages/*; do ls -1d package/*/${x##*/}/pkg_*_{pre,post}.conf 2> /dev/null done else for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do ls -1d package/$x/pkg_*_{pre,post}.conf 2> /dev/null done fi | while read y; do echo " . $y" >> $TOOLSDIR/lib/${y##*/} done
$ECHO_E "${wrappervars// /\\n}" | grep . | sort -u | while read x ; do echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0" echo "export ${x}_WRAPPER_OTHERS= ${x}_WRAPPER_REMOVE=" echo "export ${x}_WRAPPER_INSERT= ${x}_WRAPPER_APPEND=" echo "export ${x}_WRAPPER_FILTER= ${x}_WRAPPER_APPEND_PO=" done > $TOOLSDIR/lib/wrapper-config.$$ mv $TOOLSDIR/lib/wrapper-config.$$ \ $TOOLSDIR/lib/wrapper-config
touch $TOOLSDIR/.lastupdate fi
exit 0
|