-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfigure
executable file
·237 lines (192 loc) · 4.65 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
#!/bin/sh
#
# Configure script for 'prwd'
# Copyright (c) 2012-2020 Bertrand Janin <[email protected]>
#
#
VERSION="1.9.2"
# 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+=-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"
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
}
# 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*
# Check if we have a working cc
echo -n "cc... "
cat <<EOF > fake_cc.c
#include <stdio.h>
main() { printf("woot\n"); }
EOF
if ! ${CC} fake_cc.c -o /dev/null 1>/dev/null 2>/dev/null; then
not_found "No C compiler found (try to install gcc or clang)"
fi
echo ${CC}
rm -f fake_cc*
# Check if we have strlcpy
echo -n "strlcpy... "
cat <<EOF > fake_strlcpy.c
#include <string.h>
main() { char buf[32]; strlcpy(buf, "woot", sizeof(buf)); }
EOF
if ! ${CC} fake_strlcpy.c -o /dev/null 1>/dev/null 2>/dev/null; then
echo "not found (we'll use ours)"
X_OBJECTS="$X_OBJECTS strlcpy.o"
CFLAGS="$CFLAGS -DHAS_NO_STRLCPY"
else
echo yes
fi
rm -f fake_strlcpy*
# Check if we have wcslcpy
echo -n "wcslcpy... "
cat <<EOF > fake_wcslcpy.c
#include <wchar.h>
main() { wchar_t buf[32]; wcslcpy(buf, L"woot", sizeof(buf)); }
EOF
if ! ${CC} fake_wcslcpy.c -o /dev/null 1>/dev/null 2>/dev/null; then
echo "not found (we'll use ours)"
X_OBJECTS="$X_OBJECTS wcslcpy.o"
CFLAGS="$CFLAGS -DHAS_NO_WCSLCPY"
else
echo yes
fi
rm -f fake_wcslcpy*
# Check if we have wcstonum
echo -n "wcstonum... "
cat <<EOF > fake_wcstonum.c
main() { int i; const char *errstr; i = wcstonum("42", 1, 64, &errstr); }
EOF
if ! ${CC} fake_wcstonum.c -o /dev/null 1>/dev/null 2>/dev/null; then
echo "not found (we'll use ours)"
X_OBJECTS="$X_OBJECTS wcstonum.o"
CFLAGS="$CFLAGS -DHAS_NO_WCSTONUM"
else
echo yes
fi
rm -f fake_wcstonum*
generate_makefile Makefile.src > Makefile
generate_makefile src/Makefile.src > src/Makefile
generate_makefile tests/Makefile.src > tests/Makefile
generate_makefile afl/Makefile.src > afl/Makefile
echo
echo "Configured for '$OS', run 'make' (or 'gmake') to compile."