forked from OpenDUNE/OpenDUNE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.lib
2150 lines (1873 loc) · 63.7 KB
/
config.lib
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
log() {
if [ $1 = "1" ]; then
shift
echo "$@"
else
shift
fi
echo "$@" >> $config_log
}
set_default() {
ignore_extra_parameters="0"
# We set all kinds of defaults for params. Later on the user can override
# most of them; but if they don't, this default is used.
build=""
host=""
cc_build=""
cc_host=""
as_host=""
strip=""
lipo=""
awk="awk"
os="DETECT"
cpu_type="DETECT"
config_log="config.log"
prefix_dir="/usr/local"
binary_dir="games"
doc_dir="share/doc/opendune"
data_dir="share/games/opendune"
icon_dir="share/icons/hicolor/32x32/apps"
install_dir="/"
binary_name="opendune"
enable_debug="0"
enable_profiling="0"
enable_lto="0"
enable_static="1"
enable_assert="1"
enable_strip="0"
enable_universal="0"
with_osx_sysroot="1"
with_sdl="1"
with_sdlimage="1"
with_sdl2="1"
with_sdl2image="1"
with_asound="1"
with_oss="1"
with_pulse="1"
with_kai="1"
with_munt="1"
enable_builtin_depend="1"
with_makedepend="0"
with_sort="1"
with_distcc="1"
with_ccache="1"
save_params_array="
build
host
cc_build
cc_host
strip
lipo
awk
os
cpu_type
config_log
prefix_dir
binary_dir
data_dir
icon_dir
install_dir
binary_name
enable_debug
enable_profiling
enable_lto
enable_static
enable_assert
enable_strip
enable_universal
with_osx_sysroot
with_sdl
with_sdlimage
with_sdl2
with_sdl2image
with_asound
with_oss
with_pulse
with_munt
enable_builtin_depend
with_makedepend
with_sort
with_distcc
with_ccache
CC CFLAGS LDFLAGS CFLAGS_BUILD LDFLAGS_BUILD"
}
detect_params() {
# Walk over all params from the user and override any default settings if
# needed. This also handles any invalid option.
for p in "$@"; do
if [ -n "$prev_p" ]; then
eval "$prev_p=\$p"
prev_p=
continue
fi
optarg=`expr "x$p" : 'x[^=]*=\(.*\)'`
case "$p" in
--help | -h | -\?) showhelp; exit 0;;
--config-log) prev_p="config_log";;
--config-log=*) config_log="$optarg";;
--build) prev_p="build";;
--build=*) build="$optarg";;
--host) prev_p="host";;
--host=*) host="$optarg";;
--os) prev_p="os";;
--os=*) os="$optarg";;
--cpu-type) prev_p="cpu_type";;
--cpu-type=*) cpu_type="$optarg";;
--cc-build) prev_p="cc_build";;
--cc-build=*) cc_build="$optarg";;
--cc-host) prev_p="cc_host";;
--cc-host=*) cc_host="$optarg";;
--awk) prev_p="awk";;
--awk=*) awk="$optarg";;
--strip) prev_p="strip";;
--strip=*) strip="$optarg";;
--lipo) prev_p="lipo";;
--lipo=*) lipo="$optarg";;
# Alias --prefix with --prefix-dir, for compatibility with GNU autotools
--prefix-dir | --prefix) prev_p="prefix_dir";;
--prefix-dir=* | --prefix=*) prefix_dir="$optarg";;
--binary-dir) prev_p="binary_dir";;
--binary-dir=*) binary_dir="$optarg";;
--data-dir) prev_p="data_dir";;
--data-dir=*) data_dir="$optarg";;
--icon-dir) prev_p="icon_dir";;
--icon-dir=*) icon_dir="$optarg";;
--binary-name) prev_p="binary_name";;
--binary-name=*) binary_name="$optarg";;
--install-dir) prev_p="install_dir";;
--install-dir=*) install_dir="$optarg";;
--enable-debug) enable_debug="1";;
--enable-debug=*) enable_debug="$optarg";;
--enable-profiling) enable_profiling="1";;
--enable-profiling=*) enable_profiling="$optarg";;
--enable-lto) enable_lto="1";;
--enable-lto=*) enable_lto="$optarg";;
--enable-ipo) enable_lto="1";;
--enable-ipo=*) enable_lto="$optarg";;
--disable-static) enable_static="0";;
--enable-static) enable_static="2";;
--enable-static=*) enable_static="$optarg";;
--disable-assert) enable_assert="0";;
--enable-assert) enable_assert="2";;
--enable-assert=*) enable_assert="$optarg";;
--disable-strip) enable_strip="0";;
--enable-strip) enable_strip="2";;
--enable-strip=*) enable_strip="$optarg";;
--disable-universal) enable_universal="0";;
--enable-universal) enable_universal="i386 ppc x86_64";;
--enable-universal=*) enable_universal="$optarg";;
--with-sdl) with_sdl="2";;
--without-sdl) with_sdl="0";;
--with-sdl=*) with_sdl="$optarg";;
--with-sdl2) with_sdl2="2";;
--without-sdl2) with_sdl2="0";;
--with-sdl2=*) with_sdl2="$optarg";;
--with-asound) with_asound="2";;
--without-asound) with_asound="0";;
--with-asound=*) with_asound="$optarg";;
--with-alsa) with_asound="2";;
--without-alsa) with_asound="0";;
--with-alsa=*) with_asound="$optarg";;
--with-oss) with_oss="2";;
--without-oss) with_oss="0";;
--with-pulse) with_pulse="2";;
--without-pulse) with_pulse="0";;
--with-pulse=*) with_pulse="$optarg";;
--with-kai) with_kai="2";;
--without-kai) with_kai="0";;
--with-kai=*) with_kai="$optarg";;
--with-munt) with_munt="2";;
--without-munt) with_munt="0";;
--with-munt=*) with_munt="$optarg";;
--disable-builtin-depend) enable_builtin_depend="0";;
--enable-builtin-depend) enable_builtin_depend="2";;
--enable-builtin-depend=*) enable_builtin_depend="$optarg";;
--with-makedepend) with_makedepend="2";;
--without-makedepend) with_makedepend="0";;
--with-makedepend=*) with_makedepend="$optarg";;
--with-sort) with_sort="2";;
--without-sort) with_sort="0";;
--with-sort=*) with_sort="$optarg";;
--without-distcc) with_distcc="0";;
--with-distcc) with_distcc="2";;
--with-distcc=*) with_distcc="$optarg";;
--without-ccache) with_ccache="0";;
--with-ccache) with_ccache="2";;
--with-ccache=*) with_ccache="$optarg";;
--without-osx-sysroot) with_osx_sysroot="0";;
--with-osx-sysroot) with_osx_sysroot="2";;
--with-osx-sysroot=*) with_osx_sysroot="$optarg";;
CC=* | --CC=*) CC="$optarg";;
CFLAGS=* | --CFLAGS=*) CFLAGS="$optarg";;
LDFLAGS=* | --LDFLAGS=*) LDFLAGS="$optarg";;
CFLAGS_BUILD=* | --CFLAGS_BUILD=* | --CFLAGS-BUILD=*) CFLAGS_BUILD="$optarg";;
LDFLAGS_BUILD=* | --LDFLAGS_BUILD=* | --LDFLAGS-BUILD=*) LDFLAGS_BUILD="$optarg";;
--ignore-extra-parameters) ignore_extra_parameters="1";;
--* | -*)
if [ "$ignore_extra_parameters" = "0" ]; then
log 1 "Unknown option $p"
exit 1
else
log 1 "Unknown option $p ignored"
fi
;;
esac
done
if [ -n "$prev_p" ]; then
log 1 "configure: error: missing argument to --$prev_p"
exit 1
fi
# Clean the logfile
echo "" > $config_log
log 2 "Invocation: $0 $*"
}
save_params() {
# Here we save all params, so we can later on do an exact redo of this
# configuration, without having the user to re-input stuff
echo "Running configure with following options:" >> $config_log
echo "" >> $config_log
configure="$CONFIGURE_EXECUTABLE --ignore-extra-parameters"
for p in $save_params_array; do
eval "v=\"\$$p\""
p=`echo "$p" | sed 's@_@-@g;s@\n@@g;s@ @\\ @g'`
# Only save those params that aren't empty
configure="$configure --$p=\"$v\""
done
echo "$configure" >> $config_log
echo "$configure" > config.cache
echo "" >> $config_log
}
check_params() {
# Some params want to be in full uppercase, else they might not work as
# expected.. fix that here
os=`echo $os | tr '[a-z]' '[A-Z]'`
cpu_type=`echo $cpu_type | tr '[a-z]' '[A-Z]'`
# Check if all params have valid values
# OS only allows DETECT, UNIX, OSX, FREEBSD, OPENBSD, MORPHOS, BEOS, HAIKU, SUNOS, CYGWIN, MINGW, OS2, DOS, and WINCE, TOS
if [ -z "`echo $os | egrep '^(DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS|WINCE|TOS)$'`" ]; then
log 1 "configure: error: invalid option --os=$os"
log 1 " Available options are: --os=[DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|HAIKU|SUNOS|CYGWIN|MINGW|OS2|DOS|WINCE|TOS]"
exit 1
fi
# cpu_type can be either 32 or 64
if [ -z "`echo $cpu_type | egrep '^(32|64|DETECT)$'`" ]; then
log 1 "configure: error: invalid option --cpu-type=$cpu_type"
log 1 " Available options are: --cpu-type[=DETECT|32|64]"
exit 1
fi
# enable_debug should be between 0 and 4
if [ -z "`echo $enable_debug | egrep '^[0123]$'`" ]; then
log 1 "configure: error: invalid option --enable-debug=$enable_debug"
log 1 " Available options are: --enable-debug[=0123]"
exit 1
fi
detect_awk
detect_os
check_build
check_host
# Check for universal builds; they only make sense for OSX, so fail if enabled for another OS
if [ "$enable_universal" = "0" ]; then
log 1 "checking universal build... no"
else
if [ "$os" != "OSX" ]; then
log 1 "configure: error: --enable-universal only works on OSX"
exit 1
fi
log 1 "checking universal build... yes, for: $enable_universal"
fi
# Already detected by check_build
log 1 "checking build cc... $cc_build"
log 1 "checking host cc... $cc_host"
if [ "$enable_strip" != "0" ]; then
check_strip
else
log 1 "checking strip... disabled"
fi
check_lipo
if [ "$enable_builtin_depend" != "0" ]; then
log 1 "checking builtin depend... yes"
makedepend="\$(SRC_OBJS_DIR)/\$(DEPEND)"
else
log 1 "checking builtin depend... no"
fi
check_makedepend
detect_cputype
if [ "$enable_static" = "1" ]; then
if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "DOS" ]; then
enable_static="2"
else
enable_static="0"
fi
fi
if [ "$enable_static" != "0" ]; then
log 1 "checking static... yes"
if [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "OSX" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "DOS" ]; then
log 1 "WARNING: static is only known to work on Windows, DOS, MacOSX and MorphOS"
log 1 "WARNING: use static at your own risk on this platform"
sleep 5
fi
else
log 1 "checking static... no"
fi
# Show what we configured
if [ "$enable_debug" = "0" ]; then
log 1 "using debug level... no"
if [ $enable_assert -eq 1 ]; then
enable_assert=0
log 1 "disabling asserts"
fi
elif [ "$enable_profiling" != "0" ]; then
log 1 "using debug level... profiling (debug level $enable_debug)"
else
log 1 "using debug level... level $enable_debug"
fi
if [ "$enable_lto" != "0" ]; then
# GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
has_lto=`($cc_build -dumpspecs 2>&1 | grep '\%{flto') || ($cc_build -help ipo 2>&1 | grep '\-ipo')`
if [ -n "$has_lto" ]; then
log 1 "using link time optimization... yes"
else
enable_lto="0"
log 1 "using link time optimization... no"
log 1 "WARNING: you selected link time optimization but it is not found."
fi
else
log 1 "using link time optimization... no"
fi
if [ "$os" != "OSX" ] && [ "$with_osx_sysroot" != "0" ]; then
if [ "$with_osx_sysroot" = "1" ]; then
with_osx_sysroot="0"
log 1 "checking OSX sysroot... not OSX, skipping"
else
log 1 "configure: error: --with-osx-sysroot only works if OSX is the target"
exit 1
fi
fi
if [ "$with_osx_sysroot" != "0" ]; then
if [ "$enable_universal" = "0" ] && [ "$with_osx_sysroot" != "1" ] && [ "$with_osx_sysroot" != "2" ]; then
# Sysroot manually specified? Check for usability
log 1 "checking OSX sysroot... $with_osx_sysroot"
if ! check_osx_sdk "$with_osx_sysroot"; then
log 1 "Passed sysroot not found/not functional"
exit 1
fi
else
# If autodetect and no universal, use system default
if [ "$with_osx_sysroot" = "1" ] && [ "$enable_universal" = "0" ]; then
log 1 "checking OSX sysroot... no (use system default)"
else
log 1 "checking OSX sysroot... automatically"
detect_osx_sdk
fi
fi
if [ -n "$osx_sdk_path" ]; then
if [ "$enable_universal" != "0" ]; then
if [ -z "$osx_sdk_104_path" ]; then
log 1 "WARNING: Could not find a usable 10.4u SDK, the resulting"
log 1 "WARNING: binary will only run on OSX 10.5 or later"
osx_sdk_104_path="$osx_sdk_path"
fi
OSX_SYSROOT="-isysroot $osx_sdk_104_path"
OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_104_path"
else
OSX_SYSROOT="-isysroot $osx_sdk_path"
OSX_LD_SYSROOT="-Wl,-syslibroot,$osx_sdk_path"
fi
fi
else
if [ "$os" = "OSX" ]; then
log 1 "checking OSX sysroot... no (use system default)"
fi
fi
if [ "$os" = "TOS" ]; then
with_sdl2="0"
with_sdl="0"
with_asound="0"
with_oss="0"
with_pulse="0"
with_munt="0"
fi
if [ "$os" = "FREEBSD" ] && [ "$with_oss" != "0" ] && [ "$with_asound" = "1" ] ; then
# prefers OSS to ALSA under FreeBSD
with_asound="0"
fi
detect_sdl2
detect_sdl
detect_asound
detect_oss
detect_pulseaudio
detect_kai
detect_munt
if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
log 1 "checking GDI video driver... found"
else
log 1 "checking GDI video driver... not Windows, skipping"
fi
if [ "$enable_assert" != "0" ]; then
log 1 "checking assert... enabled"
else
log 1 "checking assert... disabled"
fi
detect_sort
if [ "$enable_debug" = "0" ] && [ "$enable_profiling" = "0" ] && [ "$enable_strip" != "0" ]; then
if [ "$os" = "MORPHOS" ]; then
strip_arg="--strip-all --strip-unneeded --remove-section .comment"
elif [ "$os" = "OSX" ]; then
strip_arg=""
elif [ "$os" = "OS2" ]; then
strip_arg=""
# OS2 uses strip via gcc, because it needs to be feed to emxbind
LDFLAGS="$LDFLAGS -s"
elif [ "$os" = "SUNOS" ]; then
# The GNU strip does know -s, the non-GNU doesn't
# So try to detect it (in a bit of an ugly way)
strip_arg="`$strip -s strip.test 2>/dev/null && echo \"-s\"`"
else
strip_arg="-s"
fi
log 1 "checking stripping... $strip $strip_arg"
else
strip=""
log 1 "checking stripping... skipped"
fi
if [ "$with_distcc" = "0" ]; then
log 1 "checking distcc... no"
elif [ "$with_distcc" = "1" ]; then
with_distcc="0"
log 1 "checking distcc... no (only used when forced)"
elif [ "$with_distcc" = "2" ]; then
distcc="distcc"
else
distcc="$with_distcc"
fi
if [ "$with_distcc" != "0" ]; then
res="`$distcc --version 2>/dev/null | head -n 1 | cut -b 1-6`"
if [ "$res" != "distcc" ]; then
distcc=""
log 1 "checking distcc... no"
if [ "$with_distcc" = "2" ]; then
log 1 "configure: error: no distcc detected, but was forced to be used"
exit 1
fi
if [ "$with_distcc" != "1" ]; then
log 1 "configure: error: '$with_distcc' doesn't seem a distcc to me"
exit 1
fi
fi
log 1 "checking distcc... $distcc"
fi
if [ "$with_ccache" = "0" ]; then
log 1 "checking ccache... no"
elif [ "$with_ccache" = "1" ]; then
with_ccache="0"
log 1 "checking ccache... no (only used when forced)"
elif [ "$with_ccache" = "2" ]; then
ccache="ccache"
else
ccache="$with_ccache"
fi
if [ "$with_ccache" != "0" ]; then
res="`$ccache --version 2>/dev/null | head -n 1 | cut -b 1-6`"
if [ "$res" != "ccache" ]; then
ccache=""
log 1 "checking ccache... no"
if [ "$with_ccache" = "2" ]; then
log 1 "configure: error: no ccache detected, but was forced to be used"
exit 1
fi
if [ "$with_ccache" != "1" ]; then
log 1 "configure: error: '$with_ccache' doesn't seem a ccache to me"
exit 1
fi
fi
log 1 "checking ccache... $ccache"
fi
if [ "$os" = "OSX" ] ; then
OSXAPP="OpenDUNE.app"
else
OSXAPP=""
fi
if [ -d "$ROOT_DIR/.svn" ] && [ -n "`svn help 2>/dev/null`" ]; then
log 1 "checking revision... svn detection"
elif [ -d "$ROOT_DIR/.git" ] && [ -n "`git help 2>/dev/null`" ]; then
log 1 "checking revision... git detection"
elif [ -d "$ROOT_DIR/.hg" ] && [ -n "`hg help 2>/dev/null`" ]; then
log 1 "checking revision... hg detection"
elif [ -f "$ROOT_DIR/.ottdrev" ]; then
log 1 "checking revision... source tarball"
else
log 1 "checking revision... no detection"
log 1 "WARNING: there is no means to determine the version."
log 1 "WARNING: please use a subversion, mercurial, or git checkout of OpenDUNE."
log 1 "WARNING: USE WITH CAUTION!"
sleep 5
fi
if [ -n "$install_dir" ]
then
log 1 "installation directory... $install_dir"
else
log 1 "installation directory... none"
fi
}
make_compiler_cflags() {
# Params:
# $1 - compiler
# $2 - name of the cflags variable
# $4 - name of the ldflags variable
# $5 - name of the features variable
eval eval "flags=\\\$$2"
eval eval "ldflags=\\\$$3"
eval eval "features=\\\$$4"
if [ `basename $1 | cut -c 1-3` = "icc" ]; then
# Enable some things only for certain ICC versions
cc_version=`$1 -dumpversion | cut -d. -f 1-2 | sed s@\\\.@@g`
flags="$flags -rdynamic"
ldflags="$ldflags -rdynamic"
if [ -z "$first_time_icc_check" ]; then
first_time_icc_check=no
if [ $cc_version -lt 90 ]; then
log 1 "WARNING: you seem to be using a very old version of ICC"
log 1 "WARNING: OpenDUNE hasn't been tested with this version"
sleep 5
elif [ $cc_version -lt 120 ]; then
log 1 "WARNING: you seem to be using an unsupported ICC version"
log 1 "WARNING: ICC older than 12.0 is known to fail to compile OpenDUNE"
sleep 5
fi
fi
flags="$flags -Wall"
# remark #111: statement is unreachable
flags="$flags -wd111"
# remark #181: argument is incompatible with corresponding format string conversion
# ICC is very picky about signedness of operands, warnings provided by GCC are enough
flags="$flags -wd181"
# remark #271: trailing comma is nonstandard
flags="$flags -wd271"
# remark #280: selector expression is constant
flags="$flags -wd280"
# remark #304: access control not specified ("public" by default)
flags="$flags -wd304"
# remark #383: value copied to temporary, reference to temporary used
flags="$flags -wd383"
# remark #444: destructor for base class ... is not virtual
flags="$flags -wd444"
# remark #593: variable ... was set but never used
flags="$flags -wd593"
# warning #654: overloaded virtual function ... is only partially overridden in class ...
flags="$flags -wd654"
# remark #810: conversion from ... to ... may lose significant bits
flags="$flags -wd810"
# remark #869: parameter ... was never referenced
flags="$flags -wd869"
# warning #873: function ... ::operator new ... has no corresponding operator delete ...
flags="$flags -wd873"
# remark #981: operands are evaluated in unspecified order
flags="$flags -wd981"
# remark #1418: external function definition with no prior declaration
flags="$flags -wd1418"
# remark #1419: external declaration in primary source file
flags="$flags -wd1419"
# remark #1572: floating-point equality and inequality
flags="$flags -wd1572"
# remark #1599: declaration hides variable/parameter ...
flags="$flags -wd1599"
# remark #1720: function ... ::operator new ... has no corresponding member operator delete ...
flags="$flags -wd1720"
if [ $cc_version -lt 110 ]; then
# warns about system headers with recent glibc:
# warning #1292: attribute "__nonnull__" ignored
flags="$flags -wd1292"
fi
if [ $cc_version -ge 100 ]; then
# warning #1899: multicharacter character literal (potential portability problem)
flags="$flags -wd1899"
# vec report defaults to telling where it did loop vectorisation, which is not very important
flags="$flags -vec-report=0 "
fi
if [ $cc_version -ge 110 ]; then
# remark #2259: non-pointer conversion from ... to ... may lose significant bits
flags="$flags -wd2259"
fi
if [ "$enable_lto" != "0" ]; then
has_ipo=`$1 -help ipo | grep '\-ipo'`
if [ -n "$has_ipo" ]; then
# Use IPO (only if we see IPO exists and is requested)
flags="$flags -ipo"
features="$features lto"
fi
fi
elif [ `basename $1 | grep 'clang'` ]; then
# Enable some things only for certain clang versions
cc_version="`$1 -v 2>&1 | head -n 1 | sed s@[^0-9]@@g | cut -c 1-2`"
# aliasing rules are not held in OpenDUNE code
flags="$flags -fno-strict-aliasing"
# -W alone doesn't enable all warnings enabled by -Wall; on the other hand,
# -Weverything enables too many useless warnings that can't be disabled (as of 3.0)
flags="$flags -Wall -W"
# warning: expression result unused
flags="$flags -Wno-unused-value"
# warning: explicitly assigning a variable of type '...' to itself
# it happens when using the FOR_ALL_WINDOWS_FROM_BACK_FROM macro
flags="$flags -Wno-self-assign"
if [ "$cc_version" -lt "30" ]; then
# warning: equality comparison with extraneous parentheses
flags="$flags -Wno-parentheses"
# warning: operands of ? are integers of different signs: 'unsigned int' and 'int'
flags="$flags -Wno-sign-compare"
fi
if [ "$cc_version" -ge "30" ]; then
# warning: equality comparison with extraneous parentheses
# this warning could be useful, but it warns about code in squirrel
flags="$flags -Wno-parentheses-equality"
fi
if [ "$with_ccache" != "0" -o "$with_distcc" != "0" ]; then
# ccache and distcc run separate preprocess and compile passes,
# both are fed with the same CFLAGS. Unfortunately, clang
# complains about -I when compiling preprocessed files:
# "clang: warning: argument unused during compilation: '-I /usr/include'"
flags="$flags -Qunused-arguments"
fi
if [ "$enable_assert" -eq "0" ]; then
# do not warn about unused variables when building without asserts
flags="$flags -Wno-unused-variable"
fi
# rdynamic is used to get useful stack traces from crash reports.
ldflags="$ldflags -rdynamic"
else
# Enable some things only for certain GCC versions
cc_version=`$1 -dumpversion | cut -d. -f 1-2`
if echo "$cc_version" | grep -q '\.' ; then
# remove the dot
cc_version=`echo "$cc_version" | sed s@\\\.@@g`
else
# add a 0 if the version had only one digit
cc_version="${cc_version}0"
fi
if [ "$os" != "TOS" ] && [ "$os" != "DOS" ] && [ $cc_version -lt 70 ] ; then
if [ "$with_asound" = "0" ] ; then
flags="$flags -ansi"
fi
flags="$flags -pedantic"
fi
flags="$flags -fno-common"
flags="$flags -Wall -Wsign-compare -Wundef"
flags="$flags -Wwrite-strings -Wpointer-arith"
flags="$flags -W -Wredundant-decls"
flags="$flags -Wformat=2 -Wformat-security"
flags="$flags -Wno-format-nonliteral"
if [ $enable_assert -eq 0 ]; then
# Do not warn about unused variables when building without asserts
if [ $cc_version -ge 30 ]; then
flags="$flags -Wno-unused-variable"
fi
if [ $cc_version -ge 46 ]; then
# GCC 4.6 gives more warnings, disable them too
flags="$flags -Wno-unused-but-set-variable"
flags="$flags -Wno-unused-but-set-parameter"
fi
fi
if [ $cc_version -ge 34 ]; then
# Warn when a variable is used to initialise itself:
# int a = a;
flags="$flags -Winit-self"
fi
if [ $cc_version -ge 40 ]; then
# GCC 4.0+ complains about that we break strict-aliasing.
# On most places we don't see how to fix it, and it doesn't
# break anything. So disable strict-aliasing to make the
# compiler all happy.
flags="$flags -fno-strict-aliasing"
# Warn about casting-out 'const' with regular C-style cast.
# The preferred way is const_cast<>() which doesn't warn.
flags="$flags -Wcast-qual"
fi
if [ $cc_version -ge 42 ]; then
# GCC 4.2+ automatically assumes that signed overflows do
# not occur in signed arithmetics, whereas we are not
# sure that they will not happen. It furthermore complains
# about its own optimized code in some places.
flags="$flags -fno-strict-overflow"
fi
if [ $cc_version -eq 45 ]; then
# Prevent optimisation supposing enums are in a range specified by the standard
# For details, see http://gcc.gnu.org/PR43680
flags="$flags -fno-tree-vrp"
fi
if [ $cc_version -ge 47 ]; then
# Disable bogus 'attempt to free a non-heap object' warning
flags="$flags -Wno-free-nonheap-object"
fi
if [ "$enable_lto" != "0" ]; then
# GCC 4.5 outputs '%{flto}', GCC 4.6 outputs '%{flto*}'
has_lto=`$1 -dumpspecs | grep '\%{flto'`
if [ -n "$has_lto" ]; then
# Use LTO only if we see LTO exists and is requested
if [ $cc_version -lt 46 ]; then
flags="$flags -flto"
else
flags="$flags -flto=jobserver"
fi
ldflags="$ldflags -fwhole-program"
features="$features lto"
fi
fi
has_rdynamic=`$1 -dumpspecs | grep rdynamic`
if [ -n "$has_rdynamic" ]; then
# rdynamic is used to get useful stack traces from crash reports.
flags="$flags -rdynamic"
ldflags="$ldflags -rdynamic"
fi
fi
eval "$2=\"$flags\""
eval "$3=\"$ldflags\""
eval "$4=\"$features\""
}
make_cflags_and_ldflags() {
# General CFlags for BUILD
CFLAGS_BUILD="$CFLAGS_BUILD"
# LDFLAGS for BUILD
LDFLAGS_BUILD="$LDFLAGS_BUILD"
# FEATURES for BUILD (lto)
FEATURES_BUILD=""
# General CFlags for HOST
CFLAGS="$CFLAGS"
# Libs to compile. In fact this is just LDFLAGS
LIBS=""
# LDFLAGS used for HOST
LDFLAGS="$LDFLAGS"
# FEATURES for HOST (lto)
FEATURES=""
make_compiler_cflags "$cc_build" "CFLAGS_BUILD" "LDFLAGS_BUILD" "FEATURES_BUILD"
make_compiler_cflags "$cc_host" "CFLAGS" "LDFLAGS" "FEATURES"
CFLAGS="$CFLAGS -D$os -I$ROOT_DIR/include"
if [ "$enable_debug" = "0" ]; then
# No debug, add default stuff
OBJS_SUBDIR="release"
if [ "$os" = "MORPHOS" ]; then
CFLAGS="-I/gg/os-include -noixemul -fstrict-aliasing -fexpensive-optimizations -mcpu=604 -fno-inline -mstring -mmultiple $CFLAGS"
LDFLAGS="$LDFLAGS -noixemul"
fi
if [ "$os" = "TOS" ] ; then
CFLAGS="-Ofast -fomit-frame-pointer $CFLAGS"
elif [ "$os" = "HAIKU" -a $cc_version -lt 40 ] ; then
CFLAGS="-O2 -fomit-frame-pointer $CFLAGS"
else
CFLAGS="-O2 -fomit-frame-pointer -Wno-variadic-macros $CFLAGS"
fi
else
OBJS_SUBDIR="debug"
# Each debug level reduces the optimization by a bit
if [ $enable_debug -ge 1 ]; then
CFLAGS="$CFLAGS -g -D_DEBUG"
fi
if [ $enable_debug -ge 2 ]; then
CFLAGS="$CFLAGS -fno-inline"
fi
if [ $enable_debug -ge 3 ]; then
CFLAGS="$CFLAGS -O0"
else
CFLAGS="$CFLAGS -O2"
fi
fi
if [ $enable_debug -le 2 ]; then
if basename "$cc_host" | grep "gcc" &>/dev/null; then
# Define only when compiling with GCC. Some GLIBC versions use GNU
# extensions in a way that breaks build with at least ICC.
# This requires -O1 or more, so debug level 3 (-O0) is excluded.
osversion=`uname -r | cut -f 1 -d'.'`
if [ "$os" != "OSX" ] || [ "$os" = "OSX" -a "$osversion" -ne 9 ] ; then
# FORTIFY_SOURCE causes problem with OS X 10.5 / Xcode 3.1.4
# OS X 10.5.xx is Darwin 9.xx
CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
fi
# Just add -O1 to the tools needed for building.
CFLAGS_BUILD="$CFLAGS_BUILD -D_FORTIFY_SOURCE=2 -O1"
fi
fi
if [ "$os" = "OSX" ] && [ $cc_version -eq 40 ]; then
# Apple's GCC 4.0 has a compiler bug for x86_64 with (higher) optimization,
# wrongly optimizing ^= in loops. This disables the failing optimisation.
CFLAGS="$CFLAGS -fno-expensive-optimizations"
fi
if [ "$enable_profiling" != "0" ]; then
CFLAGS="$CFLAGS -p"
LDFLAGS="$LDFLAGS -pg"
fi
if [ "`echo $1 | cut -c 1-3`" != "icc" ]; then
if [ "$os" = "CYGWIN" ]; then
flags="$flags -mwin32"
LDFLAGS="$LDFLAGS -mwin32"
fi
if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ]; then
if [ $cc_version -lt 46 ]; then
flags="$flags -mno-cygwin"
LDFLAGS="$LDFLAGS -mno-cygwin"
fi
LDFLAGS="$LDFLAGS -Wl,--subsystem,windows"
LIBS="$LIBS -lwinmm -lcomctl32 -lgdi32"
if [ $cc_version -ge 44 ]; then
LDFLAGS_BUILD="$LDFLAGS_BUILD -static-libgcc"
fi
if [ $cc_version -ge 47 ]; then
CFLAGS="$CFLAGS -mno-ms-bitfields"
fi
fi
fi
if [ "$os" = "WINCE" ]; then
LIBS="$LIBS -lcoredll -lcorelibc -laygshell -lws2 -e WinMainCRTStartup"
fi
if [ "$os" = "MORPHOS" ]; then
# -Wstrict-prototypes generates much noise because of system headers
CFLAGS="$CFLAGS -Wno-strict-prototypes"
fi
if [ "$os" = "OSX" ]; then
# Add macports include dir which is not always set a default system dir. This avoids zillions of bogus warnings.
CFLAGS="$CFLAGS -isystem/opt/local/include"
# Add OS X SDK audio frameworks
LDFLAGS="-Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit $LDFLAGS"
LDFLAGS="-Wl,-framework,CoreFoundation $LDFLAGS"
if [ -z "$sdl2_config" ] && [ -z "$sdl_config" ] ; then
LDFLAGS="$LDFLAGS -Wl,-framework,ApplicationServices"
LDFLAGS="$LDFLAGS -Wl,-framework,Carbon"
LDFLAGS="$LDFLAGS -Wl,-framework,CoreAudio"
fi
if [ "$enable_universal" = "0" ]; then
# Universal builds set this elsewhere
CFLAGS="$OSX_SYSROOT $CFLAGS"
LDFLAGS="$OSX_LD_SYSROOT $LDFLAGS"
fi
if [ "$enable_universal" = "0" ] && [ $cc_version -ge 40 ]; then
# Only set the min version when not doing an universal build.
# Universal builds set the version elsewhere.
if [ "$cpu_type" = "64" ]; then
if [ -n "$sdl2_config" ]; then
CFLAGS="$CFLAGS -mmacosx-version-min=10.6"
else
CFLAGS="$CFLAGS -mmacosx-version-min=10.5"
fi
else
gcc_cpu=`$cc_host -dumpmachine`
if [ "`echo $gcc_cpu | cut -c 1-3`" = "ppc" -o "`echo $gcc_cpu | cut -c 1-7`" = "powerpc" ]; then
# PowerPC build can run on 10.3
CFLAGS="$CFLAGS -mmacosx-version-min=10.3"
else
# Intel is only available starting from 10.4
CFLAGS="$CFLAGS -mmacosx-version-min=10.4"
fi
machine=$(machine)
case $machine in
ppc7400 | ppc7450 | ppc970)
CFLAGS="$CFLAGS -maltivec" ;;
esac
fi
fi
fi
if [ "$os" = "OS2" ]; then
LDFLAGS_BUILD="$LDFLAGS_BUILD -lstdc++"
fi