commit: e75d5c3fa5bd7751aa727e612744c0bb678ccd3b
parent: 4fc32512e9dccc5275c2656b2b441639950d0d33
author: Brian Callahan <bcallah@openbsd.org>
date: Mon, 21 Feb 2022 14:42:31 -0500
Support out-of-tree builds.
2 files changed, 25 insertions(+)
diff --git a/README.md b/README.md
@@ -89,6 +89,13 @@ $ ./configure
$ make && sudo make install
```
+Out-of-tree builds
+------------------
+The `configure` script will detect out-of-tree builds if you prefer to
+build out-of-tree. In order for this to work, the `VPATH` make extension
+is used. While not POSIX, `VPATH` is known to work with BSD make and GNU
+make. In-tree builds create a fully POSIX `Makefile`.
+
Cross compiling
---------------
Cross compiling can be achieved by running `configure` as follows:
diff --git a/configure b/configure
@@ -24,6 +24,13 @@ LDFLAGS = $ldflags
EOF
fi
+if [ ! -z "$vpath" ] ; then
+cat << EOF >> Makefile
+
+VPATH = $vpath
+EOF
+fi
+
cat << EOF >> Makefile
PREFIX = $prefix
@@ -1359,6 +1366,17 @@ else
echo "no"
fi
+printf "checking for out-of-tree build... "
+if [ "x$(dirname $0)" = "x." ] ; then
+ echo "no"
+elif [ "x$(dirname $0)" = "x$(pwd)" ] ; then
+ echo "no"
+else
+ echo "yes"
+ vpath="$(dirname $0)"
+ cflags="$cflags -I$(pwd)"
+fi
+
printf "creating Makefile... "
Makefile
echo "done"