From 919273caec8ce997a89630f6f7eabe4f4fe06416 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 15 Mar 2024 17:36:15 -0500 Subject: [PATCH] Simplify and parallelize library probe. --- scripts/make.sh | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/scripts/make.sh b/scripts/make.sh index 21b9d7cb..dd2172fd 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -57,6 +57,19 @@ hostcomp() fi } +# --as-needed removes libraries we don't use any symbols out of, but the +# compiler has no way to ignore a library that doesn't exist, so detect +# and skip nonexistent libraries for it (probing in parallel). +LIBRARIES=$( + [ -z "$V" ] && X=/dev/null || X=/dev/stderr + for i in util crypt m resolv selinux smack attr crypto z log iconv tls ssl + do + do_loudly ${CROSS_COMPILE}${CC} $CFLAGS $LDFLAGS -xc - -l$i >>$X 2>&1 \ + -o /dev/null <<<"int main(int argc,char*argv[]){return 0;}"&& + echo -l$i & + done | sort | xargs +) + # Set/record build environment information compflags() { @@ -67,7 +80,7 @@ compflags() echo '#!/bin/sh' echo echo "VERSION='$VERSION'" - echo "LIBRARIES='$(xargs 2>/dev/null < "$GENDIR/optlibs.dat")'" + echo "LIBRARIES='$LIBRARIES'" echo "BUILD='${CROSS_COMPILE}${CC} $CFLAGS -I . $OPTIMIZE '\"\$VERSION\"" echo "LINK='$LDOPTIMIZE $LDFLAGS '\"\$LIBRARIES\"" echo "PATH='$PATH'" @@ -98,29 +111,6 @@ then echo -e "\n\033[1;31mwarning: using unfinished code from toys/pending\033[0m" fi -# Probe library list if our compiler/linker options changed -if [ ! -e "$GENDIR"/optlibs.dat ] -then - echo -n "Library probe" - - # --as-needed removes libraries we don't use any symbols out of, but the - # compiler has no way to ignore a library that doesn't exist, so detect - # and skip nonexistent libraries for it. - - > "$GENDIR"/optlibs.new - [ -z "$V" ] && X=/dev/null || X=/dev/stderr - for i in util crypt m resolv selinux smack attr crypto z log iconv tls ssl - do - do_loudly ${CROSS_COMPILE}${CC} $CFLAGS $LDFLAGS -xc - -l$i >>$X 2>&1 \ - -o "$UNSTRIPPED"/libprobe <<<"int main(int argc,char*argv[]){return 0;}"&& - do_loudly echo -n ' '-l$i >> "$GENDIR"/optlibs.new - done - unset X - rm -f "$UNSTRIPPED"/libprobe - mv "$GENDIR"/optlibs.{new,dat} || exit 1 - echo -fi - # Write build variables (and set them locally), then append build invocation. compflags > "$GENDIR"/build.sh && source "$GENDIR/build.sh" && echo -e "\$BUILD lib/*.c $TOYFILES \$LINK -o $OUTNAME" >> "$GENDIR"/build.sh&& -- 2.39.2