aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-02-12 17:58:06 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2026-02-13 07:54:07 +0100
commit62ee3ef1ca13872e1f9b07f6e4e53cea8b684d72 (patch)
treed0c6844356820c3716a24e76ee3912d8e6ec1cf9
parent438fe10b069b355407cd42b244de5deb695f2338 (diff)
downloadlibweb-62ee3ef1ca13872e1f9b07f6e4e53cea8b684d72.tar.gz
Replace Makefile with configure script
Since libweb depends on dynstr, this dependency can be already available on the system, and therefore the CFLAGS and LDFLAGS should be updated according to pkg-config(1), rather than hardcoding them to the source tree.
-rw-r--r--.gitignore1
-rw-r--r--Makefile73
-rw-r--r--README.md23
-rwxr-xr-xconfigure178
4 files changed, 199 insertions, 76 deletions
diff --git a/.gitignore b/.gitignore
index a9aba1d..b8e0d43 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ examples/headers/headers
examples/hello/hello
examples/html/html
examples/put/put
+/Makefile
diff --git a/Makefile b/Makefile
deleted file mode 100644
index af79de3..0000000
--- a/Makefile
+++ /dev/null
@@ -1,73 +0,0 @@
-.POSIX:
-
-PROJECT = libweb
-PROJECT_A = $(PROJECT).a
-MAJOR_VERSION = 0
-MINOR_VERSION = 1
-PATCH_VERSION = 0
-VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
-PROJECT_SO = $(PROJECT).so.$(VERSION)
-PROJECT_SO_FQ = $(PROJECT).so.$(MAJOR_VERSION)
-PROJECT_SO_NV = $(PROJECT).so
-prefix = /usr/local
-exec_prefix = $(prefix)
-includedir = $(prefix)/include
-datarootdir = $(prefix)/share
-mandir = $(datarootdir)/man
-libdir = $(exec_prefix)/lib
-pkgcfgdir = $(libdir)/pkgconfig
-O = -O1
-CDEFS = -D_FILE_OFFSET_BITS=64 # Required for large file support on 32-bit.
-CFLAGS = $(O) $(CDEFS) -g -Iinclude -Idynstr/include -fPIC -MD -MF $(@:.o=.d)
-LDFLAGS = -shared
-DEPS = $(OBJECTS:.o=.d)
-OBJECTS = \
- form.o \
- handler.o \
- html.o \
- http.o \
- server.o \
- wildcard_cmp.o
-
-all: $(PROJECT_A) $(PROJECT_SO)
-
-install: all $(pkgcfgdir)/libweb.pc
- mkdir -p $(DESTDIR)$(includedir)
- cp -R include/libweb $(DESTDIR)$(includedir)
- chmod 0644 $(DESTDIR)$(includedir)/libweb/*.h
- mkdir -p $(DESTDIR)$(libdir)
- cp $(PROJECT_A) $(PROJECT_SO) $(DESTDIR)$(libdir)
- chmod 0755 $(libdir)/$(PROJECT_A) $(DESTDIR)$(libdir)/$(PROJECT_SO)
- ln -fs $(libdir)/$(PROJECT_SO) $(DESTDIR)$(libdir)/$(PROJECT_SO_FQ)
- ln -fs $(libdir)/$(PROJECT_SO) $(DESTDIR)$(libdir)/$(PROJECT_SO_NV)
- +cd doc && $(MAKE) install \
- DESTDIR=$(DESTDIR) \
- prefix=$(prefix) \
- datarootdir=$(datarootdir) \
- mandir=$(mandir)
-
-clean:
- rm -f $(OBJECTS) $(DEPS)
- +cd examples && $(MAKE) clean
-
-distclean: clean
- rm -f $(PROJECT_A) $(PROJECT_SO)
- +cd examples && $(MAKE) distclean
-
-FORCE:
-
-examples: FORCE
- +cd examples && $(MAKE)
-
-$(PROJECT_A): $(OBJECTS)
- $(AR) $(ARFLAGS) $@ $(OBJECTS)
-
-$(PROJECT_SO): $(OBJECTS)
- $(CC) $(LDFLAGS) $(OBJECTS) -o $@
-
-$(pkgcfgdir)/libweb.pc: libweb.pc
- mkdir -p $(pkgcfgdir)
- sed -e 's,/usr/local,$(prefix),' $< > $@
- chmod 0644 $@
-
--include $(DEPS)
diff --git a/README.md b/README.md
index d522bcf..a57fe0d 100644
--- a/README.md
+++ b/README.md
@@ -76,14 +76,23 @@ apk add cmake
Two build environments are provided for `libweb` - 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).
`libweb` can be built using the standard build process:
#### Make
+First, generate the `Makefile` via the `configure` script:
+
```sh
+$ ./configure
+```
+
+Then:
+
+```
$ make
```
@@ -93,12 +102,20 @@ the use of recursive `make`. For example, assuming `libweb` is contained on a
subdirectory:
```make
-libweb/libweb.a:
+libweb/Makefile:
+ cd libweb && ./configure
+libweb/libweb.a: libweb/Makefile
+cd libweb && $(MAKE)
```
Additionally, `libweb` can be installed using the `install` target. A
-custom prefix can be assigned via the `PREFIX` variable:
+custom prefix can be assigned via the `configure` script:
+
+```sh
+$ ./configure --prefix=$HOME/libweb-prefix
+```
+
+Or, directly from the generated `Makefile`:
```sh
$ make PREFIX=$HOME/libweb-prefix install
diff --git a/configure b/configure
new file mode 100755
index 0000000..4d055f9
--- /dev/null
+++ b/configure
@@ -0,0 +1,178 @@
+#! /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 -D_FILE_OFFSET_BITS=64 -MD -Iinclude -fPIC'
+default_LDFLAGS="-shared"
+
+CC=${CC:-$default_CC}
+
+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
+ proj_CFLAGS="$(pkg-config --cflags dynstr) $proj_CFLAGS"
+ proj_LDFLAGS="$(pkg-config --libs dynstr) $proj_LDFLAGS"
+else
+ echo "Info: dynstr not found. Using in-tree copy" >&2
+ in_tree_dynstr=1
+ proj_CFLAGS="-Idynstr/include $proj_CFLAGS"
+ proj_LDFLAGS="-Ldynstr -ldynstr $proj_LDFLAGS"
+fi
+
+proj_CFLAGS="$proj_CFLAGS $default_CFLAGS $CFLAGS"
+proj_LDFLAGS="$proj_LDFLAGS $default_LDFLAGS $LDFLAGS"
+
+cleanup()
+{
+ rm -f $F
+}
+
+F=/tmp/Makefile.libweb
+trap cleanup EXIT
+
+cat <<EOF > $F
+.POSIX:
+
+CC = ${CC}
+CFLAGS = $CFLAGS
+PROJ_CFLAGS = $proj_CFLAGS
+PROJ_LDFLAGS = $proj_LDFLAGS
+prefix = $prefix
+EOF
+
+cat <<"EOF" >> $F
+PROJECT = libweb
+PROJECT_A = $(PROJECT).a
+MAJOR_VERSION = 0
+MINOR_VERSION = 1
+PATCH_VERSION = 0
+VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
+PROJECT_SO = $(PROJECT).so.$(VERSION)
+PROJECT_SO_FQ = $(PROJECT).so.$(MAJOR_VERSION)
+PROJECT_SO_NV = $(PROJECT).so
+exec_prefix = $(prefix)
+includedir = $(prefix)/include
+datarootdir = $(prefix)/share
+mandir = $(datarootdir)/man
+libdir = $(exec_prefix)/lib
+pkgcfgdir = $(libdir)/pkgconfig
+O = -O1
+DEPS = $(OBJECTS:.o=.d)
+OBJECTS = \
+ form.o \
+ handler.o \
+ html.o \
+ http.o \
+ server.o \
+ wildcard_cmp.o
+
+all: $(PROJECT_A) $(PROJECT_SO)
+
+install: all $(pkgcfgdir)/libweb.pc
+ mkdir -p $(DESTDIR)$(includedir)
+ cp -R include/libweb $(DESTDIR)$(includedir)
+ chmod 0644 $(DESTDIR)$(includedir)/libweb/*.h
+ mkdir -p $(DESTDIR)$(libdir)
+ cp $(PROJECT_A) $(PROJECT_SO) $(DESTDIR)$(libdir)
+ chmod 0755 $(libdir)/$(PROJECT_A) $(DESTDIR)$(libdir)/$(PROJECT_SO)
+ ln -fs $(libdir)/$(PROJECT_SO) $(DESTDIR)$(libdir)/$(PROJECT_SO_FQ)
+ ln -fs $(libdir)/$(PROJECT_SO) $(DESTDIR)$(libdir)/$(PROJECT_SO_NV)
+ +cd doc && $(MAKE) install \
+ DESTDIR=$(DESTDIR) \
+ prefix=$(prefix) \
+ datarootdir=$(datarootdir) \
+ mandir=$(mandir)
+
+FORCE:
+
+.c.o:
+ $(CC) $(PROJ_CFLAGS) -c $< -o $@
+
+examples: FORCE
+ +cd examples && $(MAKE)
+
+$(PROJECT_A): $(OBJECTS)
+ $(AR) $(ARFLAGS) $@ $(OBJECTS)
+
+$(PROJECT_SO): $(OBJECTS)
+ $(CC) $(PROJ_LDFLAGS) $(OBJECTS) -o $@
+
+$(pkgcfgdir)/libweb.pc: libweb.pc
+ mkdir -p $(pkgcfgdir)
+ sed -e 's,/usr/local,$(prefix),' $< > $@
+ chmod 0644 $@
+EOF
+
+if [ $in_tree_dynstr -ne 0 ]
+then
+cat <<"EOF" >> $F
+DYNSTR = dynstr/libdynstr.a
+$(PROJECT): $(DYNSTR)
+$(DYNSTR): FORCE
+ +cd dynstr && $(MAKE) CC=$(CC)
+EOF
+fi
+
+cat <<"EOF" >> $F
+clean:
+ rm -f $(OBJECTS) $(DEPS)
+ +cd examples && $(MAKE) clean
+EOF
+
+if [ $in_tree_dynstr -ne 0 ]
+then
+cat <<"EOF" >> $F
+ +cd dynstr && $(MAKE) clean
+EOF
+fi
+
+cat <<"EOF" >> $F
+distclean: clean
+ rm -f $(PROJECT_A) $(PROJECT_SO)
+ +cd examples && $(MAKE) distclean
+ rm Makefile
+EOF
+
+cat <<"EOF" >> $F
+-include $(DEPS)
+EOF
+
+mv $F Makefile