-
-
Notifications
You must be signed in to change notification settings - Fork 116
/
configure
executable file
·1034 lines (966 loc) · 31.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
#####################################################################
# set default values
OPT_STATIC=auto
OPT_OPENSSL=auto
OPT_OPENSSL_RUNTIME=auto
OPT_GETTEXT=auto
OPT_CC=
export LC_ALL=C
CFG_LINE="$*"
INSTALL_PREFIX="/usr/local"
test -z "$CC" && CC=cc
CMD_AR=ar
CMD_INSTALL=install
BUILD_DEBUG=
BUILD_EXTRA_CFLAGS=
BUILD_EXTRA_LDFLAGS=
CHECK_LDFLAGS=
WARN_CFLAGS="-Wall -W -Wstrict-prototypes -Wnested-externs -Winline -Wpointer-arith -Wbad-function-cast -Wmissing-prototypes -Wmissing-declarations"
INSTALL_SYMLINKS="sfv-hash has160-hash gost12-256-hash gost12-512-hash edonr256-hash edonr512-hash tiger-hash tth-hash whirlpool-hash ed2k-link magnet-link"
INSTALL_LIB_STATIC=auto
INSTALL_LIB_SHARED=auto
INSTALL_PKGCONFIGDIR="$PKG_INSTALLDIR"
SHARED_LIB_MODE=${SHARED_LIB_MODE:-755}
#####################################################################
# detect and prepare temp directory
for DETECT_TMP in "$TMPDIR" "$TEMPDIR" "/tmp"; do
test -d "$DETECT_TMP" && break
done
RANDNUM=$RANDOM
test -z "$RANDNUM" && jot -r 1 2>/dev/null >dev/null && RANDNUM=$(jot -r 1 1 32767) || RANDNUM=0
BUILD_TMPDIR="$DETECT_TMP/rhash-configure-$RANDNUM-$$"
mkdir $BUILD_TMPDIR || die "Unable to create tmp dir."
TMPC="$BUILD_TMPDIR/tmp.c"
TMPT="$BUILD_TMPDIR/tmp.txt"
TMPBIN="$BUILD_TMPDIR/tmp"
TMPLOG="config.log"
rm -f "$TMPLOG"
echo "Configuration parameters: \"$CFG_LINE\"" > "$TMPLOG"
echo "Symlinks to install: $INSTALL_SYMLINKS" >> "$TMPLOG"
echo >> "$TMPLOG"
remove_tmpdir()
{
rm -rf "$BUILD_TMPDIR"
}
trap remove_tmpdir EXIT
#####################################################################
# display error message and exit
die() {
echo
echo "Error: $@" >&2
echo >&2
test -f "$TMPLOG" && echo "Error: $@" >> "$TMPLOG"
rm -f "$TMPBIN" "$TMPC" "$TMPT"
echo "Check \"$TMPLOG\" if you do not understand why it failed."
exit 1
}
#####################################################################
# helper functions for options parsing
print_help()
{
cat << EOF
Usage: configure [OPTIONS]...
Generic Options:
-h, --help display this help and exit
--cc=COMPILER C compiler to build RHash [gcc]
--ar=AR librarian to build RHash [ar]
--target=PLATFORM target platform (i386-linux, arm-linux, etc)
--with-install=PATH path to a custom install program
Directory Options:
--prefix=DIR prefix directory for installation [/usr/local]
--exec-prefix=DIR prefix directory for binaries [PREFIX]
--bindir=DIR directory for installing binaries [EXEC_PREFIX/bin]
--sysconfdir=DIR directory to look for configuration file
[PREFIX/etc]
--mandir=DIR directory for installing man pages [PREFIX/share/man]
--libdir=DIR directory for the rhash library [EXEC_PREFIX/lib]
--pkgconfigdir=DIR directory for pkg-config files [LIBDIR/pkgconfig]
--localedir=DIR directory for locale files [PREFIX/share/locale]
Features options:
--disable-FEATURE do not include FEATURE
--enable-gettext enable gettext (localization) support [autodetect]
--enable-openssl[=runtime] enable OpenSSL (optimized hash functions) support.
If runtime specified, then load OpenSSL at runtime if
the library is found [autodetect]
--enable-debug enable debug information [disable]
--enable-static[=librhash] statically link all libraries or (if =librhash)
only the LibRHash library into RHash binary [disable]
--enable-lib-static build and install LibRHash static library [auto]
--enable-lib-shared build and install LibRHash shared library [auto]
--enable-symlinks[=LIST] install symlinks to the binary [enable]
Use these options if autodetection fails:
--extra-cflags=FLAGS extra CFLAGS
--extra-ldflags=FLAGS extra LDFLAGS
EOF
exit 0
}
check_set_contains()
{
VALUE="$1"
shift
for VALID_VALUE do
if test "$VALUE" = "$VALID_VALUE"; then
return 0
fi
shift
done
return 1
}
get_opt_value()
{
echo $(echo $* | cut -d '=' -f 2-)
}
#####################################################################
# parse the command line options passed to the configure script
for OPT do
case "$OPT" in
--help|-help|-h)
print_help
;;
--prefix=*)
INSTALL_PREFIX=$(get_opt_value $OPT)
;;
--exec-prefix=*)
INSTALL_EXEC_PREFIX=$(get_opt_value $OPT)
INSTALL_EXEC_PREFIX_SET=yes
;;
--bindir=*)
INSTALL_BINDIR=$(get_opt_value $OPT)
;;
--mandir=*)
INSTALL_MANDIR=$(get_opt_value $OPT)
;;
--sysconfdir=*)
INSTALL_SYSCONFDIR=$(get_opt_value $OPT)
;;
--libdir=*)
INSTALL_LIBDIR=$(get_opt_value $OPT)
;;
--pkgconfigdir=*)
INSTALL_PKGCONFIGDIR=$(get_opt_value $OPT)
;;
--localedir=*)
INSTALL_LOCALEDIR=$(get_opt_value $OPT)
;;
--enable-gettext)
OPT_GETTEXT=yes
;;
--disable-gettext)
OPT_GETTEXT=no
;;
--enable-openssl)
OPT_OPENSSL=yes
;;
--enable-openssl=*)
OPT_OPENSSL=$(get_opt_value $OPT)
check_set_contains "$OPT_OPENSSL" "runtime" || die "Unexpected option value: $OPT"
;;
--disable-openssl)
OPT_OPENSSL=no
;;
--enable-openssl-runtime)
OPT_OPENSSL=runtime # legacy option
echo "warning: use --enable-openssl=runtime instead of $OPT" >> "$TMPLOG"
;;
--disable-openssl-runtime)
OPT_OPENSSL=yes # legacy option
echo "warning: use --enable-openssl instead of $OPT" >> "$TMPLOG"
;;
--target=*)
BUILD_TARGET=$(get_opt_value $OPT)
;;
--cc=*)
CC=$(get_opt_value $OPT)
OPT_CC=1
;;
--ar=*)
CMD_AR=$(get_opt_value $OPT)
;;
--enable-static)
OPT_STATIC=yes
;;
--enable-static=librhash)
OPT_STATIC=librhash
;;
--disable-static)
OPT_STATIC=no
;;
--enable-lib-static)
INSTALL_LIB_STATIC=yes
;;
--disable-lib-static)
INSTALL_LIB_STATIC=no
;;
--enable-lib-shared)
INSTALL_LIB_SHARED=yes
;;
--disable-lib-shared)
INSTALL_LIB_SHARED=no
;;
--enable-symlinks)
# use default INSTALL_SYMLINKS list
;;
--enable-symlinks=*)
INSTALL_SYMLINKS=$(get_opt_value $OPT)
;;
--disable-symlinks)
INSTALL_SYMLINKS=
;;
--enable-debug)
BUILD_DEBUG='-g'
;;
--enable-debug=*)
BUILD_DEBUG='-g '$(get_opt_value $OPT)
;;
--disable-debug)
BUILD_DEBUG=
;;
--with-install=*)
CMD_INSTALL=$(get_opt_value $OPT)
;;
--extra-cflags=*)
BUILD_EXTRA_CFLAGS="$BUILD_EXTRA_CFLAGS $(get_opt_value $OPT)"
;;
--extra-ldflags=*)
BUILD_EXTRA_LDFLAGS="$BUILD_EXTRA_LDFLAGS $(get_opt_value $OPT)"
;;
*)
echo "unknown option $OPT"
exit 1
;;
esac
shift
done
#####################################################################
# set variables which use INSTALL_PREFIX
test -z "$INSTALL_EXEC_PREFIX_SET" && INSTALL_EXEC_PREFIX="$INSTALL_PREFIX"
test -z "$INSTALL_BINDIR" && INSTALL_BINDIR="$INSTALL_EXEC_PREFIX/bin"
test -z "$INSTALL_MANDIR" && INSTALL_MANDIR="$INSTALL_PREFIX/share/man"
test -z "$INSTALL_SYSCONFDIR" && INSTALL_SYSCONFDIR="$INSTALL_PREFIX/etc"
test -z "$INSTALL_INCDIR" && INSTALL_INCDIR="$INSTALL_PREFIX/include"
test -z "$INSTALL_LIBDIR" && INSTALL_LIBDIR="$INSTALL_EXEC_PREFIX/lib"
test -z "$INSTALL_PKGCONFIGDIR" && INSTALL_PKGCONFIGDIR="$INSTALL_LIBDIR/pkgconfig"
test -z "$INSTALL_LOCALEDIR" && INSTALL_LOCALEDIR="$INSTALL_PREFIX/share/locale"
#####################################################################
# logging functions
log_start()
{
echo "============ Checking for $1 ============" >> "$TMPLOG"
}
log_finish()
{
echo "=============================================" >> "$TMPLOG"
echo "" >> "$TMPLOG"
}
# echo and log a start of a check
start_check() {
log_start "$1"
printf '%s' "Checking for $1 ... "
res_comment=""
}
# echo and log the results of a check
finish_check() {
if test -n "$res_comment"; then
res_comment="($res_comment)"
fi
echo "Result is: $1 $res_comment" >> "$TMPLOG"
log_finish
echo "$1 $res_comment"
res_comment=""
}
#####################################################################
# detect source directories
start_check "sources"
HAS_RHASH=no
HAS_LIBRHASH=no
HAS_BINDINGS=no
RHASH_VERSION=
RHASH_VERSION_MAJOR=
RHASH_XVERSION=
BINDINGS_VERSION=
RHASH_SRC=
LIBRHASH_SRC=
LIBRHASH_PC=
BINDINGS_SRC=
SRC_FOUND=no
test -f Makefile || die "Makefile not found"
if test -f rhash_main.c; then
HAS_RHASH=yes
SRC_FOUND=RHash
if test -d librhash; then
HAS_LIBRHASH=yes
LIBRHASH_SRC=librhash/
fi
if test -f bindings/version.properties; then
HAS_BINDINGS=yes
BINDINGS_SRC=bindings/
fi
elif test -f rhash.c; then
HAS_LIBRHASH=yes
SRC_FOUND=LibRHash
elif test -f version.properties; then
HAS_BINDINGS=yes
SRC_FOUND="RHash bindings"
fi
echo "RHASH_SRC=$RHASH_SRC, LIBRHASH_SRC=$LIBRHASH_SRC, BINDINGS_SRC=$BINDINGS_SRC" >> "$TMPLOG"
#####################################################################
# check RHash version
good_version() { echo "$1" | grep -q '^[1-9]\.[1-9][0-9]*\.[0-9]' ; }
if test "$HAS_RHASH" = "yes" || test "$HAS_LIBRHASH" = "yes"; then
test -f "${RHASH_SRC}version.h" || die "${RHASH_SRC}version.h not found"
RHASH_VERSION=$(cut -d'"' -f2 "${RHASH_SRC}version.h")
echo "RHASH_VERSION=$RHASH_VERSION" >> "$TMPLOG"
good_version "$RHASH_VERSION" || die "wrong version: $RHASH_VERSION"
_v1=$(echo $RHASH_VERSION | cut -d '.' -f 1)
_v2=$(echo $RHASH_VERSION | cut -d '.' -f 2)
_v3=$(echo $RHASH_VERSION | cut -d '.' -f 3)
RHASH_VERSION_MAJOR=$_v1
RHASH_XVERSION=$(printf "0x%02x%02x%02x%02x" "$_v1" "$_v2" "$_v3" 0)
test "$HAS_LIBRHASH" = "yes" && LIBRHASH_PC=dist/librhash.pc
fi
if test "$HAS_BINDINGS" = "yes"; then
BINDINGS_VERSION=$(cut -d = -f 2 "${BINDINGS_SRC}version.properties")
echo "BINDINGS_VERSION=$BINDINGS_VERSION" >> "$TMPLOG"
good_version "$BINDINGS_VERSION" || die "wrong bindings version: $BINDINGS_VERSION"
test -z "$RHASH_VERSION" && RHASH_VERSION="$BINDINGS_VERSION"
fi
test -n "$RHASH_VERSION" && SRC_FOUND="$SRC_FOUND $RHASH_VERSION"
finish_check "$SRC_FOUND"
test "$SRC_FOUND" = "no" && die "sources not found"
if test "$HAS_BINDINGS" = "yes" && test "$BINDINGS_VERSION" != "$RHASH_VERSION"; then
echo "Updating ${BINDINGS_SRC}version.properties"
echo "version=$RHASH_VERSION" > ${BINDINGS_SRC}version.properties
fi
#####################################################################
# helper functions for compilation checks
join_params()
{
printf '%s ' $@ | sed -e 's/ $//'
}
run_cmd() {
echo "Run: $@" >> "$TMPLOG"
$@ >> "$TMPLOG" 2>&1
TMPRES="$?"
echo "Run result: $TMPRES" >> "$TMPLOG"
echo >> "$TMPLOG"
return "$TMPRES"
}
yn_nonempty()
{
test -n "$1" && echo yes || echo no;
}
# try to run a source file compilation and return the exit code
compile_check() {
source="$1"
shift
echo >> "$TMPLOG"
echo "----- source file: $source -----" >> "$TMPLOG"
cat "$source" >> "$TMPLOG"
echo "----- end of file: $source -----" >> "$TMPLOG"
echo "$CC $OPTFLAGS $WARN_CFLAGS $CFLAGS $source $BUILD_EXTRA_CFLAGS $BUILD_EXTRA_LDFLAGS $CHECK_LDFLAGS -o $TMPBIN $@" >> "$TMPLOG"
rm -f "$TMPBIN"
$CC $OPTFLAGS $WARN_CFLAGS $CFLAGS "$source" $BUILD_EXTRA_CFLAGS $BUILD_EXTRA_LDFLAGS $CHECK_LDFLAGS -o "$TMPBIN" "$@" >> "$TMPLOG" 2>&1
TMPRES="$?"
echo "Compilation result: $TMPRES" >> "$TMPLOG"
echo >> "$TMPLOG"
return "$TMPRES"
}
cc_check() {
compile_check $TMPC $@
}
create_c_file() {
rm -f "$TMPC"
if test -n "$1"; then
echo "#include <$1>" > $TMPC || die "Can't write to the $TMPC file"
fi
}
cc_check_macro() {
create_c_file "$1"
cat >> $TMPC << EOF
#ifndef $2
#error condition not true: $2
#endif
int main(void) { return 0; }
EOF
shift 2
cc_check $@
}
cc_check_cflag() {
echo "int main(void) { return 0; }" > $TMPC
cc_check $@
}
cc_check_headers() {
rm -f "$TMPC"
while test -n "$1"; do
echo "#include <$1>" >> $TMPC
shift
done
echo "int main(void) { return 0; }" >> $TMPC
cc_check "-c"
}
cc_check_statement() {
create_c_file "$1"
cat >> $TMPC << EOF
int main(void) {
$2
return 0;
}
EOF
shift 2
cc_check $@
}
#####################################################################
# detect host and target OS
start_check "target OS"
HOST_OS=$(uname -s 2>&1)
case "$HOST_OS" in
Linux|FreeBSD|NetBSD|OpenBSD|DragonFly|BSD/OS|Darwin|SunOS|QNX|GNU|MorphOS|AIX|AmigaOS|Haiku)
;;
IRIX*)
HOST_OS=IRIX
;;
GNU/kFreeBSD)
HOST_OS=FreeBSD
;;
HP-UX*)
HOST_OS=HP-UX
;;
MINGW32*)
HOST_OS=MINGW32
;;
MINGW64*)
HOST_OS=MINGW64
;;
MSYS*)
HOST_OS=MSYS
;;
[cC][yY][gG][wW][iI][nN]*)
HOST_OS=CYGWIN
;;
OS/2*)
HOST_OS=OS/2
;;
*)
HOST_OS="$HOST_OS-UNKNOWN"
;;
esac
if test -z "$BUILD_TARGET"; then
# host's CPU/instruction set
set_host_arch() {
case "$1" in
x86_64|amd64|i[3-9]86*|i86pc|x86|x86pc|k5|k6|k6_2|k6_3|k6-2|k6-3|pentium*|athlon*|i586_i686|i586-i686) HOST_ARCH=i386 ;;
ia64) HOST_ARCH=ia64 ;;
macppc|ppc*|Power*) HOST_ARCH=ppc ;;
alpha) HOST_ARCH=alpha ;;
sun4*|sparc*) HOST_ARCH=sparc ;;
parisc*|hppa*|9000*) HOST_ARCH=hppa ;;
aarch64*) HOST_ARCH=aarch64 ;;
arm*|zaurus|cats) HOST_ARCH=arm ;;
sh3|sh4|sh4a) HOST_ARCH=sh ;;
s390) HOST_ARCH=s390 ;;
s390x) HOST_ARCH=s390x ;;
*mips*) HOST_ARCH=mips ;;
nios2) HOST_ARCH=nios2 ;;
vax) HOST_ARCH=vax ;;
xtensa*) HOST_ARCH=xtensa ;;
*) HOST_ARCH=UNKNOWN ;;
esac
}
set_host_arch "$(uname -m 2>&1)"
if test "$HOST_ARCH" = UNKNOWN; then
set_host_arch "$(uname -p 2>&1)"
fi
TARGET_OS="$HOST_OS"
TARGET_ARCH="$HOST_ARCH"
else
set_target_os() {
component=$1
part=$(echo $BUILD_TARGET | cut -d '-' -f $component)
case "$(echo $part | tr '[A-Z]' '[a-z]')" in
linux|uclinux) TARGET_OS=Linux ;;
freebsd*) TARGET_OS=FreeBSD ;;
gnu/kfreebsd) TARGET_OS=FreeBSD ;;
netbsd) TARGET_OS=NetBSD ;;
bsd/os) TARGET_OS=BSD/OS ;;
openbsd) TARGET_OS=OpenBSD ;;
dragonfly) TARGET_OS=DragonFly ;;
sunos|solaris2.*) TARGET_OS=SunOS ;;
qnx) TARGET_OS=QNX ;;
morphos) TARGET_OS=MorphOS ;;
amigaos) TARGET_OS=AmigaOS ;;
mingw32*) TARGET_OS=MINGW32 ;;
wine) TARGET_OS=Wine ;;
darwin*) TARGET_OS=Darwin ;;
cygwin*) TARGET_OS=CYGWIN ;;
esac
}
TARGET_OS="UNKNOWN"
set_target_os 3
if test "$TARGET_OS" = UNKNOWN; then
set_target_os 2
fi
TARGET_ARCH=$(echo $BUILD_TARGET | cut -d '-' -f 1)
if test "$(echo $TARGET_ARCH)" != "x86_64"; then
TARGET_ARCH=$(echo $TARGET_ARCH | tr '_' '-')
fi
fi
echo "Host OS : $HOST_OS" >> "$TMPLOG"
echo "Target OS : $TARGET_OS" >> "$TMPLOG"
echo "Target ARCH: $TARGET_ARCH" >> "$TMPLOG"
finish_check "$TARGET_OS"
test "$TARGET_OS" = UNKNOWN && die "Unknown target OS, please specify the --target option"
OS_LC="$(echo $TARGET_OS | tr '[A-Z]' '[a-z]')"
aix() { test "$OS_LC" = "aix"; }
amigaos() { test "$OS_LC" = "amigaos"; }
bsdos() { test "$OS_LC" = "bsd/os"; }
darwin() { test "$OS_LC" = "darwin"; }
dragonfly() { test "$OS_LC" = "dragonfly"; }
freebsd() { test "$OS_LC" = "freebsd" || test "$OS_LC" = "gnu/kfreebsd"; }
gnu() { test "$OS_LC" = "gnu"; }
hpux() { test "$OS_LC" = "hp-ux"; }
irix() { test "$OS_LC" = "irix"; }
linux() { test "$OS_LC" = "linux"; }
mingw32() { test "$OS_LC" = "mingw32"; }
mingw64() { test "$OS_LC" = "mingw64"; }
msys() { test "$OS_LC" = "msys"; }
cygwin() { test "$OS_LC" = "cygwin"; }
netbsd() { test "$OS_LC" = "netbsd"; }
openbsd() { test "$OS_LC" = "openbsd"; }
os2() { test "$OS_LC" = "os/2"; }
qnx() { test "$OS_LC" = "qnx"; }
sunos() { test "$OS_LC" = "sunos"; }
wine() { test "$OS_LC" = "wine"; }
win32() { cygwin || mingw32 || mingw64 || msys || wine; }
bsd() { dragonfly || freebsd || netbsd || openbsd ; }
posix_make() { aix || bsdos || hpux || irix || qnx || sunos; }
#####################################################################
# Checking CC version...
# Intel C++ Compilers (no autoselect, use CC=/some/binary ./configure)
cc_vendor=
if test "$(basename $CC)" = "icc" || test "$(basename $CC)" = "ecc"; then
start_check "$CC version"
cc_vendor=intel
cc_name=$($CC -V 2>&1 | head -n 1 | cut -d ',' -f 1)
cc_version=$($CC -V 2>&1 | head -n 1 | cut -d ',' -f 2 | cut -d ' ' -f 3)
_cc_major=$(echo $cc_version | cut -d '.' -f 1)
_cc_minor=$(echo $cc_version | cut -d '.' -f 2)
case $cc_version in
'')
cc_version="v. ?.??, bad"
cc_fail=yes
;;
10.1|11.1|12.*|13.*|20*)
cc_version="$cc_version, ok"
;;
*)
cc_version="$cc_version, bad"
cc_fail=yes
;;
esac
finish_check "$cc_version"
else
CC_TMP="$CC"
test -n "$OPT_CC" && OTHER_CC= || OTHER_CC="gcc cc"
for CC in "$CC_TMP" $OTHER_CC; do
cc_name_tmp=
if run_cmd "$CC -v"; then
cc_name_tmp=$($CC -v 2>&1 | tail -n 1 | cut -d ' ' -f 1)
elif run_cmd "$CC --version"; then
cc_name_tmp=$($CC --version 2>&1 | head -n 1 | cut -d ' ' -f 1)
fi
if echo "$cc_name_tmp" | grep -q "gcc"; then
cc_name=$cc_name_tmp
start_check "$CC version"
cc_vendor=gnu
cc_version=$($CC -dumpversion 2>&1)
if ! echo $cc_version | grep -q '^[0-9][0-9]*\.[0-9]'; then
cc_v2=$($CC -dumpfullversion -dumpversion 2>/dev/null)
if echo $cc_v2 | grep -q '^[0-9][0-9]*\.[0-9]'; then
cc_version=$cc_v2
fi
fi
case $cc_version in
2.96*)
cc_fail=yes
;;
*)
_cc_major=$(echo $cc_version | cut -d '.' -f 1)
_cc_minor=$(echo $cc_version | cut -d '.' -f 2)
_cc_mini=$(echo $cc_version | cut -d '.' -f 3)
;;
esac
finish_check "$cc_name $cc_version"
break
elif $CC --version 2>&1 | grep -q "clang"; then
start_check "$CC version"
cc_vendor=clang
cc_version=$($CC -dumpversion 2>&1)
finish_check "clang $cc_version"
break
else
cc_name_tmp=$($CC -V 2>&1 | head -n 1 | cut -d ' ' -f 2,3)
if test "$cc_name_tmp" = "Sun C"; then
start_check "$CC version"
cc_vendor=sun
cc_version=$($CC -V 2>&1 | head -n 1 | cut -d ' ' -f 4)
res_comment="experimental support"
finish_check "Sun C $cc_version"
break
fi
fi
done
fi # icc
test -z "$cc_vendor" && die "compiler not found"
test "$cc_fail" = "yes" && die "unsupported compiler version"
log_start "compiler working with default options"
if ! cc_check_cflag; then
die "compiler doesn't work"
fi
log_finish
if test "$cc_name" = "gcc" && test "$_cc_major" -gt 3; then
WARN_CFLAGS="$WARN_CFLAGS -Wdeclaration-after-statement"
fi
#####################################################################
# select optimization flags
has_optimization()
{
# posix-compatible way to find -O<n> option
for OPT in $BUILD_EXTRA_CFLAGS $BUILD_DEBUG; do
case "$OPT" in
-O[0-3]|-O) return 0 ;;
esac
done
return 1
}
has_optimization && OPTLEVEL= || OPTLEVEL="-O2"
test -n "$BUILD_DEBUG" && OPTNDEBUG= || OPTNDEBUG="-DNDEBUG"
OPTFLAGS="-pipe -ffunction-sections -fdata-sections"
check_set_contains "-fno-omit-frame-pointer" $BUILD_EXTRA_CFLAGS $BUILD_DEBUG \
|| OPTFLAGS="$OPTFLAGS -fomit-frame-pointer"
OPTFLAGS=$(join_params $BUILD_DEBUG $OPTLEVEL $OPTNDEBUG $OPTFLAGS)
# test that compiler works with options specified by command line
log_start "compiler working with provided options"
if ! cc_check_cflag; then
die "wrong compiler options provided"
fi
log_finish
#####################################################################
# detect proper shared library name
SHARED_PREFIX="lib"
STATIC_PREFIX="lib"
STATIC_EXT=".a"
SHARED_EXT=".so.${RHASH_VERSION_MAJOR}"
SO_MAJ_EXT=".so.${RHASH_VERSION_MAJOR}"
SOLINK_EXT=".so"
EXEC_EXT=
NEED_IMPLIB=no
NEED_SOLINK=yes
INSTALL_SO_DIR=$INSTALL_LIBDIR
LN_S="ln -sf"
if win32; then
LN_S="cp -pR"
EXEC_EXT=".exe"
SHARED_EXT=".dll"
SO_MAJ_EXT=$SHARED_EXT
NEED_IMPLIB=yes
NEED_SOLINK=no
INSTALL_SO_DIR=$INSTALL_BINDIR
if msys; then
SHARED_PREFIX="msys-"
elif cygwin; then
SHARED_PREFIX="cyg"
fi
elif darwin; then
SHARED_EXT=".${RHASH_VERSION}.dylib"
SO_MAJ_EXT=".${RHASH_VERSION_MAJOR}.dylib"
SOLINK_EXT=".dylib"
elif linux || bsd; then
# use the full library version for the library file extension
SHARED_EXT=".so.${RHASH_VERSION}"
fi
#####################################################################
# check for linker flags
LD_STATIC=
test "$OPT_STATIC" = "auto" && OPT_STATIC=no
if test "$OPT_STATIC" = "yes"; then
LD_STATIC=-static
test "$OPT_OPENSSL" = "runtime" && ! win32 && LD_STATIC=
fi
if test -n "$LD_STATIC"; then
start_check "linker support for $LD_STATIC"
if cc_check_cflag "$LD_STATIC"; then
test "$OPT_STATIC" = "yes" && CHECK_LDFLAGS=$LD_STATIC
else
LD_STATIC=
fi
finish_check $(yn_nonempty "$LD_STATIC")
fi
LIBDL_LDFLAGS=
if win32; then
ALLOW_RUNTIME_LINKING=yes
elif test "$OPT_STATIC" = "yes"; then
ALLOW_RUNTIME_LINKING=no
test "$OPT_OPENSSL" = "runtime" && die "static linking is incompatible with OpenSSL runtime loading"
elif test "$OPT_OPENSSL" = "auto" || test "$OPT_OPENSSL" = "runtime"; then
start_check "linker support for dlopen"
ALLOW_RUNTIME_LINKING=no
if cc_check_statement "dlfcn.h" 'dlopen("", RTLD_NOW);'; then
ALLOW_RUNTIME_LINKING=yes
elif cc_check_statement "dlfcn.h" 'dlopen("", RTLD_NOW);' "-ldl"; then
ALLOW_RUNTIME_LINKING=yes
LIBDL_LDFLAGS="-ldl"
fi
finish_check "$ALLOW_RUNTIME_LINKING"
fi
SHARED_VSCRIPT=
if ! darwin; then
start_check "linker support for --version-script"
echo "{ local: *; };" > $TMPT
cc_check_cflag "-Wl,--version-script,$TMPT -shared" &&
SHARED_VSCRIPT=",--version-script,exports.sym"
finish_check $(yn_nonempty "$SHARED_VSCRIPT")
fi
WIN_LDFLAGS=
if win32; then
start_check "linker support for --nxcompat --no-seh --dynamicbase"
cc_check_cflag "-Wl,--nxcompat,--no-seh,--dynamicbase" &&
WIN_LDFLAGS="-Wl,--nxcompat,--no-seh,--dynamicbase"
finish_check $(yn_nonempty "$WIN_LDFLAGS")
fi
#####################################################################
# detect shared and static library names and build flags
LIBRHASH_STATIC="${STATIC_PREFIX}rhash${STATIC_EXT}"
LIBRHASH_SHARED="${SHARED_PREFIX}rhash${SHARED_EXT}"
LIBRHASH_SO_MAJ="${SHARED_PREFIX}rhash${SO_MAJ_EXT}"
LIBRHASH_SOLINK="${SHARED_PREFIX}rhash${SOLINK_EXT}"
LIBRHASH_SOLINK_TARGET=
test "$NEED_SOLINK" = "yes" && LIBRHASH_SOLINK_TARGET=$LIBRHASH_SOLINK
LIBRHASH_DEF="${SHARED_PREFIX}rhash.def"
LIBRHASH_IMPLIB="${STATIC_PREFIX}rhash${SO_MAJ_EXT}${STATIC_EXT}"
LIBRHASH_EXPORTS_FILE="exports.sym"
LIBRHASH_EXPORTS_SKIP="rhash_wfile"
LIBRHASH_EXPORTS_TARGET=
LIBRHASH_SH_CFLAGS=""
LIBRHASH_SH_LDFLAGS=""
LIBRHASH_RM_FILES=
if win32; then
LIBRHASH_SH_CFLAGS="-DRHASH_EXPORTS"
LIBRHASH_SH_LDFLAGS="-shared -Wl,--out-implib=${LIBRHASH_IMPLIB}${SHARED_VSCRIPT},--output-def,${LIBRHASH_DEF}"
test -n "$SHARED_VSCRIPT" && LIBRHASH_EXPORTS_TARGET=$LIBRHASH_EXPORTS_FILE
LIBRHASH_RM_FILES="${LIBRHASH_IMPLIB} ${LIBRHASH_DEF}"
LIBRHASH_EXPORTS_SKIP="__NO_SKIP__"
elif darwin; then
LIBRHASH_SH_CFLAGS="-fpic"
LIBRHASH_SH_LDFLAGS='-dynamiclib -Wl,-install_name,$(LIBDIR)/$@'
else
LIBRHASH_SH_CFLAGS="-fpic"
LIBRHASH_SH_LDFLAGS="-shared -Wl${SHARED_VSCRIPT},-soname,\$(LIBRHASH_SO_MAJ)"
test -n "$SHARED_VSCRIPT" && LIBRHASH_EXPORTS_TARGET=$LIBRHASH_EXPORTS_FILE
fi
test "x$LIBRHASH_SO_MAJ" != "x$LIBRHASH_SHARED" && LIBRHASH_RM_FILES="$LIBRHASH_RM_FILES $LIBRHASH_SO_MAJ"
LIBRHASH_RM_FILES=$(join_params $LIBRHASH_RM_FILES $LIBRHASH_EXPORTS_TARGET $LIBRHASH_SOLINK_TARGET)
RHASH_DEFINES=
LIBRHASH_DEFINES=
RHASH_LOCALE_CFLAGS=
GETTEXT_LDFLAGS=
OPENSSL_LDFLAGS=
if test "$OPT_GETTEXT" != "no"; then
start_check "gettext"
GETTEXT_FOUND=no
if cc_check_headers "libintl.h"; then
if cc_check_statement "libintl.h" "gettext(\"\");"; then
GETTEXT_FOUND=found
elif cc_check_statement "libintl.h" "gettext(\"\");" "-lintl"; then
GETTEXT_LDFLAGS="-lintl"
GETTEXT_FOUND=found
elif cc_check_statement "libintl.h" "gettext(\"\");" "-lintl -liconv"; then
GETTEXT_LDFLAGS="-lintl -liconv"
GETTEXT_FOUND=found
fi
fi
if test "$GETTEXT_FOUND" = "found"; then
RHASH_DEFINES=$(join_params $RHASH_DEFINES -DUSE_GETTEXT)
RHASH_LOCALE_CFLAGS="-DLOCALEDIR=\\\"$INSTALL_LOCALEDIR\\\""
fi
finish_check $GETTEXT_FOUND
test "$OPT_GETTEXT" = "yes" && test "$GETTEXT_FOUND" = "no" && die "gettext library not found"
fi
if test "$OPT_OPENSSL" != "no"; then
start_check "OpenSSL"
OPENSSL_FOUND=no
if test "$ALLOW_RUNTIME_LINKING" = "no"; then
echo "No runtime library loading, because dlopen() is not found!" >> "$TMPLOG"
test "$OPT_OPENSSL" = "runtime" && die "dlopen() is required for OpenSSL runtime loading"
fi
OPENSSL_HEADERS="openssl/opensslconf.h openssl/md4.h openssl/md5.h openssl/sha.h"
if cc_check_headers $OPENSSL_HEADERS; then
if test "$OPT_OPENSSL" = "runtime" || ( test "$ALLOW_RUNTIME_LINKING" = "yes" && test "$OPT_OPENSSL" = "auto" ); then
OPENSSL_FOUND=runtime
LIBRHASH_DEFINES=$(join_params $LIBRHASH_DEFINES -DOPENSSL_RUNTIME)
OPENSSL_LDFLAGS="$LIBDL_LDFLAGS"
# note: libdl should disable -static
test -n "$LIBDL_LDFLAGS" && LD_STATIC=
elif win32 && cc_check_statement "openssl/md5.h" "MD5_Init(NULL);" "-leay32"; then
OPENSSL_FOUND=found
LIBRHASH_DEFINES=$(join_params $LIBRHASH_DEFINES -DUSE_OPENSSL)
OPENSSL_LDFLAGS="-leay32"
elif cc_check_statement "openssl/md5.h" "MD5_Init(NULL);" "-lcrypto"; then
OPENSSL_FOUND=found
LIBRHASH_DEFINES=$(join_params $LIBRHASH_DEFINES -DUSE_OPENSSL)
OPENSSL_LDFLAGS="-lcrypto"
fi
fi
finish_check $OPENSSL_FOUND
test "$OPT_OPENSSL" != "auto" && test "$OPENSSL_FOUND" = "no" && die "OpenSSL library not found"
fi
# building of static/shared binary and library
RHASH_BUILD_TARGETS="\$(RHASH_BINARY)"
RHASH_LDFLAGS="\$(OPTLDFLAGS) \$(ADDLDFLAGS)"
RHASH_TEST_OPTIONS=
RHASH_EXTRA_INSTALL=
LIBRHASH_BUILD_TARGETS=
LIBRHASH_TEST_TARGETS=
EXTRA_INSTALL_LIBSHARED=
EXTRA_UNINSTALL_LIBSHARED=
if test "$OPT_STATIC" = "no"; then
LIBRHASH_TYPE=shared
LIBRHASH_PATH="\$(LIBRHASH_SHARED)"
RHASH_TEST_OPTIONS=--shared
test "$INSTALL_LIB_SHARED" = "auto" && INSTALL_LIB_SHARED=yes
test "$INSTALL_LIB_STATIC" = "yes" && RHASH_BUILD_TARGETS="$RHASH_BUILD_TARGETS \$(LIBRHASH_STATIC)"
RHASH_LDFLAGS=$(join_params $RHASH_LDFLAGS $GETTEXT_LDFLAGS)
else
LIBRHASH_TYPE=static
LIBRHASH_PATH="\$(LIBRHASH_STATIC)"
test "$INSTALL_LIB_SHARED" = "yes" && RHASH_BUILD_TARGETS="$RHASH_BUILD_TARGETS \$(LIBRHASH_SHARED)"
RHASH_LDFLAGS=$(join_params $RHASH_LDFLAGS $LD_STATIC $GETTEXT_LDFLAGS $OPENSSL_LDFLAGS)
fi
if test "$INSTALL_LIB_STATIC" = "yes"; then
RHASH_EXTRA_INSTALL=$(join_params $RHASH_EXTRA_INSTALL install-lib-static)
LIBRHASH_BUILD_TARGETS=$LIBRHASH_STATIC
LIBRHASH_TEST_TARGETS=test-static
fi
if test "$NEED_IMPLIB" = "yes"; then
EXTRA_INSTALL_LIBSHARED="install-implib"
EXTRA_UNINSTALL_LIBSHARED="uninstall-implib"
fi
if test "$INSTALL_LIB_SHARED" = "yes"; then
RHASH_EXTRA_INSTALL=$(join_params $RHASH_EXTRA_INSTALL install-lib-shared)
LIBRHASH_BUILD_TARGETS=$(join_params $LIBRHASH_BUILD_TARGETS $LIBRHASH_SHARED)
LIBRHASH_TEST_TARGETS=$(join_params $LIBRHASH_TEST_TARGETS test-shared)
fi
# check for an old POSIX make
posix_make && Q_ASSIGN="=" || Q_ASSIGN="?="
#####################################################################
# write config.mak for the RHash makefile
if test "$HAS_RHASH" = "yes"; then
echo "Writing ${RHASH_SRC}config.mak"
cat > ${RHASH_SRC}config.mak << EOF
# -------- Generated by configure -----------
DESTDIR $Q_ASSIGN
BINDIR = \$(DESTDIR)$INSTALL_BINDIR
SYSCONFDIR = \$(DESTDIR)$INSTALL_SYSCONFDIR
MANDIR = \$(DESTDIR)$INSTALL_MANDIR
PKGCONFIGDIR = \$(DESTDIR)$INSTALL_PKGCONFIGDIR
LOCALEDIR = \$(DESTDIR)$INSTALL_LOCALEDIR
AR = $CMD_AR
CC = $CC
INSTALL = $CMD_INSTALL
LIBRHASH_STATIC = librhash/$LIBRHASH_STATIC
LIBRHASH_SHARED = librhash/$LIBRHASH_SHARED
LIBRHASH_TYPE = $LIBRHASH_TYPE
LIBRHASH_PATH = $LIBRHASH_PATH
VERSION = $RHASH_VERSION
EXEC_EXT = $EXEC_EXT
BUILD_TARGETS = $RHASH_BUILD_TARGETS
TEST_OPTIONS = $RHASH_TEST_OPTIONS
EXTRA_INSTALL = $RHASH_EXTRA_INSTALL
SYMLINKS = $INSTALL_SYMLINKS
LN_S = $LN_S
OPTFLAGS = $OPTFLAGS
OPTLDFLAGS = $WIN_LDFLAGS
WARN_CFLAGS = $WARN_CFLAGS
ADDCFLAGS = $BUILD_EXTRA_CFLAGS
ADDLDFLAGS = $BUILD_EXTRA_LDFLAGS
CONFCFLAGS = -DSYSCONFDIR=\\"$INSTALL_SYSCONFDIR\\"
LOCALECFLAGS = $RHASH_LOCALE_CFLAGS
CFLAGS = $RHASH_DEFINES \$(OPTFLAGS) \$(WARN_CFLAGS) \$(ADDCFLAGS)
LDFLAGS = $RHASH_LDFLAGS
EOF
fi
#####################################################################
# write config.mak for the LibRHash makefile
if test "$HAS_LIBRHASH" = "yes"; then
echo "Writing ${LIBRHASH_SRC}config.mak"
cat > ${LIBRHASH_SRC}config.mak << EOF
# -------- Generated by configure -----------
DESTDIR $Q_ASSIGN
INCDIR = \$(DESTDIR)$INSTALL_INCDIR
LIBDIR = \$(DESTDIR)$INSTALL_LIBDIR
SO_DIR = \$(DESTDIR)$INSTALL_SO_DIR
AR = $CMD_AR
CC = $CC
INSTALL = $CMD_INSTALL
LIBRHASH_STATIC = $LIBRHASH_STATIC
LIBRHASH_SHARED = $LIBRHASH_SHARED
LIBRHASH_SO_MAJ = $LIBRHASH_SO_MAJ
LIBRHASH_SOLINK = $LIBRHASH_SOLINK
LIBRHASH_DEF = $LIBRHASH_DEF
LIBRHASH_IMPLIB = $LIBRHASH_IMPLIB
EXPORTS_FILE = $LIBRHASH_EXPORTS_FILE
EXPORTS_SKIP = $LIBRHASH_EXPORTS_SKIP
RM_FILES = $LIBRHASH_RM_FILES
BUILD_TYPE = $LIBRHASH_TYPE
EXEC_EXT = $EXEC_EXT
EXPORTS_TARGET = $LIBRHASH_EXPORTS_TARGET
BUILD_TARGETS = $LIBRHASH_BUILD_TARGETS
TEST_TARGETS = $LIBRHASH_TEST_TARGETS
SOLINK_TARGET = $LIBRHASH_SOLINK_TARGET
SHARED_LIB_MODE = $SHARED_LIB_MODE
EXTRA_INSTALL_LIBSHARED = $EXTRA_INSTALL_LIBSHARED
EXTRA_UNINSTALL_LIBSHARED = $EXTRA_UNINSTALL_LIBSHARED
OPTFLAGS = $OPTFLAGS
OPTLDFLAGS = $WIN_LDFLAGS
WARN_CFLAGS = $WARN_CFLAGS
ADDCFLAGS = $BUILD_EXTRA_CFLAGS
ADDLDFLAGS = $BUILD_EXTRA_LDFLAGS
CFLAGS = $LIBRHASH_DEFINES \$(OPTFLAGS) \$(WARN_CFLAGS) \$(ADDCFLAGS)
LDFLAGS = \$(OPTLDFLAGS) \$(ADDLDFLAGS)
SHARED_CFLAGS = \$(CFLAGS) $LIBRHASH_SH_CFLAGS
SHARED_LDFLAGS = \$(LDFLAGS) $(join_params $OPENSSL_LDFLAGS $LIBRHASH_SH_LDFLAGS)
VERSION_CFLAGS = -DRHASH_XVERSION=$RHASH_XVERSION
BIN_STATIC_LDFLAGS = \$(LDFLAGS) $(join_params $LD_STATIC $OPENSSL_LDFLAGS)
EOF
fi