From bdb8d8a27d5907262fd895897a70c28e843f00d8 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 23 Feb 2019 16:45:08 -0500 Subject: [PATCH] redoconf: better handling of required vs optional detectors. CC.rc was the only "mandatory" detection, which was weird and inconsistent. Instead, make it optional like the others, and have it set a HAVE_CC variable appropriately (and have CXX.rc work the same way). Then, add a default.required.rc.od that checks the HAVE_* for any variable and aborts if it is not available. This allows us to fix confusing behaviour in allconfig.do, which would try every compiler on the system, but redo would print a (non-fatal) error message (and prevent redo-stamp optimization) when CC.rc failed for any non-working compilers. Now CC.rc just politely reports that it didn't find a compiler. Then we change all.rc.od to make CC.rc mandatory. Reported-by: Nathaniel Filardo --- docs/cookbook/c/.gitignore | 1 + docs/cookbook/c/all.rc.od | 2 +- docs/cookbook/c/allconfig.do | 10 +++++++--- docs/cookbook/c/arches.do | 24 +++++++++++++----------- docs/cookbook/c/hello world.list.od | 7 +++---- docs/cookbook/c/sources.do | 12 ++++++++++++ redoconf/rc.sh | 4 ++-- redoconf/rc/CC.rc.od | 5 +++-- redoconf/rc/CXX.rc.od | 2 +- redoconf/rc/default.required.rc.od | 13 +++++++++++++ 10 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 docs/cookbook/c/sources.do create mode 100644 redoconf/rc/default.required.rc.od diff --git a/docs/cookbook/c/.gitignore b/docs/cookbook/c/.gitignore index 0703d8b..210b4a3 100644 --- a/docs/cookbook/c/.gitignore +++ b/docs/cookbook/c/.gitignore @@ -4,3 +4,4 @@ hello /arches /out /out.* +/sources diff --git a/docs/cookbook/c/all.rc.od b/docs/cookbook/c/all.rc.od index 5b050d2..1ff6a57 100644 --- a/docs/cookbook/c/all.rc.od +++ b/docs/cookbook/c/all.rc.od @@ -1,6 +1,6 @@ . ./redoconf.rc rc_include \ - rc/CC.rc \ + rc/CC.required.rc \ rc/CXX.rc \ rc/libqt4.rc \ rc/libgtk2.rc \ diff --git a/docs/cookbook/c/allconfig.do b/docs/cookbook/c/allconfig.do index c659d30..807a1c9 100644 --- a/docs/cookbook/c/allconfig.do +++ b/docs/cookbook/c/allconfig.do @@ -8,9 +8,13 @@ config() { ( cd "$dir" && ../configure --host="$arch" "$@" && - redo-ifchange rc/CC.rc && + ( set --; + . ./redoconf.rc && + rc_include rc/CC.rc && + [ -n "$HAVE_CC" ] + ) && echo "$dir" - ) || : + ) || (echo "Skipping arch '$arch' $*" >&2) } for d in $(cat arches); do @@ -22,6 +26,6 @@ for d in $(cat arches); do config "out.$d" "$arch" & config "out.$d.static" "$arch" "--enable-static" & config "out.$d.opt" "$arch" "--enable-optimization" & -done +done >$3 wait diff --git a/docs/cookbook/c/arches.do b/docs/cookbook/c/arches.do index a779ebb..cb48e0a 100644 --- a/docs/cookbook/c/arches.do +++ b/docs/cookbook/c/arches.do @@ -1,14 +1,16 @@ -IFS=: -echo native >$3 -if [ -z "$NO_SLOW_TESTS" ]; then - for dir in $PATH; do - for d in "$dir"/*-cc "$dir"/*-gcc; do - base=${d##*/} - arch=${base%-*} - if [ -x "$d" ]; then echo "$arch"; fi +( + echo native + echo fake-always-fails + if [ -z "$NO_SLOW_TESTS" ]; then + IFS=: + for dir in $PATH; do + for d in "$dir"/*-cc "$dir"/*-gcc; do + base=${d##*/} + arch=${base%-*} + if [ -x "$d" ]; then echo "$arch"; fi + done done - done >>$3 -fi - + fi +) >$3 redo-always redo-stamp <$3 diff --git a/docs/cookbook/c/hello world.list.od b/docs/cookbook/c/hello world.list.od index d9f5200..cb5548b 100644 --- a/docs/cookbook/c/hello world.list.od +++ b/docs/cookbook/c/hello world.list.od @@ -1,8 +1,8 @@ -# This script is run from the output dir, -# which contains a src/ symlink to the source dir. - +# This script is run from the output dir. +# The source dir is at $S. . ./redoconf.rc rc_include all.rc +redo-ifchange "$S/sources" ( cd "$S" @@ -26,5 +26,4 @@ rc_include all.rc printf '%s\n' "$LIBGTK2" "$LIBQT4" ) >$3 -redo-always redo-stamp <$3 diff --git a/docs/cookbook/c/sources.do b/docs/cookbook/c/sources.do new file mode 100644 index 0000000..81559c6 --- /dev/null +++ b/docs/cookbook/c/sources.do @@ -0,0 +1,12 @@ +# This file changes when the list of source files changes. +# If you depend on it, you can make a target that gets +# rebuilt only when it might need to reconsider the +# list of available source files. +find . -name '*.[ch]' -o \ + -name '*.cc' -o \ + -name '*.od' -o \ + -name '*.list' | +grep -v '^\./out\.' | +sort >$3 +redo-always +redo-stamp <$3 diff --git a/redoconf/rc.sh b/redoconf/rc.sh index a5a3cd6..bc2fa4d 100644 --- a/redoconf/rc.sh +++ b/redoconf/rc.sh @@ -13,10 +13,10 @@ redo-ifchange "$REDOCONF/rc.sh" "$REDOCONF/utils.sh" _rc_exit_check() { if [ -z "$RC_INCLUDE_RAN" ]; then echo "Fatal: used redoconf/rc.sh but didn't call rc_include." >&2 - exit 99 + exit 91 elif [ -n "$RC_QUEUE" ]; then echo "Fatal: must call rc_save or rc_undo before ending." >&2 - exit 99 + exit 92 fi } trap _rc_exit_check EXIT diff --git a/redoconf/rc/CC.rc.od b/redoconf/rc/CC.rc.od index 505ee6e..03605cd 100644 --- a/redoconf/rc/CC.rc.od +++ b/redoconf/rc/CC.rc.od @@ -57,7 +57,7 @@ for d in "$@"; do x="${x#-}" [ -n "$x" ] && x="$x-" rc_replaceln ARCH "$x" - + rc_replaceln HAVE_CC 1 rc_save exit 0 fi @@ -65,4 +65,5 @@ done echo "Can't find a working C compiler." >&2 rc_undo -exit 1 +rc_replaceln CC "" +rc_save diff --git a/redoconf/rc/CXX.rc.od b/redoconf/rc/CXX.rc.od index 4859244..c6875c9 100644 --- a/redoconf/rc/CXX.rc.od +++ b/redoconf/rc/CXX.rc.od @@ -23,6 +23,7 @@ for d in "$@"; do # it to include -lstdc++, etc. # A future .rc could override this again. rc_replaceln LINK "$d" + rc_replaceln HAVE_CXX 1 rc_save exit 0 fi @@ -32,4 +33,3 @@ echo "Warning: Can't find a working C++ compiler." >&2 rc_undo rc_replaceln CXX "" rc_save -exit 0 diff --git a/redoconf/rc/default.required.rc.od b/redoconf/rc/default.required.rc.od new file mode 100644 index 0000000..157aee8 --- /dev/null +++ b/redoconf/rc/default.required.rc.od @@ -0,0 +1,13 @@ +. ./redoconf.rc + +base=${1%.required.rc} +name=${base#*/} +NAME=$(echo "$name" | tr 'a-z.' 'A-Z_') + +rc_include "$base.rc" + +eval v="\$$NAME" +if [ -z "$v" ]; then + echo "$NAME is required in order to build." >&2 + exit 1 +fi