Experimental new redoconf C/C++ build/autoconfiguration system.

To test it out, try this:
	./do -j10 build
	cd docs/cookbook/c
	redo -j10 test

It should detect all the compilers on your system and make three
separate builds for each one: normal, debug, and optimized.  Then it
tries to run a test program under each one.

If there are windows cross compilers and you also have 'wine'
installed, it'll try running the test program under wine as well.

redoconf currently has no documentation other than the example program.
We'll fix that later.
This commit is contained in:
Avery Pennarun 2019-02-03 01:14:51 -05:00
commit 6dae51f4d2
67 changed files with 1777 additions and 1 deletions

71
redoconf/trycompile Normal file
View file

@ -0,0 +1,71 @@
#!/bin/sh -e
die() {
echo "$0: trycompile: $*" >&2
exit 99
}
ctype=$1
linktype=$2
code=$3
case $ctype in
cc)
[ -n "$CC" ] || die 'must set $CC first.'
useCC="$CC"
useCF="$CFLAGS"
useExt=".c"
;;
cxx)
[ -n "$CXX" ] || die 'must set $CXX first.'
useCC="$CXX"
useCF="$CXXFLAGS"
useExt=".cc"
;;
*)
die "unknown compile type '$ctype'"
;;
esac
case $linktype in
link|run)
[ -n "$LINK" ] || die 'must set $LINK first.'
;;
nolink)
;;
*)
die "unknown link type '$linktype'"
;;
esac
base="try.$$.tmp"
out="$base.o"
out2="$base.exe"
src="$base$useExt"
rm -f "$src" "$out" "$out2"
set -x
: "[trycompile]" "$@"
main=
[ -n "$RCC_NO_MAIN" ] || main="int main() { return 0; }"
printf '%s' "
$code
$main
" >"$src"
NL="
"
IFS="$NL"
set +e
set -f
# We intentionally want to split the variables here,
# splitting on $NL, so we don't quote them.
# 'set -f' prevents interpreting wildcards, which
# we don't want to treat as special.
(
$useCC $CPPFLAGS $useCF -o "$out" -c "$src" || exit
if [ "$linktype" = "link" -o "$linktype" = "run" ]; then
$LINK $LDFLAGS -o "$out2" "$out" $LIBS || exit
fi
if [ "$linktype" = "run" ]; then
$RUN "./$out2" || exit
fi
)
rv=$?
rm -f "$src" "$out" "$out2"
exit "$rv"