This commit is contained in:
2025-09-11 21:12:30 -04:00
parent c43284a7d6
commit 6a13171bf1
3 changed files with 55 additions and 41 deletions

68
configure vendored
View File

@@ -7,70 +7,84 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. VAR=VALUE.
CC C compiler command [detected] CC C compiler command [detected]
CFLAGS C compiler flags [-g, ...] CFLAGS C compiler flags [-g, ...]
LDFLAGS C linker flags LDFLAGS C linker flags
--prefix=<path> Set the install path --prefix=<path> Set the install path
--debug Flags for debug build, overides CFLAGS --debug Flags for debug build, overrides CFLAGS
EOF EOF
exit 0 exit 0
} }
echo () { printf "%s\n" "$*" ; } cmdexists() { type "$1" >/dev/null 2>&1 ; }
cmdexists () { type "$1" >/dev/null 2>&1 ; } trycc() { [ -z "$CC" ] && cmdexists "$1" && CC=$1 ; }
trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
prefix=/usr/bin/ prefix=/usr/local
CFLAGS="-std=c23 -O2 -pipe -Wall -Wextra -Wpedantic -Wformat=2 -Wshadow -Wcast-qual -Wcast-align=strict -Wconversion -Wsign-conversion -Wnull-dereference -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wswitch-enum -Wundef -fstack-protector-strong -D_FORTIFY_SOURCE=3 -fPIE -pie -fno-plt -Wl,-z,relro,-z,now" # release flags CFLAGS="-std=c23"
LDFLAGS= LDFLAGS=
CC= CC=
printf "checking for C compiler... " printf "checking for C compiler... "
trycc clang
trycc gcc trycc gcc
trycc clang
trycc cc trycc cc
trycc icx trycc icx
printf "%s\n" "$CC" printf "%s\n" "$CC"
DEBUG=false DEBUG=false
for arg ; do for arg; do
case "$arg" in case "$arg" in
--help|h) usage ;; --help|-h) usage ;;
--prefix=*) prefix=${arg#*=} ;; --prefix=*) prefix=${arg#*=} ;;
--debug=*) DEBUG=true ;; --debug) DEBUG=true ;;
CFLAGS=*) CFLAGS=${arg#*=} ;; CFLAGS=*) CFLAGS=${arg#*=} ;;
LDFLAGS=*) LDFLAGS=${arg#*=} ;; LDFLAGS=*) LDFLAGS=${arg#*=} ;;
CC=*) CC=${arg#*=} ;; CC=*) CC=${arg#*=} ;;
*) prinf "Unrecognized option %s" $arg;; *) printf "Unrecognized option %s\n" "$arg" ;;
esac esac
done done
printf "checking whether C compiler works... " printf "checking whether C compiler works... "
status="fail"
tmpc="$(mktemp -d)/test.c" tmpc="$(mktemp -d)/test.c"
echo "typedef int x;" > "$tmpc" echo "typedef int x;" > "$tmpc"
if output=$($CC $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then if output=$($CC $CFLAGS -c -o /dev/null "$tmpc" 2>&1); then
printf "yes\n" printf "yes\n"
else else
printf "no; %s\n" "$output" printf "no; %s\n" "$output"
exit 1 exit 1
fi fi
if [ -z "$DEBUG" ]; then GDEBUGCFLAGS="-std=c23 -O0 -g3 -Wall -Wextra -Wpedantic -Werror -Wshadow -Wdouble-promotion -Wformat=2 -Wnull-dereference -Wconversion -Wsign-conversion -Wcast-qual -Wcast-align=strict -Wpointer-arith -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wundef -Wunreachable-code -Wswitch-enum -fanalyzer -fsanitize=undefined,address -fstack-protector-strong -D_FORTIFY_SOURCE=3"
CFLAGS="-std=c23 -O0 -g3 -Wall -Wextra -Wpedantic -Werror -Wshadow -Wdouble-promotion -Wformat=2 -Wnull-dereference -Wconversion -Wsign-conversion -Wcast-qual -Wcast-align=strict -Wpointer-arith -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wundef -Wunreachable-code -Wswitch-enum -fanalyzer -fsanitize=undefined,address -fstack-protector-strong -D_FORTIFY_SOURCE=3" CDEBUGCFLAGS="-std=gnu2x -O0 -g3 -Wall -Wextra -Wpedantic -Werror -Wshadow -Wdouble-promotion -Wformat=2 -Wnull-dereference -Wconversion -Wsign-conversion -Wcast-qual -Wcast-align=strict -Wpointer-arith -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wundef -Wunreachable-code -Wswitch-enum -fanalyzer -fsanitize=undefined,address -fstack-protector-strong -D_FORTIFY_SOURCE=3"
fi
case "$OSTYPE" if [ -z "$DEBUG" ]; then
case "cygwin"|"msys") echo "enabling windows specific flags" ; CFLAGS="-v ${CFLAGS}";; case "$CC" in
gcc) CFLAGS="$GDEBUGFLAGS";;
clang) CFLAGS="$CDEBUGFLAGS";;
*) ;; *) ;;
easc easc
else
case "$CC" in
gcc) ;;
clang) ;;
*) ;;
easc
fi
case "$OSTYPE" in
cygwin|msys)
echo "enabling windows specific flags"
CFLAGS="-v $CFLAGS"
;;
esac
printf "creating config.mak... " printf "creating config.mak... "
printf "PREFIX=%s\n" "$prefix" > config.mak {
printf "CFLAGS=%s\n" "$CFLAGS" >> config.mak printf "PREFIX=%s\n" "$prefix"
printf "LDFLAGS=%s\n" "$LDFLAGS" >> config.mak printf "CFLAGS=%s\n" "$CFLAGS"
printf "CC=%s\n" "$CC" >> config.mak printf "LDFLAGS=%s\n" "$LDFLAGS"
printf "CC=%s\n" "$CC"
} > config.mak
printf "done\n" printf "done\n"

View File

@@ -48,7 +48,8 @@ static void usage(int status)
print_option("--make", "Use the GNU make build system (default)"); print_option("--make", "Use the GNU make build system (default)");
print_option("--bare", "Minimal C project structure"); print_option("--bare", "Minimal C project structure");
print_option("--flat", "All files in project root."); print_option("--flat", "All files in project root.");
print_option("--extras=<arg1>,<arg2>", "Extra build options, Pass list to list out options."); print_option("--extras=<arg1>,<arg2>",
"Extra build options, Pass list to list out options.");
puts(" --help display this help text and exit"); puts(" --help display this help text and exit");
puts(" --version output version information and exit"); puts(" --version output version information and exit");
} }

View File

@@ -1,21 +1,20 @@
#!/bin/sh #!/bin/sh
# Usage: ./Cleanup # Usage: ./Cleanup
fatal() { fatal() {
echo "$@" echo "fatal: $*" >&2
echo fail. exit 1
exit 1
} }
if [ ! -d "./tools" ]; then run() {
echo "error: must be run from parent directory" "$@" || fatal "could not run: $*"
exit 1 }
fi
sh ./tools/format || fatal Could not run './tools/format' [ -d "./tools" ] || fatal "must be run from parent directory"
rm -rf .cache || fatal Could not run 'rm -rf .cache'
rm -f compile_commands.json || fatal Could not run 'rm -f compile_commands.json'
make distclean || fatal Could not run 'make dist-clean'
echo done. run sh ./tools/format
run rm -rf .cache
run rm -f compile_commands.json
run make distclean
echo "done."