]> git.stg.codes - stg.git/blob - projects/stargazer/build
Ticket. MybeSet()function call added for the change-policy-timeout.
[stg.git] / projects / stargazer / build
1 #!/bin/sh
2
3 #   $Revision: 1.57 $
4 #   $Author: faust $
5 #   $Date: 2010/05/09 12:39:01 $
6 ######################################################
7
8 # Installation path prefix
9
10 #PREFIX=""
11
12 # Binaries access bits
13
14 BIN_MODE=0755
15
16 # Data files access bits
17
18 DATA_MODE=0644
19
20 # Dir access bits
21
22 DIR_MODE=0755
23
24 # Binaries and data files owner
25
26 OWNER=root
27
28 OS=unknown
29 sys=`uname -s`
30 release=`uname -r`
31 major=`printf "%s" "$release" | cut -d. -f1`
32 BUILD_DIR=`pwd`
33 CONFFILE="../../Makefile.conf"
34 VAR_DIR="./inst/var/stargazer"
35 MIN_XMLRPCC_VERSION="1.06.27"
36 XMLRPC_FEATURES="c++2 abyss-server"
37
38
39 if [ "$1" = "debug" ]
40 then
41     DEFS="$DEFS -DDEBUG"
42     MAKEOPTS="$MAKEOPTS -j1"
43     CFLAGS="$CFLAGS -ggdb3 -W -Wall"
44     CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall"
45     DEBUG="yes"
46 else
47     DEFS="$DEFS -DNDEBUG"
48     DEBUG="no"
49 fi
50
51 CFLAGS="$CFLAGS -I/usr/local/include"
52 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
53 LDFLAGS="$LDFLAGS -L/usr/local/lib"
54
55 if [ "$sys" = "Linux" ]
56 then
57     OS=linux
58     ETC_DIR="./inst/linux/etc/stargazer"
59     MAKE="make"
60 fi
61
62 if [ "$sys" = "FreeBSD" ]
63 then
64     case $major in
65         4) OS=bsd;;
66         5) OS=bsd5;;
67         6) OS=bsd5;;
68         7) OS=bsd7;;
69         *) OS=bsd7;;
70     esac
71     ETC_DIR="./inst/freebsd/etc/stargazer"
72     MAKE="gmake"
73 fi
74
75 if [ "$sys" = "Darwin" ]
76 then
77     OS=darwin
78     ETC_DIR="./inst/freebsd/etc/stargazer"
79     MAKE="gmake"
80 fi
81
82 if [ "$OS" = "unknown" ]
83 then
84     printf "#############################################################################\n"
85     printf "# Sorry, but stargazer is currently supported by Linux, FreeBSD and Darwin. #\n"
86     printf "#############################################################################\n"
87     exit 1
88 fi
89
90 printf "#############################################################################\n"
91 printf "       Building STG 2.4 for $sys $release\n"
92 printf "#############################################################################\n"
93
94 STG_LIBS="logger.lib
95           crypto.lib
96           common.lib
97           scriptexecuter.lib
98           conffiles.lib
99           pinger.lib
100           dotconfpp.lib
101           smux.lib"
102
103 PLUGINS="authorization/ao
104          authorization/inetaccess
105          configuration/sgconfig
106          other/ping
107          other/rscript
108          other/radius
109          other/smux
110          store/files
111          capture/cap_nf"
112
113 if [ "$OS" = "linux" ]
114 then
115     DEFS="$DEFS -DLINUX"
116     PLUGINS="$PLUGINS
117              capture/ether_linux"
118     LIB_THREAD=-lpthread
119 else
120     LIBICONV="-liconv"
121     if [ "$OS" = "bsd" ]
122     then
123         DEFS="$DEFS -DFREE_BSD"
124         LIB_THREAD=-lc_r
125     else
126         if [ "$OS" = "bsd7" ]
127         then
128             DEFS="$DEFS -DFREE_BSD5"
129             LIB_THREAD=-lpthread
130         else
131             if [ "$OS" == "darwin" ]
132             then
133                 DEFS="$DEFS -DDARWIN"
134                 LIB_THREAD=-lpthread
135                 LIBICONV=""
136             else
137                 LIB_THREAD=-lc_r
138             fi
139         fi
140     fi
141     PLUGINS="$PLUGINS
142              capture/ether_freebsd
143              capture/divert_freebsd"
144 fi
145
146 if [ -z "$CC" ]
147 then
148     CC=gcc
149 fi
150
151 if [ -z "$CXX" ]
152 then
153     CXX=g++
154 fi
155
156 printf "Checking CC... "
157 $CC --version > /dev/null 2> /dev/null
158 if [ $? != 0 ]
159 then
160     printf "FAIL!\n"
161     printf "$CC not found\n"
162     exit;
163 fi
164 printf "found\n"
165 printf "Checking CXX... "
166 $CXX --version > /dev/null 2> /dev/null
167 if [ $? != 0 ]
168 then
169     printf "FAIL!\n"
170     printf "$CXX not found\n"
171     exit;
172 fi
173 printf "found\n"
174
175 printf "Checking endianess... "
176 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
177 $CC $CFLAGS $LDFLAGS build_check.c -o fake
178 if [ $? != 0 ]
179 then
180     printf "FAIL!\n"
181     printf "Endianess checking failed\n"
182     exit;
183 else
184     ./fake
185     if [ $? = 1 ]
186     then
187         ARCH=le
188         CXXFLAGS="$CXXFLAGS -DARCH_LE"
189         CFLAGS="$CFLAGS -DARCH_LE"
190         printf "Little Endian\n"
191     else
192         ARCH=be
193         CXXFLAGS="$CXXFLAGS -DARCH_BE"
194         CFLAGS="$CFLAGS -DARCH_BE"
195         printf "Big Endian\n"
196     fi
197 fi
198 rm -f fake
199
200 printf "Checking for -lexpat... "
201 printf "#include <expat.h>\nint main() { return 0; }\n" > build_check.c
202 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
203 if [ $? != 0 ]
204 then
205     CHECK_EXPAT=no
206     printf "no\n"
207 else
208     CHECK_EXPAT=yes
209     printf "yes\n"
210 fi
211 rm -f fake
212
213 printf "Checking for iconv 2nd argument... "
214 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
215 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
216 if [ $? != 0 ]
217 then
218     printf "non-const\n"
219 else
220     DEFS="$DEFS -DCONST_ICONV"
221     printf "const\n"
222 fi
223 rm -f fake
224
225 printf "Checking for fb_config... "
226 FB_VERSION=`fb_config --version 2> /dev/null`
227 if [ "$?" != "0" ]
228 then
229     printf "no\n"
230     printf "Checking for -lfbclient... "
231     printf "int main() { return 0; }\n" > build_check.c
232     $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
233     if [ $? != 0 ]
234     then
235         CHECK_FBCLIENT=no
236         printf "no\n"
237     else
238         FB_CFLAGS=""
239         FB_LDFLAGS="-lfbclient"
240         CHECK_FBCLIENT=yes
241         printf "yes\n"
242     fi
243     rm -f fake
244 else
245     printf "yes\n"
246     printf "Checking for fb_config --cflags... "
247     FB_CFLAGS=`fb_config --cflags`
248     if [ "$?" != "0" ]
249     then
250         CHECK_FBCLIENT=no
251         printf "no\n"
252     else
253         printf "[$FB_CFLAGS]\n"
254         printf "Checking for fb_config --libs "
255         FB_LDFLAGS=`fb_config --libs`
256         if [ "$?" != "0" ]
257         then
258             CHECK_FBCLIENT=no
259             printf "no\n"
260         else
261             CHECK_FBCLIENT=yes
262             printf "[$FB_LDFLAGS]\n"
263         fi
264     fi
265 fi
266
267
268 printf "Checking for mysql_config... "
269 printf "#include <mysql.h>\nint main() { return 0; }\n" > build_check.c
270 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
271 if [ $? != 0 ]
272 then
273     printf "no\n";
274     printf "Checking for -lmysqlclient... "
275     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
276     if [ $? != 0 ]
277     then
278         CHECK_MYSQLCLIENT=no
279         printf "no\n"
280     else
281         CHECK_MYSQLCLIENT=yes
282         MYSQL_CFLAGS=""
283         MYSQL_LDFLAGS="-lmysqlclient_r"
284         printf "yes\n"
285     fi
286     rm -f fake
287 else
288     printf "yes\n"
289     printf "Checking for mysql_config --cflags... "
290     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
291     if [ $? != 0 ]
292     then
293         CHECK_MYSQLCLIENT=no
294         printf "no\n"
295     else
296         printf "[$MYSQL_CFLAGS]\n"
297         printf "Checking for mysql_config --libs_r... "
298         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
299         if [ $? != 0 ]
300         then
301             CHECK_MYSQLCLIENT=no
302             printf "no\n"
303         else
304             CHECK_MYSQLCLIENT=yes
305             printf "[$MYSQL_LDFLAGS]\n"
306         fi
307     fi
308 fi
309
310 printf "Checking for pg_config... "
311 printf "#include <libpq-fe.h>\nint main() { return 0; }\n" > build_check.c
312 PG_VERSION=`pg_config --version 2> /dev/null`
313 if [ $? != 0 ]
314 then
315     printf "no\n";
316     printf "Checking for -lpq... "
317     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
318     if [ $? != 0 ]
319     then
320         CHECK_PQ=no
321         printf "no\n"
322     else
323         CHECK_PQ=yes
324         printf "yes\n"
325     fi
326     rm -f fake
327 else
328     printf "yes\n";
329     printf "Checking for pg_config --includedir... "
330     PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null`
331     if [ $? != 0 ]
332     then
333         CHECK_PQ=no
334         printf "no\n"
335     else
336         printf "[$PG_CFLAGS]\n"
337         printf "Checking for pg_config --libdir... "
338         PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null`
339         if [ $? != 0 ]
340         then
341             CHECK_PQ=no
342             printf "no\n"
343         else
344             CHECK_PQ=yes
345             printf "[$PG_LDFLAGS]\n"
346         fi
347     fi
348 fi
349
350 printf "Checking for xmlrpc-c-config... "
351 printf "#include <xmlrpc-c/base.hpp>\nint main() { return 0; }\n" > build_check.c
352 XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
353 if [ $? != 0 ]
354 then
355     printf "no\n";
356     printf "Checking for -lxmlrpc... "
357     $CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
358     if [ $? != 0 ]
359     then
360         CHECK_XMLRPC=no
361         printf "no\n"
362     else
363         CHECK_XMLRPC=yes
364         printf "yes\n"
365     fi
366     rm -f fake
367 elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
368 then
369     printf "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)\n";
370     CHECK_XMLRPC=no
371 else
372     printf "yes (version $XMLRPCC_VERSION)\n";
373     printf "Checking for xmlrpc-c-config --cflags... "
374     XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
375     if [ $? != 0 ]
376     then
377         CHECK_XMLRPC=no
378         printf "no\n"
379     else
380         printf "[$XMLRPC_CFLAGS]\n"
381         printf "Checking for xmlrpc-c-config --libs... "
382         XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
383         if [ $? != 0 ]
384         then
385             CHECK_XMLRPC=no
386             printf "no\n"
387         else
388             CHECK_XMLRPC=yes
389             printf "[$XMLRPC_LDFLAGS]\n"
390         fi
391     fi
392 fi
393
394 printf "Checking for -lpcap... "
395 printf "#include <pcap.h>\nint main() { return 0; }\n" > build_check.c
396 $CC $CFLAGS $LDFLAGS build_check.c -lpcap -o fake > /dev/null 2> /dev/null
397 if [ $? != 0 ]
398 then
399     CHECK_PCAP=no
400     printf "no\n"
401 else
402     CHECK_PCAP=yes
403     printf "yes\n"
404 fi
405 rm -f fake
406
407 printf "Checking for -lnfnetlink... "
408 printf "#include <stdint.h>\n#include <netinet/in.h>\n#include <linux/netfilter.h>\nint main() { return 0; }\n" > build_check.c
409 $CC $CFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null
410 if [ $? != 0 ]
411 then
412     CHECK_NFNETLINK=no
413     printf "no\n"
414 else
415     CHECK_NFNETLINK=yes
416     NETLINK_LDFLAGS="-lnfnetlink"
417     printf "yes\n"
418 fi
419 rm -f fake
420
421 printf "Checking for -lnetfilter_queue... "
422 printf "#include <stdint.h>\n#include <libnetfilter_queue/libnetfilter_queue.h>\nint main() { return 0; }\n" > build_check.c
423 $CC $CFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null
424 if [ $? != 0 ]
425 then
426     CHECK_NFQ=no
427     printf "no\n"
428 else
429     CHECK_NFQ=yes
430     NFQ_LDFLAGS="-lnetfilter_queue"
431     printf "yes\n"
432 fi
433 rm -f fake
434
435 if [ "$OS" = "linux" ]
436 then
437     printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
438     printf "#include <linux/types.h>\n" > build_check.c
439     printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
440     printf "int main() { return 0; }\n" >> build_check.c
441     $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
442     if [ $? != 0 ]
443     then
444         CHECK_IP_QUEUE_H=no
445         printf "no\n"
446     else
447         CHECK_IP_QUEUE_H=yes
448         DEFS="$DEFS -DHAS_IP_QUEUE_H"
449         PLUGINS="$PLUGINS
450                  capture/ipq_linux"
451         printf "yes\n"
452     fi
453     rm -f fake
454 fi
455
456 rm -f build_check.c
457
458 if [ "$CHECK_EXPAT" != "yes" ]
459 then
460     printf -- "-lexpat not found!\n"
461     exit 1
462 fi
463
464 if [ "$CHECK_FBCLIENT" = "yes" ]
465 then
466     STG_LIBS="$STG_LIBS
467               ibpp.lib"
468     PLUGINS="$PLUGINS
469              store/firebird"
470 fi
471
472 if [ "$CHECK_PQ" = "yes" ]
473 then
474     PLUGINS="$PLUGINS
475              store/postgresql"
476 fi
477
478 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
479 then
480     PLUGINS="$PLUGINS
481              store/mysql"
482 fi
483
484 if [ "$CHECK_XMLRPC" = "yes" ]
485 then
486     PLUGINS="$PLUGINS
487              configuration/rpcconfig"
488 fi
489
490 if [ "$CHECK_PCAP" = "yes" ]
491 then
492     PLUGINS="$PLUGINS
493              capture/pcap"
494 fi
495
496 if [ "$CHECK_NFNETLINK" = "yes" -a "$CHECK_NFQ" = "yes" ]
497 then
498     PLUGINS="$PLUGINS
499              capture/nfqueue"
500 fi
501
502 printf "OS=$OS\n" > $CONFFILE
503 printf "STG_TIME=yes\n" >> $CONFFILE
504 printf "DEBUG=$DEBUG\n" >> $CONFFILE
505 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
506 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
507 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
508 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
509 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
510 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
511 printf "ARCH=$ARCH\n" >> $CONFFILE
512 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
513 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
514 if [ "$CHECK_FBCLIENT" = "yes" ]
515 then
516     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
517     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
518 fi
519 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
520 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
521 then
522     printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE
523     printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE
524 fi
525 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
526 if [ "$CHECK_PQ" = "yes" ]
527 then
528     printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE
529     printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE
530 fi
531 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
532 if [ "$CHECK_XMLRPC" = "yes" ]
533 then
534     printf "XMLRPC_CFLAGS=$XMLRPC_CFLAGS\n" >> $CONFFILE
535     printf "XMLRPC_LDFLAGS=$XMLRPC_LDFLAGS\n" >> $CONFFILE
536 fi
537 printf "CHECK_PCAP=$CHECK_PCAP\n" >> $CONFFILE
538 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
539 if [ "$CHECK_NFNETLINK" = "yes" ]
540 then
541     printf "NETLINK_LDFLAGS=$NETLINK_LDFLAGS\n" >> $CONFFILE
542 fi
543 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
544 if [ "$CHECK_NFQ" = "yes" ]
545 then
546     printf "NFQ_LDFLAGS=$NFQ_LDFLAGS\n" >> $CONFFILE
547 fi
548 printf "DEFS=$DEFS\n" >> $CONFFILE
549 printf "STG_LIBS=" >> $CONFFILE
550 for lib in $STG_LIBS
551 do
552     printf "$lib " >> $CONFFILE
553 done
554 printf "\n" >> $CONFFILE
555 printf "PLUGINS=" >> $CONFFILE
556 for plugin in $PLUGINS
557 do
558     printf "$plugin " >> $CONFFILE
559 done
560 printf "\n" >> $CONFFILE
561 printf "CC=$CC\n" >> $CONFFILE
562 printf "CXX=$CXX\n" >> $CONFFILE
563 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
564 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
565 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
566 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
567 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
568 printf "PREFIX=$PREFIX\n" >> $CONFFILE
569 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
570 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
571 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
572 printf "OWNER=$OWNER\n" >> $CONFFILE
573 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
574 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
575
576 mkdir -p modules
577
578 if [ "$1" != "debug" ]
579 then
580     $MAKE $MAKEOPTS
581 else
582     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
583 fi