forked from asmedit/gxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·1195 lines (1043 loc) · 34.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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
###############################################################################
#
# Copyright (C) 2003-2011 Anders Gavare. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This is a minimal configure script, hardcoded for GXemul. This script
# figures out which compiler flags will work, and creates Makefiles in
# sub-directories. A config.h file is also created.
#
#
# ---> FOR NORMAL USE, JUST RUN ./configure WITHOUT OPTIONS!
#
#
# To compile the emulator with profiling (during development), use
# CXXFLAGS="-pg", run the emulator, and then run 'gprof gxemul' and study
# the results.
#
# Or better, using callgrind/cachegrind/kcachegrind:
# valgrind --tool=callgrind --dump-instr=yes ./gxemul -e testm88k test/FileLoader_A.OUT_M88K
# or
# valgrind --tool=cachegrind ./gxemul -e testm88k test/FileLoader_A.OUT_M88K
# followed by
# kcachegrind
#
#
# The main things that are detected by this script:
#
# o) special hacks for some OSes
# o) which compiler(s) to use (overridden by setting CXX)
# o) which compiler flags to use (overridden by setting CXXFLAGS)
# o) X11 flags and libraries (TODO: should be possible to override
# via command line options?)
#
# The general philosophy regarding command line switches is that anything
# which can be incorporated into the program as a runtime command line option
# should be, instead of requiring a recompile.
#
###############################################################################
#
# Figure out the default prefix for "make install":
#
# If the PREFIX environment variable is set before running configure, it is
# used. The DEFAULTPREFIX calculated here is only used if PREFIX is undefined.
#
DEFAULTPREFIX=/usr/local
# Special exception for Linux systems: /usr
if [ z`uname` = zLinux ]; then
DEFAULTPREFIX=/usr
else
TRY=/usr/local
if [ -d $TRY/bin ]; then
DEFAULTPREFIX=$TRY
else
TRY=/opt
if [ -d $TRY ]; then
DEFAULTPREFIX=$TRY
else
TRY=/usr
if [ -d $TRY ]; then
DEFAULTPREFIX=$TRY
fi
fi
fi
fi
OTHERLIBS="$LDFLAGS"
UNITTESTS=YES
# Figure out if this is a stable version (0.x.x).
X=`basename \`pwd\`|cut -d \- -f 2-|cut -c1-2`
if [ z"$X" = z0. ]; then
# Stable.
:
else
# Development.
UNSTABLE=YES
fi
if [ z"$*" != z ]; then
# Parse command line options:
for a in $*; do
if [ z$a = z--disable-x ]; then
NOX11=YES
else if [ z$a = z--without-unittests ]; then
UNITTESTS=NO
else if [ z$a = z--disable-valgrind ]; then
DISABLEVALGRIND=YES
else if [ z$a = z--debug ]; then
DEBUG=YES
else if [ z$a = z--help ]; then
printf "usage: $0 [options]\n\n"
echo " --disable-x don't include X11 support,"\
"even if the host supports it"
echo " --disable-valgrind don't use valgrind, even"\
"if it is installed"
echo " --without-unittests don't include unit tests"
echo " --debug configure for a" \
"debug build (turn off optimizations)"
echo
echo "If the PREFIX environment variable is set," \
"it will override the default"
echo "value, which on this platform is: $DEFAULTPREFIX"
echo
exit
else
echo "Invalid option: $a"
echo "Run $0 --help to get a list of" \
"available options."
exit
fi; fi; fi; fi; fi
done
fi
###############################################################################
#
# Configure options:
#
# This creates a config.h file, which is then included from include/misc.h.
#
###############################################################################
# Head of config.h:
printf "/*
* THIS FILE IS AUTOMATICALLY CREATED BY configure!
* DON'T EDIT THIS FILE MANUALLY, IT WILL BE OVERWRITTEN.
*/
\n#ifndef CONFIG_H\n#define CONFIG_H\n\n" > config.h
# Figure out if VERSION should be defined.
X=`basename \`pwd\`|cut -d \- -f 2-`
if [ z"$X" = zgxemul ]; then
printf "#define VERSION \"(unknown version)\"\n" >> config.h
else
printf "#define VERSION \"$X\"\n" >> config.h
fi
if [ z"$UNSTABLE" = zYES ]; then
printf "#define UNSTABLE_DEVEL\n" >> config.h
fi
if [ z"$UNITTESTS" = zYES ]; then
printf "#define WITHUNITTESTS\n" >> config.h
fi
if [ z"$DEBUG" = zYES ]; then
echo "Building a debug version!"
CXXFLAGS="-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC $CXXFLAGS"
else
CXXFLAGS="-DNDEBUG $CXXFLAGS"
fi
ZZ=`echo compiled on \`uname\`/\`uname -m\`, \`date\``
printf "#define COMPILE_DATE \"$ZZ\"\n" >> config.h
# Include support for all CPU types:
printf "#define ADD_ALL_CPU_FAMILIES " >> config.h
# Alpha
printf " add_cpu_family(alpha_cpu_family_init, ARCH_ALPHA);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_alpha.o cpu_alpha_palcode.o memory_alpha.o"
CPU_TOOLS="$CPU_TOOLS generate_alpha_misc"
# ARM
printf " add_cpu_family(arm_cpu_family_init, ARCH_ARM);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_arm.o cpu_arm_coproc.o memory_arm.o "
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p0_u0_w0.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p0_u0_w1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p0_u1_w0.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p0_u1_w1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p1_u0_w0.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p1_u0_w1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p1_u1_w0.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p1_u1_w1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_dpi.o tmp_arm_r.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r0.o tmp_arm_r1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r2.o tmp_arm_r3.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r4.o tmp_arm_r5.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r6.o tmp_arm_r7.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r8.o tmp_arm_r9.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_ra.o tmp_arm_rb.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_rc.o tmp_arm_rd.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_re.o tmp_arm_rf.o tmp_arm_multi.o"
CPU_TOOLS="$CPU_TOOLS generate_arm_dpi generate_arm_r"
CPU_TOOLS="$CPU_TOOLS generate_arm_loadstore generate_arm_multi"
# M88K
printf " add_cpu_family(m88k_cpu_family_init, ARCH_M88K);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_m88k.o memory_m88k.o"
CPU_TOOLS="$CPU_TOOLS generate_m88k_bcnd"
CPU_TOOLS="$CPU_TOOLS generate_m88k_loadstore"
# MIPS
printf " add_cpu_family(mips_cpu_family_init, ARCH_MIPS);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_mips.o cpu_mips_coproc.o "
CPU_ARCHS="$CPU_ARCHS cpu_mips_instr_unaligned.o"
CPU_TOOLS="$CPU_TOOLS generate_mips_loadstore"
CPU_TOOLS="$CPU_TOOLS generate_mips_loadstore_multi"
# POWER/PowerPC
printf " add_cpu_family(ppc_cpu_family_init, ARCH_PPC);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_ppc.o"
CPU_TOOLS="$CPU_TOOLS generate_ppc_loadstore"
# SuperH
printf " add_cpu_family(sh_cpu_family_init, ARCH_SH);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_sh.o memory_sh.o"
printf "\n" >> config.h
###############################################################################
#
# Special hacks for some host OSes:
#
###############################################################################
if [ z"`uname|cut -c 1-6`" = zCYGWIN ]; then
CYGWIN=YES
if [ z"$CXX" = z ]; then
# Assume GNU C++ on Cygwin (Windows) systems.
CC=g++
fi
fi
###############################################################################
#
# Create the Makefile header:
#
###############################################################################
rm -f _Makefile.header
printf "#
# DO NOT EDIT THIS FILE! It is automagically created by
# the configure script, based on Makefile.skel.
#\n\n" >> _Makefile.header
# Try with the simplest possible test program. Actually, test static variables
# as well, because GXemul uses things like NULL-initialized global pointers,
# and it is important that they work. (Some versions of GCC on Solaris are
# known to be completely broken, for instance.)
echo '#include <stdio.h>
int main(int argc, char *argv[])
{
static int x = 0;
static int y = 1;
printf("%i,%i", x, y);
return 0;
}
' > _testprog.cc
# Try to detect which C++ compiler to use, if CXX is not set:
printf "checking which C++ compiler to use... "
rm -f _testprog
if [ z"$CXX" = z ]; then
# Try g++ first:
printf "#!/bin/sh\ng++ $CXXFLAGS _testprog.cc -o _testprog >" > _test.sh
printf " /dev/null 2> /dev/null\n" >> _test.sh
chmod 755 _test.sh
./_test.sh > /dev/null 2> /dev/null
if [ -x _testprog ]; then
if [ z`./_testprog` = z0,1 ]; then
CXX=g++
else
printf "broken g++ detected\n"
printf "The test program:\n\n"
cat _testprog.cc
printf "\nshould have resulted in 0,1, but the"
printf " result was: "
./_testprog
printf "\n\nchecking for other C++ compilers... "
fi
fi
rm -f _testprog
# If both g++ and c++ exist, then c++ might be a vendor specific
# compiler which produces faster code:
printf "#!/bin/sh\nc++ $CXXFLAGS _testprog.cc -o _testprog >" > _test.sh
printf " /dev/null 2> /dev/null\n" >> _test.sh
chmod 755 _test.sh
./_test.sh > /dev/null 2> /dev/null
if [ -x _testprog ]; then
if [ z`./_testprog` = z0,1 ]; then
CXX=c++
else
printf "broken c++ detected\n"
printf "checking for other C++ compilers... "
fi
fi
rm -f _testprog
rm -f _test.sh
fi
rm -f _testprog
if [ z"$CXX" = z ]; then
printf "no working compiler detected\n"
printf "\nPlease set the CXX environment variable to a working C++ "
printf "compiler before running\nthe configure script, and make"
printf " sure that the CXXFLAGS environment variable is\nalso valid"
printf " for that compiler.\n"
exit
fi
echo "$CXX $CXXFLAGS"
if [ z$NOX11 = z ]; then
printf "checking for X11 headers and libs\n"
# Try to compile a small X11 test program:
printf "#include <X11/Xlib.h>
#include <stdio.h>
Display *dis;
void f(void) {
dis = XOpenDisplay(NULL);
}
int main(int argc, char *argv[])
{ return 0; }
" > _test_x11.cc
XOK=0
XINCLUDE=-I/usr/X11R6/include
$CXX $CXXFLAGS _test_x11.cc -c -o _test_x11.o $XINCLUDE 2> /dev/null
XLIB="-L/usr/X11R6/lib -lX11"
$CXX $CXXFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
XOK=1
fi
rm -f _test_x11 _test_x11.o
if [ z$XOK = z0 ]; then
XINCLUDE=-I/usr/local/include
$CXX $CXXFLAGS _test_x11.cc -c -o _test_x11.o $XINCLUDE 2> /dev/null
XLIB="-L/usr/local/lib -lX11"
$CXX $CXXFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
XOK=1
fi
fi
rm -f _test_x11 _test_x11.o
# Special case for some 64-bit Linux/x86_64 systems:
if [ z$XOK = z0 ]; then
$CXX $CXXFLAGS _test_x11.cc -c -o _test_x11.o $XINCLUDE 2> /dev/null
XLIB="-L/usr/X11R6/lib64 -lX11"
$CXX $CXXFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
XOK=1
fi
fi
rm -f _test_x11 _test_x11.o
if [ z$XOK = z0 ]; then
XINCLUDE=""
$CXX $CXXFLAGS _test_x11.cc -c -o _test_x11.o $XINCLUDE 2> /dev/null
# -lsocket for Solaris
XLIB="-lX11 -lsocket"
$CXX $CXXFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
XOK=1
fi
rm -f _test_x11 _test_x11.o
fi
if [ z`uname` = zNetBSD ]; then
echo "Using NetBSD hack for X11 libs..."
XLIB="$XLIB -Wl,-rpath,/usr/X11R6/lib"
fi
if [ z`uname` = zOpenBSD ]; then
if [ z`uname -m` = zarc ]; then
echo "Using old OpenBSD/arc hack for X11 libs..."
XLIB="$XLIB -Wl,-rpath,/usr/X11R6/lib"
fi
fi
if [ z$XOK = z0 ]; then
echo "Failed to compile X11 test program." \
"Configuring without X11."
else
printf "X11 headers: $XINCLUDE\n"
printf "X11 libraries: $XLIB\n"
echo "XINCLUDE=$XINCLUDE" >> _Makefile.header
echo "XLIB=$XLIB" >> _Makefile.header
printf "#define WITH_X11\n" >> config.h
fi
rm -f _test_x11.cc
fi
if [ z$HPUX = zYES ]; then
CXXFLAGS="-D_XOPEN_SOURCE_EXTENDED $CXXFLAGS"
printf "#define HPUX\n" >> config.h
fi
if [ z$OSF1 = zYES ]; then
CXXFLAGS="-D_XOPEN_SOURCE=500 -D_OSF_SOURCE -D_POSIX_PII_SOCKET $CXXFLAGS"
fi
# CWARNINGS:
printf "checking whether -Wall can be used... "
$CXX $CXXFLAGS _testprog.cc -o _testprog -Wall 2> /dev/null
if [ -x _testprog ]; then
printf "yes\n"
CWARNINGS="-Wall $CWARNINGS"
else
printf "no\n"
fi
rm -f _testprog _testprog.err
# -Wstrict-aliasing
printf "checking whether -Wstrict-aliasing can be used... "
$CXX $CXXFLAGS -Wstrict-aliasing _testprog.cc -o _testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CWARNINGS="-Wstrict-aliasing $CWARNINGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
# -Wnon-virtual-dtor
printf "checking whether -Wnon-virtual-dtor can be used... "
$CXX $CXXFLAGS -Wnon-virtual-dtor _testprog.cc -o _testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CWARNINGS="-Wnon-virtual-dtor $CWARNINGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
# -Wextra -Wno-unused-parameter
printf "checking whether -Wextra -Wno-unused-parameter can be used... "
$CXX $CXXFLAGS -Wextra -Wno-unused-parameter _testprog.cc -o _testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CWARNINGS="$CWARNINGS -Wextra -Wno-unused-parameter"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
# -Wcast-qual
#printf "checking whether -Wcast-qual can be used... "
#$CXX $CXXFLAGS -Wcast-qual _testprog.cc -o _testprog 1> _testprog.stdout 2>&1
#cat _testprog.stdout >> _testprog.error
#if grep strict _testprog.error > /dev/null 2>&1; then
#printf "no\n"
#else
#if [ -x _testprog ]; then
# CWARNINGS="-Wcast-qual $CWARNINGS"
#printf "yes\n"
# else
#printf "no\n"
# fi
#fi
#rm -f _testprog _testprog.error _testprog.stdout
# -Wshadow
printf "checking whether -Wshadow can be used... "
$CXX $CXXFLAGS -Wshadow _testprog.cc -o _testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CWARNINGS="-Wshadow $CWARNINGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
# -O optimization for non-debug builds. Try -O and -O3.
if [ ! z"$DEBUG" = zYES ]; then
$CXX $CXXFLAGS -O _testprog.cc -o _testprog 2> /dev/null
if [ -x _testprog ]; then
rm -f _testprog
$CXX $CXXFLAGS -O3 _testprog.cc -o _testprog 2> /dev/null
if [ -x _testprog ]; then
CXXFLAGS="-O3 $CXXFLAGS"
else
CXXFLAGS="-O $CXXFLAGS"
fi
fi
fi
rm -f _testprog
# -fpeephole
if [ ! z"$DEBUG" = zYES ]; then
printf "checking whether -fpeephole can be used... "
$CXX $CXXFLAGS -fpeephole _testprog.cc -o _testprog > _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep peephole _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CXXFLAGS="-fpeephole $CXXFLAGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
fi
# -fomit-frame-pointer
if [ ! z"$DEBUG" = zYES ]; then
printf "checking whether -fomit-frame-pointer can be used... "
$CXX $CXXFLAGS -fomit-frame-pointer _testprog.cc -o \
_testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep frame _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CXXFLAGS="-fomit-frame-pointer $CXXFLAGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
fi
# -fstrict-aliasing
if [ ! z"$DEBUG" = zYES ]; then
printf "checking whether -fstrict-aliasing can be used... "
$CXX $CXXFLAGS -fstrict-aliasing _testprog.cc -o \
_testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CXXFLAGS="-fstrict-aliasing $CXXFLAGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
fi
# -fno-rtti
if [ ! z"$DEBUG" = zYES ]; then
printf "checking whether -fno-rtti can be used... "
$CXX $CXXFLAGS -fno-rtti _testprog.cc -o _testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep rtti _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CXXFLAGS="-fno-rtti $CXXFLAGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
fi
# -g, for development builds
if [ z"$UNSTABLE" = zYES ]; then
printf "checking whether -g can be used... "
$CXX $CXXFLAGS -g _testprog.cc -o _testprog > _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if [ -x _testprog ]; then
CXXFLAGS="-g $CXXFLAGS"
printf "yes\n"
else
printf "no\n"
fi
rm -f _testprog _testprog.error _testprog.stdout
fi
# -lrt for nanosleep?
printf "checking whether -lrt is required for nanosleep... "
printf "#include <time.h>\n#include <stdio.h>
int main(int argc, char *argv[]){nanosleep(NULL,NULL);return 0;}\n" > _testns.cc
$CXX $CXXFLAGS _testns.cc -o _testns 2> /dev/null
if [ ! -x _testns ]; then
$CXX $CXXFLAGS -lrt _testns.cc -o _testns 2> /dev/null
if [ ! -x _testns ]; then
printf "WARNING! COULD NOT COMPILE WITH nanosleep AT ALL!\n"
else
# -lrt for nanosleep
OTHERLIBS="-lrt $OTHERLIBS"
printf "yes\n"
fi
else
printf "no\n"
fi
rm -f _testns.cc _testns
# -lresolv for inet_pton?
printf "checking whether -lresolv is required for inet_pton... "
printf "int inet_pton(void); int main(int argc, " > _testr.cc
printf "char *argv[]) { return inet_pton(); }\n" >> _testr.cc
$CXX $CXXFLAGS _testr.cc -o _testr 2> /dev/null
if [ ! -x _testr ]; then
$CXX $CXXFLAGS _testr.cc -lresolv -o _testr 2> /dev/null
if [ ! -x _testr ]; then
$CXX $CXXFLAGS _testr.cc -lresolv -lnsl -o _testr 2> /dev/null
if [ ! -x _testr ]; then
printf "no, using inet_aton\n"
else
# -lresolv -lnsl for inet_pton
OTHERLIBS="-lresolv -lnsl $OTHERLIBS"
printf "yes (and -lnsl)\n"
printf "#define HAVE_INET_PTON\n" >> config.h
fi
else
# -lresolv for inet_pton
OTHERLIBS="-lresolv $OTHERLIBS"
printf "yes\n"
printf "#define HAVE_INET_PTON\n" >> config.h
fi
else
printf "no\n"
printf "#define HAVE_INET_PTON\n" >> config.h
fi
rm -f _testr.cc _testr.o _testr
# -lm?
printf "checking for math libs..."
printf "#include <math.h>\nint main(int argc, char *argv[]) { " > _testr.cc
printf "double x = sqrt(sin((double)argc)); return (int)x; }\n" >> _testr.cc
$CXX $CXXFLAGS _testr.cc -o _testr 2> /dev/null
if [ ! -x _testr ]; then
$CXX $CXXFLAGS _testr.cc -lm -o _testr 2> /dev/null
if [ ! -x _testr ]; then
$CXX $CXXFLAGS _testr.cc -lm -lcpml -o _testr 2> /dev/null
if [ ! -x _testr ]; then
printf "\nWARNING! Could not compile math test "
printf "at all!\nContinuing anyway.\n\n"
else
# -lm AND -lcpml
OTHERLIBS="-lm -lcpml $OTHERLIBS"
printf " -lm -lcpml\n"
fi
else
# Normal -lm
OTHERLIBS="-lm $OTHERLIBS"
printf " -lm\n"
fi
else
printf " none needed\n"
fi
rm -f _testr.cc _testr.o _testr
# strlcpy missing?
printf "checking for strlcpy... "
printf "#include <string.h>
int main(int argc, char *argv[]) { char *p; char *q; size_t x;
x = strlcpy(p, q, 50); return 0;}\n" > _tests.cc
$CXX $CXXFLAGS _tests.cc -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "missing, using mystrlcpy\n"
printf "#define strlcpy mystrlcpy\n" >> config.h
printf "#define strlcat mystrlcat\n" >> config.h
printf "#define USE_STRLCPY_REPLACEMENTS\n" >> config.h
else
printf "found\n"
fi
rm -f _tests.cc _tests.o _tests
# strtoull missing?
printf "checking for strtoull... "
printf "#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
long long x = strtoull(argv[1], NULL, 0); return 0;}\n" > _tests.cc
$CXX $CXXFLAGS _tests.cc -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "missing, using mystrtoull\n"
printf "#define strtoull mystrtoull\n" >> config.h
else
printf "found\n"
fi
rm -f _tests.cc _tests.o _tests
# mkstemp missing?
printf "checking for mkstemp... "
printf "#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[]) { int x; char y[4] = \"abc\";
x = mkstemp(y); return 0;}\n" > _tests.cc
$CXX $CXXFLAGS _tests.cc -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "missing, using workaround (perhaps not working properly)\n"
printf "#define mkstemp mymkstemp\n" >> config.h
else
printf "found\n"
fi
rm -f _tests.cc _tests.o _tests
# fseeko missing?
printf "checking for fseeko... "
printf "#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <sys/types.h>
int main(int argc, char *argv[]) { fseeko(NULL, 0, 0); return 0;}\n" > _tests.cc
$CXX $CXXFLAGS $CWARNINGS _tests.cc -o _tests 2> /dev/null
if [ ! -x _tests ]; then
# Try with _LARGEFILE_SOURCE (hack to make fseeko
# work on 64-bit Linux):
$CXX $CXXFLAGS -D_LARGEFILE_SOURCE $CWARNINGS _tests.cc -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "missing\n"
printf "WARNING! fseeko missing from libc. Using a hack, "
printf "which probably doesn't work.\n"
printf "#define HACK_FSEEKO\n" >> config.h
else
printf "using -D_LARGEFILE_SOURCE hack\n"
CXXFLAGS="$CXXFLAGS -D_LARGEFILE_SOURCE"
fi
else
printf "found\n"
fi
rm -f _tests.cc _tests.o _tests
# socklen_t missing?
# (for example really old OpenBSD/arc 2.3, inside the emulator)
printf "checking for socklen_t... "
printf "#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
int main(int argc, char *argv[]) { socklen_t x; return 0;}\n" > _tests.cc
$CXX $CXXFLAGS _tests.cc -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "no, using int\n"
CXXFLAGS="$CXXFLAGS -Dsocklen_t=int"
else
printf "socklen_t\n"
fi
rm -f _tests.cc _tests.o _tests
# MAP_ANON missing? (On some HP-UX systems? Use MAP_ANONYMOUS instead.)
printf "checking for MAP_ANON... "
rm -f _tests
printf "#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
int main(int argc, char *argv[]) { int x = MAP_ANON; return 0;}\n" > _tests.cc
$CXX $CXXFLAGS _tests.cc -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
int main(int argc, char *argv[])
{ int x = MAP_ANONYMOUS; return 0;}\n" > _tests.cc
$CXX $CXXFLAGS _tests.cc -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "no\n\n"
printf "WARNING! Neither MAP_ANON nor MAP_ANONYMOUS work on "
printf "this system.\nPlease try to compile anyway, and report"
printf " to me whether it builds/runs or not.\n\n"
printf "#define MAP_ANON 0\n" >> config.h
printf "#define NO_MAP_ANON\n" >> config.h
else
printf "using MAP_ANONYMOUS\n"
printf "#define MAP_ANON MAP_ANONYMOUS\n" >> config.h
fi
else
printf "yes\n"
fi
rm -f _tests.cc _tests.o _tests
# Check for PRIx64 in inttypes.h:
printf "checking for PRIx64 in inttypes.h... "
printf "#include <inttypes.h>\nint main(int argc, char *argv[])\n
{\n#ifdef PRIx64\nreturn 0;\n#else\nreturn 1;\n#endif\n}\n" > _testpri.cc
$CXX $CXXFLAGS _testpri.cc -o _testpri 2> /dev/null
if [ ! -x _testpri ]; then
printf "\nERROR! COULD NOT COMPILE PRIx64 TEST PROGRAM AT ALL!\n"
exit
else
if ./_testpri; then
printf "yes\n"
else
$CXX $CXXFLAGS -D__STDC_FORMAT_MACROS _testpri.cc -o _testpri 2> /dev/null
if [ -x _testpri ]; then
printf "using __STDC_FORMAT_MACROS\n"
CXXFLAGS="$CXXFLAGS -D__STDC_FORMAT_MACROS"
else
printf "no, using an ugly hack instead, "
printf "#define NO_C99_PRINTF_DEFINES\n" >> config.h
# Try llx first:
printf "#include <stdio.h>\n#include <inttypes.h>\nint main(int argc, char *argv[]){
printf(\"%%llx\\\n\", (int64_t)128);return 0;}\n" > _testpri.cc
rm -f _testpri
$CXX $CXXFLAGS $CWARNINGS _testpri.cc -o _testpri 2> /dev/null
if [ z`./_testpri` = z80 ]; then
printf "PRIx64=llx\n"
printf "#define NO_C99_64BIT_LONGLONG\n" >> config.h
else
# Try lx too:
printf "#include <stdio.h>\n#include <inttypes.h>\nint main(int argc, char *argv[]){
printf(\"%%lx\\\n\", (int64_t)128);return 0;}\n" > _testpri.cc
rm -f _testpri
$CXX $CXXFLAGS $CWARNINGS _testpri.cc -o _testpri 2> _testpri.result
if [ z`./_testpri` = z80 ]; then
printf "PRIx64=lx\n"
else
printf "\nFailed, neither lx nor llx worked!\n"
exit
fi
fi
fi
fi
fi
rm -f _testpri.cc _testpri _testpri.result
# Check for 64-bit off_t:
printf "checking for 64-bit off_t... "
printf "#include <stdio.h>\n#include <inttypes.h>\n#include <sys/types.h>\n
int main(int argc, char *argv[]){printf(\"%%i\\\n\",
(int)sizeof(off_t));return 0;}\n" > _testoff.cc
$CXX $CXXFLAGS _testoff.cc -o _testoff 2> /dev/null
if [ ! -x _testoff ]; then
printf "\nWARNING! COULD NOT COMPILE off_t TEST PROGRAM AT ALL!\n"
else
if [ z`./_testoff` = z8 ]; then
printf "yes\n"
else
$CXX $CXXFLAGS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
_testoff.cc -o _testoff 2> /dev/null
if [ ! -x _testoff ]; then
printf "\nWARNING! COULD NOT COMPILE off_t TEST "
printf "PROGRAM!\n"
else
if [ z`./_testoff` = z8 ]; then
CXXFLAGS="-D_FILE_OFFSET_BITS=64 $CXXFLAGS"
CXXFLAGS="-D_LARGEFILE_SOURCE $CXXFLAGS"
printf "using -D_FILE_OFFSET_BITS=64"
printf " -D_LARGEFILE_SOURCE\n"
else
printf "NO\n"
printf "Warning! No 64-bit off_t. Continuing "
printf "anyway.\n"
fi
fi
fi
fi
rm -f _testoff.cc _testoff
# Check for u_int8_t etc:
# These are needed because some header files in src/include/ use u_int*
# instead of uint*, and I don't have time to rewrite them all.
printf "checking for u_int8_t... "
printf "#include <stdio.h>\n#include <inttypes.h>\n#include <sys/types.h>\n
int main(int argc, char *argv[]){printf(\"%%i\\\n\",
(int)sizeof(u_int8_t));return 0;}\n" > _testuint.cc
$CXX $CXXFLAGS _testuint.cc -o _testuint 2> /dev/null
if [ ! -x _testuint ]; then
rm -f _testuint*
printf "#include <stdio.h>\n#include <inttypes.h>
\n#include <sys/types.h>\nint main(int argc, char *argv[])
{printf(\"%%i\\\n\", (int)sizeof(uint8_t));return 0;}\n" > _testuint.cc
$CXX $CXXFLAGS _testuint.cc -o _testuint 2> /dev/null
if [ ! -x _testuint ]; then
printf "no\n\nERROR: No u_int8_t or uint8_t. Aborting\n"
# TODO: Automagically detect using various combinations
# of char, int, short, long etc.
exit
fi
printf "typedef uint8_t u_int8_t;\n" >> config.h
printf "typedef uint16_t u_int16_t;\n" >> config.h
printf "typedef uint32_t u_int32_t;\n" >> config.h
printf "uint8_t\n"
else
printf "yes\n"
fi
rm -f _testuint.cc _testuint
printf "checking for u_int64_t... "
printf "#include <stdio.h>\n#include <inttypes.h>\n#include <sys/types.h>\n
int main(int argc, char *argv[]){printf(\"%%i\\\n\",
(int)sizeof(u_int64_t));return 0;}\n" > _testuint.cc
$CXX $CXXFLAGS _testuint.cc -o _testuint 2> /dev/null
if [ ! -x _testuint ]; then
rm -f _testuint*
printf "#include <stdio.h>\n#include <inttypes.h>
\n#include <sys/types.h>\nint main(int argc, char *argv[])
{printf(\"%%i\\\n\", (int)sizeof(uint64_t));return 0;}\n" > _testuint.cc
$CXX $CXXFLAGS _testuint.cc -o _testuint 2> /dev/null
if [ ! -x _testuint ]; then
printf "no\n\nERROR: No u_int64_t or uint64_t. Aborting\n"
# TODO: Automagically detect using various combinations
# of char, int, short, long etc.
exit
fi
printf "typedef uint64_t u_int64_t;\n" >> config.h
printf "uint64_t\n"
else
printf "yes\n"
fi
rm -f _testuint*
printf "checking for __FUNCTION__... "