#!/usr/bin/env bash # # --- T2-COPYRIGHT-NOTE-BEGIN --- # T2 SDE: scripts/Build-Tools # Copyright (C) 2004 - 2024 The T2 SDE Project # Copyright (C) 1998 - 2003 ROCK Linux Project # # This Copyright note is generated by scripts/Create-CopyPatch, # 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 version 2. # --- T2-COPYRIGHT-NOTE-END --- config=default stagelevel=9 cleanup=0 while [ "$1" ]; do case "$1" in -cleanup) cleanup=1; shift ;; -cfg) config=$2; shift; shift ;; -[0-9]) options="$options $1" stagelevel=${1#-}; shift ;; *) echo "Usage: $0 [ -cfg config ] [ -0 | -9 ] \\" echo " ${0//?/ } [ -cleanup ]"; exit 1 ;; esac done . scripts/parse-config . scripts/functions.in var_remove PATH ":" $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin var_remove PATH ":" $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper mkdir -p src mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib if [ $toolsdir = cross ]; then mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/{var/adm,etc,share,include} [ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/usr ] || ln -s . build/$SDECFG_ID/TOOLCHAIN/$toolsdir/usr [ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/sbin ] || ln -s bin build/$SDECFG_ID/TOOLCHAIN/$toolsdir/sbin [ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/var/adm/logs ] || ln -s ../../../../var/adm/logs \ build/$SDECFG_ID/TOOLCHAIN/$toolsdir/var/adm/logs mkdir -p build/$SDECFG_ID/var/adm/logs fi x="$(bash scripts/xfind.sh config/$config/. package/. scripts/. \ misc/. architecture/. target/. \( ! -name '*.cache' ! \ -name '*.patch*' ! -name '.*' ! -name 'svn-commit.tmp' \ \( ! -name '*.conf' -o -name 'pkg*.conf' \) \) -a -type f \ -newer build/$SDECFG_ID/TOOLCHAIN/$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 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate if echo "$x" | grep -qv " config/$config/"; 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/" rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/* rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/getdu rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/getfiles rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/fl_wrparse rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/fl_stparse rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate fi if [ ! -f build/$SDECFG_ID/TOOLCHAIN/$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 misc/tools-source/cmd_wrapper.c \ -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \ -o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/tmp.$$ || exit 1 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/{tmp.$$,cmd_wrapper} build_wrapper() { local x="$(echo ${1//,/ })" y z wrappervars="$wrappervars $x" while shift; [ $# != 0 ] do wrappers="$wrappers $1" tmp=`mktemp -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper` { echo '#!/usr/bin/env 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 "build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$1" done } while read script; do . $script done < <(bash scripts/xfind.sh package/. \ $(get_reverted `get_expanded target/%/. $targetchain`) misc/. -name 'wrappers.in') echo_status "Building $toolsdir/wrapper/strip_wrapper" cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$ #!/usr/bin/env bash if [ "\$STRIP_WRAPPER_NOLOOP" = 1 ]; then echo "Error: Strip wrapper is looping!" >&2 exit 1 fi if [ "\$SDECFG_DEBUG" = 0 -o "\$STRIP_WRAPPER_BYPASS" = 1 ]; then PATH=\${PATH//\$STRIP_WRAPPER_MYPATH:/} export STRIP_WRAPPER_NOLOOP=1 exec "\$(basename \$0)" "\$@" fi exit 0 EOT chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$ mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper{.$$,} wrappers="$wrappers strip_wrapper" for x in strip $arch_target-strip; do [ $crossnative = cross -a $x = strip ] && continue ln -sf strip_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$x wrappers="$wrappers $x" done case $arch_target in *mingw32*) uname_machine=MINGW32 ;; *darwin*) uname_machine=Darwin ;; *) uname_machine=Linux ;; esac echo_status "Building $toolsdir/wrapper/{arch,uname}" cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname.$$ #!/usr/bin/env bash arch=\$(echo \${arch_machine} | sed 's/armv.*/arm/; s/sparcv.*/sparc/; s/powerpc/ppc/') echo "You should not run uname during the build: \$*" >&2 [ -z "\$1" ] && set -- '-s' # shorten long options opts="\$(echo " \$*" | sed 's/--all/-a/; s/--kernel-name/-s/; s/--nodename/-n/; s/--kernel-release/-r/; s/--release/-r/; s/--machine/-m/; s/--processor/-p/; s/--operating-system/-o/; s/--kernel-version/-v/;')" str= # expand combined options opts="\$(echo "\$opts" | sed 's/[^-]/ -&/g; s/- //g; s/-a/-m -n -r -s -v/')" newopts="\${opts// -s/}" [ "\$newopts" != "\$opts" ] && str="\$str $uname_machine" opts="\$newopts" newopts="\${opts// -n/}" [ "\$newopts" != "\$opts" ] && str="\$str \$(hostname)" opts="\$newopts" newopts="\${opts// -r/}" if [ "\$newopts" != "\$opts" ]; then # TODO: not hardcode system version [ $SDECFG_KERNEL = "darwin" ] && str="\$str 21.5.0" || str="\$str $(sed -n 's/\[V\] \([^ ]*\).*/\1/p' \ $base/package/*/linux-header/linux-header.desc)-inside-t2-sandbox" fi opts="\$newopts" newopts="\${opts// -v/}" [ "\$newopts" != "\$opts" ] && str="\$str #1 SMP $(date)" opts="\$newopts" newopts="\${opts// -m/}" [ "\$newopts" != "\$opts" ] && str="\$str \$arch" opts="\$newopts" newopts="\${opts// -p/}" [ "\$newopts" != "\$opts" ] && str="\$str unknown" opts="\$newopts" newopts="\${opts// -o/}" [ "\$newopts" != "\$opts" ] && str="\$str GNU/$uname_machine" if [ "\$newopts" ]; then echo "uname wrapper: Unknown option: '\$newopts'" >&2 exit 1 fi echo \${str:1} # skip the leading blank EOT unset uname_machine cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch.$$ #!/bin/sh echo "You should not run arch during the build!" >&2 echo "$(echo $arch | arch2uname)" EOT chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/{arch,uname}.$$ mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch{.$$,} mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname{.$$,} wrappers="$wrappers arch uname" if [ $crossnative = cross ]; then echo_status "Building $toolsdir/wrapper/ldconfig" cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ldconfig.$$ #!/bin/sh echo "You should not run ldconfig during the build!" >&2 EOT chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ldconfig.$$ mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ldconfig{.$$,} wrappers="$wrappers ldconfig" fi echo_status "Building $toolsdir/wrapper/install_wrapper" cp misc/tools-source/install_wrapper.sh build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install_wrapper chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install_wrapper ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/cp ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ln ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/mv wrappers="$wrappers install_wrapper install cp ln mv" # Remove unknown, spurious wrappers from potential prev. run wrappers=" $wrappers " # add whitespace for quick match below for w in $(ls build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/); do [ "${wrappers// $w /}" = "$wrappers" ] && rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$w done # Various small tools for x in getdu getfiles fl_wrparse fl_stparse; do echo_status "Building $toolsdir/bin/$x" $BUILDCC -Wall -O2 misc/tools-source/$x.c \ -o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x.$$ || exit 1 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x.$$ \ build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x done # Flist Wrapper Library if [ "$SDECFG_FLIST" = "flwrapper" ]; then echo_status "Building $toolsdir/lib/fl_wrapper.so" tmp=build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/tmp.$$ $BUILDCC -Wall -Os misc/archive/hello.c -o $tmp FLWRAPPER_LIBC=$(readelf --dynamic $tmp | sed -n 's/.*\[\(lib[cC].*\)]/\1/p') [ ! "$FLWRAPPER_LIBC" ] && FLWRAPPER_LIBC=$(ldd $tmp | sed -n '/lib[cC]\./ { s/.* => //; s/[\t ]*\([^\t ]*\).*/\1/p }') rm -f $tmp if [ ! "$FLWRAPPER_LIBC" ]; then abort 'Unable to detect default libc for flwrapper' fi if [ $stagelevel -lt 2 ]; then FLWRAPPER_BASEDIR=-DFLWRAPPER_BASEDIR=\"$base\" else FLWRAPPER_BASEDIR= fi bash misc/tools-source/fl_wrapper.c.sh > src/fl_wrapper_$$.c $BUILDCC -O2 -shared -fPIC -Wall -Wno-format-truncation \ src/fl_wrapper_$$.c $FLWRAPPER_BASEDIR \ -DFLWRAPPER_LIBC=\"${FLWRAPPER_LIBC##*/}\" \ -o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so.$$ -ldl || exit 1 rm src/fl_wrapper_$$.c mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so.$$ \ build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so echo_status "Testing $toolsdir/lib/fl_wrapper.so" if ! bash -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 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so echo; exit 1 fi fi # Create Parse-Config Collection echo_status "Creating $toolsdir/lib/parse-config" bash scripts/xfind.sh \ architecture/$arch/. kernel/$kernel/. package/. $(get_reverted `get_expanded target/%/. $targetchain`) misc/ -type f \ '(' -name 'parse-config' -o -name 'parse-config-[0-9]' ')' \ -printf '%f\t%p\n' | sed \ -e 's,^parse-config\t,5\t,g' -e 's,^parse-config-\(.\)\t,\1\t,g' | \ sort -n | gawk '{ $1="."; print; }' \ > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config.$$ mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config.$$ \ build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config bash scripts/xfind.sh \ architecture/$arch/. kernel/$kernel/. package/. $(get_reverted `get_expanded target/%/. $targetchain`) misc/ -type f \ -name 'parse-config-fixarch' \ -printf '%f\t%p\n' | sort | gawk '{ $1="."; print; }' \ > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch.$$ mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch.$$ \ build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch # Create pkg_*_{pre,post}.conf files echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf" rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_*_{pre,post}.conf for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do for y in `echo package/$x/pkg_*_{pre,post}.conf`; do if [ -f $y ]; then echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/} fi done done for y in `echo architecture/$arch/pkg_*_{pre,post}.conf`; do if [ -f $y ]; then echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/} fi done for y in `echo kernel/$kernel/pkg_*_{pre,post}.conf`; do if [ -f $y ]; then echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/} fi done for y in `echo target/$target/pkg_*_{pre,post}.conf`; do if [ -f $y ]; then echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/} fi done echo -e "${wrappervars// / }" | 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 > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/wrapper-config.$$ mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/wrapper-config.$$ \ build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/wrapper-config touch build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate fi exit 0