10f66f451Sopenharmony_ci#!/bin/bash
20f66f451Sopenharmony_ci
30f66f451Sopenharmony_ci# Grab default values for $CFLAGS and such.
40f66f451Sopenharmony_ci
50f66f451Sopenharmony_ciif [ ! -z "$ASAN" ]; then
60f66f451Sopenharmony_ci  # Turn ASan on.
70f66f451Sopenharmony_ci  CFLAGS="-fsanitize=address $CFLAGS"
80f66f451Sopenharmony_ci  # Optional, but effectively necessary if you want useful backtraces.
90f66f451Sopenharmony_ci  CFLAGS="-O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls $CFLAGS"
100f66f451Sopenharmony_cifi
110f66f451Sopenharmony_ci
120f66f451Sopenharmony_ciexport LANG=c
130f66f451Sopenharmony_ciexport LC_ALL=C
140f66f451Sopenharmony_ciset -o pipefail
150f66f451Sopenharmony_cisource scripts/portability.sh
160f66f451Sopenharmony_ci
170f66f451Sopenharmony_ci[ -z "$KCONFIG_CONFIG" ] && KCONFIG_CONFIG=.config
180f66f451Sopenharmony_ci[ -z "$OUTNAME" ] && OUTNAME=toybox"${TARGET:+-$TARGET}"
190f66f451Sopenharmony_ciUNSTRIPPED="generated/unstripped/$(basename "$OUTNAME")"
200f66f451Sopenharmony_ci
210f66f451Sopenharmony_ci# Try to keep one more cc invocation going than we have processors
220f66f451Sopenharmony_ci[ -z "$CPUS" ] && \
230f66f451Sopenharmony_ci  CPUS=$(($(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null)+1))
240f66f451Sopenharmony_ci
250f66f451Sopenharmony_ci# Respond to V= by echoing command lines as well as running them
260f66f451Sopenharmony_ciDOTPROG=
270f66f451Sopenharmony_cido_loudly()
280f66f451Sopenharmony_ci{
290f66f451Sopenharmony_ci  [ ! -z "$V" ] && echo "$@" || echo -n "$DOTPROG"
300f66f451Sopenharmony_ci  "$@"
310f66f451Sopenharmony_ci}
320f66f451Sopenharmony_ci
330f66f451Sopenharmony_ci# Is anything under directory $2 newer than file $1
340f66f451Sopenharmony_ciisnewer()
350f66f451Sopenharmony_ci{
360f66f451Sopenharmony_ci  CHECK="$1"
370f66f451Sopenharmony_ci  shift
380f66f451Sopenharmony_ci  [ ! -z "$(find "$@" -newer "$CHECK" 2>/dev/null || echo yes)" ]
390f66f451Sopenharmony_ci}
400f66f451Sopenharmony_ci
410f66f451Sopenharmony_ciecho "Generate headers from toys/*/*.c..."
420f66f451Sopenharmony_ci
430f66f451Sopenharmony_cimkdir -p generated/unstripped
440f66f451Sopenharmony_ci
450f66f451Sopenharmony_ciif isnewer generated/Config.in toys
460f66f451Sopenharmony_cithen
470f66f451Sopenharmony_ci  echo "Extract configuration information from toys/*.c files..."
480f66f451Sopenharmony_ci  scripts/genconfig.sh
490f66f451Sopenharmony_cifi
500f66f451Sopenharmony_ci
510f66f451Sopenharmony_ci# Create a list of all the commands toybox can provide. Note that the first
520f66f451Sopenharmony_ci# entry is out of order on purpose (the toybox multiplexer command must be the
530f66f451Sopenharmony_ci# first element of the array). The rest must be sorted in alphabetical order
540f66f451Sopenharmony_ci# for fast binary search.
550f66f451Sopenharmony_ci
560f66f451Sopenharmony_ciif isnewer generated/newtoys.h toys
570f66f451Sopenharmony_cithen
580f66f451Sopenharmony_ci  echo -n "generated/newtoys.h "
590f66f451Sopenharmony_ci
600f66f451Sopenharmony_ci  echo "USE_TOYBOX(NEWTOY(toybox, NULL, TOYFLAG_STAYROOT))" > generated/newtoys.h
610f66f451Sopenharmony_ci  $SED -n -e 's/^USE_[A-Z0-9_]*(/&/p' toys/*/*.c \
620f66f451Sopenharmony_ci	| $SED 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -s -k 1,1 \
630f66f451Sopenharmony_ci	| $SED 's/[^ ]* //'  >> generated/newtoys.h
640f66f451Sopenharmony_ci  [ $? -ne 0 ] && exit 1
650f66f451Sopenharmony_cifi
660f66f451Sopenharmony_ci
670f66f451Sopenharmony_ci[ ! -z "$V" ] && echo "Which C files to build..."
680f66f451Sopenharmony_ci
690f66f451Sopenharmony_ci# Extract a list of toys/*/*.c files to compile from the data in $KCONFIG_CONFIG
700f66f451Sopenharmony_ci# (First command names, then filenames with relevant {NEW,OLD}TOY() macro.)
710f66f451Sopenharmony_ci
720f66f451Sopenharmony_ci[ -d ".git" ] && GITHASH="$(git describe --tags --abbrev=12 2>/dev/null)"
730f66f451Sopenharmony_ci[ ! -z "$GITHASH" ] && GITHASH="-DTOYBOX_VERSION=\"$GITHASH\""
740f66f451Sopenharmony_ciTOYFILES="$($SED -n 's/^CONFIG_\([^=]*\)=.*/\1/p' "$KCONFIG_CONFIG" | xargs | tr ' [A-Z]' '|[a-z]')"
750f66f451Sopenharmony_ciTOYFILES="$(egrep -l "TOY[(]($TOYFILES)[ ,]" toys/*/*.c)"
760f66f451Sopenharmony_ciCFLAGS="$CFLAGS $(cat generated/cflags)"
770f66f451Sopenharmony_ciBUILD="$(echo ${CROSS_COMPILE}${CC} $CFLAGS -I . $OPTIMIZE $GITHASH)"
780f66f451Sopenharmony_ciLIBFILES="$(ls lib/*.c | grep -v lib/help.c)"
790f66f451Sopenharmony_ciTOYFILES="lib/help.c main.c $TOYFILES"
800f66f451Sopenharmony_ci
810f66f451Sopenharmony_ciif [ "${TOYFILES/pending//}" != "$TOYFILES" ]
820f66f451Sopenharmony_cithen
830f66f451Sopenharmony_ci  echo -e "\n\033[1;31mwarning: using unfinished code from toys/pending\033[0m"
840f66f451Sopenharmony_cifi
850f66f451Sopenharmony_ci
860f66f451Sopenharmony_cigenbuildsh()
870f66f451Sopenharmony_ci{
880f66f451Sopenharmony_ci  # Write a canned build line for use on crippled build machines.
890f66f451Sopenharmony_ci
900f66f451Sopenharmony_ci  echo "#!/bin/sh"
910f66f451Sopenharmony_ci  echo
920f66f451Sopenharmony_ci  echo "PATH='$PATH'"
930f66f451Sopenharmony_ci  echo
940f66f451Sopenharmony_ci  echo "BUILD='$BUILD'"
950f66f451Sopenharmony_ci  echo
960f66f451Sopenharmony_ci  echo "LINK='$LINK'"
970f66f451Sopenharmony_ci  echo
980f66f451Sopenharmony_ci  echo "FILES='$LIBFILES $TOYFILES'"
990f66f451Sopenharmony_ci  echo
1000f66f451Sopenharmony_ci  echo
1010f66f451Sopenharmony_ci  echo '$BUILD $FILES $LINK'
1020f66f451Sopenharmony_ci}
1030f66f451Sopenharmony_ci
1040f66f451Sopenharmony_ciif ! cmp -s <(genbuildsh 2>/dev/null | head -n 6 ; echo LINK="'"$LDOPTIMIZE $LDFLAGS) \
1050f66f451Sopenharmony_ci          <(head -n 7 generated/build.sh 2>/dev/null | $SED '7s/ -o .*//')
1060f66f451Sopenharmony_cithen
1070f66f451Sopenharmony_ci  echo -n "Library probe"
1080f66f451Sopenharmony_ci
1090f66f451Sopenharmony_ci  # We trust --as-needed to remove each library if we don't use any symbols
1100f66f451Sopenharmony_ci  # out of it, this loop is because the compiler has no way to ignore a library
1110f66f451Sopenharmony_ci  # that doesn't exist, so we have to detect and skip nonexistent libraries
1120f66f451Sopenharmony_ci  # for it.
1130f66f451Sopenharmony_ci
1140f66f451Sopenharmony_ci  > generated/optlibs.dat
1150f66f451Sopenharmony_ci  for i in util crypt m resolv selinux smack attr crypto z log iconv
1160f66f451Sopenharmony_ci  do
1170f66f451Sopenharmony_ci    echo "int main(int argc, char *argv[]) {return 0;}" | \
1180f66f451Sopenharmony_ci    ${CROSS_COMPILE}${CC} $CFLAGS $LDFLAGS -xc - -o generated/libprobe $LDASNEEDED -l$i > /dev/null 2>/dev/null &&
1190f66f451Sopenharmony_ci    echo -l$i >> generated/optlibs.dat
1200f66f451Sopenharmony_ci    echo -n .
1210f66f451Sopenharmony_ci  done
1220f66f451Sopenharmony_ci  rm -f generated/libprobe
1230f66f451Sopenharmony_ci  echo
1240f66f451Sopenharmony_cifi
1250f66f451Sopenharmony_ci
1260f66f451Sopenharmony_ci# LINK needs optlibs.dat, above
1270f66f451Sopenharmony_ci
1280f66f451Sopenharmony_ciLINK="$(echo $LDOPTIMIZE $LDFLAGS -o "$UNSTRIPPED" $LDASNEEDED $(cat generated/optlibs.dat))"
1290f66f451Sopenharmony_cigenbuildsh > generated/build.sh && chmod +x generated/build.sh || exit 1
1300f66f451Sopenharmony_ci
1310f66f451Sopenharmony_ci#TODO: "make $SED && make" doesn't regenerate config.h because diff .config
1320f66f451Sopenharmony_ciif true #isnewer generated/config.h "$KCONFIG_CONFIG"
1330f66f451Sopenharmony_cithen
1340f66f451Sopenharmony_ci  echo "Make generated/config.h from $KCONFIG_CONFIG."
1350f66f451Sopenharmony_ci
1360f66f451Sopenharmony_ci  # This long and roundabout sed invocation is to make old versions of sed
1370f66f451Sopenharmony_ci  # happy. New ones have '\n' so can replace one line with two without all
1380f66f451Sopenharmony_ci  # the branches and tedious mucking about with hyperspace.
1390f66f451Sopenharmony_ci  # TODO: clean this up to use modern stuff.
1400f66f451Sopenharmony_ci
1410f66f451Sopenharmony_ci  $SED -n \
1420f66f451Sopenharmony_ci    -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \
1430f66f451Sopenharmony_ci    -e 't notset' \
1440f66f451Sopenharmony_ci    -e 's/^CONFIG_\(.*\)=y.*/\1/' \
1450f66f451Sopenharmony_ci    -e 't isset' \
1460f66f451Sopenharmony_ci    -e 's/^CONFIG_\([^=]*\)=\(.*\)/#define CFG_\1 \2/p' \
1470f66f451Sopenharmony_ci    -e 'd' \
1480f66f451Sopenharmony_ci    -e ':notset' \
1490f66f451Sopenharmony_ci    -e 'h' \
1500f66f451Sopenharmony_ci    -e 's/.*/#define CFG_& 0/p' \
1510f66f451Sopenharmony_ci    -e 'g' \
1520f66f451Sopenharmony_ci    -e 's/.*/#define USE_&(...)/p' \
1530f66f451Sopenharmony_ci    -e 'd' \
1540f66f451Sopenharmony_ci    -e ':isset' \
1550f66f451Sopenharmony_ci    -e 'h' \
1560f66f451Sopenharmony_ci    -e 's/.*/#define CFG_& 1/p' \
1570f66f451Sopenharmony_ci    -e 'g' \
1580f66f451Sopenharmony_ci    -e 's/.*/#define USE_&(...) __VA_ARGS__/p' \
1590f66f451Sopenharmony_ci    $KCONFIG_CONFIG > generated/config.h || exit 1
1600f66f451Sopenharmony_cifi
1610f66f451Sopenharmony_ci
1620f66f451Sopenharmony_ciif [ ! -f generated/mkflags ] || [ generated/mkflags -ot scripts/mkflags.c ]
1630f66f451Sopenharmony_cithen
1640f66f451Sopenharmony_ci  do_loudly $HOSTCC scripts/mkflags.c -o generated/mkflags || exit 1
1650f66f451Sopenharmony_cifi
1660f66f451Sopenharmony_ci
1670f66f451Sopenharmony_ci# Process config.h and newtoys.h to generate FLAG_x macros. Note we must
1680f66f451Sopenharmony_ci# always #define the relevant macro, even when it's disabled, because we
1690f66f451Sopenharmony_ci# allow multiple NEWTOY() in the same C file. (When disabled the FLAG is 0,
1700f66f451Sopenharmony_ci# so flags&0 becomes a constant 0 allowing dead code elimination.)
1710f66f451Sopenharmony_ci
1720f66f451Sopenharmony_cimake_flagsh()
1730f66f451Sopenharmony_ci{
1740f66f451Sopenharmony_ci  # Parse files through C preprocessor twice, once to get flags for current
1750f66f451Sopenharmony_ci  # .config and once to get flags for allyesconfig
1760f66f451Sopenharmony_ci  for I in A B
1770f66f451Sopenharmony_ci  do
1780f66f451Sopenharmony_ci    (
1790f66f451Sopenharmony_ci    # define macros and select header files with option string data
1800f66f451Sopenharmony_ci
1810f66f451Sopenharmony_ci    echo "#define NEWTOY(aa,bb,cc) aa $I bb"
1820f66f451Sopenharmony_ci    echo '#define OLDTOY(...)'
1830f66f451Sopenharmony_ci    if [ "$I" == A ]
1840f66f451Sopenharmony_ci    then
1850f66f451Sopenharmony_ci      cat generated/config.h
1860f66f451Sopenharmony_ci    else
1870f66f451Sopenharmony_ci      $SED '/USE_.*([^)]*)$/s/$/ __VA_ARGS__/' generated/config.h
1880f66f451Sopenharmony_ci    fi
1890f66f451Sopenharmony_ci    echo '#include "lib/toyflags.h"'
1900f66f451Sopenharmony_ci    cat generated/newtoys.h
1910f66f451Sopenharmony_ci
1920f66f451Sopenharmony_ci    # Run result through preprocessor, glue together " " gaps leftover from USE
1930f66f451Sopenharmony_ci    # macros, delete comment lines, print any line with a quoted optstring,
1940f66f451Sopenharmony_ci    # turn any non-quoted opstring (NULL or 0) into " " (because fscanf can't
1950f66f451Sopenharmony_ci    # handle "" with nothing in it, and mkflags uses that).
1960f66f451Sopenharmony_ci
1970f66f451Sopenharmony_ci    ) | ${CROSS_COMPILE}${CC} -E - | \
1980f66f451Sopenharmony_ci    $SED -n -e 's/" *"//g;/^#/d;t clear;:clear;s/"/"/p;t;s/\( [AB] \).*/\1 " "/p'
1990f66f451Sopenharmony_ci
2000f66f451Sopenharmony_ci  # Sort resulting line pairs and glue them together into triplets of
2010f66f451Sopenharmony_ci  #   command "flags" "allflags"
2020f66f451Sopenharmony_ci  # to feed into mkflags C program that outputs actual flag macros
2030f66f451Sopenharmony_ci  # If no pair (because command's disabled in config), use " " for flags
2040f66f451Sopenharmony_ci  # so allflags can define the appropriate zero macros.
2050f66f451Sopenharmony_ci
2060f66f451Sopenharmony_ci  done | sort -s | $SED -n -e 's/ A / /;t pair;h;s/\([^ ]*\).*/\1 " "/;x' \
2070f66f451Sopenharmony_ci    -e 'b single;:pair;h;n;:single;s/[^ ]* B //;H;g;s/\n/ /;p' | \
2080f66f451Sopenharmony_ci    tee generated/flags.raw | generated/mkflags > generated/flags.h || exit 1
2090f66f451Sopenharmony_ci}
2100f66f451Sopenharmony_ci
2110f66f451Sopenharmony_ciif isnewer generated/flags.h toys "$KCONFIG_CONFIG"
2120f66f451Sopenharmony_cithen
2130f66f451Sopenharmony_ci  echo -n "generated/flags.h "
2140f66f451Sopenharmony_ci  make_flagsh
2150f66f451Sopenharmony_cifi
2160f66f451Sopenharmony_ci
2170f66f451Sopenharmony_ci# Extract global structure definitions and flag definitions from toys/*/*.c
2180f66f451Sopenharmony_ci
2190f66f451Sopenharmony_cifunction getglobals()
2200f66f451Sopenharmony_ci{
2210f66f451Sopenharmony_ci  for i in toys/*/*.c
2220f66f451Sopenharmony_ci  do
2230f66f451Sopenharmony_ci    NAME="$(echo $i | $SED 's@.*/\(.*\)\.c@\1@')"
2240f66f451Sopenharmony_ci    DATA="$($SED -n -e '/^GLOBALS(/,/^)/b got;b;:got' \
2250f66f451Sopenharmony_ci            -e 's/^GLOBALS(/struct '"$NAME"'_data {/' \
2260f66f451Sopenharmony_ci            -e 's/^)/};/' -e 'p' $i)"
2270f66f451Sopenharmony_ci
2280f66f451Sopenharmony_ci    [ ! -z "$DATA" ] && echo -e "// $i\n\n$DATA\n"
2290f66f451Sopenharmony_ci  done
2300f66f451Sopenharmony_ci}
2310f66f451Sopenharmony_ci
2320f66f451Sopenharmony_ciif isnewer generated/globals.h toys
2330f66f451Sopenharmony_cithen
2340f66f451Sopenharmony_ci  echo -n "generated/globals.h "
2350f66f451Sopenharmony_ci  GLOBSTRUCT="$(getglobals)"
2360f66f451Sopenharmony_ci  (
2370f66f451Sopenharmony_ci    echo "$GLOBSTRUCT"
2380f66f451Sopenharmony_ci    echo
2390f66f451Sopenharmony_ci    echo "extern union global_union {"
2400f66f451Sopenharmony_ci    echo "$GLOBSTRUCT" | \
2410f66f451Sopenharmony_ci      $SED -n 's/struct \(.*\)_data {/	struct \1_data \1;/p'
2420f66f451Sopenharmony_ci    echo "} this;"
2430f66f451Sopenharmony_ci  ) > generated/globals.h
2440f66f451Sopenharmony_cifi
2450f66f451Sopenharmony_ci
2460f66f451Sopenharmony_ciif [ ! -f generated/mktags ] || [ generated/mktags -ot scripts/mktags.c ]
2470f66f451Sopenharmony_cithen
2480f66f451Sopenharmony_ci  do_loudly $HOSTCC scripts/mktags.c -o generated/mktags || exit 1
2490f66f451Sopenharmony_cifi
2500f66f451Sopenharmony_ci
2510f66f451Sopenharmony_ciif isnewer generated/tags.h toys
2520f66f451Sopenharmony_cithen
2530f66f451Sopenharmony_ci  echo -n "generated/tags.h "
2540f66f451Sopenharmony_ci
2550f66f451Sopenharmony_ci  $SED -n '/TAGGED_ARRAY(/,/^)/{s/.*TAGGED_ARRAY[(]\([^,]*\),/\1/;p}' \
2560f66f451Sopenharmony_ci    toys/*/*.c lib/*.c | generated/mktags > generated/tags.h
2570f66f451Sopenharmony_cifi
2580f66f451Sopenharmony_ci
2590f66f451Sopenharmony_ciif [ ! -f generated/config2help ] || [ generated/config2help -ot scripts/config2help.c ]
2600f66f451Sopenharmony_cithen
2610f66f451Sopenharmony_ci  do_loudly $HOSTCC scripts/config2help.c -o generated/config2help || exit 1
2620f66f451Sopenharmony_cifi
2630f66f451Sopenharmony_ciif isnewer generated/help.h generated/Config.in
2640f66f451Sopenharmony_cithen
2650f66f451Sopenharmony_ci  echo "generated/help.h"
2660f66f451Sopenharmony_ci  generated/config2help Config.in $KCONFIG_CONFIG > generated/help.h || exit 1
2670f66f451Sopenharmony_cifi
2680f66f451Sopenharmony_ci
2690f66f451Sopenharmony_ci[ ! -z "$NOBUILD" ] && exit 0
2700f66f451Sopenharmony_ci
2710f66f451Sopenharmony_ciecho -n "Compile $OUTNAME"
2720f66f451Sopenharmony_ci[ ! -z "$V" ] && echo
2730f66f451Sopenharmony_ciDOTPROG=.
2740f66f451Sopenharmony_ci
2750f66f451Sopenharmony_ci# This is a parallel version of: do_loudly $BUILD $FILES $LINK || exit 1
2760f66f451Sopenharmony_ci
2770f66f451Sopenharmony_ci# Any headers newer than the oldest generated/obj file?
2780f66f451Sopenharmony_ciX="$(ls -1t generated/obj/* 2>/dev/null | tail -n 1)"
2790f66f451Sopenharmony_ci# TODO: redo this
2800f66f451Sopenharmony_ciif [ ! -e "$X" ] || [ ! -z "$(find toys -name "*.h" -newer "$X")" ]
2810f66f451Sopenharmony_cithen
2820f66f451Sopenharmony_ci  rm -rf generated/obj && mkdir -p generated/obj || exit 1
2830f66f451Sopenharmony_cielse
2840f66f451Sopenharmony_ci  rm -f generated/obj/{main,lib_help}.o || exit 1
2850f66f451Sopenharmony_cifi
2860f66f451Sopenharmony_ci
2870f66f451Sopenharmony_ci# build each generated/obj/*.o file in parallel
2880f66f451Sopenharmony_ci
2890f66f451Sopenharmony_ciPENDING=
2900f66f451Sopenharmony_ciLNKFILES=
2910f66f451Sopenharmony_ciDONE=0
2920f66f451Sopenharmony_ciCOUNT=0
2930f66f451Sopenharmony_ciCLICK=
2940f66f451Sopenharmony_ci
2950f66f451Sopenharmony_cifor i in $LIBFILES click $TOYFILES
2960f66f451Sopenharmony_cido
2970f66f451Sopenharmony_ci  [ "$i" == click ] && CLICK=1 && continue
2980f66f451Sopenharmony_ci
2990f66f451Sopenharmony_ci  X=${i/lib\//lib_}
3000f66f451Sopenharmony_ci  X=${X##*/}
3010f66f451Sopenharmony_ci  OUT="generated/obj/${X%%.c}.o"
3020f66f451Sopenharmony_ci  LNKFILES="$LNKFILES $OUT"
3030f66f451Sopenharmony_ci
3040f66f451Sopenharmony_ci  # $LIBFILES doesn't need to be rebuilt if older than .config, $TOYFILES does
3050f66f451Sopenharmony_ci  # ($TOYFILES contents can depend on CONFIG symbols, lib/*.c never should.)
3060f66f451Sopenharmony_ci
3070f66f451Sopenharmony_ci  [ "$OUT" -nt "$i" ] && [ -z "$CLICK" -o "$OUT" -nt "$KCONFIG_CONFIG" ] &&
3080f66f451Sopenharmony_ci    continue
3090f66f451Sopenharmony_ci
3100f66f451Sopenharmony_ci  do_loudly $BUILD -c $i -o $OUT &
3110f66f451Sopenharmony_ci  PENDING="$PENDING $!"
3120f66f451Sopenharmony_ci  COUNT=$(($COUNT+1))
3130f66f451Sopenharmony_ci
3140f66f451Sopenharmony_ci  # ratelimit to $CPUS many parallel jobs, detecting errors
3150f66f451Sopenharmony_ci
3160f66f451Sopenharmony_ci  for j in $PENDING
3170f66f451Sopenharmony_ci  do
3180f66f451Sopenharmony_ci    [ "$COUNT" -lt "$CPUS" ] && break;
3190f66f451Sopenharmony_ci
3200f66f451Sopenharmony_ci    wait $j
3210f66f451Sopenharmony_ci    DONE=$(($DONE+$?))
3220f66f451Sopenharmony_ci    COUNT=$(($COUNT-1))
3230f66f451Sopenharmony_ci    PENDING="${PENDING## $j}"
3240f66f451Sopenharmony_ci  done
3250f66f451Sopenharmony_ci  [ $DONE -ne 0 ] && break
3260f66f451Sopenharmony_cidone
3270f66f451Sopenharmony_ci
3280f66f451Sopenharmony_ci# wait for all background jobs, detecting errors
3290f66f451Sopenharmony_ci
3300f66f451Sopenharmony_cifor i in $PENDING
3310f66f451Sopenharmony_cido
3320f66f451Sopenharmony_ci  wait $i
3330f66f451Sopenharmony_ci  DONE=$(($DONE+$?))
3340f66f451Sopenharmony_cidone
3350f66f451Sopenharmony_ci
3360f66f451Sopenharmony_ci[ $DONE -ne 0 ] && exit 1
3370f66f451Sopenharmony_ci
3380f66f451Sopenharmony_cido_loudly $BUILD $LNKFILES $LINK || exit 1
3390f66f451Sopenharmony_ciif [ ! -z "$NOSTRIP" ] ||
3400f66f451Sopenharmony_ci  ! do_loudly ${CROSS_COMPILE}${STRIP} "$UNSTRIPPED" -o "$OUTNAME"
3410f66f451Sopenharmony_cithen
3420f66f451Sopenharmony_ci  [ -z "$NOSTRIP" ] && echo "strip failed, using unstripped"
3430f66f451Sopenharmony_ci  rm -f "$OUTNAME" &&
3440f66f451Sopenharmony_ci  cp "$UNSTRIPPED" "$OUTNAME" ||
3450f66f451Sopenharmony_ci    exit 1
3460f66f451Sopenharmony_cifi
3470f66f451Sopenharmony_ci
3480f66f451Sopenharmony_ci# gcc 4.4's strip command is buggy, and doesn't set the executable bit on
3490f66f451Sopenharmony_ci# its output the way SUSv4 suggests it do so. While we're at it, make sure
3500f66f451Sopenharmony_ci# we don't have the "w" bit set so things like bzip2's "cp -f" install don't
3510f66f451Sopenharmony_ci# overwrite our binary through the symlink.
3520f66f451Sopenharmony_cido_loudly chmod 555 "$OUTNAME" || exit 1
3530f66f451Sopenharmony_ci
3540f66f451Sopenharmony_ciecho
355