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
|
#!/bin/sh
GCC="gcc"
MAKE=""
LEX=""
YACC=""
OS=""
PKG_CONFIG=`which pkg-config`
PERL=`which perl`
LOCALBASE=/usr/local
PREFIX=$LOCALBASE
VERSION=0.0.1
COMPAT_DIR="./compat"
YACC_SRC="cfg_file.y"
LEX_SRC="cfg_file.l"
YACC_OUTPUT="cfg_yacc.c"
LEX_OUTPUT="cfg_lex.c"
CONFIG="config.h"
SOURCES="upstream.c cfg_utils.c memcached.c main.c util.c worker.c fstring.c url.c perl.c protocol.c mem_pool.c filter.c plugins/surbl.c ${LEX_OUTPUT} ${YACC_OUTPUT}"
MODULES="surbl"
CFLAGS="$CFLAGS -W -Wpointer-arith -Wno-unused-parameter"
CFLAGS="$CFLAGS -Wno-unused-function -Wunused-variable -Wno-sign-compare"
CFLAGS="$CFLAGS -Wunused-value -ggdb -I${LOCALBASE}/include"
CFLAGS="$CFLAGS "
LDFLAGS="$LDFLAGS -L/usr/lib -L${LOCALBASE}/lib"
OPT_FLAGS="-O -pipe -fno-omit-frame-pointer"
DEPS="config.h cfg_file.h memcached.h util.h main.h upstream.h fstring.h url.h perl.h mem_pool.h protocol.h filter.h ${LEX_OUTPUT} ${YACC_OUTPUT}"
EXEC=rspamd
USER=postfix
GROUP=postfix
INSTALL="/usr/bin/install -v"
MKDIR="/usr/bin/install -v -d"
MANPATH="${PREFIX}/share/man"
SUBDIRS="test utils"
MAKEFILE="Makefile"
MAKEFILE_IN="Makefile.in"
PERL_MAKEFILE="perl/Makefile.PL.in"
PERLCFLAGS=""
PERLLDFLAGS=""
DEPENDS_FILE=".depends"
OPTS=""
TARGETS="${EXEC}"
prepare_config()
{
echo "#ifndef CONFIG_H_IN" > $CONFIG
echo "#define CONFIG_H_IN" >> $CONFIG
cat "$CONFIG.in" >> $CONFIG
}
finish_config()
{
echo "#endif" >> $CONFIG
}
cleanup()
{
rm -f autotest.c
rm -f autotest
INCLUDE=""
}
have_opt()
{
echo "#define HAVE_$1" >> $CONFIG
OPTS="$OPTS HAVE_$1"
}
check_compiler()
{
GCC=`PATH="$PATH:$PREFIX/bin:$LOCALBASE/bin" which gcc`
echo -n "Testing for gcc: "
if [ -x $GCC ] ; then
echo "found -> $GCC"
return 0
else
echo "not found"
exit 1
fi
}
check_make()
{
MAKE=`PATH="$PATH:$PREFIX/bin:$LOCALBASE/bin" which make`
echo -n "Testing for make: "
if [ -x $MAKE ] ; then
echo "found -> $MAKE"
return 0
else
echo "not found"
exit 1
fi
}
check_lex()
{
LEX=`PATH="$PATH:$PREFIX/bin:$LOCALBASE/bin" which lex`
echo -n "Testing for lex: "
if [ -x $LEX ] ; then
echo "found -> $LEX"
return 0
else
echo "not found"
exit 1
fi
}
check_yacc()
{
YACC=`PATH="$PATH:$PREFIX/bin:$LOCALBASE/bin" which yacc`
echo -n "Testing for yacc: "
if [ -x $YACC ] ; then
echo "found -> $YACC"
return 0
else
echo "not found"
exit 1
fi
}
check_function()
{
FUNCTION=$1
while [ $# -ne 0 -a -n $2 ] ; do
shift
if [ "F$INCLUDE" = "F" ] ; then
INCLUDE="$1"
else
INCLUDE="$INCLUDE $1"
fi
done
echo -n "Testing for $FUNCTION: "
echo >> config.log
echo "Testing for $FUNCTION: " >> config.log
echo "#include <sys/types.h>" > autotest.c
if [ "F$INCLUDE" != "F" ] ; then
for inc in $INCLUDE ; do
echo "#include \"$inc\"" >> autotest.c
done
fi
echo "#include <stdlib.h>" >> autotest.c
echo "int main (int argc, char **argv) { $FUNCTION; return 0; }" >> autotest.c
echo "$GCC $PTHREAD_CFLAGS $CFLAGS -o autotest $LDFLAGS $LIBS $PTHREAD_LDFLAGS autotest.c" >>config.log
$GCC $PTHREAD_CFLAGS $CFLAGS -o autotest $LDFLAGS $LIBS $PTHREAD_LDFLAGS autotest.c >>config.log 2>&1
if [ $? -eq 0 ] ; then
echo "found"
cleanup
echo "-> OK" >> config.log
return 0
else
echo "not found"
echo "-> FAILED" >> config.log
echo "Failed program was:" >> config.log
cat autotest.c >> config.log
cleanup
return 1
fi
}
check_include()
{
INCLUDE="$1"
echo -n "Testing for $INCLUDE: "
echo >> config.log
echo "Testing for $INCLUDE: " >> config.log
echo "#include <sys/types.h>" > autotest.c
echo "#include \"$INCLUDE\"" >> autotest.c
echo "#include <stdlib.h>" >> autotest.c
echo "int main (int argc, char **argv) { return 0; }" >> autotest.c
echo "$GCC $CFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS $PTHREAD_LDFLAGS autotest.c" >>config.log
$GCC $CFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS $PTHREAD_LDFLAGS autotest.c >>config.log 2>&1
if [ $? -eq 0 ] ; then
echo "found"
echo "-> OK" >> config.log
_CFLAG=`echo "$INCLUDE" | sed -e 's/[./]/_/g' | tr '[:lower:]' '[:upper:]'`
have_opt $_CFLAG
cleanup
return 0
else
echo "not found"
echo "-> FAILED" >> config.log
echo "Failed program was:" >> config.log
cat autotest.c >> config.log
cleanup
return 1
fi
}
check_macro()
{
MACRO=$1
while [ $# -ne 1 -a -n $1 ] ; do
shift
if [ "F$INCLUDE" = "F" ] ; then
INCLUDE="$1"
else
INCLUDE="$INCLUDE $1"
fi
done
echo -n "Testing for $MACRO: "
echo >> config.log
echo "Testing for $MACRO: " >> config.log
echo "#include <sys/types.h>" > autotest.c
for inc in $INCLUDE ; do
echo "#include \"$inc\"" >> autotest.c
done
echo "#include \"${INCLUDE}\"" >> autotest.c
echo "#include <stdlib.h>" >> autotest.c
echo "int main (int argc, char **argv) {" >>autotest.c
echo "#ifndef $MACRO" >>autotest.c
echo "#error \"$MACRO not defined\"" >>autotest.c
echo "#endif" >> autotest.c
echo "}" >>autotest.c
echo "$GCC $CFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS $PTHREAD_LDFLAGS autotest.c" >> config.log
$GCC $CFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS $PTHREAD_LDFLAGS autotest.c >>config.log 2>&1
if [ $? -eq 0 ] ; then
echo "found"
cleanup
echo "-> OK" >> config.log
return 0
else
echo "not found"
echo "-> FAILED" >> config.log
echo "Failed program was:" >> config.log
cat autotest.c >> config.log
cleanup
return 1
fi
}
check_lib()
{
LIB=$1
while [ $# -ne 1 -a -n $1 ] ; do
shift
if [ "F$INCLUDE" = "F" ] ; then
INCLUDE="$1"
else
INCLUDE="$INCLUDE $1"
fi
done
echo -n "Testing for lib$LIB: "
echo >> config.log
echo "Testing for lib$LIB: " >> config.log
echo "#include <sys/types.h>" > autotest.c
if [ "F$INCLUDE" != "F" ] ; then
for inc in $INCLUDE ; do
echo "#include \"$inc\"" >> autotest.c
done
fi
echo "#include <stdlib.h>" >> autotest.c
echo "int main (int argc, char **argv) { return 0; }" >> autotest.c
echo "$GCC $CFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS -l$LIB $PTHREAD_LDFLAGS autotest.c" >>config.log
$GCC $CFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS -l$LIB $PTHREAD_LDFLAGS autotest.c >>config.log 2>&1
if [ $? -eq 0 ] ; then
echo "found"
LIBS="$LIBS -l$LIB"
cleanup
echo "-> OK" >> config.log
return 0
else
echo "not found"
echo "-> FAILED" >> config.log
echo "Failed program was:" >> config.log
cat autotest.c >> config.log
cleanup
return 1
fi
}
check_package()
{
PACKAGE=$1
PLIBS=`$PKG_CONFIG --libs $PACKAGE`
PCFLAGS=`$PKG_CONFIG --cflags $PACKAGE`
while [ $# -ne 1 -a -n $1 ] ; do
shift
if [ "F$INCLUDE" = "F" ] ; then
INCLUDE="$1"
else
INCLUDE="$INCLUDE $1"
fi
done
echo -n "Testing for $PACKAGE: "
echo >> config.log
echo "Testing for $PACKAGE: " >> config.log
echo "#include <sys/types.h>" > autotest.c
if [ "F$INCLUDE" != "F" ] ; then
for inc in $INCLUDE ; do
echo "#include \"$inc\"" >> autotest.c
done
fi
echo "#include <stdlib.h>" >> autotest.c
echo "int main (int argc, char **argv) { return 0; }" >> autotest.c
echo "$GCC $CFLAGS $PCFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS $PLIBS $PTHREAD_LDFLAGS autotest.c" >>config.log
$GCC $CFLAGS $PCFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS $PLIBS $PTHREAD_LDFLAGS autotest.c >>config.log 2>&1
if [ $? -eq 0 ] ; then
echo "found"
LIBS="$LIBS $PLIBS"
CFLAGS="$CFLAGS $PCFLAGS"
cleanup
echo "-> OK" >> config.log
return 0
else
echo "not found"
echo "-> FAILED" >> config.log
echo "Failed program was:" >> config.log
cat autotest.c >> config.log
cleanup
return 1
fi
}
check_perl()
{
echo -n "Testing for $PERL: "
echo >> config.log
echo "Testing for $PERL: " >> config.log
if [ ! -x $PERL ] ; then
echo "not found"
echo "-> FAILED" >> config.log
cleanup
return 1
fi
PERLCFLAGS=`$PERL -MExtUtils::Embed -e ccopts`
PERLLDFLAGS=`$PERL -MExtUtils::Embed -e ldopts`
echo "#include <stdlib.h>" > autotest.c
echo "#include <EXTERN.h>" >> autotest.c
echo "#include <perl.h>" >> autotest.c
echo "int main (int argc, char **argv) { PERL_SYS_INIT3(&argc,&argv,&env); return 0; }" >> autotest.c
echo "$GCC $CFLAGS $PERLCFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS $PERLLDFLAGS $PTHREAD_LDFLAGS autotest.c" >>config.log
$GCC $CFLAGS $PERLCFLAGS $PTHREAD_CFLAGS -o autotest $LDFLAGS $LIBS $PERLLDFLAGS $PTHREAD_LDFLAGS autotest.c >>config.log 2>&1
if [ $? -eq 0 ] ; then
echo "found"
cleanup
echo "-> OK" >> config.log
return 0
else
echo "not found"
echo "-> FAILED" >> config.log
echo "Failed program was:" >> config.log
cat autotest.c >> config.log
cleanup
return 1
fi
}
check_os()
{
_OS=`uname -s`
case "$_OS" in
FreeBSD*)
OS="freebsd"
CFLAGS="${CFLAGS}"
INSTALL="/usr/bin/install -C -S -v"
MKDIR="/usr/bin/install -d -v"
MANPATH="${PREFIX}/man"
echo "#define FREEBSD" >> $CONFIG ;;
Linux*) OS="linux" CFLAGS="${CFLAGS} -D_GNU_SOURCE"
echo "#define LINUX" >> $CONFIG ;;
Solaris*) OS="solaris" CFLAGS="${CFLAGS}"
echo "#define SOLARIS" >> $CONFIG ;;
*) OS="unknown" ;;
esac
}
check_user()
{
_user=$1
echo -n "Checking for user $_user: "
grep $_user /etc/passwd > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "found"
return 0
else
echo "not found"
return 1
fi
}
check_group()
{
_group=$1
echo -n "Checking for group $_group: "
grep $_group /etc/group > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "found"
return 0
else
echo "not found"
return 1
fi
}
check_depends()
{
ifdep=""
depends=""
if [ ! -f $DEPENDS_FILE ] ; then
return 0
fi
while read line ; do
echo $line | grep '#if' > /dev/null
if [ $? -eq 0 ] ; then
ifdep=`echo $line | sed -e 's/^#if \([A-Za-z0-9_]*\)$/\1/'`
elif [ "F$ifdep" != "F" ] ; then
echo $line | grep "#endif" > /dev/null
if [ $? -eq 0 ] ; then
ifdep=""
else
echo $OPTS | grep $ifdep > /dev/null
if [ $? -eq 0 ] ; then
depends="$depends $line"
fi
fi
else
depends="$depends $line"
fi
done < $DEPENDS_FILE
obj_depends=`echo $depends | sed -e 's/\([^ ]\{1,\}\)\/\([^/]\{1,\}\).c/\2.o/g'`
echo "DEPENDS=$depends" >> $MAKEFILE
echo "OBJ_DEPENDS=$obj_depends" >> $MAKEFILE
for _dep in $depends ; do
_obj_dep=`echo $_dep | sed -e 's/\([^ ]\{1,\}\)\/\([^/]\{1,\}\).c/\2.o/g'`
cat >> $MAKEFILE.dep << END
${_obj_dep}: ${_dep}
\$(CC) \$(OPT_FLAGS) \$(CFLAGS) \$(PTHREAD_CFLAGS) -o ${_obj_dep} -c ${_dep}
END
done
}
write_modules()
{
# Write modules init function
echo "#ifndef MODULES_H" > modules.h
echo "#include \"config.h\"" >> modules.h
echo "#include \"modules.h\"" > modules.c
echo "module_t modules[] = {" >> modules.c;
modules_num=0
for m in $MODULES ; do
echo "{\"${m}\", ${m}_module_init, ${m}_module_config, ${m}_module_reconfig}," >> modules.c
echo "int ${m}_module_init(struct config_file *cfg, struct module_ctx **ctx);" >> modules.h
echo "int ${m}_module_config(struct config_file *cfg);" >> modules.h
echo "int ${m}_module_reconfig(struct config_file *cfg);" >> modules.h
modules_num=`expr $modules_num + 1`
done
echo "};" >> modules.c
echo "#endif" >> modules.h
echo "#define MODULES_NUM $modules_num" >> $CONFIG
SOURCES="$SOURCES modules.c"
OBJECTS=`echo $SOURCES | sed -e 's/\.c/\.o/g'`
}
write_perl()
{
# Write to perl Makefile
sed -e "s|%%libs%%|${LDFLAGS} ${LIBS}|" < $PERL_MAKEFILE > .pl_tmp
sed -e "s|%%include%%|${CFLAGS}|" < .pl_tmp > .pl2_tmp
PERL_MAKEFILE=`echo ${PERL_MAKEFILE} | sed -e 's|.in$||'`
mv .pl2_tmp $PERL_MAKEFILE
rm -f .pl_tmp .pl2_tmp
CURDIR=`pwd`
cd `dirname ${PERL_MAKEFILE}`
$PERL Makefile.PL
cd $CURDIR
}
write_subdirs()
{
# Write subdirs makefiles
clean_target="clean-subdirs: "
dist_clean_target="dist-clean-subdirs: "
for sub in $SUBDIRS ; do
cp $MAKEFILE $sub/$MAKEFILE
saved_pwd=`pwd`
old_objs=`echo $OBJECTS | sed -e 's/\([^. ]*\.o\)/..\/\1/g'`
old_srcs=`echo $SOURCES | sed -e 's/\([^. ]*\.c\)/..\/\1/g'`
cd $sub
sub_src="`echo *.c`"
sub_obj="`echo $sub_src | sed -e 's/\.c/\.o/g'`"
echo "SOURCES=$sub_src" >> $MAKEFILE
echo "OBJECTS=$sub_obj" >> $MAKEFILE
check_depends
cat Makefile.in >> $MAKEFILE
if [ -f $MAKEFILE.dep ] ; then
cat $MAKEFILE.dep >> $MAKEFILE
rm -f $MAKEFILE.dep
fi
for _sub_src in $sub_src ; do
_sub_obj=`echo $_sub_src | sed -e 's/\.c/\.o/g'`
cat >> $MAKEFILE << END
${_sub_obj}: ${_sub_src}
\$(CC) \$(OPT_FLAGS) \$(CFLAGS) \$(PTHREAD_CFLAGS) -o ${_sub_obj} -c ${_sub_src}
END
done
cd $saved_pwd
dist_clean_target="$dist_clean_target ${sub}-dist-clean"
clean_target="$clean_target ${sub}-clean"
done
# Write IN file
cat $MAKEFILE_IN >> $MAKEFILE
# Process clean targets for all subdirs
echo $dist_clean_target >> $MAKEFILE
echo $clean_target >> $MAKEFILE
for sub in $SUBDIRS ; do
cat >> $MAKEFILE << END
${sub}-clean:
cd ${sub} && make clean && cd ..
${sub}-dist-clean:
cd ${sub} && make dist-clean && cd ..
${sub}:
cd ${sub} && make && cd ..
END
done
}
write_result()
{
echo "Compiler: $GCC" >> config.log
echo "Make: $MAKE" >> config.log
echo "Sources: $SOURCES" >> config.log
echo "Cflags: $CFLAGS" >> config.log
echo "Ldflags: $LDFLAGS" >> config.log
echo "Libs: $LIBS" >> config.log
echo "#define RVERSION \"${VERSION}\"" >> $CONFIG
echo "#define HASH_COMPAT" >> $CONFIG
write_modules
write_perl
# Make CFLAGS more readable
CFLAGS="$CFLAGS $PERLCFLAGS"
LIBS="$LIBS $PERLLDFLAGS"
CFLAGS=`echo $CFLAGS | tr [:space:] \\\n | sed -e 's/$/ \\\/' | sed -e '$,$s/\\\//' | sort -r -k2 | uniq`
LDFLAGS=`echo $LDFLAGS | tr [:space:] \\\n | sed -e 's/$/ \\\/' | sed -e '$,$s/\\\//' | sort -r -k2 | uniq`
LIBS=`echo $LIBS | tr [:space:] \\\n | sed -e 's/$/ \\\/' | sed -e '$,$s/\\\//' | sort -r -k2 | uniq`
cat > $MAKEFILE << END
# This is ${EXEC} Makefile
# For options edit Makefile.in, this file is autogenerated by configure
CC=$GCC
# Optimization flags
OPT_FLAGS=$OPT_FLAGS
# Compile time flags
CFLAGS=$CFLAGS
# Link time flags
LDFLAGS=$LDFLAGS
# Libraries to link
LIBS=$LIBS
# ${EXEC} sources
SOURCES=$SOURCES
# ${EXEC} objects
OBJECTS=$OBJECTS
# Version of product
VERION=$VERSION
# Detected operation system
OS=$OS
# Lex and yacc executables
LEX=$LEX
YACC=$YACC
# Pthread specific flags
PTHREAD_CFLAGS=$PTHREAD_CFLAGS
PTHREAD_LDFLAGS=$PTHREAD_LDFLAGS
# Prefix to install
PREFIX=$PREFIX
# Where local libs and includes are located
LOCALBASE=$LOCALBASE
# Install commands
INSTALL=$INSTALL
MKDIR=$MKDIR
# Executable name
EXEC=$EXEC
# User and group
RSPAMD_USER=$USER
RSPAMD_GROUP=$GROUP
# All target dependenses
TARGETS=$TARGETS $SUBDIRS
# Common dependenses
DEPS=$DEPS
# Path to install manual page
MANPATH=$MANPATH
# Subdirectories
SUBDIRS=$SUBDIRS
END
write_subdirs
# Write build targets to makefile
cat >> $MAKEFILE << END
${EXEC}: \$(OBJECTS)
\$(CC) \$(PTHREAD_LDFLAGS) \$(LDFLAGS) \$(OBJECTS) \$(LIBS) -o \$(EXEC)
END
for o in $OBJECTS ; do
SO=`echo $o | sed -e 's/\.o/\.c/g'`
cat >> $MAKEFILE << END
${o}: \$(DEPS) ${SO}
\$(CC) \$(OPT_FLAGS) \$(CFLAGS) \$(PTHREAD_CFLAGS) -o ${o} -c ${SO}
END
done
cat >> $MAKEFILE << END
${LEX_OUTPUT}: cfg_file.h ${LEX_SRC} ${YACC_OUTPUT}
\$(LEX) -o${LEX_OUTPUT} ${LEX_SRC}
${YACC_OUTPUT}: cfg_file.h ${YACC_SRC}
\$(YACC) -d -o ${YACC_OUTPUT} ${YACC_SRC}
END
}
for option
do
case "$option" in
-*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;
*) value="" ;;
esac
case "$option" in
--help) help=yes ;;
--prefix) PREFIX=$value ;;
--user) USER=$value ;;
--group) GROUP=$value ;;
--enable-debug) CFLAGS="$CFLAGS -DWITH_DEBUG" OPT_FLAGS="" ;;
--enable-opt) OPT_FLAGS="-O3 -pipe" ;;
--add-module) SOURCES="$SOURCES $value"
if [ ! -f $value ] ; then
echo "Cannot find $value, please check path"
exit 1
fi
modline=`grep '/***MODULE:' $value`
if [ F"$modline" = "F" ] ; then
echo "Cannot find /***MODULE line in $value, please check syntax"
exit 1
fi
name=`echo $modline | sed 's/.*MODULE:\([^: ]*\).*/\1/'`
MODULES="$MODULES $name" ;;
--disable-module) SOURCES=`echo $SOURCES | sed -e "s/${value}//g"`
if [ ! -f $value ] ; then
echo "Cannot find $value, please check path"
exit 1
fi
modline=`grep '/***MODULE:' $value`
if [ F"$modline" = "F" ] ; then
echo "Cannot find /***MODULE line in $value, please check syntax"
exit 1
fi
name=`echo $modline | sed 's/.*MODULE:\([^: ]*\).*/\1/'`
MODULES=`echo $MODULES | sed -e "s/${name}//g"` ;;
*)
echo "$0: error: invalid option \"$option\""
exit 1
;;
esac
done
if [ "F$help" = "Fyes" ] ; then
cat << END
--help this message
--prefix=PATH set the installation prefix
--enable-debug turn on extra debug messages
--enable-opt turn on extra optimization
--add-module add additional C module
--disable-module do not include C module
--user=USER set user to use
--group=GROUP set group to use
END
exit 1
fi
CFLAGS="$CFLAGS -I$PREFIX/include"
LDFLAGS="$LDFLAGS -L$PREFIX/lib"
echo "Starting configure for rmilter" >config.log
echo $0 $@ >> config.log
prepare_config
check_compiler
check_make
check_lex
check_yacc
check_os
check_lib "event" "event.h"
if [ $? -eq 1 ] ; then
echo "Libevent not found, check config.log for details"
exit 1
fi
check_lib "pcre" "pcre.h"
if [ $? -eq 1 ] ; then
echo "PCRE not found, check config.log for details"
exit 1
fi
check_lib "m"
check_lib "pcre"
check_lib "md"
if [ $? -eq 1 ] ; then
cp $COMPAT_DIR/md5.c .
cp $COMPAT_DIR/md5.h .
SOURCES="$SOURCES md5.c"
DEPS="$DEPS md5.h"
have_opt "OWN_MD5"
fi
check_lib "util"
if [ $? -eq 0 ] ; then
have_opt "LIBUTIL"
fi
check_function "pidfile_open" "sys/param.h" "libutil.h"
if [ $? -eq 0 ] ; then
have_opt "PIDFILE"
fi
check_function "strlcpy" "string.h"
if [ $? -eq 1 ] ; then
cp $COMPAT_DIR/strlcpy.c .
cp $COMPAT_DIR/strlcpy.h .
SOURCES="$SOURCES strlcpy.c"
DEPS="$DEPS strlcpy.h"
have_opt "STRLCPY_H"
fi
check_function "bzero" "string.h"
check_function "srandomdev"
if [ $? -eq 0 ] ; then
have_opt "SRANDOMDEV"
fi
check_function "getpagesize" "unistd.h"
if [ $? -eq 0 ] ; then
have_opt "GETPAGESIZE"
fi
check_function "setproctitle" "unistd.h"
if [ $? -eq 0 ] ; then
have_opt "SETPROCTITLE"
fi
check_include "endian.h"
check_include "libutil.h"
check_include "machine/endian.h"
check_include "sys/time.h"
check_include "time.h"
check_include "stdint.h"
if [ $? -eq 1 ] ; then
check_include "inttypes.h"
fi
check_include "strlcpy.h"
check_include "md5.h"
check_include "sys/queue.h"
if [ $? -eq 1 ] ; then
cp $COMPAT_DIR/queue.h .
DEPS="$DEPS queue.h"
fi
check_macro "SLIST_FOREACH_SAFE" "sys/queue.h"
if [ $? -eq 1 ] ; then
cp $COMPAT_DIR/queue.h .
DEPS="$DEPS queue.h"
have_opt "OWN_QUEUE_H"
fi
check_macro "PATH_MAX" "limits.h"
if [ $? -eq 1 ] ; then
check_macro "MAXPATHLEN" "sys/param.h"
if [ $? -eq 1 ] ; then
have_opt "MAXPATHLEN"
echo "#define MAXPATHLEN 4096" >> $CONFIG
else
have_opt "MAXPATHLEN"
fi
else
have_opt "PATH_MAX"
fi
check_package "glib-2.0" "glib.h"
check_package "gmime-2.0" "gmime/gmime.h"
if [ $? -eq 1 ] ; then
echo "Package gmime-2.0 not found, check config.log for details"
exit 1
fi
check_perl
if [ $? -eq 1 ] ; then
echo "Perl or libperl not found, check config.log for details"
exit 1
fi
check_group $GROUP
if [ $? -ne 0 ] ; then
TARGETS="$TARGETS creategroup"
fi
check_user $USER
if [ $? -ne 0 ] ; then
TARGETS="$TARGETS createuser"
fi
write_result
finish_config
|