From c0e56edaf256adb6c60c5a052525a1ffbb927901 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 8 Oct 2012 00:02:30 -0500 Subject: New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate. --- scripts/make.sh | 85 +++++++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 45 deletions(-) (limited to 'scripts') diff --git a/scripts/make.sh b/scripts/make.sh index af56e6d1..6c1672e3 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -10,6 +10,33 @@ then exit 1 fi +echo "Make generated/config.h from .config." + +# This long and roundabout sed invocation is to make old versions of sed happy. +# New ones have '\n' so can replace one line with two without all the branches +# and tedious mucking about with hold space. + +sed -n \ + -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \ + -e 't notset' \ + -e 's/^CONFIG_\(.*\)=y.*/\1/' \ + -e 't isset' \ + -e 's/^CONFIG_\([^=]*\)=\(.*\)/#define CFG_\1 \2/p' \ + -e 'd' \ + -e ':notset' \ + -e 'h' \ + -e 's/.*/#define CFG_& 0/p' \ + -e 'g' \ + -e 's/.*/#define USE_&(...)/p' \ + -e 'd' \ + -e ':isset' \ + -e 'h' \ + -e 's/.*/#define CFG_& 1/p' \ + -e 'g' \ + -e 's/.*/#define USE_&(...) __VA_ARGS__/p' \ + .config > generated/config.h || exit 1 + + echo "Extract configuration information from toys/*.c files..." scripts/genconfig.sh @@ -22,47 +49,41 @@ echo "Generate headers from toys/*/*.c..." echo "generated/newtoys.h" -function newtoys() -{ - for i in toys/*/*.c - do - sed -n -e '1,/^config [A-Z]/s/^USE_/&/p' $i || exit 1 - done -} echo "NEWTOY(toybox, NULL, TOYFLAG_STAYROOT)" > generated/newtoys.h -newtoys | sed 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -k 1,1 \ +sed -n -e 's/^USE_[A-Z0-9_]*(/&/p' toys/*/*.c \ + | sed 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -k 1,1 \ | sed 's/[^ ]* //' >> generated/newtoys.h # Extract global structure definitions and flag definitions from toys/*/*.c function getglobals() { + NEWTOYS="$(cat generated/config.h generated/newtoys.h | gcc -E - | sed 's/" *"//g')" for i in toys/*/*.c do NAME="$(echo $i | sed 's@.*/\(.*\)\.c@\1@')" echo -e "// $i\n" - sed -n -e '/^DEFINE_GLOBALS(/,/^)/b got;b;:got' \ - -e 's/^DEFINE_GLOBALS(/struct '"$NAME"'_data {/' \ + sed -n -e '/^GLOBALS(/,/^)/b got;b;:got' \ + -e 's/^GLOBALS(/struct '"$NAME"'_data {/' \ -e 's/^)/};/' -e 'p' $i # And get flag definitions - FLAGS="$(sed -n \ + FLAGS="$(echo "$NEWTOYS" | sed -n \ -e "s/.*TOY($NAME"',[ \t]*"\([^"]*\)"[ \t]*,.*)/\1/' \ - -e 't keep;d;:keep' \ - -e 's/[><=][0-9][0-9]*//g' \ - -e 's/+.//g' \ - -e 's/([^)]*)//g' \ - -e 's/[-?^:&#|@*]//g' \ - -e 'p' \ - generated/newtoys.h)" + -e 't keep;d;:keep' -e 's/^[<>=][0-9]//' -e 's/[?&^]//' \ + -e 't keep' -e 's/[><=][0-9][0-9]*//g' -e 's/+.//g' \ + -e 's/([^)]*)//g' -e 's/[-?^:&#|@*]//g' -e 'p')" + echo "#ifdef FOR_${NAME}" X=0 while [ $X -lt ${#FLAGS} ] do - echo -ne "#define OPTFLAG_${NAME}_${FLAGS:$X:1}\t" + echo -ne "#define FLAG_${FLAGS:$X:1}\t" X=$(($X+1)) echo "(1<<$((${#FLAGS}-$X)))" done + echo "#define TT this.${NAME}" + echo "#endif" done } @@ -85,32 +106,6 @@ then scripts/config2help.py Config.in > generated/help.h || exit 1 fi -echo "Make generated/config.h from .config." - -# This long and roundabout sed invocation is to make old versions of sed happy. -# New ones have '\n' so can replace one line with two without all the branches -# and tedious mucking about with hold space. - -sed -n \ - -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \ - -e 't notset' \ - -e 's/^CONFIG_\(.*\)=y.*/\1/' \ - -e 't isset' \ - -e 's/^CONFIG_\([^=]*\)=\(.*\)/#define CFG_\1 \2/p' \ - -e 'd' \ - -e ':notset' \ - -e 'h' \ - -e 's/.*/#define CFG_& 0/p' \ - -e 'g' \ - -e 's/.*/#define USE_&(...)/p' \ - -e 'd' \ - -e ':isset' \ - -e 'h' \ - -e 's/.*/#define CFG_& 1/p' \ - -e 'g' \ - -e 's/.*/#define USE_&(...) __VA_ARGS__/p' \ - .config > generated/config.h || exit 1 - # Extract a list of toys/*/*.c files to compile from the data in ".config": # 1) Get a list of C files in toys/* and glue them together into a regex we can -- cgit v1.2.3