summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-03-19 02:56:49 +0000
committerAlyssa Ross <hi@alyssa.is>2021-03-21 14:30:45 +0000
commit29b36eebd46d52d3b229993c471fcaa270d0c257 (patch)
treef024a70606ed02017fe8a4e786b0195c059f83a4
parentb1a2b237ca56d941d92c7e1fabc0b3da3e8de10e (diff)
downloaducspi-vsock-29b36eebd46d52d3b229993c471fcaa270d0c257.tar
ucspi-vsock-29b36eebd46d52d3b229993c471fcaa270d0c257.tar.gz
ucspi-vsock-29b36eebd46d52d3b229993c471fcaa270d0c257.tar.bz2
ucspi-vsock-29b36eebd46d52d3b229993c471fcaa270d0c257.tar.lz
ucspi-vsock-29b36eebd46d52d3b229993c471fcaa270d0c257.tar.xz
ucspi-vsock-29b36eebd46d52d3b229993c471fcaa270d0c257.tar.zst
ucspi-vsock-29b36eebd46d52d3b229993c471fcaa270d0c257.zip
configure: create, to generate config.h
This will allow programs to refer to BINDIR to find other ucspi-vsock
programs, which allows programs to be implemented in terms of each
other.

Message-Id: <20210319025648.17925-4-hi@alyssa.is>
Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>
-rw-r--r--.gitignore5
-rw-r--r--Makefile.in (renamed from Makefile)12
-rwxr-xr-xconfigure49
3 files changed, 63 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index a63eff4..89a0408 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
-# SPDX-FileCopyrightText: 2020 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2020-2021 Alyssa Ross <hi@alyssa.is>
 
 *.o
+*.tmp
 vsockclient
 vsockserver
+config.h
+Makefile
diff --git a/Makefile b/Makefile.in
index e05e32f..3260e85 100644
--- a/Makefile
+++ b/Makefile.in
@@ -7,8 +7,8 @@ CFLAGS = -Wall -Wextra -O -g
 INSTALL = install
 INSTALL_PROGRAM = $(INSTALL)
 
-prefix = /usr/local
-bindir = $(prefix)/bin
+prefix = @PREFIX@
+bindir = @BINDIR@
 
 PROGRAMS = vsockclient vsockserver
 
@@ -20,6 +20,10 @@ install: $(PROGRAMS)
 	$(INSTALL_PROGRAM) $(PROGRAMS) $(DESTDIR)$(bindir)
 .PHONY: install
 
+config.h: configure
+	@echo "Error: config.h is outdated.  Please re-run ./configure." >&2
+	@exit 1
+
 vsockclient: vsockclient.o env.o log.o num.o vsock.o
 	$(CC) $(LDFLAGS) -o $@ $@.o env.o log.o num.o vsock.o $(LDLIBS)
 vsockserver: vsockserver.o env.o log.o num.o vsock.o
@@ -31,3 +35,7 @@ vsockserver.o: env.h log.h num.h vsock.h
 clean:
 	rm -f $(PROGRAMS) *.o
 .PHONY: clean
+
+distclean: clean
+	rm -f config.h Makefile *.tmp
+.PHONY: distclean
diff --git a/configure b/configure
new file mode 100755
index 0000000..38c926c
--- /dev/null
+++ b/configure
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+
+set -ue
+
+prefix=/usr/local
+bindir=
+
+unrecognized=
+
+for arg; do
+	if [ "$arg" = "--help" ]; then
+		cat <<EOF
+Usage: $0 [OPTION]..."
+
+Options:
+  -h, --help
+  --prefix=PREFIX         Default: /usr/local
+  --bindir=BINDIR         Default: PREFIX/bin
+EOF
+		exit
+	fi
+done
+
+for arg; do
+	if printf "%s" "$arg" | grep -q "^--prefix="; then
+		prefix="$(printf "%s" "$arg" | cut -d= -f2-)"
+	elif printf "%s" "$arg" | grep -q "^--bindir="; then
+		bindir="$(printf "%s" "$arg" | cut -d= -f2-)"
+	else
+		unrecognized="$unrecognized $arg"
+	fi
+done
+
+bindir="${bindir:-$prefix/bin}"
+
+echo "// Generated by $0${*:+ $*}" > config.h.tmp
+echo "#define PREFIX \"$prefix\"" >> config.h.tmp
+echo "#define BINDIR \"$bindir\"" >> config.h.tmp
+mv config.h.tmp config.h
+
+sed -e "s#@PREFIX@#$prefix#g" -e "s#@BINDIR@#$bindir#g" Makefile.in > Makefile.tmp
+mv Makefile.tmp Makefile
+
+if [ -n "$unrecognized" ]; then
+	echo "Warning: unrecognized options:$unrecognized" >&2
+fi