aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: 86a4e0b8fae9ee950ae28083c49e3fac87744fe0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh -e

die() {
    printf '%s: %s\n' "${0##*/}" "$*" >&2
    exit 1
}

out() { printf '%s\n' "$@" ;}

usage() {
    out "usage: $0 [options]" \
        "Options:" \
        "  --prefix=dir         Set prefix directory" \
        "  --bindir=dir         Set directory where executables will be installed" \
        "  --manprefix=dir      Set directory where manual pages will be installed" \
        "  --with-netcat=opt    Whether to build netcat [yes,no,auto](default: auto)" \
        "  --with-less-t=opt    Whether to build mandoc with 'less -T' tagfile support" \
        "                                                 [yes,no,auto](default: auto)" \
        "  --with-fts=opt       One of glibc, musl-fts, none, auto (default: auto)" \
        "  --with-system-zlib   Use system zlib"
    exit 1
}

prefix=/usr/local
# We don't want expansion
# shellcheck disable=2016
{
    bindir='$(PREFIX)/bin'
    manprefix='${PREFIX}/share/man'
}
fts=auto
netcat=auto
lesst=auto
host=

for arg; do
    case $arg in
        --help) usage ;;
        --prefix=*) prefix=${arg#*=} ;;
        --bindir=*) bindir=${arg#*=} ;;
        --manprefix=*) manprefix=${arg#*=} ;;
        --with-fts=*) fts=${arg#*=}  ;;
        --with-system-zlib) zlib=1   ;;
        --with-less-t) lesst=yes     ;;
        --without-less-t) lesst=no   ;;
        --with-less-t=*) lesst=${arg#*=} ;;
        --with-netcat) netcat=yes    ;;
        --without-netcat) netcat=no  ;;
        --with-netcat=*) netcat=${arg#*=} ;;
        -*) die "Unknown flag: '$arg'" ;;
        *=*) export "${arg:?}";;
        *) die "Unknown option: '$arg'"
    esac
done

trap 'rm -f config.mk' EXIT
trap 'rm -f config.mk; exit 1' INT

: "${CC:=cc}" "${PKG_CONFIG:=pkg-config}"

printf 'checking system type... '
[ "$host" ] || host=$($CC -dumpmachine 2>/dev/null) || die "Could not determine host"
out "$host"

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}

EOF

case $netcat in
    auto|yes)
        printf 'checking for libtls... '
        if tlslib=$("$PKG_CONFIG" --static --libs libtls 2>/dev/null); then
            out "$tlslib"
            out "TLSLIB = $tlslib" "BIN += nc" >>config.mk
            out "MAN += usr.bin/nc/nc.1" >>config.mk
        else
            out "none"
            [ "$netcat" = yes ] && die "No tls library found"
        fi
esac

printf 'checking for zlib... '
if [ "$zlib" = 1 ]; then
    zlib=$($PKG_CONFIG --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
        $PKG_CONFIG --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

case $lesst in
    auto|yes)
        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
            [ "$lesst" = yes ] && die "less doesn't support '-T' flag"
        fi
esac

out "written config.mk" "Run 'make' to compile otools"
trap - EXIT INT