Replace handwritten Makefile with configure script

This commit is contained in:
Xavier Del Campo Romero 2023-10-16 01:20:49 +02:00
parent b2be8b4658
commit 6fa38f4d83
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2
4 changed files with 172 additions and 52 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ build/
slcl
*.o
*.d
Makefile

View File

@ -1,51 +0,0 @@
.POSIX:
PREFIX = /usr/local
DST = $(PREFIX)/bin
PROJECT = slcl
O = -Og
CDEFS = -D_FILE_OFFSET_BITS=64 # Required for large file support on 32-bit.
CFLAGS = $(O) $(CDEFS) -g -Wall -Ilibweb/include -Ilibweb/dynstr/include \
-MD -MF $(@:.o=.d)
LIBS = -lcjson -lssl -lm -lcrypto
DEPS = $(OBJECTS:.o=.d)
DYNSTR = libweb/dynstr/libdynstr.a
DYNSTR_FLAGS = -Llibweb/dynstr -ldynstr
LIBWEB = libweb/libslweb.a
SLWEB_FLAGS = -Llibweb -lweb
OBJECTS = \
auth.o \
base64.o \
cftw.o \
hex.o \
jwt.o \
main.o \
page.o \
style.o
all: $(PROJECT)
install: all usergen
mkdir -p $(DST)
cp slcl usergen $(DST)
chmod 0755 $(DST)/slcl
chmod 0755 $(DST)/usergen
+cd doc && $(MAKE) PREFIX=$(PREFIX) install
clean:
rm -f $(OBJECTS) $(DEPS)
+cd libweb && $(MAKE) clean
+cd libweb/dynstr && $(MAKE) clean
FORCE:
$(PROJECT): $(OBJECTS) $(DYNSTR) $(LIBWEB)
$(CC) $(OBJECTS) $(LDFLAGS) $(LIBS) $(SLWEB_FLAGS) $(DYNSTR_FLAGS) -o $@
$(DYNSTR): FORCE
+cd libweb/dynstr && $(MAKE)
$(LIBWEB): FORCE
+cd libweb && $(MAKE)
-include $(DEPS)

View File

@ -74,7 +74,8 @@ sudo apt install cmake xxd jq
Two build environments are provided for `slcl` - feel free to choose any of
them:
- A mostly POSIX-compliant [`Makefile`](Makefile).
- A [`configure`](configure) POSIX shell and mostly POSIX-compliant
[`Makefile`](Makefile).
- A [`CMakeLists.txt`](CMakeLists.txt).
`slcl` can be built using the standard build process:
@ -82,6 +83,7 @@ them:
#### Make
```sh
$ ./configure
$ make
```

168
configure vendored Executable file
View File

@ -0,0 +1,168 @@
#! /bin/sh
set -e
default_prefix=/usr/local
prefix=$default_prefix
default_CC='c99'
# FILE_OFFSET_BITS=64 is required for large file support on 32-bit platforms.
default_CFLAGS='-O1 -g -D_FILE_OFFSET_BITS=64 -Wall -MD -MF $(@:.o=.d)'
default_LDFLAGS="-lcjson -lssl -lm -lcrypto"
CC=${CC:-$default_CC}
CFLAGS=${CFLAGS:-"$default_CFLAGS $default_NPCFLAGS"}
LDFLAGS=${LDFLAGS:-$default_LDFLAGS}
help()
{
cat <<-EOF
$0 [OPTION ...]
--prefix Set installation directory [$default_prefix]
Some influential environment variables:
CC C compiler [$default_CC]
CFLAGS C compiler flags [$default_CFLAGS]
LDFLAGS Link-time flags [$default_LDFLAGS]
EOF
}
while true; do
split_arg=0
if printf "%s" "$1" | grep -e '=' > /dev/null
then
key="$(printf "%s" "$1" | cut -d '=' -f1)"
value="$(printf "%s" "$1" | cut -d '=' -f2)"
split_arg=1
else
key="$1"
value="$2"
fi
case "$key" in
--prefix ) prefix="$value"; shift; test $split_arg -eq 0 && shift ;;
-h | --help ) help; exit 0 ;;
* ) test "$1" != "" && help && exit 1 || break ;;
esac
done
if pkg-config dynstr
then
in_tree_dynstr=0
CFLAGS="$CFLAGS $(pkg-config --cflags dynstr)"
LDFLAGS="$LDFLAGS $(pkg-config --libs dynstr)"
else
echo "Info: dynstr not found. Using in-tree copy" >&2
in_tree_dynstr=1
CFLAGS="$CFLAGS -Ilibweb/dynstr/include"
LDFLAGS="$LDFLAGS -Llibweb/dynstr -ldynstr"
fi
if pkg-config libweb
then
in_tree_libweb=0
CFLAGS="$CFLAGS $(pkg-config --cflags libweb)"
LDFLAGS="$LDFLAGS $(pkg-config --libs libweb)"
else
echo "Info: libweb not found. Using in-tree copy" >&2
in_tree_libweb=1
CFLAGS="$CFLAGS -Ilibweb/include"
LDFLAGS="$LDFLAGS -Llibweb -lweb"
fi
cleanup()
{
rm -f $F
}
F=/tmp/Makefile.slcl
trap cleanup EXIT
cat <<EOF > $F
.POSIX:
CC = $CC
PREFIX = $prefix
DST = $prefix/bin
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
EOF
cat <<"EOF" >> $F
PROJECT = slcl
DEPS = $(OBJECTS:.o=.d)
OBJECTS = \
auth.o \
base64.o \
cftw.o \
hex.o \
jwt.o \
main.o \
page.o \
style.o
all: $(PROJECT)
install: all usergen
mkdir -p $(DST)
cp slcl usergen $(DST)
chmod 0755 $(DST)/slcl
chmod 0755 $(DST)/usergen
+cd doc && $(MAKE) PREFIX=$(PREFIX) install
FORCE:
$(PROJECT): $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
EOF
if [ $in_tree_dynstr -ne 0 ]
then
cat <<"EOF" >> $F
DYNSTR = libweb/dynstr/libdynstr.a
$(PROJECT): $(DYNSTR)
$(DYNSTR): FORCE
+cd libweb/dynstr && $(MAKE) CC=$(CC)
EOF
fi
if [ $in_tree_libweb -ne 0 ]
then
cat <<"EOF" >> $F
LIBWEB = libweb/libslweb.a
$(PROJECT): $(LIBWEB)
$(LIBWEB): FORCE
+cd libweb && $(MAKE) CC=$(CC)
EOF
fi
cat <<"EOF" >> $F
clean:
rm -f $(OBJECTS) $(DEPS)
EOF
if [ $in_tree_dynstr -ne 0 ]
then
cat <<"EOF" >> $F
+cd libweb/dynstr && $(MAKE) clean
EOF
fi
if [ $in_tree_libweb -ne 0 ]
then
cat <<"EOF" >> $F
+cd libweb && $(MAKE) clean
EOF
fi
cat <<"EOF" >> $F
distclean: clean
rm Makefile
EOF
cat <<"EOF" >> $F
-include $(DEPS)
EOF
mv $F Makefile