From 7a5cb958177d4a1efd96f7b4074307731bfe9c06 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 4 Mar 2022 04:11:01 -0600 Subject: [PATCH] Move UNSTRIPPED to configure, merge LDASNEEDED into LDFLAGS (which comes early enough in the command line now), use shoter : ${NAME:=val} syntax for the if-not-set-then-set variables, have CFLAGS append to inherited instead of if-not-set (it was already doing that for -funsigned-char so we're 8 bit clean, everything else is warnings management and one -Werror for function with no prototype). --- configure | 44 +++++++++++++------------------------------- scripts/make.sh | 6 ++---- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/configure b/configure index 89053d82..368cf216 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #!/bin/bash -# This sets environment variables used by scripts/make.sh +# set environment variables used by scripts/make.sh # People run ./configure out of habit, so do "defconfig" for them. @@ -11,41 +11,23 @@ then exit $? fi -# CFLAGS and OPTIMIZE are different so you can add extra CFLAGS without -# disabling default optimizations -[ -z "$CFLAGS" ] && CFLAGS="-Wall -Wundef -Wno-char-subscripts -Werror=implicit-function-declaration -Wno-pointer-sign -Wno-string-plus-int" -# Required for our expected ABI. we're 8-bit clean thus "char" must be unsigned. -CFLAGS="$CFLAGS -funsigned-char" -[ -z "$OPTIMIZE" ] && OPTIMIZE="-Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-strict-aliasing" +# Warn about stuff, disable stupid warnings, be 8-bit clean for utf8. +CFLAGS="$CFLAGS -Wall -Wundef -Wno-char-subscripts -Werror=implicit-function-declaration -Wno-char-subscripts -Wno-pointer-sign -Wno-string-plus-int -funsigned-char" + +# Set default values if variable not already set +: ${CC:=cc} ${HOSTCC:=cc} ${GENERATED:=generated} ${KCONFIG_CONFIG:=.config} +: ${OUTNAME:=toybox${TARGET:+-$TARGET}} +: ${UNSTRIPPED:=$GENERATED/unstripped/${OUTNAME/*\//}} +: ${OPTIMIZE:=-Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-strict-aliasing} + # set ASAN=1 to enable "address sanitizer" and debuggable backtraces [ -z "$ASAN" ] || { CFLAGS="$CFLAGS -O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address"; NOSTRIP=1; } # We accept LDFLAGS, but by default don't have anything in it if [ "$(uname)" == "Darwin" ] then - [ -z "$LDOPTIMIZE" ] && LDOPTIMIZE="-Wl,-dead_strip" + : ${LDOPTIMIZE:=-Wl,-dead_strip} ${STRIP:=strip} else - [ -z "$LDOPTIMIZE" ] && LDOPTIMIZE="-Wl,--gc-sections" - LDASNEEDED="-Wl,--as-needed" + : ${LDOPTIMIZE:=-Wl,--gc-sections -Wl,--as-needed} ${STRIP:=strip -s -R .note* -R .comment} +# LDASNEEDED="-Wl,--as-needed" # must go at end of compiler command line fi - -# The makefile provides defaults for these, so this only gets used if -# you call scripts/make.sh and friends directly. - -[ -z "$CC" ] && CC=cc - -# Strip harder on Linux. -# Darwin's strip doesn't have equivalents of the binutils -s or -R. -[ -z "$STRIP" ] && STRIP=strip -if [ "$(uname)" != "Darwin" ] -then - [ -z "$STRIP" ] && STRIP="strip -s -R .note* -R .comment" -fi - -# If HOSTCC needs CFLAGS or LDFLAGS, just add them to the variable -# ala HOSTCC="blah-cc --static" -[ -z "$HOSTCC" ] && HOSTCC=cc - -[ -z "$GENERATED" ] && GENERATED=generated -[ -z "$KCONFIG_CONFIG" ] && KCONFIG_CONFIG=.config -[ -z "$OUTNAME" ] && OUTNAME=toybox"${TARGET:+-$TARGET}" diff --git a/scripts/make.sh b/scripts/make.sh index f097717e..291ff80a 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -5,8 +5,6 @@ set -o pipefail source scripts/portability.sh -UNSTRIPPED="generated/unstripped/$(basename "$OUTNAME")" - # Default to running one more parallel cc instance than we have processors : ${CPUS:=$(($(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null)+1))} @@ -89,7 +87,7 @@ then for i in util crypt m resolv selinux smack attr crypto z log iconv tls ssl do echo "int main(int argc, char *argv[]) {return 0;}" | \ - ${CROSS_COMPILE}${CC} $CFLAGS $LDFLAGS -xc - -o generated/libprobe $LDASNEEDED -l$i > /dev/null 2>/dev/null && + ${CROSS_COMPILE}${CC} $CFLAGS $LDFLAGS -xc - -o generated/libprobe -l$i > /dev/null 2>/dev/null && echo -l$i >> generated/optlibs.dat echo -n . done @@ -99,7 +97,7 @@ fi # LINK needs optlibs.dat, above -LINK="$(echo $LDOPTIMIZE $LDFLAGS -o "$UNSTRIPPED" $LDASNEEDED $(cat generated/optlibs.dat))" +LINK="$(echo $LDOPTIMIZE $LDFLAGS -o "$UNSTRIPPED" $(cat generated/optlibs.dat))" genbuildsh > generated/build.sh && chmod +x generated/build.sh || exit 1 #TODO: "make $SED && make" doesn't regenerate config.h because diff .config -- 2.39.2