-
Notifications
You must be signed in to change notification settings - Fork 1
/
acsite.m4
executable file
·2436 lines (2218 loc) · 65.4 KB
/
acsite.m4
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
dnl
dnl acsite.m4
dnl
dnl Copyright 2002, 2015 by Anthony Howe. All rights reserved.
dnl
dnl
dnl SNERT_JOIN_UNIQ(var, word_list,[head|tail])
dnl
AC_DEFUN([SNERT_JOIN_UNIQ],[
list=`eval echo \$$1`
AS_IF([test -n "$2"],[
for item in $2; do
AS_IF([expr " $list " : ".* $item " >/dev/null],[
],[
AS_IF([test "$3" = 'head'],[
list="$item${list:+ $list}"
],[
list="${list:+$list }$item"
])
])
done
])
eval $1="\"$list\""
])
dnl
dnl SNERT_CHECK_DEFINE(symbol, header_file)
dnl
AC_DEFUN([SNERT_CHECK_DEFINE],[
AC_LANG_PUSH([C])
AC_CACHE_CHECK([for $1 macro],ac_cv_define_$1,[
AC_RUN_IFELSE([
AC_LANG_SOURCE([[
#include <$2>
int main()
{
#ifdef $1
return 0;
#else
return 1;
#endif
}
]])
],[
ac_cv_define_$1=yes
],[
ac_cv_define_$1=no
])
])
AC_LANG_POP([C])
AS_IF([test $ac_cv_define_$1 = 'yes'],[
AC_DEFINE_UNQUOTED([HAVE_MACRO_]translit($1, [a-z], [A-Z]))
AH_TEMPLATE([HAVE_MACRO_]translit($1, [a-z], [A-Z]))
])
])
dnl
dnl SNERT_CHECK_PREDEFINE(symbol)
dnl
AC_DEFUN(SNERT_CHECK_PREDEFINE,[
dnl Supply a common C header to satisfy SNERT_CHECK_DEFINE 2nd arg.
SNERT_CHECK_DEFINE($1,[stdlib.h])
])
dnl
dnl SNERT_DEFINE(name[, value])
dnl
AC_DEFUN([SNERT_DEFINE],[
name=AS_TR_CPP($1)
AS_IF([test -n "$2"],[value="$2"],[eval value="\$$name"])
AC_DEFINE_UNQUOTED($name,["$value"])
])
dnl
dnl SNERT_FIND_FILE(wild_file, directories, if-found, not-found)
dnl if-found can reference the found $dir_val
dnl
AC_DEFUN([SNERT_FIND_FILE],[
AS_VAR_PUSHDEF([snert_dir], [snert_find_file_$1])
AS_VAR_SET([snert_dir],'no')
AC_MSG_CHECKING([for location of $1])
dnl File to find specifies an extension?
AS_IF([expr "$1" : '.*\.[[0-9a-zA-Z]]' >/dev/null],[
dnl Has an extension.
pattern="$1"
],[
dnl No extension, so look for any extension (.a and .so variants).
dnl Without the dot (.) to mark the end of the name prefix
dnl we can inadvertantly match libraries with similar prefixes,
dnl ie. libz and libzephyr
pattern="$1.*"
])
for d in $2; do
AS_IF([ls -1 $d/$pattern >/dev/null 2>&1],[
AS_VAR_SET([snert_dir],[$d])
break
])
done
AS_VAR_COPY([dir_val],[snert_dir])
dnl AS_IF([test "$dir_val" = 'no'],AC_MSG_RESULT(no),AC_MSG_RESULT(yes))
AC_MSG_RESULT($dir_val)
AS_VAR_IF([snert_dir],[no],[$4],[$3])
AS_VAR_POPDEF([snert_dir])
])
dnl
dnl SNERT_FIND_DIR(subdir, directories, if-found, not-found)
dnl
AC_DEFUN([SNERT_FIND_DIR],[
AS_VAR_PUSHDEF([snert_dir], [snert_find_file_$1])
AS_VAR_SET([snert_dir],'no')
AC_MSG_CHECKING([for location of $1])
for d in $2; do
AS_IF([test -d "$d/$1"],[
AS_VAR_SET([snert_dir],[$d])
break
])
done
AS_VAR_COPY([dir_val],[snert_dir])
AC_MSG_RESULT($dir_val)
AS_VAR_IF([snert_dir],[no],[$4],[$3])
AS_VAR_POPDEF([snert_dir])
])
dnl
dnl SNERT_CHECK_PACKAGE_HEADER(header, if-found, not-found[, extra_dirs])
dnl
AC_DEFUN([SNERT_CHECK_PACKAGE_HEADER],[
SNERT_FIND_FILE([$1],[$4 /usr/pkg/include /usr/local/include /usr/include],[$2],[$3])
])
dnl
dnl SNERT_CHECK_PACKAGE_LIB(library, if-found, not-found[, extra_dirs])
dnl
AC_DEFUN([SNERT_CHECK_PACKAGE_LIB],[
SNERT_FIND_FILE([$1],[$4 /usr/pkg/lib /usr/local/lib /usr/lib64 /usr/lib/x86_64-linux-gnu /usr/lib /lib64 /lib/x86_64-linux-gnu /lib],[$2],[$3])
])
dnl
dnl SNERT_IF_SYSTEM_DIR(word, if-system, not-system)
dnl
m4_define([SNERT_IF_SYSTEM_DIR],[
AS_CASE([$1],[/usr/include|/usr/lib64|/usr/lib/x86_64-linux-gnu|/usr/lib|/lib64|/lib/x86_64-linux-gnu|/lib],[$2],[$3])
])
dnl
dnl SNERT_CHECK_PACKAGE(
dnl name, headers, libs, [funcs],
dnl with_base, with_inc, with_lib,
dnl [extra_includes], [define_and_subst=true]
dnl )
dnl
AC_DEFUN([SNERT_CHECK_PACKAGE],[
AS_ECHO()
AS_ECHO("Checking for $1 package...")
AS_ECHO()
dnl with_name=`AS_ECHO([$1]) | tr '[[a-z -]]' '[[A-Z_]]'`
dnl Watch out for leading and trailing whitespace with m4 macros;
dnl everything delimited by open/close paren and/or commas is
dnl part of the argument, so pretty formatting for readability
dnl can screw with string compares. Use echo to trim whitespace.
with_base=`AS_ECHO([$5])`
AS_IF([test "$with_base" != 'no'],[
dnl Careful with --with options as they can be specified,
dnl without a base directory path, in which case ignore it.
AS_IF([test "$with_base" = 'yes'],[
with_base=''
])
dnl dnl Save any preset flags.
dnl eval extra_LIBS="\${LIBS_$1}"
dnl eval extra_LDFLAGS="\${LDFLAGS_$1}"
dnl eval extra_CPPFLAGS="\${CPPFLAGS_$1}"
found=0
headers=0
for f in $2; do
headers=`expr $headers + 1`
cache_id=AS_TR_SH(ac_cv_header_$f)
SNERT_CHECK_PACKAGE_HEADER([$f],[
found=`expr $found + 1`
dnl Remember the location we found the header
dnl even if its a system directory.
have=AS_TR_CPP(HAVE_$f)
dnl Wanted to have the filepath saved in the
dnl macro, but for backwards compatibility with
dnl HAVE_header_h defines set by other tests best
dnl keep it the same value to avoid warnings (or
dnl error with -Werror).
AC_DEFINE_UNQUOTED($have,[1])
dnl Here we REALLY need the filepath for other
dnl potential configure tests.
AC_CACHE_VAL($cache_id,[eval $cache_id="\"$dir_val/$f\""])
SNERT_IF_SYSTEM_DIR([$dir_val],[
dnl Ignore system directories.
SNERT_JOIN_UNIQ([CPPFLAGS_$1])
],[
SNERT_JOIN_UNIQ([CPPFLAGS_$1],["-I$dir_val"],[head])
])
],[
AC_CACHE_VAL($cache_id,[eval $cache_id='no'])
],[${with_base:+$with_base/include} $6])
done
dnl If we don't have all the headers, skip checking for the libraries.
dnl Consider the case where we have libssl et al., but not the headers.
AS_IF([test $headers -eq $found], [
for f in $3; do
SNERT_CHECK_PACKAGE_LIB([$f],[
have=AS_TR_CPP(HAVE_$f)
AC_DEFINE_UNQUOTED($have,["$dir_val"])
SNERT_IF_SYSTEM_DIR([$dir_val],[
lib=`basename $f | sed -e's/^lib//'`
SNERT_JOIN_UNIQ([LIBS_$1],["-l$lib"],[tail])
],[
SNERT_JOIN_UNIQ([LDFLAGS_$1],["-L$dir_val"])
AS_IF([expr "$f" : '.*\.a$' >/dev/null],[
dnl Explicit static library.
SNERT_JOIN_UNIQ([LIBS_$1],["$dir_val/$f"],[tail])
],[
lib=`basename $f | sed -e's/^lib//'`
SNERT_JOIN_UNIQ([LIBS_$1],["-l$lib"],[tail])
])
])
],[],[${with_base:+$with_base/lib} $7])
done
])
define_and_subst=`AS_ECHO([$9])`
AS_CASE([$define_and_subst],
[false|no|0],[
dnl Caller wants to take care of this, possibly
dnl to append extra flags before committing the
dnl defines and substutions.
:
],[
dnl Default.
SNERT_DEFINE(CPPFLAGS_[$1])
SNERT_DEFINE(LDFLAGS_[$1])
SNERT_DEFINE(LIBS_[$1])
AC_SUBST(CPPFLAGS_[$1])
AC_SUBST(LDFLAGS_[$1])
AC_SUBST(LIBS_[$1])
dnl Deprecated versions to phase out.
SNERT_DEFINE(CFLAGS_[$1],`eval echo \$CPPFLAGS_[$1]`)
SNERT_DEFINE(HAVE_LIB_[$1],`eval echo \$LIBS_[$1]`)
AC_SUBST(CFLAGS_[$1],`eval echo \$CPPFLAGS_[$1]`)
AC_SUBST(HAVE_LIB_[$1],`eval echo \$LIBS_[$1]`)
])
AS_IF([test -n "$4"],[
save_LIBS="$LIBS"
save_LDFLAGS="$LDFLAGS"
save_CPPFLAGS="$CPPFLAGS"
eval LIBS=\"\$LIBS_$1 $LIBS\"
eval LDFLAGS=\"\$LDFLAGS_$1 $LDFLAGS\"
eval CPPFLAGS=\"\$CPPFLAGS_$1 $CPPFLAGS\"
AC_CHECK_FUNCS([$4],[],[],[$8])
CPPFLAGS="$save_CPPFLAGS"
LDFLAGS="$save_LDFLAGS"
LIBS="$save_LIBS"
])
],[
AC_MSG_NOTICE([Package $1 has been explicitly disabled.])
])
])
dnl
dnl SNERT_OPTION_ENABLE_DEBUG
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_DEBUG,[
dnl Assert that CFLAGS is defined. When AC_PROC_CC is called to
dnl check the compiler and CC == gcc is found and CFLAGS is
dnl undefined, then it gets assigned "-g -O2", which is just
dnl annoying when you want the default to no debugging.
CPPFLAGS="${CPPFLAGS}"
CFLAGS="${CFLAGS}"
AC_ARG_ENABLE(debug,[AS_HELP_STRING([--enable-debug],[enable compiler debug option])])
AS_IF([test ${enable_debug:-no} = 'yes'],[
CFLAGS="-g -O0${CFLAGS:+ $CFLAGS}"
],[
AC_DEFINE(NDEBUG,[1],[Disable debug code])
enable_debug='no'
])
])
dnl
dnl SNERT_OPTION_ENABLE_TRACK
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_TRACK,[
AC_ARG_ENABLE(track,[AS_HELP_STRING([--enable-track],[enable memory leak tracking])],[
dnl We define this through -D instead of config.h.
CFLAGS="-DTRACK${CFLAGS:+ $CFLAGS}"
])
])
dnl
dnl SNERT_SNERT
dnl
AC_DEFUN([SNERT_SNERT],[
LIBSNERT='-lsnert'
# Makefile macro to compile C into an object file.
COMPILE='${CC} ${CFLAGS} ${CC_O} $''*$O -c $<'
dnl COMPILE='${CC} ${CFLAGS} -c $<'
# Makefile macro to archive an object file.
ARCHIVE='${AR} rc ${LIB} $$obj'
# Assume the following traditional extensions.
ac_libext='a'
LIBEXT=$ac_libext
AC_SUBST(COMPILE)
AC_SUBST(ARCHIVE)
AC_SUBST(LIBEXT)
AC_SUBST(LIBSNERT)
AC_CHECK_TOOL(RANLIB, ranlib, true)
])
AC_DEFUN([SNERT_CC_INFO],[
AC_REQUIRE([SNERT_OPTION_ENABLE_DEBUG])
AC_REQUIRE([AC_PROG_CC])
AC_USE_SYSTEM_EXTENSIONS
AC_LANG([C])
AS_IF([test "$GCC" = 'yes'],[
GCC_MAJOR=`$CC -dM -E -xc /dev/null | sed -n -e 's/.*__GNUC__ \(.*\)/\1/p'`
GCC_MINOR=`$CC -dM -E -xc /dev/null | sed -n -e 's/.*__GNUC_MINOR__ \(.*\)/\1/p'`
GCC_PATCH=`$CC -dM -E -xc /dev/null | sed -n -e 's/.*__GNUC_PATCHLEVEL__ \(.*\)/\1/p'`
dnl Nothing wrong using a char for a subscript.
AS_IF([test $GCC_MAJOR -ge 3],[CFLAGS="-Wno-char-subscripts${CFLAGS:+ $CFLAGS}"])
dnl This list keeps getting bigger with each version of gcc. Turn them all off.
dnl dnl Option to ignore extra support functions.
dnl AS_IF([test $GCC_MAJOR -gt 4 -o \( $GCC_MAJOR -eq 4 -a $GCC_MINOR -ge 3 \) ],[CFLAGS="-Wno-unused-function${CFLAGS:+ $CFLAGS}"])
dnl dnl Option to silience Valgrind and ProtoThread macro warnings.
dnl AS_IF([test $GCC_MAJOR -gt 4 -o \( $GCC_MAJOR -eq 4 -a $GCC_MINOR -ge 6 \) ],[CFLAGS="-Wno-unused-but-set-variable${CFLAGS:+ $CFLAGS}"])
dnl dnl Option to silience warnings for const I might need.
dnl AS_IF([test $GCC_MAJOR -gt 6 -o \( $GCC_MAJOR -eq 6 -a $GCC_MINOR -ge 2 \) ],[CFLAGS="-Wno-unused-const-variable${CFLAGS:+ $CFLAGS}"])
AS_IF([test $GCC_MAJOR -gt 3],[CFLAGS="-Wno-unused${CFLAGS:+ $CFLAGS}"])
CFLAGS="-Wall $CFLAGS"
])
AS_IF([test ${platform:-UNKNOWN} = 'CYGWIN'],[
AS_IF([test ${enable_debug:-no} = 'no'],[CFLAGS="-s${CFLAGS:+ $CFLAGS}"])
CFLAGS="-I/usr/include/w32api${CFLAGS:+ $CFLAGS}"
LDFLAGS="-L/usr/lib/w32api${LDFLAGS:+ $LDFLAGS}"
dnl AS_IF([test ${enable_win32:-no} = 'yes'],[
dnl dnl -s strip, no symbols
dnl dnl -mno-cygwin native windows console app
dnl dnl -mwindows native windows gui app
dnl dnl -lws2_32 WinSock2 library
dnl CFLAGS="-mno-cygwin ${CFLAGS}"
dnl LIBS="-lws2_32 ${LIBS}"
dnl ])
])
dnl Tradional cc options.
dnl NOTE SunOS as(1) _wants_ a space between -o and its argument.
CC_E='-o'
CC_E_NAME='-o $@'
CC_O='-o'
CC_O_NAME='-o $''*$O'
LD=$CC
AC_SUBST(CC_E)
AC_SUBST(CC_E_NAME)
AC_SUBST(CC_O)
AC_SUBST(CC_O_NAME)
dnl Check for recent ANSI C additions that HAVE_HEADER_STDC check
dnl doesn't distinguish between C89 and C99.
AC_CHECK_HEADERS([stdarg.h])
SNERT_CHECK_DEFINE([va_copy], [stdarg.h])
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(size_t)
AC_CHECK_SIZEOF(off_t)
AC_CHECK_SIZEOF(double)
AC_CHECK_SIZEOF(long double)
AC_CHECK_SIZEOF(long long int)
SNERT_SNERT
])
AC_DEFUN([SNERT_TAR_SETTINGS],[
AC_MSG_CHECKING(for tar file list option to use)
AS_IF([tar --version 2>&1 | grep '(GNU tar)' >/dev/null],[
TAR_I='-T'
],[
TAR_I='-I'
])
AC_SUBST(TAR_I)
AC_MSG_RESULT($TAR_I)
])
dnl
dnl SNERT_CHECK_LIB(lib, symbol)
dnl
dnl Only check AC_CHECK_LIB if $lib not already in $LIBS
dnl
AC_DEFUN(SNERT_CHECK_LIB,[
AS_IF([echo "$LIBS" | grep -- "-l$1" >/dev/null],[
echo "checking for $2 in $1... (cached) yes"
],[
dnl For SunOS. Beware of using AC_SEARCH_LIBS() on SunOS
dnl platforms, because some functions appear as stubs in
dnl other libraries.
AC_CHECK_LIB([$1], [$2])
])
])
dnl
dnl SNERT_GET_NUMERIC_DEFINE(header_file, symbol)
dnl
AC_DEFUN(SNERT_GET_NUMERIC_DEFINE,[
AS_VAR_PUSHDEF([ac_Header], [snert_cv_define_$1_$2])dnl
AC_CACHE_CHECK([for $2],[ac_Header],[
AC_RUN_IFELSE([
AC_LANG_SOURCE([[
#include <stdio.h>
#include <$1>
int main()
{
#ifdef $2
FILE *fp;
if ((fp = fopen("snert_output.txt", "w")) == NULL)
return 1;
fprintf(fp, "%d", $2);
fclose(fp);
return 0;
#else
return 1;
#endif
}
]])
],[
AS_VAR_SET([ac_Header], [[`cat snert_output.txt`]])
rm -f snert_output.txt
])
])
AS_VAR_POPDEF([ac_Header])dnl
])
AC_DEFUN(SNERT_OPTION_DB_185,[
AC_ARG_ENABLE(db-185
[AS_HELP_STRING([[--enable-db-185 ]],[link with DB 1.85])]
)
])
dnl
dnl SNERT_BERKELEY_DB
dnl
dnl Sets $with_db to yes or no
dnl Sets $db_lib to the library -l option or an empty string.
dnl
AC_DEFUN(SNERT_OPTION_WITH_DB,[
AC_ARG_WITH(db, [[ --with-db[=DIR] Berkeley DB package, optional base directory]])
AC_ARG_WITH(db-inc, [[ --with-db-inc=DIR specific Berkeley DB include directory]])
AC_ARG_WITH(db-lib, [[ --with-db-lib=DIR specific Berkeley DB library directory]])
])
AC_DEFUN(SNERT_BERKELEY_DB,[
AS_IF([test ${with_db:-yes} != 'no'],[
echo
echo "Check for Berkeley DB support..."
echo
bdb_save_LIBS=$LIBS
bdb_save_CFLAGS=$CFLAGS
bdb_save_LDFLAGS=$LDFLAGS
dnl Short list of system directories to try.
AS_IF([ test -d "$with_db_inc" ],[
BDB_DIRS="$with_db_inc"
],[ test -d "$with_db/include" ],[
BDB_DIRS="$with_db/include"
],[
BDB_DIRS="/opt /usr/pkg/include /usr/local/include /usr/include"
])
dnl Find all instances of db.h
AC_LANG_PUSH(C)
bdb_best_major=-1
bdb_best_minor=-1
for h in `find $BDB_DIRS -name db.h 2>/dev/null`; do
AC_MSG_CHECKING($h)
I_DIR=`dirname $h`
dnl Version subdirectory.
v=`basename $I_DIR`
if test $v = 'include' ; then
d=$I_DIR
v=''
else
d=`dirname $I_DIR`
fi
d=`dirname $d`
dnl Determine matching lib directory.
if test -d "$with_db_lib" ; then
L_DIR="$with_db_lib"
elif test -d $d/lib64/$v ; then
L_DIR="$d/lib64/$v"
elif test -d $d/lib/$v ; then
L_DIR="$d/lib/$v"
elif test -d $d/lib64 ; then
L_DIR="$d/lib64"
else
L_DIR="$d/lib"
fi
dnl Don't need to add system locations to options.
if test ${I_DIR} != '/usr/include' ; then
CFLAGS="-I$I_DIR $CFLAGS"
fi
if test ${L_DIR} != '/usr/lib64' -a ${L_DIR} != '/usr/lib' ; then
LDFLAGS="-L$L_DIR $LDFLAGS"
fi
dnl Extract the version number.
bdb_major=`grep DB_VERSION_MAJOR $h | cut -f 3`
if test -n "$bdb_major" ; then
bdb_minor=`grep DB_VERSION_MINOR $h | cut -f 3`
bdb_create='db_create'
else
dnl Assume oldest version commonly found used by BSD variants.
bdb_major=1
bdb_minor=85
bdb_create='dbopen'
check_libc='c'
fi
AC_MSG_RESULT(${bdb_major}.${bdb_minor})
dnl Library search based on include version directory.
for l in $v db $check_libc ; do
if test "$l" != 'c'; then
LIBS="-l$l $LIBS"
fi
bdb_name=$l
AC_MSG_CHECKING([for $bdb_create in lib$bdb_name])
AC_LINK_IFELSE([
AC_LANG_SOURCE([[
#include <stdlib.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <db.h>
int
main(int argc, char **argv)
{
#ifdef DB_VERSION_MAJOR
DB *db = NULL;
return db_create(&db, NULL, 0) != 0 || db == NULL;
#else
DB *db = dbopen("access.db", 0, 0, 0, NULL);
return 0;
#endif
}
]])
],[
found=yes
AC_MSG_RESULT(yes)
AC_DEFINE_UNQUOTED(HAVE_DB_H)
if test $bdb_major = 1 ; then
AC_DEFINE_UNQUOTED(HAVE_DBOPEN)
else
AC_DEFINE_UNQUOTED(HAVE_DB_CREATE)
fi
dnl Assume newest is best.
if test $bdb_major -gt $bdb_best_major \
-o \( $bdb_major -eq $bdb_best_major -a $bdb_minor -gt $bdb_best_minor \); then
bdb_best_major=$bdb_major
bdb_best_minor=$bdb_minor
if test -n "$l" ; then
BDB_I_DIR=$I_DIR
BDB_L_DIR=$L_DIR
AC_SUBST(HAVE_LIB_DB, "-l$l")
AC_SUBST(CFLAGS_DB, "-I$BDB_I_DIR")
AC_SUBST(LDFLAGS_DB, "-L$BDB_L_DIR")
AC_DEFINE_UNQUOTED(HAVE_LIB_DB, "-l$l")
AC_DEFINE_UNQUOTED(CFLAGS_DB, "-I$BDB_I_DIR")
AC_DEFINE_UNQUOTED(LDFLAGS_DB, "-L$BDB_L_DIR")
fi
fi
],[
AC_MSG_RESULT(no)
])
LIBS="$bdb_save_LIBS"
done
LDFLAGS="$bdb_save_LDFLAGS"
CFLAGS="$bdb_save_CFLAGS"
done
AC_LANG_POP(C)
if test $bdb_best_major -gt -1; then
bdb_version="$bdb_best_major.$bdb_best_minor"
AC_DEFINE_UNQUOTED(HAVE_DB_MAJOR, $bdb_best_major)
AC_DEFINE_UNQUOTED(HAVE_DB_MINOR, $bdb_best_minor)
AC_MSG_RESULT([checking best Berkeley DB version... $bdb_version])
else
AC_MSG_RESULT([checking best Berkeley DB version... not found])
fi
AH_VERBATIM([HAVE_DB_MAJOR],[
/*
* Berkeley DB
*/
#undef IGNORE_CORRUPT_CACHE_ISSUE_WITH_DB_185
#undef HAVE_DB_MAJOR
#undef HAVE_DB_MINOR
#undef HAVE_DB_CREATE
#undef HAVE_DBOPEN
#undef HAVE_DB_H
#undef HAVE_LIB_DB
#undef LDFLAGS_DB
#undef CFLAGS_DB
])
LDFLAGS="$bdb_save_LDFLAGS"
CFLAGS="$bdb_save_CFLAGS"
LIBS="$bdb_save_LIBS"
])
])
dnl
dnl SNERT_FIND_LIB([name],[found],[notfound])
dnl
m4_define([SNERT_FIND_LIB],[
AS_VAR_PUSHDEF([snert_lib], [snert_find_lib_$1])dnl
AS_ECHO
AS_ECHO("Finding dynamic library $1 ...")
AS_ECHO
AS_VAR_SET([snert_lib], 'no')
AC_CHECK_HEADER([dlfcn.h], [
AC_DEFINE(HAVE_DLFCN_H,[],[dynamic library support])
AC_CHECK_TOOL(ldd_tool, ldd)
AS_IF([test ${ldd_tool:-no} != 'no'],[
AC_CHECK_LIB([dl],[dlopen])
AC_MSG_CHECKING([for $1])
AC_RUN_IFELSE([
AC_LANG_SOURCE([[
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_DLFCN_H
# include <dlfcn.h>
#endif
int
main(int argc, char **argv)
{
void *handle;
handle = dlopen(argv[1], RTLD_NOW);
return dlerror() != NULL;
}
]])
],[
libpath=[`$ldd_tool ./conftest$ac_exeext | sed -n -e "/lib$1/s/.* \([^ ]*lib$1[^ ]*\).*/\1/p"`]
AS_IF([./conftest$ac_exeext ${libpath:-unknown}],[
AS_VAR_SET([snert_lib], [${libpath}])
],[
AS_VAR_SET([snert_lib], 'no')
])
])
AC_MSG_RESULT(AS_VAR_GET([snert_lib]))
])
])
AS_IF([test AS_VAR_GET([snert_lib]) != 'no'], [$2], [$3])[]
AS_VAR_POPDEF([snert_lib])
])
AC_DEFUN(SNERT_FIND_LIBC,[
SNERT_FIND_LIB([c],[
AC_DEFINE_UNQUOTED(LIBC_PATH, ["$snert_find_lib_c"])
AH_TEMPLATE([LIBC_PATH],[C Library Path (see DebugMalloc)])
], [])
])
dnl
dnl SNERT_PLATFORM
dnl
AC_DEFUN(SNERT_PLATFORM,[
dnl TODO migrate $platform to $target_os
dnl AC_CANONICAL_TARGET
platform=`uname -s|sed -e 's/^\([[a-zA-Z0-9]]*\)[[^a-zA-Z0-9]].*/\1/'`
AC_SUBST(platform, $platform)
AS_ECHO("platform is... $platform")
AS_IF([test -e /etc/debian_version],[
echo "this Linux is a Debian" `cat /etc/debian_version`
apt-get install -y gcc libc6-dev
isDebian='yes'
])
AC_PATH_PROGS([MD5SUM],[md5sum md5])
AS_CASE([$platform],
[NetBSD],[
dnl LDFLAGS="-Wl,-R/usr/pkg/lib $LDFLAGS"
:
])
AC_DEFINE_UNQUOTED(${snert_macro_prefix}_PLATFORM, [["${platform}"]])
AC_DEFINE_UNQUOTED(${snert_macro_prefix}_BUILD_HOST, [["`hostname`"]])
])
dnl
dnl SNERT_CHECK_CONFIGURE
dnl
AC_DEFUN(SNERT_CHECK_CONFIGURE,[
# When we have no makefile, do it ourselves...
dnl snert_configure_command="$[]0 $[]@"
AC_PATH_PROGS([AUTOCONF],[autoconf-2.69 autoconf],[no])
AS_IF([test ${AUTOCONF:-no} != 'no' -a \( acsite.m4 -nt configure -o configure.ac -nt configure \)],[
AS_ECHO('Rebuilding the configure script first...')
${AUTOCONF} -f
AS_ECHO('Restarting configure script...')
AS_ECHO
AS_ECHO("$snert_configure_command")
exec $snert_configure_command
])
])
dnl
dnl SNERT_LIBSNERT
dnl
AC_DEFUN(SNERT_LIBSNERT,[
saved_cflags=$CFLAGS
saved_ldflags=$LDFLAGS
CFLAGS="-I../../include $CFLAGS"
LDFLAGS="-L../../lib $LDFLAGS"
AC_CHECK_LIB(snert, parsePath)
if test "$ac_cv_lib_snert_parsePath" = 'no'; then
AS_ECHO
AC_MSG_WARN([The companion library, LibSnert, is required.])
AS_ECHO
ac_cv_lib_snert_parsePath='required'
CFLAGS=$saved_cflags
LDFLAGS=$saved_ldflags
fi
snert_libsnert=$ac_cv_lib_snert_parsePath
])
AC_DEFUN(SNERT_OPTION_ENABLE_32BIT,[
AC_ARG_ENABLE(32bit,
[AS_HELP_STRING([--enable-32bit ],[enable compile & link options for 32-bit])],
[
CFLAGS="-m32${CFLAGS:+ $CFLAGS}"
LDFLAGS="-m32${LDFLAGS:+ $LDFLAGS}"
]
)
])
AC_DEFUN(SNERT_OPTION_ENABLE_64BIT,[
AC_ARG_ENABLE(64bit,
[AS_HELP_STRING([--enable-64bit ],[enable compile & link options for 64-bit])],
[
CFLAGS="-m64${CFLAGS:+ $CFLAGS}"
LDFLAGS="-m64${LDFLAGS:+ $LDFLAGS}"
]
)
])
dnl
dnl SNERT_OPTION_ENABLE_WIN32
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_MINGW,[
AC_ARG_ENABLE(mingw,
[AS_HELP_STRING([--enable-mingw ],[generate native Windows application using mingw])],
[
enable_win32='yes'
AC_SUBST(ENABLE_MINGW, 'yes')
CFLAGS="-mno-cygwin -I/usr/include/w32api ${CFLAGS}"
LDFLAGS="-mno-cygwin -L/usr/lib/w32api ${LDFLAGS}"
]
)
])
dnl
dnl SNERT_OPTION_WITH_WINDOWS_SDK
dnl
AC_DEFUN(SNERT_OPTION_WITH_WINDOWS_SDK,[
AC_ARG_WITH(windows-sdk,
[AS_HELP_STRING([--with-windows-sdk=dir ],[Windows Platform SDK base directory])],
[
enable_win32='yes'
AC_SUBST(WITH_WINDOWS_SDK, $with_windows_sdk)
AC_DEFINE(WITH_WINDOWS_SDK, $with_windows_sdk,[Windows SDK])
CFLAGS="-mno-cygwin -I${with_windows_sdk}/include ${CFLAGS}"
LDFLAGS="-mno-cygwin -L${with_windows_sdk}/lib ${LDFLAGS}"
]
)
])
dnl
dnl SNERT_OPTION_ENABLE_BCC32
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_BCC32,[
AC_ARG_ENABLE(bcc32,
[AS_HELP_STRING([--enable-bcc32 ],[generate native Windows application using Borland C++ 5.5])],
[
enable_bcc32='yes'
CC=bcc32
]
)
])
dnl
dnl SNERT_OPTION_ENABLE_RUN_USER(default_user_name)
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_RUN_USER,[
AC_ARG_ENABLE(run-user,
[AS_HELP_STRING([--enable-run-user=user ],[specifiy the process user name, default is "$1"])],
[enable_run_user="$enableval"], [enable_run_user=$1]
)
AC_DEFINE_UNQUOTED(RUN_AS_USER, ["$enable_run_user"])
AC_SUBST(enable_run_user)
])
dnl
dnl SNERT_OPTION_ENABLE_RUN_GROUP(default_group_name)
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_RUN_GROUP,[
AC_ARG_ENABLE(run-group,
[AS_HELP_STRING([--enable-run-group=group ],[specifiy the process group name, default is "$1"])],
[enable_run_group="$enableval"], [enable_run_group=$1]
)
AC_DEFINE_UNQUOTED(RUN_AS_GROUP, ["$enable_run_group"])
AC_SUBST(enable_run_group)
])
dnl
dnl SNERT_OPTION_ENABLE_CACHE_TYPE(default_cache_type)
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_CACHE_TYPE,[
AC_ARG_ENABLE(cache-type,
[AS_HELP_STRING([--enable-cache-type=type ],[specifiy the cache type: bdb, flatfile, hash])],
[
# Force a specific type.
case "$enableval" in
bdb|flatfile|hash)
enable_cache_type="$enableval"
AC_DEFINE_UNQUOTED(CACHE_TYPE, ["$enable_cache_type"])
;;
*)
enable_cache_type="$1"
esac
], [
# Depends on whether Berkeley DB is available.
enable_cache_type="$1"
]
)
])
dnl
dnl SNERT_OPTION_ENABLE_CACHE_FILE
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_CACHE_FILE,[
AC_ARG_ENABLE(cache-file,
[AS_HELP_STRING([--enable-cache-file=filepath ],[specifiy the cache file])],
[
enable_cache_file="$enableval"
], [
if test -d /var/cache ; then
# Linux http://www.pathname.com/fhs/pub/fhs-2.3.html
enable_cache_file='${localstatedir}/cache/${PACKAGE_NAME}.db'
elif test -d /var/db ; then
# FreeBSD, OpenBSD, NetBSD
enable_cache_file='${localstatedir}/db/${PACKAGE_NAME}.db'
else
echo "Cannot find a suitable location for the cache file."
echo "Please specify --enable-cache-file."
exit 1
fi
]
)
snert_cache_file=`eval echo $enable_cache_file`
AC_DEFINE_UNQUOTED(CACHE_FILE, ["`eval echo ${snert_cache_file}`"])
AC_SUBST(snert_cache_file)
AC_SUBST(enable_cache_file)
])
dnl
dnl SNERT_OPTION_ENABLE_PID(default)
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_PID,[
AC_ARG_ENABLE(pid,
[AS_HELP_STRING([--enable-pid=filepath ],[specifiy an alternative pid file path])],
[
],[
dnl Almost all unix machines agree on this location.
if test -z "$1"; then
enable_pid='${localstatedir}/run/${PACKAGE_NAME}.pid'
else
enable_pid=$1
fi
]
)
snert_pid_file=`eval echo $enable_pid`
AC_DEFINE_UNQUOTED(PID_FILE, ["`eval echo ${snert_pid_file}`"])
AC_SUBST(snert_pid_file)
AC_SUBST(enable_pid)
])
dnl
dnl SNERT_OPTION_ENABLE_SOCKET(default)
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_SOCKET,[
AC_ARG_ENABLE(socket,
[AS_HELP_STRING([--enable-socket=filepath ],[specifiy an alternative Unix domain socket])],
[
],[
dnl Almost all unix machines agree on this location.
dnl Note though that if you have more than one file
dnl here, its recommended to create a subdirectory
dnl with all the related files.
if test -z "$1"; then
enable_socket='${localstatedir}/run/${PACKAGE_NAME}.socket'
else
enable_socket=$1
fi
]
)
snert_socket_file=`eval echo $enable_socket`
AC_DEFINE_UNQUOTED(SOCKET_FILE, ["`eval echo ${snert_socket_file}`"])
AC_SUBST(snert_socket_file)
AC_SUBST(enable_socket)
])
dnl
dnl SNERT_OPTION_ENABLE_POPAUTH
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_POPAUTH,[
AC_ARG_ENABLE(popauth,
[AS_HELP_STRING([--enable-popauth ],[enable POP-before-SMTP macro checking in smf API])],
[AC_DEFINE(HAVE_POP_BEFORE_SMTP,[],[Enable POP-before-SMTP])]
)
])
dnl
dnl SNERT_OPTION_ENABLE_STARTUP_DIR
dnl
AC_DEFUN(SNERT_OPTION_ENABLE_STARTUP_DIR,[
AC_ARG_ENABLE(startup-dir,
[AS_HELP_STRING([--enable-startup-dir=dir ],[specifiy the startup script directory location])],
[
STARTUP_DIR="$enableval"
STARTUP_EXT='.sh'
], [
if test -d '/usr/local/etc/rc.d'; then
# FreeBSD
STARTUP_DIR='/usr/local/etc/rc.d'
STARTUP_EXT='.sh'
elif test -d '/etc/init.d'; then
# SunOS, Debian Linux, System V variant
STARTUP_DIR='/etc/init.d'
elif test -d '/etc/rc.d/init.d'; then
# Linux, System V variant
STARTUP_DIR='/etc/rc.d/init.d'
else
# OpenBSD has no place to put startup
# scripts that might be used by rc.local.
STARTUP_DIR='/usr/local/sbin'
STARTUP_EXT='.sh'
fi
]
)
AC_SUBST(STARTUP_DIR)
AC_SUBST(STARTUP_EXT)
])