aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-10-16 01:20:49 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-10-25 22:13:23 +0200
commit6fa38f4d83dfd67bba9ef49bb2d1ece3a57e95d1 (patch)
tree6bc81a482538a9dea82ae6f60432fffb0ad1c9ff
parentb2be8b4658deea570b2a1890b6b45a7b2e95b615 (diff)
downloadslcl-6fa38f4d83dfd67bba9ef49bb2d1ece3a57e95d1.tar.gz
Replace handwritten Makefile with configure script
-rw-r--r--.gitignore1
-rw-r--r--Makefile51
-rw-r--r--README.md4
-rwxr-xr-xconfigure168
4 files changed, 172 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore
index 339e89f..65f85dd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ build/
slcl
*.o
*.d
+Makefile
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 68e56b6..0000000
--- a/Makefile
+++ /dev/null
@@ -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)
diff --git a/README.md b/README.md
index 134ec6f..d2d8e0a 100644
--- a/README.md
+++ b/README.md
@@ -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
```
diff --git a/configure b/configure
new file mode 100755
index 0000000..886360f
--- /dev/null
+++ b/configure
@@ -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