-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconfigure
executable file
·1225 lines (1127 loc) · 33.3 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
# Configure file made by MagicalTux
# I took many parts of this code from "standard" configure scripts made by autoconf, but also
# written a big part of it
VERSION='$Id: configure 570 2005-12-01 23:15:33Z Yor $'
# nice line found in standard-like configure script
export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed myself to sh."; sh $0 $argv; kill $$)
case `uname` in
CYGWIN*)
if [ x"$BASH" = x ]; then
echo "Cygwin has a poor sh, switching to bash !"
/bin/bash $0 $*
kill $$
fi
;;
esac
# Default values :
WITH_MYSQL="no"
WITH_MYSQL_PATH="/usr/local/mysql:/usr/local:/usr:/"
WITH_LIBM="/usr/local"
WITH_ZLIB="yes"
WITH_OPTIMIZE="std"
WITH_WIN32="no"
WITH_PRO="no"
WITH_FDS=1024
WITH_C99="no"
WITH_MAKE="no"
PREFIX=~
PLATFORM=auto
srcdir=src/
# Specific config
OBJECTS="common"
CONFIGFILE="src/include/config.h"
MAKEFILE="Makefile"
LAST_LIBS="-lmysql -lmysqlclient -lws2_32 -ldl -lz -lm -lstdc++"
FREYA_VERSION="4.0"
# Autoinstall values...
ZLIB_LAST_VERSION="1.2.3"
# Initial values
INCLUDES="-I../include"
LIBS="-L../lib"
CC_OPTIONS="-pipe -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter"
COMP_OPTIONS=""
LOADABLE_EXT=".so"
# Forced revision number
# Use when .svn directories are not available
# RELEASED_SVN=0
CONFIGURE_LINE="'"`echo $0 | cut -d"'" -f- --output-delimiter='"'"'"'"'`"'"
# arguments loop
while :
do
case $# in
0)
break
;;
#
esac
option=$1
shift
CONFIGURE_LINE="$CONFIGURE_LINE '"`echo $option | cut -d"'" -f- --output-delimiter='"'"'"'"'`"'"
# Make all options have two hyphens
orig_option=$option # Save original for error messages
case $option in
--*) ;;
-*) option=-$option ;;
esac
# Split out the argument for options that take them
case $option in
--*=*)
optarg=`echo $option | sed -e 's/^[^=]*=//'`
;;
esac
case $option in
--prefix=*)
PREFIX="$optarg"
;;
--platform=*)
PLATFORM="$optarg"
;;
--with-*)
case "$option" in
*=*) ;;
*) optarg=yes ;;
esac
withopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g' | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
eval $withopt="\$optarg"
;;
--without-*)
withopt=`echo ${option} | sed 's:^--::;s:out::;s:-:_:g' | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
eval $withopt=no
;;
--choosesql)
# special function to offer the user to choose : MySQL or not ?
WITH_MYSQL=""
echo -n "What version do you want to compile ? [T]xt/[S]ql/[C]ancel"
while [ x$WITH_MYSQL = x ]; do
ANSWER="xx"
read -n1 -r -s ANSWER 2>/dev/null
if [ x"$ANSWER" = xxx ]; then
echo
echo -n "Type first letter and press [Return] : "
read ANSWER
fi
if [ x"$ANSWER" = x"C" ]; then ANSWER="c"; fi
if [ x"$ANSWER" = x"S" ]; then ANSWER="s"; fi
if [ x"$ANSWER" = x"T" ]; then ANSWER="t"; fi
if [ x"$ANSWER" = x"c" ]; then
echo
echo "Installation cancelled by user request."
exit 1
fi
if [ x"$ANSWER" = x"t" ]; then
echo
echo "Configuring installation for TEXT mode."
WITH_MYSQL="no"
fi
if [ x"$ANSWER" = x"s" ]; then
echo
echo "Configuring installation for SQL mode."
WITH_MYSQL="yes"
fi
done
;;
--help)
exec 1>&2
echo "Freya Configure Script"
echo "Written by MagicalTux <[email protected]>"
echo
echo "Usage : $0 [OPTIONS]"
echo
echo "Options: [defaults in brackets]"
echo ' --prefix=MYDIR install into MYDIR [~]'
echo ' --help print this message'
echo " --platform=PLATFORM set compile platform [$(uname)]"
echo
echo ' --with-mysql=PATH Enable MySQL support [autodetect]'
echo ' --with-libm=PATH set path to libm [autodetect]'
echo ' --with-zlib=PATH set path to libz [autodetect]'
echo ' --with-fds=n set maximum number of connections [1024]'
echo ' --with-optimize=LEVEL set compiler optimization level (read below) [std]'
echo ' --with-c99 enable C99 standard for compiling'
echo ' --with-win32 cross-compile for Win32'
echo
echo 'You can pass parameters to --with-mysql to say where you have'
echo 'MySQL installed. For example : --with-mysql=/usr/local/mysql'
echo
echo 'Valid optimization levels are :'
echo ' - no : No optimization of the code'
echo ' - low : Standard optimization of the code'
echo ' - std : Optimize even more (all safe optimizations - default)'
echo ' - high : Optimize yet more (all optimization options enabled)'
echo ' - size : Optimize for smaller binaries'
exit 0
;;
*)
echo "configure: Unrecognized option: \"$option\"; use --help for usage." >&2
exit 1
;;
esac
done
##### EXPAND PREFIX
TEMP=`pwd`
# sh on cygwin does not expand ~ to $HOME
PREFIX=`echo $PREFIX | sed 's:~:'"$HOME:"`
cd $PREFIX
PREFIX=`pwd`
cd $TEMP
##### OPTIMIZATION LEVEL
# first : lowercase it
WITH_OPTIMIZE=`echo $WITH_OPTIMIZE | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
# then test the value
if [ "$WITH_OPTIMIZE" = "low" ]; then
CC_OPTIONS="$CC_OPTIONS -O1"
fi
if [ "$WITH_OPTIMIZE" = "std" ]; then
CC_OPTIONS="$CC_OPTIONS -O2"
fi
if [ "$WITH_OPTIMIZE" = "high" ]; then
CC_OPTIONS="$CC_OPTIONS -O3"
echo "Warning: Maximal optimization enabled - do not complain if it crashes."
fi
if [ "$WITH_OPTIMIZE" = "size" ]; then
CC_OPTIONS="$CC_OPTIONS -Os"
fi
##### ENABLE -g GCC FLAG ?
##### C99 ?
if [ x"$WITH_C99" = x"yes" ]; then
CC_OPTIONS="$CC_OPTIONS -std=c99"
fi
##### PLATFORM DETECTION
echo -n "Checking for platform... "
if [ "$PLATFORM" = "auto" ]; then
PLATFORM=`uname`
echo $PLATFORM
else
echo "$PLATFORM (forced)"
fi
##### IS CYGWIN ?
TEST=`echo $PLATFORM | grep -i CYGWIN`
if [ x$TEST = x ]; then
# not cygwin
IS_CYGWIN=no
else
# cygwin !
IS_CYGWIN=yes
fi
##### MAKE OR GMAKE DETECTION
# detect : make or gmake ?
TEST=`echo $PLATFORM | grep FreeBSD`
if [ x$TEST = x ]; then
# not FreeBSD -> make
MAKE=make
else
MAKE=gmake
fi
##### SANE BUILD ENVIRONMENT ?
echo "Checking whether build environment is sane... "
sleep 1
echo timestamp > conftestfile
# Do this in a subshell so we don't clobber the current shell's
# arguments. FIXME: maybe try `-L' hack like GETLOADAVG test?
if (set X `ls -t configure conftestfile`; test "$2" = conftestfile)
then
# Ok.
rm -f conftestfile
else
rm -f conftestfile
echo "error: newly created file is older than distributed files!"
echo "Check your system clock"
exit 1
fi
##### FIND OUT PATH_SEPARATOR
# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
echo "#! /bin/sh" >conf$$.sh
echo "exit 0" >>conf$$.sh
chmod +x conf$$.sh
if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
PATH_SEPARATOR=';'
else
PATH_SEPARATOR=:
fi
rm -f conf$$.sh
fi
##### $(MAKE) SET BY MAKE/GMAKE ?
echo -n "Checking whether $MAKE sets \$(MAKE) ... "
echo "all:" >.config.tmp
echo ' @echo '"'"'ac_maketemp="$(MAKE)"'"'" >>.config.tmp
eval `$MAKE -f .config.tmp 2>/dev/null | grep temp=`
rm -f .config.tmp
if test -n "$ac_maketemp"; then
echo yes
MAKEFILE_MUST_SET_MAKE=""
else
echo no
MAKEFILE_MUST_SET_MAKE="MAKE = $MAKE"
fi
##### DETECT GCC
echo -n "Checking for gcc... "
CCLIST="gcc cc gcc-3.3 gcc-3.2 gcc-3.4 gcc-2.95"
if [ "$WITH_WIN32" != "no" ]; then
if [ "$IS_CYGWIN" = "no" ]; then
CCLIST="/usr/bin/*mingw*gcc /usr/bin/*mingw*cc /usr/bin/*mingw*gcc-3.3 /usr/bin/*mingw*gcc-3.2 /usr/bin/*mingw*gcc-3.4 /usr/bin/*mingw*gcc-2.95 $CCLIST"
if [ x$CC != x ]; then
# check if $CC is Ming
TEST=`$CC -v 2>&1 | grep ^Thread | grep win32`
# Thread model: win32
if [ x$TEST = x ]; then
# thread model is not win32
CC=""
fi
fi
else
# Cygwin's special way to do win32 applications
CC_OPTIONS="$CC_OPTIONS -mno-cygwin"
COMP_OPTIONS="$COMP_OPTIONS -mno-cygwin"
fi
fi
if [ x$CC != x ]; then
CCLIST="$CC $CCLIST"
fi
CC=""
for foo in $CCLIST; do
XCC=`which $foo`
if [ x$XCC = x ]; then
:
else
CC="$XCC"
echo $CC
break 2
fi
done
if [ x$CC = x ]; then
echo "not found" >&2
exit 1
fi
##### DETECT AR
echo -n "Checking for ar... "
ARLIST="ar"
if [ "$WITH_WIN32" != "no" ]; then
if [ "$IS_CYGWIN" = "no" ]; then
ARLIST="/usr/bin/*mingw*ar $ARLIST"
fi
fi
if [ x$AR != x ]; then
ARLIST="$AR $ARLIST"
fi
AR=""
for foo in $ARLIST; do
XAR=`which $foo`
if [ x$XAR = x ]; then
:
else
AR="$XAR"
echo $AR
break 2
fi
done
if [ x$AR = x ]; then
echo "not found" >&2
exit 1
fi
##### DETECT DEFAULT OUTPUT OF THE C COMPILER
echo -n "Checking for C compiler default output... "
echo "int main() { ; return 0; }" >.config.tmp.c
$CC $CC_OPTIONS .config.tmp.c
BINARY_EXT=""
FOUND=""
for foo in a_out.exe a.exe .config.tmp.exe .config.exe a.out .config.tmp a.* .config.tmp.* b.out; do
test -f "$foo" || continue
case $foo in
*.c | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj )
;;
[ab].out )
FOUND=y
break;;
*.* )
FOUND=y
BINARY_EXT=`expr "$foo" : '[^.]*\(\..*\)'`
break;;
* )
FOUND=y
break;;
#
esac
done
if [ x$FOUND = x ]; then
echo "not found"
echo "The binary output of gcc on your system was not found."
exit 1
fi
echo $foo
rm -f $foo .config.tmp.c
CC_DEFAULT_OUTPUT=$foo
if [ x$BINARY_EXT != x ]; then
echo "Default executable files extention : $BINARY_EXT"
if [ x"$BINARY_EXT" = "x.exe" ]; then
LOADABLE_EXT=".dll"
fi
fi
if [ "$WITH_WIN32" != "no" ]; then
echo -n "Checking wether $CC is able to compile windows applications... "
echo "#include <windows.h>" >.config.tmp.c
echo 'int main() { return 0; }' >>.config.tmp.c
$CC $CC_OPTIONS .config.tmp.c 2>/dev/null
if [ "$?" != "0" ]; then
echo "no"
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
echo "It seems that $CC is not able to build windows applications."
echo "Please look at the configure help"
exit 1
fi
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
echo yes
fi
##### CHECK FOR LIBM
if [ "$WITH_LIBM" = no ]; then
echo "Can't compile Freya without libm !"
exit 1
fi
echo -n "Checking for libm... "
echo "#include <stdlib.h>" >.config.tmp.c
echo "#include <math.h>" >>.config.tmp.c
echo 'int main() { printf("%d",cos(0)); return 0; }' >>.config.tmp.c
# try default even if a path is present in $WITH_LIBM
$CC $CC_OPTIONS .config.tmp.c -lm 2>/dev/null
if [ "$?" != "0" ]; then
# test with the path
$CC .config.tmp.c -L{$WITH_LIBM}/lib -lz 2>/dev/null
if [ "$?" != "0" ]; then
# try to set also for the include
$CC .config.tmp.c -L{$WITH_LIBM}/lib -I{$WITH_LIBM}/include -lz 2>/dev/null
if [ "$?" != "0" ]; then
echo "not found"
echo "libm support seems not available on your system."
echo "You need libm in order to compile freya."
exit 1
fi
# ok !
INCLUDES="$INCLUDES -I{$WITH_LIBM}/include"
LIBS="$LIBS -L{$WITH_LIBM}/lib -lm"
else
LIBS="$LIBS -L{$WITH_LIBM}/lib -lm"
fi
else
LIBS="$LIBS -lm"
fi
echo yes
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
##### CHECK FOR ZLIB
if [ "$WITH_ZLIB" = no ]; then
echo "Can't compile Freya without ZLib !"
exit 1
fi
echo -n "Checking for zlib... "
if [ x"$WITH_ZLIB" = x"yes" ]; then
if [ x"$WITH_WIN32" != x"no" ]; then
WITH_ZLIB="${PWD}/zlib"
else
WITH_ZLIB="/usr/local"
fi
fi
echo "#include <stdlib.h>" >.config.tmp.c
echo "#include <stdio.h>" >>.config.tmp.c
echo "#include <zlib.h>" >>.config.tmp.c
echo 'int main() { printf("%s",zlib_version); return 0; }' >>.config.tmp.c
# try default even if a path is present in $WITH_ZLIB
$CC $CC_OPTIONS .config.tmp.c -lz 2>/dev/null
if [ "$?" != "0" ]; then
# test with the path
$CC $CC_OPTIONS .config.tmp.c -L${WITH_ZLIB}/lib -lz 2>/dev/null
if [ "$?" != "0" ]; then
# try to set also for the include
$CC $CC_OPTIONS .config.tmp.c -L${WITH_ZLIB}/lib -I${WITH_ZLIB}/include -lz 2>/dev/null
if [ "$?" != "0" ]; then
echo "not found"
echo "ZLib support seems not available on your system."
echo "You need ZLib in order to compile freya."
if [ x"$WITH_WIN32" = x"no" ]; then
if [ -w /usr ]; then
echo "I can download and install ZLib $ZLIB_LAST_VERSION for you."
echo -n "Do you want me to do that ? [y/N]"
read ANSWER
if [ x"$ANSWER" = x"Y" ]; then ANSWER="y"; fi
if [ x"$ANSWER" != x"y" ]; then exit 1; fi
ZLIB="zlib-$ZLIB_LAST_VERSION"
# try to wget zlib...
echo "Downloading zlib..."
wget -q http://www.gzip.org/zlib/${ZLIB}.tar.gz
if [ ! -f ${ZLIB}.tar.gz ]; then
wget -q http://www.zlib.net/${ZLIB}.tar.gz
if [ ! -f ${ZLIB}.tar.gz ]; then
echo "I couldn't download $ZLIB ."
echo "Maybe this is not the last version or the two webistes are down."
echo "Or maybe ou didn't install wget !"
exit 1
fi
fi
tar xzf ${ZLIB}.tar.gz
if [ ! -d ${ZLIB} ]; then
rm -f ${ZLIB}.tar.gz
echo "Couldn't extract zlib... Please check that tar works !"
exit 1
fi
cd $ZLIB
echo "Configuring zlib..."
./configure --prefix=/usr >/dev/null
if [ "$?" != "0" ]; then
cd ..
rm -fr ${ZLIB} ${ZLIB}.tar.gz
echo "Couldn't configure zlib... Please check the error message !"
exit 1
fi
echo "Compiling zlib..."
make >/dev/null
if [ "$?" != "0" ]; then
cd ..
rm -fr ${ZLIB} ${ZLIB}.tar.gz
echo "Couldn't build zlib. Please check the error message !"
exit 1
fi
echo "Installing zlib..."
make install
if [ "$?" != "0" ]; then
cd ..
rm -fr ${ZLIB} ${ZLIB}.tar.gz
echo "Couldn't install zlib. Please check that you are root !"
exit 1
fi
cd ..
rm -fr ${ZLIB} ${ZLIB}.tar.gz
echo "ZLIB successfully built and installed. Please re-run configure !"
exit 1
fi
else
echo "You need to cross-compile ZLib in order to get it running !"
echo -n "Do you want me to do that ? [y/N]"
read ANSWER
if [ x"$ANSWER" = x"Y" ]; then ANSWER="y"; fi
if [ x"$ANSWER" != x"y" ]; then exit 1; fi
ZLIB="zlib-$ZLIB_LAST_VERSION"
# try to wget zlib...
echo "Downloading zlib..."
wget -q http://www.gzip.org/zlib/${ZLIB}.tar.gz
if [ ! -f ${ZLIB}.tar.gz ]; then
wget -q http://www.zlib.net/${ZLIB}.tar.gz
if [ ! -f ${ZLIB}.tar.gz ]; then
echo "I couldn't download $ZLIB ."
echo "Maybe this is not the last version or the two webistes are down."
echo "Or maybe ou didn't install wget !"
exit 1
fi
fi
tar xzf ${ZLIB}.tar.gz
if [ ! -d ${ZLIB} ]; then
rm -f ${ZLIB}.tar.gz
echo "Couldn't extract zlib... Please check that tar works !"
exit 1
fi
cd $ZLIB
echo "Cross-compiling ZLib..."
ZLIB_CC_OPT="-O3"
if [ x"$IS_CYGWIN" != x"no" ]; then
ZLIB_CC_OPT="$ZLIB_CC_OPT -mno-cygwin"
fi
ZLIB_OBJ="adler32 compress crc32 gzio uncompr deflate trees zutil inflate infback inftrees inffast"
ZLIB_OBJ2=""
for foo in $ZLIB_OBJ; do
$CC $ZLIB_CC_OPT -c -o ${foo}.o ${foo}.c
if [ "$?" != "0" ]; then
echo "Failed to compile ${foo}.c !"
exit 1
fi
ZLIB_OBJ2="$ZLIB_OBJ2 ${foo}.o"
done
# link the objects
$AR rcs zlib.a $ZLIB_OBJ2
if [ "$?" != "0" ]; then
echo "Failed to link objects for zlib.a !"
exit 1
fi
echo "Installing..."
cd ..
mkdir zlib zlib/lib zlib/include 2>/dev/null
cp ${ZLIB}/zlib.a zlib/lib
cp ${ZLIB}/zlib.h ${ZLIB}/zconf.h zlib/include
echo "Cleaning..."
rm -fr $ZLIB ${ZLIB}.tar.gz
WITH_ZLIB="${PWD}/zlib"
fi
fi
# ok !
INCLUDES="$INCLUDES -I${WITH_ZLIB}/include"
LIBS="$LIBS -L${WITH_ZLIB}/lib -lz"
else
LIBS="$LIBS -L${WITH_ZLIB}/lib -lz"
fi
else
LIBS="$LIBS -lz"
fi
if [ "$WITH_WIN32" = "no" ]; then
ZLIB_VERSION=`./$CC_DEFAULT_OUTPUT`
echo $ZLIB_VERSION
else
# cannot run compiled files when cross-compiling
echo "yes"
fi
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
##### CHECK FOR -ldl (non-Win32 only)
if [ x"$WITH_WIN32" = x"no" ]; then
echo -n "Checking for libdl... "
echo "#include <dlfcn.h>" >.config.tmp.c
echo 'int main() { dlclose(0); return 0; }' >>.config.tmp.c
$CC $CC_OPTIONS .config.tmp.c 2>/dev/null
if [ "$?" != "0" ]; then
$CC $CC_OPTIONS .config.tmp.c -ldl 2>/dev/null
if [ "$?" != "0" ]; then
echo "no"
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
echo "Could not find libdl."
echo "Please check that you are using an UNIX distribution."
exit 1
else
# -ldl required for libdl
LIBS="$LIBS -ldl"
fi
fi
echo yes
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
fi
##### CHECK FOR SIZE OF void*
echo -n "Checking for size of system pointers... "
if [ x"$WITH_WIN32" = x"no" ]; then
echo "#include <stdio.h>" >.config.tmp.c
echo 'int main() { printf("%d",sizeof(void *)); return 0; }' >>.config.tmp.c
$CC $CC_OPTIONS .config.tmp.c 2>/dev/null
if [ "$?" != "0" ]; then
echo "failed"
echo "Somehow, your system didn't accept to show the value of sizeof(void *)"
echo "Please report your OS and system details to the bugreport"
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
exit 1
fi
INT_SIZE=`"./$CC_DEFAULT_OUTPUT"`
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
if [ $INT_SIZE -le 0 ]; then
echo "failed"
echo "The system returned '$INT_SIZE', which is obviously wrong."
exit 1
fi
echo $INT_SIZE
echo -n "Checking for CPU int... "
echo "#include <stdio.h>" >.config.tmp.c
echo 'int main() {' >>.config.tmp.c
for foo in int long_int long_long_int short_int; do
foo2=`echo "$foo" | sed -e 's/_/ /g'`
echo 'if (sizeof('"$foo2"') == sizeof(void *)) { puts("'"$foo2"'"); return 0; }' >>.config.tmp.c
done
echo 'return 0; }' >>.config.tmp.c
$CC $CC_OPTIONS .config.tmp.c 2>/dev/null
if [ "$?" != "0" ]; then
echo "failed"
echo "Please report your OS and system details to the bugreport"
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
exit 1
fi
CPU_INT=`"./$CC_DEFAULT_OUTPUT"`
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
CPU_INT=`echo $CPU_INT` # strip newline
if [ x"$CPU_INT" = x ]; then
echo "failed"
echo "Please report your OS and system details to the bugreport"
exit 1
fi
echo $CPU_INT
else
# Win32 is 32 bits, so that's 4 bytes
echo "4"
CPU_INT="int"
fi
##### CHECK FOR FDS
# First, make sure WITH_FDS is an integer
WITH_FDS=$[ $WITH_FDS ]
if [ $WITH_FDS -lt 64 ]; then
echo "Error: --with-fds should have a value higher than or equal to 64"
exit 1
fi
# Test program
echo -n "Checking if FD_SETSIZE can be set to $WITH_FDS... "
echo "#define FD_SETSIZE $WITH_FDS" >.config.tmp.c
if [ "$WITH_WIN32" != "no" ]; then
# on win32 compiles, winsock support is important
echo "#define __USE_W32_SOCKETS" >>.config.tmp.c
echo "#include <windows.h>" >>.config.tmp.c
fi
echo "#include <sys/types.h>" >>.config.tmp.c
echo "#if FD_SETSIZE != $WITH_FDS" >>.config.tmp.c
echo "# error THATS BAD" >>.config.tmp.c
echo "#endif" >>.config.tmp.c
echo 'int main() { return 0; }' >>.config.tmp.c
$CC $CC_OPTIONS .config.tmp.c 2>/dev/null
if [ "$?" != "0" ]; then
echo "no"
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
echo "If you are running Linux, please edit /usr/include/bits/typesizes.h"
echo "and modify the value of __FD_SETSIZE to $WITH_FDS"
exit 1
fi
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
echo "ok"
##### CHECK FOR WINSOCKS2 (Win32 only)
if [ x"$WITH_WIN32" != x"no" ]; then
echo -n "Checking for winsock2... "
echo "#define __USE_W32_SOCKETS" >.config.tmp.c
echo "#include <windows.h>" >>.config.tmp.c
echo 'int main() { return 0; }' >>.config.tmp.c
$CC $CC_OPTIONS .config.tmp.c -lws2_32 2>/dev/null
if [ "$?" != "0" ]; then
echo "no"
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
echo "Your cross compiling environement seems incomplete."
echo "Please check that you have the MS Visual Studio includes in the default include path."
exit 1
fi
echo yes
LIBS="$LIBS -lws2_32"
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
fi
##### CHECK FOR MYSQL
if [ x"$WITH_MYSQL" != x"no" ]; then
echo -n "Checking for mysql... "
if [ x"$WITH_WIN32" != x"no" ]; then
echo -e "#define USE_W32_SOCKETS\n#include <windows.h>\n#include <mysql/mysql.h>\nint main() { mysql_get_client_version(); return 0; }" >.config.tmp.c
$CC $CC_OPTIONS .config.tmp.c -lmysql $LIBS -lstdc++ 2>/dev/null
if [ "$?" != "0" ]; then
echo "not found"
echo "Please make sure you have libmysql.a & mysql includes from MagicalTux in your mingw dir !"
exit 1
fi
echo "yes"
rm -f $CC_DEFAULT_OUTPUT .config.tmp.c
LIBS="$LIBS -lmysql -lstdc++"
OBJECTS="$OBJECTS login char_sql login_txt-converter char_txt-converter ladmin"
else
if [ "$WITH_MYSQL" = "yes" ]; then
WITH_MYSQL="$WITH_MYSQL_PATH"
fi
# search for mysql-config in $WITH_MYSQL_PATH, then in $PATH
WITH_MYSQL_CONFIG=""
IFS_OLD="$IFS"
IFS=$PATH_SEPARATOR
for foo in $WITH_MYSQL; do
if [ -x ${foo}/bin/mysql_config ]; then
WITH_MYSQL=$foo
WITH_MYSQL_CONFIG=${foo}/bin/mysql_config
break 2
fi
done
if [ x$WITH_MYSQL_CONFIG = x ]; then
for foo in $PATH; do
if [ -x ${foo}/mysql_config ]; then
WITH_MYSQL=`dirname "$foo"`
WITH_MYSQL_CONFIG=${foo}/mysql_config
break 2
fi
done
fi
IFS="$IFS_OLD"
if [ x$WITH_MYSQL_CONFIG = x ]; then
echo "not found"
echo "Try to configure with --with-mysql=/path/to/mysql"
echo "or disable mysql support with --without-mysql"
exit
else
MYSQL_VERSION=`$WITH_MYSQL_CONFIG --version`
MYSQL_VERSION_MAJOR=`echo $MYSQL_VERSION | cut -d. -f1`
if [ "$MYSQL_VERSION_MAJOR" -le 3 ]; then
CC_OPTIONS="$CC_OPTIONS "`$WITH_MYSQL_CONFIG --cflags`
else
INCLUDES="$INCLUDES "`$WITH_MYSQL_CONFIG --include`
fi
SQL_LIBS=`$WITH_MYSQL_CONFIG --libs`
LIBS="$LIBS $SQL_LIBS"
echo "$MYSQL_VERSION in $WITH_MYSQL"
OBJECTS="$OBJECTS login char_sql login_txt-converter char_txt-converter ladmin"
fi
fi
else
OBJECTS="$OBJECTS login char ladmin tool"
fi
# add common objects that needs to be at the end (map)
OBJECTS="$OBJECTS map"
##### CLEANUP $LIBS AND $INCLUDES A BIT (to make them look better)
LIBS=`echo $LIBS | sed 's/ +/ /'`
INCLUDES=`echo $INCLUDES | sed 's/ +/ /'`
# find out dups
NEWLIBS=""
set dummy $LIBS
while true; do
LIB="$2"
if [ x$LIB = x ]; then
break
fi
case $LIB in
-L*)
shift
continue
;;
-l*)
# nothing to do
:
;;
*)
echo "Bad value $LIB found in LIBS !"
echo "LIBS=$LIBS"
echo "Please send that to the bug report !"
exit 1
;;
esac
LIBDIR=""
case $1 in
-L*)
LIBDIR="$1 "
;;
esac
# check if LIB is already in $NEWLIBS
TEST=`echo "$NEWLIBS" | grep -- "$LIB"`
if [ "x$TEST" = x ]; then
# add lib to NEWLIBS
NEWLIBS="$NEWLIBS ${LIBDIR}$LIB"
fi
shift
done
LIBS=`echo $NEWLIBS`
# reorder libs : some libs must be at the end
for foo in $LAST_LIBS; do
foo2=`echo "$LIBS " | sed "s/$foo //;"`
if [ x"$LIBS " != x"$foo2" ]; then
LIBS="$foo2 $foo"
fi
done
LIBS=`echo $LIBS`
##### CLEANUP $srcdir FOR MAKEFILES
echo -n "Cleaning up source dir (removing Makefiles)..."
(
find $srcdir -name Makefile
find $srcdir -name GNUmakefile
find $srcdir -name makefile
)|(
while read foo; do
rm -f $foo
done
)
echo "done"
##### GENERATE config.h
echo "Generating $CONFIGFILE ..."
cat >$CONFIGFILE <<EOF
/* Configuration file for Freya
* $VERSION
*
* This file is generated. Do not edit it.
*/
#ifndef __FREYA_CONFIG_H_
#define __FREYA_CONFIG_H_
EOF
if [ "$WITH_MYSQL" != no ]; then
echo "/* MySQL support enabled */" >>$CONFIGFILE
echo "#undef TXT_ONLY" >>$CONFIGFILE
echo "#define USE_SQL" >>$CONFIGFILE
echo "#define USE_MYSQL" >>$CONFIGFILE
echo >>$CONFIGFILE
else
echo "/* MySQL support disabled */" >>$CONFIGFILE
echo "#define TXT_ONLY" >>$CONFIGFILE
echo "#undef USE_SQL" >>$CONFIGFILE
echo "#undef USE_MYSQL" >>$CONFIGFILE
echo >>$CONFIGFILE
fi
if [ "$IS_CYGWIN" != no ]; then
echo "/* Cygwin environement */" >>$CONFIGFILE
echo "#define __CYGWIN" >>$CONFIGFILE
echo >>$CONFIGFILE
else
echo "/* Standard unix environement */" >>$CONFIGFILE
echo "#undef __CYGWIN" >>$CONFIGFILE
echo >>$CONFIGFILE
fi
if [ x"$IS_CYGWIN" != x"no" ]; then
echo "/* reset CYGWIN:s FD_SETSIZE value */" >>$CONFIGFILE
echo "#ifdef FD_SETSIZE" >>$CONFIGFILE
echo "#undef FD_SETSIZE" >>$CONFIGFILE
echo "#endif" >>$CONFIGFILE
echo "#define FD_SETSIZE $WITH_FDS" >>$CONFIGFILE
echo >>$CONFIGFILE
fi
if [ x"$WITH_WIN32" != x"no" ]; then
# win32 support...
echo "/* Win32 support enabled */" >>$CONFIGFILE
echo "#ifndef __WIN32" >>$CONFIGFILE
echo "#define __WIN32" >>$CONFIGFILE
echo "#warning Your Win32 compiler is broken, it should define __WIN32 by himself !" >>$CONFIGFILE
echo "#endif" >>$CONFIGFILE
echo "#ifdef FD_SETSIZE" >>$CONFIGFILE
echo "#undef FD_SETSIZE" >>$CONFIGFILE
echo "#endif" >>$CONFIGFILE
echo "#define FD_SETSIZE $WITH_FDS" >>$CONFIGFILE
echo >>$CONFIGFILE
else
echo "/* Win32 support disabled */" >>$CONFIGFILE
echo "#undef __WIN32" >>$CONFIGFILE
echo >>$CONFIGFILE
# debian linux need that (default 1024 set on __FD_SETSIZE passed to FD_SETSIZE)...
echo "/* debian linux (and some other linux) need that */" >>$CONFIGFILE
echo "#ifdef FD_SETSIZE" >>$CONFIGFILE
echo "#undef FD_SETSIZE" >>$CONFIGFILE
echo "#endif" >>$CONFIGFILE
echo "#define FD_SETSIZE $WITH_FDS" >>$CONFIGFILE
echo >>$CONFIGFILE
fi
echo "/* enable dynamic addon linking */" >>$CONFIGFILE
echo "#define DYNAMIC_LINKING" >>$CONFIGFILE
echo >>$CONFIGFILE
# usage of standard ISO/IEC 9899:1999
if [ x"$WITH_C99" = x"yes" ]; then
echo "#ifdef __STDC_VERSION__" >>$CONFIGFILE
echo "# if __STDC_VERSION__ >= 199901L" >>$CONFIGFILE
echo "# ifndef WITH_C99" >>$CONFIGFILE
echo "# define WITH_C99" >>$CONFIGFILE
echo "# endif" >>$CONFIGFILE
echo "# endif" >>$CONFIGFILE
echo "#endif" >>$CONFIGFILE
echo >>$CONFIGFILE
fi
# CPU int for AMD64 support
echo "/* CPU INT detected. This int is equal in term of size to the void * pointer size */" >>$CONFIGFILE
echo "#define CPU_INT $CPU_INT" >>$CONFIGFILE
echo >>$CONFIGFILE
# loadable modules extention
echo '#define ADDONS_EXT "'`echo $LOADABLE_EXT | cut -d'"' -f- --output-delimiter='\"'`'"' >>$CONFIGFILE
# few things...
echo "/* configure misc */" >>$CONFIGFILE
echo '#define CONF_PLATFORM "'`echo $PLATFORM | cut -d'"' -f- --output-delimiter='\"'`'"' >>$CONFIGFILE
echo '#define CONF_PREFIX "'`echo $PREFIX | cut -d'"' -f- --output-delimiter='\"'`'"' >>$CONFIGFILE
echo '#define CONF_DATE "'`date -R | cut -d'"' -f- --output-delimiter='\"'`'"' >>$CONFIGFILE
echo '#define CONF_CONFIGURE "'`echo $CONFIGURE_LINE | cut -d'"' -f- --output-delimiter='\"'`'"' >>$CONFIGFILE
echo '#define CONF_INCLUDES "'`echo $INCLUDES | cut -d'"' -f- --output-delimiter='\"'`'"' >>$CONFIGFILE
echo '#define CONF_LIBS "'`echo $LIBS | cut -d'"' -f- --output-delimiter='\"'`'"' >>$CONFIGFILE
echo >>$CONFIGFILE
echo '#endif' >>$CONFIGFILE
echo >>$CONFIGFILE
##### GENERATE Makefile
# Make sure $CONFIGFILE exists
touch $CONFIGFILE
MAKE_RULES=""
MAKE_CLEAN_RULES=""
BUILD_LINE="Compiling Freya v${FREYA_VERSION} (SVN#\$(SVN))"
BUILD_OPT=""
if [ x"$WITH_MYSQL" != x"no" ]; then
BUILD_OPT="$BUILD_OPT MySQL"
fi