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. --- This is how the new vsockserver program will know where to find vsockserver-socketbinder and vsockserverd. .gitignore | 5 ++++- Makefile => Makefile.in | 12 ++++++++-- configure | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) rename Makefile => Makefile.in (78%) create mode 100755 configure 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 similarity index 78% rename from Makefile rename to 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 -- 2.30.0