91 lines
2.2 KiB
Bash
Executable File
91 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $0 [OPTION]... [VAR=VALUE]...
|
|
|
|
To assign environment variables (e.g., CC, CFLAGS...), specify them as
|
|
VAR=VALUE.
|
|
|
|
CC C compiler command [detected]
|
|
CFLAGS C compiler flags [-g, ...]
|
|
LDFLAGS C linker flags
|
|
|
|
--prefix=<path> Set the install path
|
|
--debug Flags for debug build, overrides CFLAGS
|
|
|
|
EOF
|
|
exit 0
|
|
}
|
|
|
|
cmdexists() { type "$1" >/dev/null 2>&1 ; }
|
|
trycc() { [ -z "$CC" ] && cmdexists "$1" && CC=$1 ; }
|
|
|
|
prefix=/usr/local
|
|
CFLAGS="-std=c23"
|
|
LDFLAGS=
|
|
CC=
|
|
|
|
printf "checking for C compiler... "
|
|
trycc gcc
|
|
trycc clang
|
|
trycc cc
|
|
trycc icx
|
|
printf "%s\n" "$CC"
|
|
|
|
DEBUG=false
|
|
for arg; do
|
|
case "$arg" in
|
|
--help|-h) usage ;;
|
|
--prefix=*) prefix=${arg#*=} ;;
|
|
--debug) DEBUG=true ;;
|
|
CFLAGS=*) CFLAGS=${arg#*=} ;;
|
|
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
|
|
CC=*) CC=${arg#*=} ;;
|
|
*) printf "Unrecognized option %s\n" "$arg" ;;
|
|
esac
|
|
done
|
|
|
|
printf "checking whether C compiler works... "
|
|
tmpc="$(mktemp -d)/test.c"
|
|
echo "typedef int x;" > "$tmpc"
|
|
if output=$($CC $CFLAGS -c -o /dev/null "$tmpc" 2>&1); then
|
|
printf "yes\n"
|
|
else
|
|
printf "no; %s\n" "$output"
|
|
exit 1
|
|
fi
|
|
|
|
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"
|
|
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"
|
|
|
|
if [ -z "$DEBUG" ]; then
|
|
case "$CC" in
|
|
gcc) CFLAGS="$GDEBUGFLAGS";;
|
|
clang) CFLAGS="$CDEBUGFLAGS";;
|
|
*) ;;
|
|
esac
|
|
else
|
|
case "$CC" in
|
|
gcc) ;;
|
|
clang) ;;
|
|
*) ;;
|
|
esac
|
|
fi
|
|
|
|
case "$OSTYPE" in
|
|
cygwin|msys)
|
|
echo "enabling windows specific flags"
|
|
CFLAGS="-v $CFLAGS"
|
|
;;
|
|
esac
|
|
|
|
printf "creating config.mak... "
|
|
{
|
|
printf "PREFIX=%s\n" "$prefix"
|
|
printf "CFLAGS=%s\n" "$CFLAGS"
|
|
printf "LDFLAGS=%s\n" "$LDFLAGS"
|
|
printf "CC=%s\n" "$CC"
|
|
} > config.mak
|
|
printf "done\n"
|