-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure
executable file
·415 lines (363 loc) · 7.75 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
#!/bin/sh
# This configure script written by Brian Callahan <bcallah@openbsd.org>
# and released into the Public Domain.
cccheck() {
if [ ! -z "$CC" ] ; then
cat << EOF > conftest.c
int main(void){return 0;}
EOF
$CC $cflags $ldflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
./conftest
if [ $? -eq 0 ] ; then
rm -f conftest conftest.o conftest.c
cc="$CC"
return 0
fi
else
rm -f conftest conftest.o conftest.c
fi
fi
for compiler in cc clang pcc xlc cparser gcc ; do
cat << EOF > conftest.c
int main(void){return 0;}
EOF
$compiler $cflags $ldflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
./conftest
if [ $? -eq 0 ] ; then
rm -f conftest conftest.o conftest.c
cc="$compiler"
return 0
else
rm -f conftest conftest.o conftest.c
echo "could not build working executables"
echo "Please ensure your C compiler is a native compiler"
exit 1
fi
else
rm -f conftest conftest.o conftest.c
fi
done
return 1
}
cflagscheck() {
cat << EOF > conftest.c
int main(void){return 0;}
EOF
$cc $cflags $1 -o conftest.o -c conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.o conftest.c
return 1
else
rm -f conftest conftest.o conftest.c
return 0
fi
}
ltoflagcheck() {
cat << EOF > conftest.c
int main(void){return 0;}
EOF
$cc $cflags -flto -o conftest.o -c conftest.c > /dev/null 2>&1
$cc $ldflags -flto -Wl,-O3 -o conftest conftest.o > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.o conftest.c
return 1
else
rm -f conftest conftest.o conftest.c
return 0
fi
}
pledgecheck() {
cat << EOF > conftest.c
#include <unistd.h>
int main(void){pledge(NULL,NULL);return 0;}
EOF
$cc $cflags $ldflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.o conftest.c
return 0
else
rm -f conftest conftest.o conftest.c
return 1
fi
}
reallocarraycheck() {
cat << EOF > conftest.c
#include <stdlib.h>
int main(void){reallocarray(NULL, 0, 0);return 0;}
EOF
$cc $cflags $ldflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.o conftest.c
return 0
else
rm -f conftest conftest.o conftest.c
return 1
fi
}
strlcatcheck() {
cat << EOF > conftest.c
#include <string.h>
int main(void){strlcat(NULL,NULL,0);return 0;}
EOF
$cc $cflags $ldflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.o conftest.c
return 0
else
rm -f conftest conftest.o conftest.c
return 1
fi
}
strlcpycheck() {
cat << EOF > conftest.c
#include <string.h>
int main(void){strlcpy(NULL,NULL,0);return 0;}
EOF
$cc $cflags $ldflags -o conftest conftest.c > /dev/null 2>&1
if [ $? -eq 0 ] ; then
rm -f conftest conftest.o conftest.c
return 0
else
rm -f conftest conftest.o conftest.c
return 1
fi
}
# Option variables
if [ ! -z "$PREFIX" ] ; then
prefix="$PREFIX"
else
prefix="/usr/local"
fi
if [ ! -x "$(command -v ed)" ] ; then
prog="ed"
else
prog="oed"
fi
cflags=""
lto=0
static=0
setmandir=0
# Options
for opt
do
case "$opt" in
--prefix=*)
prefix=`echo $opt | cut -d '=' -f 2`
;;
--mandir=*)
mandir=`echo $opt | cut -d '=' -f 2`
setmandir=1
;;
--cc=*)
CC=${opt#*=}
;;
--cflags=*)
CFLAGS=${opt#*=}
;;
--ldflags=*)
LDFLAGS=${opt#*=}
;;
--disable-lto|--enable-lto)
if [ "x$opt" = "x--enable-lto" ] ; then
lto=1
else
lto=0
fi
;;
--disable-static|--enable-static)
if [ "x$opt" = "x--enable-static" ] ; then
static=1
else
static=0
fi
;;
--program-name=*)
prog=`echo $opt | cut -d '=' -f 2`
;;
--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 [$prefix/man]"
printf " --cc=CC "
echo "Use specified C compiler [default=cc]"
printf " --cflags=CFLAGS "
echo "Use specified CFLAGS [default=\"-g -O2 -pipe -w\"]"
printf " --ldflags=LDFLAGS "
echo "Use specified LDFLAGS"
printf " --program-name=NAME "
echo "Install executable as NAME [default=$prog]"
printf " --enable-lto "
echo "Enable link-time optimization [default=no]"
printf " --enable-static "
echo "Statically link executables [default=no]"
exit 1
;;
*)
;;
esac
done
if [ $setmandir -eq 0 ] ; then
mandir="$prefix/man"
fi
if [ ! -z "$CFLAGS" ] ; then
flags="$CFLAGS"
else
flags=""
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
if [ "x$flags" = "x" ] ; then
flags="-g -O2 -pipe -w -I$(pwd)"
else
flags="$flags -I$(pwd)"
fi
for flag in $flags ; do
printf "checking whether %s accepts %s... " $cc $flag
cflagscheck $flag
if [ $? -eq 0 ] ; then
echo "no"
else
cflags="$cflags $flag"
echo "yes"
fi
done
if [ $lto -eq 1 ] ; then
printf "checking for -flto compiler flag... "
ltoflagcheck
if [ $? -eq 0 ] ; then
echo "no"
else
cflags="$cflags -flto"
ldflags="$ldflags -flto -Wl,-O3"
echo "yes"
fi
fi
printf "checking for OS... "
os=`uname -s`
echo "$os"
case "x$os" in
"xLinux"|"xCYGWIN"*)
cflags="$cflags -D_GNU_SOURCE"
;;
"xNetBSD")
cflags="$cflags -D_OPENBSD_SOURCE"
;;
esac
cat << EOF > config.h
/* This file automatically generated by configure. */
EOF
needreallocarray=0
needstrlcat=0
needstrlcpy=0
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
needreallocarray=1
echo "no"
fi
printf "checking for strlcat... "
strlcatcheck
if [ $? -eq 0 ] ; then
echo "#define HAVE_STRLCAT" >> config.h
echo "yes"
else
needstrlcat=1
echo "no"
fi
printf "checking for strlcpy... "
strlcpycheck
if [ $? -eq 0 ] ; then
echo "#define HAVE_STRLCPY" >> config.h
echo "yes"
else
needstrlcpy=1
echo "no"
fi
echo "" >> config.h
if [ $needreallocarray -eq 1 ] ; then
echo "extern void *reallocarray(void *, size_t, size_t);" >> config.h
fi
if [ $needstrlcat -eq 1 ] ; then
echo "extern size_t strlcat(char *, const char *, size_t);" >> config.h
fi
if [ $needstrlcpy -eq 1 ] ; then
echo "extern size_t strlcpy(char *, const char *, size_t);" >> config.h
fi
if [ ! -z "$cflags" ] ; then
cflags="${cflags## }"
fi
if [ ! -z "$ldflags" ] ; then
ldflags="${ldflags## }"
fi
printf "creating Makefile... "
cat << EOF > Makefile
# This Makefile automatically generated by configure.
CC = $cc
EOF
if [ ! -z "$cflags" ] ; then
cat << EOF >> Makefile
CFLAGS = $cflags
EOF
fi
if [ ! -z "$ldflags" ] ; then
cat << EOF >> Makefile
LDFLAGS = $ldflags
EOF
fi
cat << EOF >> Makefile
PREFIX = $prefix
MANDIR = $mandir
PROG = $prog
OBJS = buf.o glbl.o io.o main.o re.o sub.o undo.o \\
regcomp.o regerror.o regexec.o regfree.o \\
reallocarray.o strlcat.o strlcpy.o
all: \${PROG}
\${PROG}: \${OBJS}
\${CC} \${LDFLAGS} -o \${PROG} \${OBJS}
install:
install -d \${DESTDIR}\${PREFIX}/bin
install -d \${DESTDIR}\${MANDIR}/man1
install -c -s -m 755 \${PROG} \${DESTDIR}\${PREFIX}/bin
install -c -m 644 ed.1 \${DESTDIR}\${MANDIR}/man1/\${PROG}.1
test:
@echo "No tests"
clean:
rm -f \${PROG} \${OBJS}
distclean: clean
rm -f Makefile config.h
EOF
echo "done"