switch to modular configure-based buildsystem

This commit is contained in:
Jeremy Baxter 2024-01-25 21:12:12 +13:00
parent b5d61a25cb
commit 751fca09e1
4 changed files with 119 additions and 8 deletions

1
.gitignore vendored
View file

@ -6,4 +6,5 @@ luac
*.o *.o
*.so *.so
config.mk
include/ include/

View file

@ -1,14 +1,11 @@
include config.mk
PREFIX = /usr/local PREFIX = /usr/local
MANPREFIX = ${PREFIX}/man MANPREFIX = ${PREFIX}/man
CC = cc CC = ${_CC}
CFLAGS = -std=c99 -pedantic -fpic -O2 -Iexternal/lua -Wall -Wextra CFLAGS = -std=c99 ${_CFLAGS} -pedantic -Iexternal/lua -Wall -Wextra -D_DEFAULT_SOURCE
CPPFLAGS = -D_DEFAULT_SOURCE LDFLAGS = -lm ${_LDFLAGS}
LDFLAGS = -lm
# Enable readline
#CPPFLAGS += -DLUA_USE_READLINE
#LDFLAGS += -lreadline
OBJS = callisto.o lcl.o lenviron.o lextra.o lfs.o ljson.o lprocess.o util.o OBJS = callisto.o lcl.o lenviron.o lextra.o lfs.o ljson.o lprocess.o util.o
LIBS = libcallisto.a liblua.a LIBS = libcallisto.a liblua.a

View file

@ -59,6 +59,7 @@ Untar it then enter the directory with Callisto's source code.
After that, run After that, run
./configure
make make
to compile Callisto and all its dependencies. to compile Callisto and all its dependencies.

112
configure vendored Executable file
View file

@ -0,0 +1,112 @@
#!/usr/bin/env sh
# simple and flexible configure script for people who don't like to waste time
# licensed to the public domain
set -e
mkf=config.mk
# utility functions
present () {
command -v "$1" 1>/dev/null 2>/dev/null
}
using () {
printf "using $1\n"
}
error () {
>&2 printf "$(basename $0): $1\n"
exit 1
}
# generators
## C compiler
gen_CC () {
if ! [ -z "$cc" ]; then
using "$cc"
return 0
fi
if present clang; then
cc=clang
elif present cc; then
cc=cc
elif present gcc; then
cc=gcc
else
error "C compiler not found, please acquire a copy of LLVM Clang or the GNU C compiler"
fi
using "$cc"
}
## flags used in the compilation step
gen_CFLAGS () {
if [ -z "$debug" ]; then
cflags="-O2"
else
cflags="-O0 -g"
fi
for flag in $cflags; do
using "$flag"
done
}
## flags used in the linking step
gen_LDFLAGS () {
if pkg-config readline; then
ldflags="$(pkg-config --libs readline)"
fi
if present ld.lld; then
ldflags="$ldflags -fuse-ld=lld"
elif present ld.gold; then
ldflags="$ldflags -fuse-ld=gold"
fi
[ -z "$debug" ] && ldflags="$ldflags -Wl,--gc-sections"
for flag in $ldflags; do
using "$flag"
done
}
# command line interface
while getopts c:dhr ch; do
case "$ch" in
c) cc="$OPTARG" ;;
d) debug=1 ;;
r) unset debug ;;
h)
cat <<EOF
configure: create an optimised makefile for the current environment
options:
-c: force use of a particular compiler
-d: build in debug mode, with debug symbols enabled
-r: build in release mode with optimisation flags enabled (default)
-h: show this help message
EOF
exit 0
;;
?) exit 1 ;;
:) exit 1 ;;
esac
done
# creating the makefile
gen_CC
gen_CFLAGS
gen_LDFLAGS
printf '# generated by configure
_CC = %s
_CFLAGS = %s
_LDFLAGS =%s
' \
"$cc" \
"$cflags" \
"$ldflags"\
>"$mkf"