-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure
executable file
·410 lines (370 loc) · 7.96 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
#!/bin/sh
#
# configure - configure script for Yadex
# AYM 2002-09-15
#
# This file is copyright André Majorel 2002-2003.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307, USA.
set -e
APPNAME=yadex
VERSION=`cat VERSION`
CC=
CXX=
HAVE_STRL=
HAVE_ARC4RANDOM=
INTERFACE=x11 # "bgi" or "x11"
PLATFORM=unix # "dos" or "unix"
PREFIX=/usr/local
#
# check - perform a test
#
check () {
cdir=/tmp
cbasename=${APPNAME}_$$.c
cout=${APPNAME}_$$.out
printf '%s' "$3" >$cdir/$cbasename
printf 'checking %s...' "$1"
if (cd $cdir && $CC -c $cbasename >$cout 2>&1)
then
echo " yes"
eval "$2=1"
return 0
else
echo " no"
sed 's/^/> /' $cdir/$cout
eval "$2="
return 1
fi
}
#
# genc - generate config.cc
#
genc () {
pathname=$BUILDDIR/config.cc
echo generating $pathname
(
set -e
echo '// DO NOT EDIT -- generated by ./configure'
echo
echo '#include "config.h"'
echo
echo 'const char *yadex_etc_path[] ='
echo '{'
sed 's/\\/\\\\/g; s/"/\\"/g; s/^.*/ "&",/;' $BUILDDIR/config.etc
echo ' 0'
echo '};'
echo
echo 'const char *yadex_share_path[] ='
echo '{'
sed 's/\\/\\\\/g; s/"/\\"/g; s/^.*/ "&",/;' $BUILDDIR/config.share
echo ' 0'
echo '};'
echo
) >$pathname
}
#
# genbool - generate a boolean macro definition
#
genbool () {
name=$1
if [ -n "`eval echo \\$HAVE_"$name"`" ]; then
echo "#define Y_$name"
else
echo "//#define Y_$name"
fi
}
#
# genh - generate config.h
#
genh () {
pathname=$BUILDDIR/config.h
echo generating $pathname
(
set -e
echo '// DO NOT EDIT -- generated by ./configure'
echo
echo 'extern const char *yadex_etc_path[];'
echo 'extern const char *yadex_share_path[];'
echo
) >$pathname
}
#
# Parse the command line
#
while [ "$#" -ge 1 ]
do
case "$1" in
--help)
echo "Usage:"
echo " configure --help"
echo " configure [--prefix path] [--cc string] [--cxx string]"
exit 0
;;
--cc)
shift
if [ "$#" -lt 1 ]
then
echo "configure: --cc requires an argument" 1>&2
exit 1
fi
CC="$1"
;;
--cc=*)
CC=`expr "x$1" : 'x--cc=\(.*\)'`
;;
--cxx)
shift
if [ "$#" -lt 1 ]
then
echo "configure: --cxx requires an argument" 1>&2
exit 1
fi
CXX="$1"
;;
--cxx=*)
CXX=`expr "x$1" : 'x--cxx=\(.*\)'`
;;
--prefix)
shift
if [ "$#" -lt 1 ]
then
echo "configure: --prefix requires an argument" 1>&2
exit 1
fi
PREFIX="$1"
;;
--prefix=*)
PREFIX=`expr "x$1" : 'x--prefix=\(.*\)'`
;;
-*)
echo "configure: bad argument \"$1\"" 1>&2
exit 1
;;
*)
echo "configure: too many arguments" 1>&2
exit 1
esac
shift
done
#
# Sanity checks
#
if expr "x$PREFIX" : x/ >/dev/null
then
true
else
echo "configure: --prefix: argument is not an absolute path" 1>&2
exit 1
fi
# Solaris /bin/grep doesn't know about -Fx.
GREP=/usr/xpg4/bin/grep
[ -x $GREP ] || GREP=grep
#
# Look for a C compiler
#
# We try "gcc" first as commercial Unixen often have a bundled
# "cc" command that's useless for our purposes (antiquated KNR
# compiler or front-end that just hangs waiting for an answer from
# some licence manager).
#
printf "looking for a C compiler..."
if [ -n "$CC" ]
then
printf ' using user-supplied value:'
else
CC=
for c in clang egcc gcc c89 c89; do
if type $c >/dev/null 2>&1; then
CC=$c
break
fi
done
if [ "x$CC" == "x" ]; then
echo "error: none of (clang, egcc, gcc, c89, cc) work, is your PATH set right?" 1>&2
exit 1
fi
fi
echo " $CC"
#
# Does the C compiler actually work ?
#
cdir=/tmp
cbasename=${APPNAME}_$$.c
cout=${APPNAME}_$$.out
printf "checking whether the C compiler works..."
echo 'int n;' >$cdir/$cbasename
if (cd $cdir && $CC -c $cbasename >$cout 2>&1)
then
echo " yes"
else
echo " no"
sed 's/^/> /' $cdir/$cout
echo "error: looks like the C compiler is not working" 1>&2
exit 1
fi
check "for strl{cat,cpy}" HAVE_STRL '
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *tmp = calloc(1, 7);
strlcpy(tmp, "foo", 7);
strlcat(tmp, "bar", 7);
free(tmp);
return 0;
}
' || true
check "for arc4random" HAVE_ARC4RANDOM '
#include <stdlib.h>
int main(int argc, char *argv[])
{
int x = (int) arc4random();
return x;
}
' || true
#
# Look for a C++ compiler
#
# We try "g++" first, then "c++", then "cxx".
#
printf "looking for a C++ compiler..."
if [ -n "$CXX" ]
then
printf ' using user-supplied value:'
else
CXX=
for c in clang++ eg++ g++ c++ cxx; do
if type $c >/dev/null 2>&1; then
CXX=$c
break
fi
done
if [ "x$CXX" == "x" ]; then
echo "error: none of (clang++, eg++, g++, c++, cxx) work, is your PATH set right?" 1>&2
exit 1
fi
fi
echo " $CXX"
#
# Does the C++ compiler actually work ?
#
cdir=/tmp
cbasename=${APPNAME}_$$.cc
cout=${APPNAME}_$$.out
printf "checking whether the C++ compiler works..."
echo 'int n;' >$cdir/$cbasename
if (cd $cdir && $CXX -c $cbasename >$cout 2>&1)
then
echo " yes"
else
echo " no"
sed 's/^/> /' $cdir/$cout
echo "error: looks like the C++ compiler is not working" 1>&2
exit 1
fi
#
# Create the directory where the build-specific files go
#
SYSTEM_RAW="`uname -n`_`uname -a | cksum`"
SYSTEM="`echo "$SYSTEM_RAW" | tr -dc '[:alnum:]._-'`"
BUILDDIR=obj/$SYSTEM
echo "build directory is $BUILDDIR"
mkdir -p $BUILDDIR
#
# FHS paths
#
if expr "$PREFIX" : '//*usr/*$' >/dev/null
then
BINDIR=/usr/bin # FHS-ly correct is /usr/games
ETCDIR=/etc/$APPNAME/%v
ETCDIRNV=/etc/$APPNAME
MANDIR=/usr/share/man
SHAREDIR=/usr/share/games/$APPNAME/%v
SHAREDIRNV=/usr/share/games/$APPNAME
elif expr "$PREFIX" : '//*usr//*local/*$' >/dev/null
then
BINDIR=/usr/local/bin # FHS-ly correct is /usr/local/games
ETCDIR=/etc/$APPNAME/%v
ETCDIRNV=/etc/$APPNAME
MANDIR=/usr/local/man
SHAREDIR=/usr/local/share/games/$APPNAME/%v
SHAREDIRNV=/usr/local/share/games/$APPNAME
elif expr "$PREFIX" : '//*opt/*$' >/dev/null
then
echo '/opt ? Surely you mean /opt/something, Mr. Feynman !' 1>&2
exit 1
elif expr "$PREFIX" : '//*opt//*[^/]' >/dev/null
then
BINDIR=$PREFIX/bin
ETCDIR=/etc/opt/`expr "$PREFIX" : '//*opt//*\(.*\)'`
ETCDIRNV=
MANDIR=$PREFIX/man
SHAREDIR=$PREFIX/share
SHAREDIRNV=
else # Probably /home/joe/*
BINDIR=$PREFIX/bin
ETCDIR=$PREFIX/etc
ETCDIRNV=
MANDIR=$PREFIX/man
SHAREDIR=$PREFIX/share
SHAREDIRNV=
fi
#
# Write Makefile.config
#
echo generating $BUILDDIR/Makefile.config
(
echo "# DO NOT EDIT -- generated by ./configure"
echo
echo "BINDIR = $BINDIR"
echo "CC = $CC"
echo "CXX = $CXX"
echo "ETCDIR = $ETCDIR" | sed "s/%v/$VERSION/g"
echo "ETCDIRNV = $ETCDIRNV"
echo "HAVE_STRL = $HAVE_STRL"
echo "HAVE_ARC4RANDOM = $HAVE_ARC4RANDOM"
echo "INTERFACE = $INTERFACE"
echo "MANDIR = $MANDIR"
echo "PLATFORM = $PLATFORM"
echo "SHAREDIR = $SHAREDIR" | sed "s/%v/$VERSION/g"
echo "SHAREDIRNV = $SHAREDIRNV"
) >$BUILDDIR/Makefile.config
#
# YGD files search path
#
echo generating $BUILDDIR/config.share
$GREP -Fvx '' <<EOF >"$BUILDDIR/config.share"
.
~/.$APPNAME/%v
~/.$APPNAME
$SHAREDIR
$SHAREDIRNV
EOF
#
# Config files search path
#
echo generating $BUILDDIR/config.etc
$GREP -Fvx '' <<EOF >"$BUILDDIR/config.etc"
.
~/.$APPNAME/%v
~/.$APPNAME
$ETCDIR
$ETCDIRNV
EOF
#
# Write config.h and config.cc
#
genc
genh
exit 0