aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCem Keylan <cem@ckyln.com>2021-07-22 03:23:56 +0300
committerCem Keylan <cem@ckyln.com>2021-07-22 03:23:56 +0300
commitaf32ee39f2576858321483d77699f7d4a5a8bf24 (patch)
tree52a010d225d100caa2075bb18956a37d72dd5a92
parent507ba2bdc6d01c53a72cdee1f8c5c8db0ba1a1aa (diff)
downloadotools-af32ee39f2576858321483d77699f7d4a5a8bf24.tar.gz
add configure script
-rw-r--r--.gitignore1
-rw-r--r--Makefile25
-rw-r--r--config.mk34
-rwxr-xr-xconfigure102
4 files changed, 118 insertions, 44 deletions
diff --git a/.gitignore b/.gitignore
index ac7a71d..17e1976 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@
/pax
/signify
/lib/libc/hash/*hl.c
+config.mk
diff --git a/Makefile b/Makefile
index 9e9d30d..eefdbe2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,11 @@
-include config.mk
+CFLAGS += -Wall -Wno-pointer-sign -Wno-maybe-uninitialized \
+ -Wno-attributes -I${PWD}/includedir \
+ -D 'DEF_WEAK(n)=_Static_assert(1, "")' \
+ -idirafter ${PWD}/include \
+ -idirafter ${PWD}/sys \
+ -idirafter ${PWD}/lib/libutil \
+ -idirafter ${PWD}/lib/libcrypto
+
BIN = \
diff \
doas \
@@ -79,6 +86,11 @@ MAN = \
bin/pax/tar.1 \
usr.bin/signify/signify.1
+MANDOCLIBS = ${LIB}
+GREPLIBS = ${LIB}
+
+include config.mk
+
.y.c:
${YACC} -o $@ $<
.c.o:
@@ -89,13 +101,6 @@ MAN = \
all: ${BIN}
${BINOBJ}: ${LIB}
-MANDOCLIBS = ${LIB}
-GREPLIBS = ${LIB}
-ifeq (${ZLIB}, lib/libz/libz.a)
- MANDOCLIBS += ${ZLIB}
- GREPLIBS += ${ZLIB}
-endif
-
# ------------------------------------------------------------------------------
# diff
DIFFOBJ = \
@@ -152,8 +157,8 @@ GREPOBJ = \
usr.bin/grep/util.o
BINOBJ += ${GREPOBJ}
-grep: ${GREPOBJ} ${LIB}
- ${CC} ${LDFLAGS} -o $@ ${GREPOBJ} ${LIB} -lz
+grep: ${GREPOBJ} ${GREPLIBS}
+ ${CC} ${LDFLAGS} -o $@ ${GREPOBJ} ${LIB} ${ZLIB} ${LIBFTS}
# ------------------------------------------------------------------------------
# m4
diff --git a/config.mk b/config.mk
deleted file mode 100644
index 57b774d..0000000
--- a/config.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-PREFIX = /usr/local
-BINDIR = ${PREFIX}/bin
-MANPREFIX = ${PREFIX}/share/man
-
-AR ?= ar
-CC ?= cc
-RANLIB ?= ranlib
-RM ?= rm -f
-YACC ?= yacc
-
-
-# You can uncomment the latter if you aren't using libtls-bearssl. If you
-# aren't linking statically, '-ltls' should be suffice.
-TLSLIB = `pkgconf --static --libs libtls`
-
-# You can replace the following to 'lib/libz/libz.a' in order to build with the
-# in-source zlib.
-ZLIB = -lz
-
-# If fts is available on your system, we need to disable building it here.
-# Change with 1 if you are using musl-fts, 2 if you are using glibc.
-FTS=0
-
-CFLAGS += -Wall -Wno-pointer-sign -Wno-maybe-uninitialized \
- -Wno-attributes -I${PWD}/includedir \
- -D 'DEF_WEAK(n)=_Static_assert(1, "")' \
- -idirafter ${PWD}/include \
- -idirafter ${PWD}/sys \
- -idirafter ${PWD}/lib/libutil \
- -idirafter ${PWD}/lib/libcrypto
-
-# If you are using a less implementation with tags support, uncomment
-# the following.
-# CFLAGS += -DHAVE_LESS_T
diff --git a/configure b/configure
new file mode 100755
index 0000000..6e879d8
--- /dev/null
+++ b/configure
@@ -0,0 +1,102 @@
+#!/bin/sh -e
+
+trap 'rm -f config.mk' EXIT
+trap 'rm -f config.mk; exit 1' INT
+
+die() {
+ printf '%s: %s\n' "${0##*/}" "$*" >&2
+ exit 1
+}
+
+out() { printf '%s\n' "$@" ;}
+
+prefix=/usr/local
+# We don't want expansion
+# shellcheck disable=2016
+{
+ bindir='$(PREFIX)/bin'
+ manprefix='${PREFIX}/share/man'
+}
+fts=auto
+host=
+
+for arg; do
+ case $arg in
+ --prefix=*) prefix=${arg#*=} ;;
+ --bindir=*) bindir=${arg#*=} ;;
+ --with-fts=*) fts=${arg#*=} ;;
+ --with-system-zlib) zlib=1 ;;
+ -*) die "Unknown flag: '$arg'" ;;
+ *=*) export "$arg";;
+ *) die "Unknown option: '$arg'"
+ esac
+done
+
+: ${CC:=cc}
+
+printf 'checking system type... '
+[ "$host" ] || host=$($CC -dumpmachine 2>/dev/null) || die "Could not determine host"
+out "$host"
+
+printf 'checking for libtls... '
+tlslib=$(pkgconf --static --libs libtls) || die "No tls library found"
+out "$tlslib"
+
+case $host in
+ *linux*) ;;
+ *) die "Unsupported system: $host"
+esac
+
+cat <<EOF >config.mk
+PREFIX = $prefix
+BINDIR = $bindir
+MANPREFIX = $manprefix
+
+AR ?= ${AR:-ar}
+CC ?= ${CC:-cc}
+RANLIB ?= ${RANLIB:-ranlib}
+RM ?= rm -f
+YACC ?= ${YACC:-yacc}
+
+TLSLIB = $tlslib
+EOF
+
+printf 'checking for zlib... '
+if [ "$zlib" = 1 ]; then
+ zlib=$(pkgconf --static --libs zlib)
+ out "$zlib"
+ out "ZLIB = $zlib" >> config.mk
+else
+ zlib=lib/libz/libz.a
+ out "in source"
+ out "ZLIB = $zlib" "MANDOCLIBS += $zlib" "GREPLIBS += $zlib" >>config.mk
+fi
+
+printf 'checking for fts... '
+if [ "$fts" = auto ]; then
+ if out "#include <fts.h>" | $CC -E - >/dev/null 2>&1; then
+ fts=glibc
+ pkgconf --exists musl-fts && fts=musl-fts
+ else
+ fts=none
+ fi
+fi
+
+out "$fts"
+
+case $fts in
+ glibc) out "CFLAGS += -DHAVE_FTS" ;;
+ musl-fts) out "CFLAGS += -DHAVE_FTS" "LIBFTS = -lfts" ;;
+ none) out "LIBOBJ += lib/libc/gen/fts.o"
+esac >>config.mk
+
+printf "Checking if less supports '-T'... "
+if echo | less -T test >/dev/null 2>&1; then
+ out yes
+ out "CFLAGS += -DHAVE_LESS_T" >>config.mk
+else
+ out no
+fi
+
+out "written config.mk" "Run 'make' to compile otools"
+trap - EXIT INT