-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure
executable file
·437 lines (390 loc) · 8.15 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#!/bin/sh
# This configure script written by Brian Callahan <[email protected]>
# and released into the Public Domain.
cccheck() {
if [ ! -z "$CC" ] ; then
cat << EOF > conftest.c
int main(void){return 0;}
EOF
$CC -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
./conftest
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
cc="$CC"
return 0
else
echo "could not build working executables"
echo "Please ensure your C compiler is a native compiler"
exit 1
fi
else
rm -f conftest conftest.c
fi
fi
for compiler in cc clang pcc xlc gcc ; do
cat << EOF > conftest.c
int main(void){return 0;}
EOF
$compiler -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
./conftest
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
cc="$compiler"
return 0
else
echo "could not build working executables"
echo "Please ensure your C compiler is a native compiler"
exit 1
fi
else
rm -f conftest conftest.c
fi
done
return 1
}
deadcheck() {
cat << EOF > conftest.c
#include <stdlib.h>
__dead void usage(void){exit(1);}int main(void){usage();return 0;}
EOF
$cc $tflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
return 0
else
rm -f conftest conftest.c
return 1
fi
}
dead2check() {
cat << EOF > conftest.c
#include <stdlib.h>
__dead2 void usage(void){exit(1);}int main(void){usage();return 0;}
EOF
$cc $tflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
return 0
else
rm -f conftest conftest.c
return 1
fi
}
noreturncheck() {
cat << EOF > conftest.c
#include <stdlib.h>
__attribute__((__noreturn__)) void usage(void){exit(1);}int main(void){usage();return 0;}
EOF
$cc $tflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
return 0
else
rm -f conftest conftest.c
return 1
fi
}
ohashinitcheck() {
cat << EOF > conftest.c
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <ohash.h>
int main(void){ohash_init(NULL, 0, NULL);return 0;}
EOF
$cc $tflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
return 0
else
rm -f conftest conftest.c
return 1
fi
}
pledgecheck() {
cat << EOF > conftest.c
#include <unistd.h>
int main(void){pledge(NULL,NULL);return 0;}
EOF
$cc $tflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
return 0
else
rm -f conftest conftest.c
return 1
fi
}
reallocarraycheck() {
cat << EOF > conftest.c
#include <stdlib.h>
int main(void){reallocarray(NULL, 0, 0);return 0;}
EOF
$cc $tflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
return 0
else
rm -f conftest conftest.c
return 1
fi
}
strlcpycheck() {
cat << EOF > conftest.c
#include <string.h>
int main(void){strlcpy(NULL,NULL,0);return 0;}
EOF
$cc $tflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
return 0
else
rm -f conftest conftest.c
return 1
fi
}
strtonumcheck() {
cat << EOF > conftest.c
#include <stdlib.h>
int main(void){strtonum(NULL, 0, 0, NULL);return 0;}
EOF
$cc $tflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.c
return 0
else
rm -f conftest conftest.c
return 1
fi
}
wflagcheck() {
cat << EOF > conftest.c
int main(void){return 0;}
EOF
$cc -w -o conftest conftest.c > /dev/null 2> conftest.err
grep ':' conftest.err > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.err conftest.c
return 1
else
rm -f conftest conftest.err conftest.c
return 0
fi
}
# Option variables
if [ ! -z "$PREFIX" ] ; then
prefix="$PREFIX"
else
prefix="/usr/local"
fi
bindirset=0
mandirset=0
bindir="$prefix/bin"
mandir="$prefix/share/man"
instprog="om4"
static=0
# Options
for opt
do
case "$opt" in
--prefix=*)
prefix=`echo $opt | cut -d '=' -f 2`
if [ $bindirset -eq 0 ] ; then
bindir="$prefix/bin"
fi
if [ $mandirset -eq 0 ] ; then
mandir="$prefix/share/man"
fi
;;
--bindir=*)
bindir=`echo $opt | cut -d '=' -f 2`
;;
--mandir=*)
mandir=`echo $opt | cut -d '=' -f 2`
;;
--disable-m4|--enable-m4)
if [ "x$opt" = "x--enable-m4" ] ; then
instprog="m4"
else
instprog="om4"
fi
;;
--disable-static|--enable-static)
if [ "x$opt" = "x--enable-static" ] ; then
static=1
else
static=0
fi
;;
--help|-h)
echo "Usage: configure [options]"
echo ""
echo "Options:"
printf " --help or -h "
echo "Display this help message"
printf " --prefix=PREFIX "
echo "Top level install directory is PREFIX [$prefix]"
printf " --mandir=MANDIR "
echo "Manual pages are installed to MANDIR [$mandir]"
printf " --enable-m4 "
echo "Binary name will be m4 [default=$instprog]"
printf " --enable-static "
echo "Statically link executables [default=no]"
exit 1
;;
*)
;;
esac
done
if [ ! -z "$CFLAGS" ] ; then
cflags="$CFLAGS -DEXTENDED -I."
else
cflags="-DEXTENDED -I."
fi
if [ ! -z "$LDFLAGS" ] ; then
ldflags="$LDFLAGS "
else
ldflags=""
fi
if [ $static -ne 0 ] ; then
ldflags="${ldflags}-static"
fi
printf "checking for C compiler... "
cccheck
if [ $? -ne 0 ] ; then
echo "not found"
echo "Please install a C compiler and re-run configure."
exit 1
else
echo "$cc"
fi
printf "checking for -w compiler flag... "
wflagcheck
if [ $? -ne 0 ] ; then
echo "no"
else
cflags="$cflags -w"
echo "yes"
fi
printf "checking for OS... "
os=`uname -s`
echo "$os"
libs="-lm"
case "x$os" in
"xLinux"|"xCYGWIN"*)
cflags="$cflags -D_GNU_SOURCE"
;;
"xOpenBSD")
libs="$libs -lutil"
;;
"xNetBSD")
tflags="-D_OPENBSD_SOURCE"
cflags="$cflags $tflags"
;;
esac
cat << EOF > config.h
/* This file automatically generated by configure. */
EOF
printf "checking for __dead... "
deadcheck
if [ $? -eq 0 ] ; then
echo "yes"
else
echo "no"
printf "checking for __dead2... "
dead2check
if [ $? -eq 0 ] ; then
echo "#define __dead __dead2" >> config.h
echo "yes"
else
echo "no"
printf "checking for __attribute__((__noreturn__))... "
noreturncheck
if [ $? -eq 0 ] ; then
echo "#define __dead __attribute__((__noreturn__))" >> config.h
echo "yes"
else
echo "#define __dead" >> config.h
echo "no"
fi
fi
fi
printf "checking for ohash_init... "
ohashinitcheck
if [ $? -eq 0 ] ; then
echo "#define HAVE_OHASH" >> config.h
echo "yes"
else
echo "no"
fi
printf "checking for pledge... "
pledgecheck
if [ $? -eq 0 ] ; then
echo "#define HAVE_PLEDGE" >> config.h
echo "yes"
else
echo "no"
fi
printf "checking for reallocarray... "
reallocarraycheck
if [ $? -eq 0 ] ; then
echo "#define HAVE_REALLOCARRAY" >> config.h
echo "yes"
else
echo "no"
fi
printf "checking for strlcpy... "
strlcpycheck
if [ $? -eq 0 ] ; then
echo "#define HAVE_STRLCPY" >> config.h
echo "yes"
else
echo "no"
fi
printf "checking for strtonum... "
strtonumcheck
if [ $? -eq 0 ] ; then
echo "#define HAVE_STRTONUM" >> config.h
echo "yes"
else
echo "no"
fi
printf "creating Makefile... "
cat << EOF > Makefile
# This Makefile automatically generated by configure.
CC = $cc
CFLAGS = $cflags
EOF
if [ ! -z "$ldflags" ] ; then
cat << EOF >> Makefile
LDFLAGS = $ldflags
EOF
fi
cat << EOF >> Makefile
PREFIX = $prefix
BINDIR = $bindir
MANDIR = $mandir
PROG = $instprog
OBJS = eval.o expr.o look.o main.o misc.o gnum4.o trace.o tokenizer.o \\
parser.o ohash.o reallocarray.o strlcpy.o strtonum.o
all: \${PROG}
\${PROG}: \${OBJS}
\${CC} \${LDFLAGS} -o \${PROG} \${OBJS} $libs
parser.c parser.h: parser.y
yacc -d parser.y && mv y.tab.c parser.c && mv y.tab.h parser.h
tokenizer.o: parser.h
install:
install -d \${DESTDIR}\${BINDIR}
install -d \${DESTDIR}\${MANDIR}/man1
install -c -s -m 755 \${PROG} \${DESTDIR}\${BINDIR}
install -c -m 644 m4.1 \${DESTDIR}\${MANDIR}/man1/\${PROG}.1
test:
@echo "No tests"
clean:
rm -f \${PROG} \${OBJS} parser.c parser.h
distclean: clean
rm -f Makefile config.h
EOF
echo "done"