-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·292 lines (239 loc) · 5.01 KB
/
configure
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/bin/sh
#
# Configure script for 'ksh'
# Copyright (c) 2012-2019 Bertrand Janin <[email protected]>
#
#
VERSION="6.3"
# Some shells have shitty echos
alias echo=/bin/echo
# Attempt tp guess the best CC.
if [ -z "$CC" ]; then
if cc -v 1>/dev/null 2>/dev/null; then
export CC=cc
else
export CC=gcc
fi
fi
# generate_makefile() - Generate the main Makefile
# $1 - file to append at the end
generate_makefile() {
echo "# Automagically generated by 'configure'"
echo
echo "CFLAGS+=$CFLAGS -std=c99 -pedantic"
echo "CFLAGS+=-I."
echo "CFLAGS+=-Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual"
echo "CFLAGS+=-Wstrict-prototypes -Wmissing-prototypes"
echo "CFLAGS+=-Wmissing-declarations -Wnested-externs -Winline"
echo "CFLAGS+=-DVERSION=\\\"$VERSION\\\" $X_CFLAGS"
echo
echo "LDFLAGS+=-lcurses"
echo
if [ "$DEBUG_MODE" = "Y" ]; then
echo "CFLAGS+=-Wall -ggdb -O0"
else
echo "CFLAGS+=-Wall -O2"
fi
if [ -n "$X_OBJECTS" ]; then
echo "EXTRA_OBJECTS=$X_OBJECTS"
fi
echo "CC?=$CC"
echo "PREFIX?=$PREFIX"
echo "MANDIR=$MANDIR"
cat "$1"
}
# usage() - Spit out basic help
usage() {
echo "usage: ./configure [-h] [-d] [platform]"
echo
echo " -h this help screen."
echo " -d configure for debug mode (-ggdb -O1)"
echo
echo "By default, this script will attempt to detect your OS and will guess the most"
echo "appropriate configuration. If it gets your system wrong, you can force it,"
echo "here is the list of ''supported'' platforms:"
echo
echo " bsd - OpenBSD, FreeBSD, OS X, Darwin, ..."
echo " linux - Linux"
exit
}
# not_found() - Exit 'cause we're missing something
not_found() {
message="$1"
echo "not found"
echo
echo ERROR: $message
exit 2
}
# test_compile() - ingest stdin and test compile it
# $1 - what's being tested
# $2 - what's added to X_OBJECTS
# $3 - what's added to CFLAGS
test_compile() {
name=$1
x_object_addition=$2
cflags_addition=$3
echo -n "$name... "
cat > test_compile.c
if ! ${CC} test_compile.c -o /dev/null 1>/dev/null 2>/dev/null; then
echo "not found (we'll use ours)"
if [ -n "$2" ]; then
X_OBJECTS="$X_OBJECTS $x_object_addition"
fi
if [ -n "$3" ]; then
CFLAGS="$CFLAGS $cflags_addition"
fi
else
echo yes
fi
rm -f test_compile*
}
# Command-line arguments
while true; do
case "$1" in
-h|--help)
usage
exit 2
;;
-d|--debug)
echo "Debug mode... enabled"
DEBUG_MODE="Y"
shift
;;
--prefix=*)
PREFIX="${1##--prefix=}"
shift
;;
--mandir=*)
MANDIR="${1##--mandir=}"
shift
;;
# Skip all random long opts passed by packagers thinking this
# is autoconf-compatible.
--*)
shift
;;
*)
break
;;
esac
done
# Detect platform
echo -n "Target platform... "
OS=`uname`
if [ -n "$1" ]; then
OS="$1"
fi
echo $OS
# Platform-specific configuration
case $OS in
Linux|Unix|POSIX)
X_CFLAGS="-D_GNU_SOURCE"
MANDEST="share/man"
;;
*BSD)
;;
Darwin)
MANDEST="share/man"
;;
*)
echo
echo "Sorry but '$OS' is currently unsupported, you can attemp 'bsd' or 'linux' as"
echo "target and cross your fingers. In order to do that you just need to give either"
echo "one as parameter to ./configure. You can get the official list of supported "
echo "platform with ./configure -l"
exit
esac
# Default paths
[ -z "$PREFIX" ] && PREFIX="/usr/local"
[ -z "$MANDEST" ] && MANDEST="man"
[ -z "$MANDIR" ] && MANDIR="${PREFIX}/${MANDEST}"
# Check for make
echo -n "make... "
cat <<EOF > fake_makefile
all:
@echo found
EOF
if ! make -f fake_makefile 1>/dev/null 2>/dev/null; then
not_found "Make not found (try to install make or gmake)"
fi
echo found
rm -f fake_makefile*
test_compile cc <<EOF
main() {
printf("woot\n");
}
EOF
test_compile strlcpy strlcpy.o <<EOF
main() {
char buf[32];
strlcpy(buf, "woot", sizeof(buf));
}
EOF
test_compile strlcat strlcat.o <<EOF
main() {
char buf[32];
strlcat(buf, "woot", sizeof(buf));
}
EOF
test_compile strtonum strtonum.o <<EOF
main() {
const char *errstr;
int i = strtonum("42", 1, 64, &errstr);
}
EOF
test_compile pledge pledge.o <<EOF
main() {
int i = pledge("", "");
}
EOF
test_compile issetugid issetugid.o <<EOF
main() {
int i = issetugid();
}
EOF
test_compile setresgid setresgid.o <<EOF
main() {
int i = setresgid(9999, 9999, 9999);
}
EOF
test_compile setresuid setresuid.o <<EOF
main() {
int i = setresuid(9999, 9999, 9999);
}
EOF
test_compile stravis stravis.o -DHAS_NO_STRAVIS <<EOF
#include <vis.h>
main() {
int i = stravis(NULL, NULL, 0);
}
EOF
test_compile reallocarray reallocarray.o <<EOF
#include <stdlib.h>
main() {
char *c = reallocarray(NULL, 0, 0);
}
EOF
test_compile sys_siglist siglist.o <<EOF
#include <signal.h>
main() {
char *c = sys_siglist[9];
}
EOF
test_compile sys_signame signame.o <<EOF
#include <signal.h>
main() {
char *c = sys_signame[9];
}
EOF
test_compile unvis "vis.o unvis.o" <<EOF
#include <vis.h>
main() {
char c[32];
strunvis(c, "woot");
}
EOF
generate_makefile Makefile.src > Makefile
generate_makefile src/Makefile.src > src/Makefile
echo
echo "Configured for '$OS', run 'make' (or 'gmake') to compile."