configure: add -w and -W flags for selecting libraries to support

-wreadline will build in support for libreadline, for example
This commit is contained in:
Jeremy Baxter 2024-02-27 18:04:18 +13:00
parent b41bec792a
commit e86912a601
3 changed files with 46 additions and 6 deletions

View file

@ -6,7 +6,7 @@ LUADIR = external/lua
CC = ${_CC} CC = ${_CC}
CFLAGS = ${_CFLAGS} -I${LUADIR} -pedantic -Wall -Wextra CFLAGS = ${_CFLAGS} -I${LUADIR} -pedantic -Wall -Wextra
CPPFLAGS = -D_DEFAULT_SOURCE CPPFLAGS = -D_DEFAULT_SOURCE ${_CPPFLAGS}
LDFLAGS = ${_LDFLAGS} LDFLAGS = ${_LDFLAGS}
OBJS = callisto.o lcl.o lenviron.o lextra.o lfs.o ljson.o \ OBJS = callisto.o lcl.o lenviron.o lextra.o lfs.o ljson.o \

View file

@ -46,8 +46,9 @@ This means that the same binary will likely work across different Linux
distributions/versions. The only strictly required library is libc distributions/versions. The only strictly required library is libc
which is available on all systems. which is available on all systems.
*libreadline support is automatically enabled by the configure script *libreadline support can be enabled at build time, but is disabled by
if the system supports it. Otherwise support for it is turned off. default. To force building with libreadline support, pass the
`-wreadline` flag to the configure script.
## Installation ## Installation

45
configure vendored
View file

@ -9,6 +9,10 @@ mkf=config.mk
cflags='-std=c99' cflags='-std=c99'
cppflags='-DLUA_USE_POSIX' cppflags='-DLUA_USE_POSIX'
ldflags='-lm' ldflags='-lm'
# optional libraries to build with support for; a dynamically
# linked Lua 5.4 library may be supported here later
optlibs='readline'
withlibs=''
# #
## utility functions ## utility functions
@ -94,7 +98,10 @@ gen_CFLAGS () {
cflags="$cflags -O0 -g" cflags="$cflags -O0 -g"
fi fi
for flag in $cflags; do if inlist readline "$withlibs"; then
cppflags="$cppflags -DLUA_USE_READLINE"
fi
for flag in $cflags $cppflags; do for flag in $cflags $cppflags; do
using "$flag" using "$flag"
done done
@ -105,7 +112,7 @@ gen_CFLAGS () {
## flags used in the linking step ## flags used in the linking step
gen_LDFLAGS () { gen_LDFLAGS () {
if pkg-config readline; then if inlist readline "$withlibs"; then
ldflags="$ldflags $(pkg-config --libs readline)" ldflags="$ldflags $(pkg-config --libs readline)"
fi fi
if present ld.lld; then if present ld.lld; then
@ -122,11 +129,22 @@ gen_LDFLAGS () {
ldflags="$(trim "$ldflags")" ldflags="$(trim "$ldflags")"
} }
#
## misc. functions
#
assertvalidlib () {
if ! inlist "$OPTARG" "$optlibs"; then
throw "invalid library '$OPTARG'; supported libraries are:
$optlibs"
fi
}
# #
## command line interface ## command line interface
# #
while getopts c:dhr ch; do while getopts c:dhrw:W: ch; do
case "$ch" in case "$ch" in
c) cc="$OPTARG" ;; c) cc="$OPTARG" ;;
d) debug=1 ;; d) debug=1 ;;
@ -140,9 +158,30 @@ options:
-d: build in debug mode, with debug symbols enabled -d: build in debug mode, with debug symbols enabled
-r: build in release mode with optimisation flags enabled (default) -r: build in release mode with optimisation flags enabled (default)
-h: show this help message -h: show this help message
-wname: build with support for the given library; see the list below
-Wname: build without support for the given library
If a -w or -W option is supplied on the command line, then the
argument is checked against the following list of libraries:
EOF EOF
for lib in $optlibs; do
printf ' - %s\n' "$lib"
done
exit 0 exit 0
;; ;;
w)
assertvalidlib
if ! inlist "$OPTARG" "$withlibs"; then
withlibs="$withlibs $OPTARG"
fi
;;
W)
assertvalidlib
if inlist "$OPTARG" "$withlibs"; then
withlibs="$(removefrom "$OPTARG" "$withlibs")"
fi
;;
?) exit 1 ;; ?) exit 1 ;;
:) exit 1 ;; :) exit 1 ;;
esac esac