-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure
executable file
·692 lines (580 loc) · 15.5 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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
#!/bin/sh
#
# Copyright (C) 2016 Richard Burke
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
cf_fatal() {
echo "`tput setaf 1 2>/dev/null`$@`tput sgr0 2>/dev/null`" >&2
cf_cleanup
exit 1
}
cf_cmd_exists() {
type "$1" >/dev/null 2>&1
return $?
}
cf_try_cmd() {
if eval "test -n \"\$$1\""; then
return 0
fi
if cf_cmd_exists "$2"; then
eval "$1=$2"
return $?
fi
return 1
}
cf_try_cmds() {
VAR="$1"
shift
for CMD in "$@"; do
if cf_try_cmd "$VAR" "$CMD"; then
return 0
fi
done
return 1
}
cf_determine_os() {
if ! cf_cmd_exists uname; then
cf_fatal 'This script requires uname to run'
fi
if ! OS=`uname`; then
cf_fatal 'Unable to run uname'
fi
}
cf_create_temp_files() {
if ! cf_cmd_exists mktemp; then
cf_fatal 'This script requires mktemp to run'
fi
if ! TMP_C=`mktemp /tmp/wedconfigureXXXXXXXXXX.c`; then
cf_fatal 'Unable to create temporary file'
fi
if ! TMP_O=`mktemp /tmp/wedconfigureXXXXXXXXXX.o`; then
cf_fatal 'Unable to create temporary file'
fi
}
cf_check_for_c_compiler() {
printf 'Checking if a C compiler exists... '
if cf_try_cmds CC cc gcc clang; then
printf "$CC\n"
else
printf "no\n"
cf_fatal 'Unable to find a C compiler. Is gcc or clang installed?'
fi
}
cf_check_for_cxx_compiler() {
printf 'Checking if a C++ compiler exists... '
if cf_try_cmds CXX g++ clang++; then
printf "$CXX\n"
else
printf "no\n"
cf_fatal 'Unable to find a C++ compiler. Is g++ or clang++ installed?'
fi
}
cf_compile() {
COMP="$1"
TEST_CFLAGS="$2"
TEST_LDFLAGS="$3"
OUTPUT=`$COMP $TEST_CFLAGS -o "$TMP_O" "$TMP_C" $TEST_LDFLAGS 2>&1`
return $?
}
cf_compile_basic() {
cat >"$TMP_C" <<EOF
int main(int argc, char *argv[]) {
return 0;
}
EOF
cf_compile "$@"
}
cf_check_compiler_works() {
TYPE="$1"
COMP="$2"
printf "Checking if $TYPE compiler works... "
if cf_compile_basic "$COMP"; then
printf "yes\n"
else
printf "no\n"
cf_fatal "Unable to create executable:\n$OUTPUT"
fi
}
cf_check_flag() {
TYPE="$1"
COMP="$2"
FLAG="$3"
printf "Checking if $TYPE compiler accepts flag $FLAG... "
if cf_compile_basic "$COMP" "$FLAG"; then
printf "yes\n"
else
printf "no\n"
cf_fatal "$FLAG is required to build wed"
fi
}
cf_check_c_cflags() {
for f in '-std=c99' '-O2'; do
cf_check_flag 'C' "$CC" "$f"
CFLAGS_BASE="$CFLAGS_BASE $f"
done
}
cf_check_cpp_cflags() {
for f in '-std=c++98' '-O2'; do
cf_check_flag 'C++' "$CXX" "$f"
CXXFLAGS_BASE="$CXXFLAGS_BASE $f"
done
}
cf_check_if_have_pkg_config() {
printf 'Checking if pkg-config is present...'
if cf_cmd_exists pkg-config; then
HAS_PKG_CONFIG=1
printf "yes\n"
else
HAS_PKG_CONFIG=0
printf "no\n"
fi
}
cf_check_if_lib_is_present() {
FLAG_VAR="$1"
COMP="$2"
LIB="$3"
eval "FLAG_VAL=\"\$$FLAG_VAR\""
printf "Checking if lib $LIB is present... "
if [ $HAS_PKG_CONFIG -eq 1 ]; then
LIB_CFLAGS=`pkg-config --cflags "$LIB" 2>/dev/null`
LIB_LDFLAGS=`pkg-config --libs "$LIB" 2>/dev/null`
fi
if [ $? -ne 0 ] || [ $HAS_PKG_CONFIG -eq 0 ]; then
LIB_CFLAGS=
LIB_LDFLAGS="-l$LIB"
fi
if cf_compile "$COMP" "$FLAG_VAL $LIB_CFLAGS -O0" "$LDFLAGS_BASE $LIB_LDFLAGS"; then
if [ -n "$LIB_CFLAGS" ]; then
eval "$FLAG_VAR=\"$FLAG_VAL $LIB_CFLAGS\""
fi
if [ -n "$LIB_LDFLAGS" ]; then
LDFLAGS_BASE="$LDFLAGS_BASE $LIB_LDFLAGS"
fi
printf "yes\n"
return 0
fi
printf "no\n"
return 1
}
cf_check_if_have_ncurses() {
cat >"$TMP_C" <<EOF
#include <curses.h>
int main(int argc, char *argv[]) {
initscr();
return 0;
}
EOF
for lib in ncursesw ncurses curses; do
if cf_check_if_lib_is_present CFLAGS_BASE "$CC" "$lib"; then
return 0
fi
done
cf_fatal 'The ncurses library is required to build wed'
}
cf_check_if_have_gpm() {
if [ "$OS" != 'Linux' ]; then
return 0
fi
if cf_check_if_lib_is_present CFLAGS_BASE "$CC" gpm; then
return 0
fi
cf_fatal 'The gpm library is required to build wed'
}
cf_check_if_have_pcre() {
cat >"$TMP_C" <<EOF
#include <pcre.h>
int main(int argc, char *argv[]) {
pcre_version();
return 0;
}
EOF
if cf_check_if_lib_is_present CFLAGS_BASE "$CC" pcre; then
return 0
fi
cf_fatal 'The PCRE library is required to build wed'
}
cf_check_if_have_rt() {
if [ "$OS" = 'Darwin' ]; then
return 0
fi
cat >"$TMP_C" <<EOF
#include <time.h>
int main(int argc, char *argv[]) {
struct timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
return 0;
}
EOF
if cf_check_if_lib_is_present CFLAGS_BASE "$CC" rt; then
return 0
fi
cf_fatal 'The librt library is required to build wed'
}
cf_check_if_have_gnu_source_highlight() {
if [ $WED_FEATURE_GNU_SOURCE_HIGHLIGHT -eq 1 ]; then
cf_check_for_cxx_compiler
cf_check_compiler_works 'C++' "$CXX"
cf_check_cpp_cflags
cf_check_if_have_boost_regex
cf_check_if_have_lib_gnu_source_highlight
fi
}
cf_check_if_have_boost_regex() {
cat >"$TMP_C" <<EOF
#include <boost/regex.hpp>
int main(int argc, char *argv[]) {
boost::regex r(".*");
return 0;
}
EOF
if cf_check_if_lib_is_present CXXFLAGS_BASE "$CXX" boost_regex; then
return 0
fi
cf_fatal 'The Boost Regex library is required to build wed'
}
cf_check_if_have_lib_gnu_source_highlight() {
cat >"$TMP_C" <<EOF
#include "srchilite/sourcehighlight.h"
int main(int argc, char *argv[]) {
srchilite::SourceHighlight sourceHighlight("esc.outlang");
return 0;
}
EOF
if cf_check_if_lib_is_present CXXFLAGS_BASE "$CXX" source-highlight; then
return 0
fi
cf_fatal 'The GNU Source-highlight library is required to build wed'
}
cf_check_if_have_lua() {
if [ $WED_FEATURE_LUA -eq 1 ]; then
cf_check_if_have_lib_lua
cf_check_if_have_lua_cli_client
if [ $WED_STATIC_BUILD -eq 1 ]; then
cf_check_if_have_lib_lpeg
# Don't check for LPeg when building on Travis CI
#
# The liblua5.1-lpeg2 package is not in the Travis CI apt package
# whitelist. The lua-lpeg package is in the whitelist but causes
# apt-get install to fail. Therefore we have to disable this check
# when running under Travis CI
elif ! [ "$TRAVIS" = 'true' ]; then
cf_check_if_have_lpeg
fi
fi
}
cf_check_if_have_lib_lua() {
cat >"$TMP_C" <<EOF
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
int main(int argc, char *argv[]) {
lua_State *state = luaL_newstate();
lua_close(state);
return 0;
}
EOF
for v in 3 2 1; do
for lib in lua5.$v lua-5.$v lua5$v; do
if cf_check_if_lib_is_present CFLAGS_BASE "$CC" "$lib"; then
return 0
fi
done
done
if cf_check_if_lib_is_present CFLAGS_BASE "$CC" 'lua'; then
return 0
fi
cf_fatal 'The Lua library is required to build wed'
}
cf_check_if_have_lua_cli_client() {
printf 'Checking if lua cli client is present... '
LUA_CLI_CLIENT='lua'
if cf_cmd_exists "$LUA_CLI_CLIENT"; then
printf 'yes\n'
return 0
fi
for v in 3 2 1; do
for lua_client in lua5.$v lua5$v; do
if cf_cmd_exists "$lua_client"; then
LUA_CLI_CLIENT="$lua_client"
printf 'yes\n'
return 0
fi
done
done
printf 'no\n'
cf_fatal 'The standalone cli Lua interpreter is required to test for lpeg'
}
cf_check_if_have_lib_lpeg() {
cat >"$TMP_C" <<EOF
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
int luaopen_lpeg(lua_State *);
int main(int argc, char *argv[]) {
lua_State *state = luaL_newstate();
lua_getglobal(state, "package");
lua_getfield(state, -1, "preload");
lua_pushcfunction(state, luaopen_lpeg);
lua_setfield(state, -2, "lpeg");
lua_close(state);
return 0;
}
EOF
for v in 3 2 1; do
for lib in lua5.${v}-lpeg lua-5.${v}-lpeg lua5${v}-lpeg; do
if cf_check_if_lib_is_present CFLAGS_BASE "$CC" "$lib"; then
return 0
fi
done
done
if cf_check_if_lib_is_present CFLAGS_BASE "$CC" 'lua-lpeg'; then
return 0
fi
cf_fatal 'The Lua LPeg library is required to build wed'
}
cf_check_if_have_lpeg() {
printf 'Checking if lpeg is present... '
if $LUA_CLI_CLIENT -e "require('lpeg')" >/dev/null 2>&1; then
printf 'yes\n'
else
printf 'no\n'
cf_fatal 'The Lua LPeg library is required to build wed'
fi
}
cf_check_if_have_bison() {
printf 'Checking if bison is present... '
if cf_cmd_exists "$BISON"; then
printf 'yes\n'
else
printf 'no\n'
cf_fatal 'The GNU Bison parser generator is required to build wed'
fi
}
cf_check_if_have_flex() {
printf 'Checking if flex is present... '
if cf_cmd_exists "$FLEX"; then
printf 'yes\n'
else
printf 'no\n'
cf_fatal 'The Flex lexer is required to build wed'
fi
}
cf_add_os_specific_flags() {
case "$OS" in
Linux)
CFLAGS_BASE="$CFLAGS_BASE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
;;
*BSD)
CFLAGS_BASE="$CFLAGS_BASE -I/usr/local/include"
CXXFLAGS_BASE="$CFLAGS_BASE -I/usr/local/include"
LDFLAGS_BASE="$LDFLAGS_BASE -L/usr/local/lib"
;;
CYGWIN*)
CFLAGS_BASE="$CFLAGS_BASE -U__STRICT_ANSI__"
;;
esac
}
cf_add_general_flags() {
CFLAGS_BASE="$CFLAGS_BASE -DNDEBUG"
if [ $WED_FEATURE_GNU_SOURCE_HIGHLIGHT -eq 1 ]; then
LDFLAGS_BASE="$LDFLAGS_BASE -lstdc++"
fi
}
cf_add_static_flags() {
if [ $WED_STATIC_BUILD -eq 0 ]; then
return
fi
if [ $WED_FEATURE_LUA -eq 1 ]; then
LDFLAGS="$LDFLAGS -lm"
fi
LDFLAGS="$LDFLAGS -lpthread -ldl -lc -static"
}
cf_determine_pcre_version() {
printf 'Checking if PCRE version is at least 8.20... '
WED_PCRE_VERSION_GE_8_20=`pcre-config --version 2>/dev/null | awk -F'.' \
'BEGIN { output = 0; } \
NR == 1 && ($1 > 8 || ($1 == 8 && $2 >= 20)) { output = 1; } \
END { print output; }' 2>/dev/null`
if [ $WED_PCRE_VERSION_GE_8_20 -eq 1 ]; then
printf 'yes\n'
else
printf 'no\n'
fi
}
cf_determine_default_sdt() {
if [ $WED_FEATURE_LUA -eq 1 ]; then
WED_DEFAULT_SDT='sl'
elif [ $WED_FEATURE_GNU_SOURCE_HIGHLIGHT -eq 1 ]; then
WED_DEFAULT_SDT='sh'
fi
}
cf_write_config() {
OUTFILE='config.mk'
cat >"$OUTFILE" <<EOF
CC=$CC
CXX=$CXX
CFLAGS=$CFLAGS_BASE $CFLAGS
CXXFLAGS=$CXXFLAGS_BASE $CXXFLAGS
LDFLAGS=$LDFLAGS_BASE $LDFLAGS
PREFIX=$PREFIX
WEDRUNTIME=\$(PREFIX)/share/wed
FLEX=$FLEX
BISON=$BISON
WED_STATIC_BUILD=$WED_STATIC_BUILD
WED_PCRE_VERSION_GE_8_20=$WED_PCRE_VERSION_GE_8_20
WED_FEATURE_LUA=$WED_FEATURE_LUA
WED_FEATURE_GNU_SOURCE_HIGHLIGHT=$WED_FEATURE_GNU_SOURCE_HIGHLIGHT
WED_DEFAULT_SDT=$WED_DEFAULT_SDT
EOF
printf "$OUTFILE generated\n"
}
cf_check_if_have_make() {
MAKE_CMD='make'
if [ "${OS#*BSD}" != "$OS" ]; then
MAKE_CMD='gmake'
fi
if ! cf_cmd_exists "$MAKE_CMD"; then
cf_fatal "$MAKE_CMD is required to build wed"
fi
printf "Run \"$MAKE_CMD && sudo $MAKE_CMD install\" to build and install wed\n"
}
cf_init() {
TMP_C=
TMP_O=
CFLAGS_BASE=
CXXFLAGS_BASE=
LDFLAGS_BASE=
PREFIX=/usr/local
FLEX=flex
BISON=bison
WED_STATIC_BUILD=0
WED_FEATURE_LUA=1
WED_FEATURE_GNU_SOURCE_HIGHLIGHT=0
WED_DEFAULT_SDT=wed
cf_determine_os
cf_create_temp_files
}
cf_parse_args() {
for opt in "$@"; do
case "$opt" in
-h|--help)
cf_usage
cf_cleanup
exit 0
;;
--prefix=*)
PREFIX=${opt#*=}
;;
# The static option is experimental having only been tested on
# Ubuntu. It will most likely not work elsewhere without further
# work. Therefore it is not listed in the help message options
--static)
WED_STATIC_BUILD=1
;;
--enable-lua)
WED_FEATURE_LUA=1
;;
--disable-lua)
WED_FEATURE_LUA=0
;;
--enable-gnu-source-highlight)
WED_FEATURE_GNU_SOURCE_HIGHLIGHT=1
;;
--disable-gnu-source-highlight)
WED_FEATURE_GNU_SOURCE_HIGHLIGHT=0
;;
CC=*)
CC="${opt#*=}"
;;
CXX=*)
CXX="${opt#*=}"
;;
CFLAGS=*)
CFLAGS="${opt#*=}"
;;
CXXFLAGS=*)
CXXFLAGS="${opt#*=}"
;;
LDFLAGS=*)
LDFLAGS="${opt#*=}"
;;
FLEX=*)
FLEX="${opt#*=}"
;;
BISON=*)
BISON="${opt#*=}"
;;
PREFIX=*)
PREFIX="${opt#*=}"
;;
*)
cf_fatal "Invalid argument: $opt"
;;
esac
done
}
cf_cleanup() {
rm "$TMP_C" 2>/dev/null
rm "$TMP_O" 2>/dev/null
}
cf_usage() {
echo "
configure [OPTIONS] [VARIABLE=VALUE]...
OPTIONS:
-h,--help Print this message
--prefix=PATH Installation prefix (Default: $PREFIX)
Use lua (Scintillua) for syntax highlighting (enabled by default)
--enable-lua
--disable-lua
Use GNU Source-highlight for syntax highlighting (disabled by default)
--enable-gnu-source-highlight
--disable-gnu-source-highlight
VARIABLES:
CC C compiler
CXX C++ compiler
CFLAGS C compiler flags
CXXFLAGS C++ compiler flags
LDFLAGS Linker flags
FLEX Flex Lexer
BISON Bison Parser generator
PREFIX Installation prefix
"
}
main() {
cf_init
cf_parse_args "$@"
cf_check_for_c_compiler
cf_check_compiler_works 'C' "$CC"
cf_check_c_cflags
cf_check_if_have_pkg_config
cf_add_os_specific_flags
cf_check_if_have_ncurses
cf_check_if_have_gpm
cf_check_if_have_pcre
cf_check_if_have_rt
cf_check_if_have_lua
cf_check_if_have_gnu_source_highlight
cf_check_if_have_bison
cf_check_if_have_flex
cf_add_general_flags
cf_add_static_flags
cf_determine_pcre_version
cf_determine_default_sdt
cf_write_config
cf_check_if_have_make
cf_cleanup
}
main "$@"