]> git.stg.codes - stg.git/blob - stargazer/build
Reorganize plugins.
[stg.git] / 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/smux
109          store/files
110          capture/cap_nf"
111
112 if [ "$OS" = "linux" ]
113 then
114     DEFS="$DEFS -DLINUX"
115     PLUGINS="$PLUGINS
116              capture/ether_linux"
117     LIB_THREAD=-lpthread
118 else
119     LIBICONV="-liconv"
120     if [ "$OS" = "bsd" ]
121     then
122         DEFS="$DEFS -DFREE_BSD"
123         LIB_THREAD=-lc_r
124     else
125         if [ "$OS" = "bsd7" ]
126         then
127             DEFS="$DEFS -DFREE_BSD5"
128             LIB_THREAD=-lpthread
129         else
130             if [ "$OS" == "darwin" ]
131             then
132                 DEFS="$DEFS -DDARWIN"
133                 LIB_THREAD=-lpthread
134             else
135                 LIB_THREAD=-lc_r
136             fi
137         fi
138     fi
139     PLUGINS="$PLUGINS
140              capture/ether_freebsd
141              capture/divert_freebsd"
142 fi
143
144 if [ -z "$CC" ]
145 then
146     CC=gcc
147 fi
148
149 if [ -z "$CXX" ]
150 then
151     CXX=g++
152 fi
153
154 printf "Checking CC... "
155 $CC --version > /dev/null 2> /dev/null
156 if [ $? != 0 ]
157 then
158     printf "FAIL!\n"
159     printf "$CC not found\n"
160     exit;
161 fi
162 printf "found\n"
163 printf "Checking CXX... "
164 $CXX --version > /dev/null 2> /dev/null
165 if [ $? != 0 ]
166 then
167     printf "FAIL!\n"
168     printf "$CXX not found\n"
169     exit;
170 fi
171 printf "found\n"
172
173 printf "Checking endianess... "
174 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
175 $CC $CFLAGS $LDFLAGS build_check.c -o fake
176 if [ $? != 0 ]
177 then
178     printf "FAIL!\n"
179     printf "Endianess checking failed\n"
180     exit;
181 else
182     ./fake
183     if [ $? = 1 ]
184     then
185         ARCH=le
186         CXXFLAGS="$CXXFLAGS -DARCH_LE"
187         CFLAGS="$CFLAGS -DARCH_LE"
188         printf "Little Endian\n"
189     else
190         ARCH=be
191         CXXFLAGS="$CXXFLAGS -DARCH_BE"
192         CFLAGS="$CFLAGS -DARCH_BE"
193         printf "Big Endian\n"
194     fi
195 fi
196 rm -f fake
197
198 printf "Checking for -lexpat... "
199 printf "#include <expat.h>\nint main() { return 0; }\n" > build_check.c
200 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
201 if [ $? != 0 ]
202 then
203     CHECK_EXPAT=no
204     printf "no\n"
205 else
206     CHECK_EXPAT=yes
207     printf "yes\n"
208 fi
209 rm -f fake
210
211 printf "Checking for iconv 2nd argument... "
212 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
213 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
214 if [ $? != 0 ]
215 then
216     printf "non-const\n"
217 else
218     DEFS="$DEFS -DCONST_ICONV"
219     printf "const\n"
220 fi
221 rm -f fake
222
223 printf "Checking for fb_config... "
224 FB_VERSION=`fb_config --version 2> /dev/null`
225 if [ "$?" != "0" ]
226 then
227     printf "no\n"
228     printf "Checking for -lfbclient... "
229     printf "int main() { return 0; }\n" > build_check.c
230     $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
231     if [ $? != 0 ]
232     then
233         CHECK_FBCLIENT=no
234         printf "no\n"
235     else
236         FB_CFLAGS=""
237         FB_LDFLAGS="-lfbclient"
238         CHECK_FBCLIENT=yes
239         printf "yes\n"
240     fi
241     rm -f fake
242 else
243     printf "yes\n"
244     printf "Checking for fb_config --cflags... "
245     FB_CFLAGS=`fb_config --cflags`
246     if [ "$?" != "0" ]
247     then
248         CHECK_FBCLIENT=no
249         printf "no\n"
250     else
251         printf "[$FB_CFLAGS]\n"
252         printf "Checking for fb_config --libs "
253         FB_LDFLAGS=`fb_config --libs`
254         if [ "$?" != "0" ]
255         then
256             CHECK_FBCLIENT=no
257             printf "no\n"
258         else
259             CHECK_FBCLIENT=yes
260             printf "[$FB_LDFLAGS]\n"
261         fi
262     fi
263 fi
264
265
266 printf "Checking for mysql_config... "
267 printf "#include <mysql.h>\nint main() { return 0; }\n" > build_check.c
268 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
269 if [ $? != 0 ]
270 then
271     printf "no\n";
272     printf "Checking for -lmysqlclient... "
273     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
274     if [ $? != 0 ]
275     then
276         CHECK_MYSQLCLIENT=no
277         printf "no\n"
278     else
279         CHECK_MYSQLCLIENT=yes
280         MYSQL_CFLAGS=""
281         MYSQL_LDFLAGS="-lmysqlclient_r"
282         printf "yes\n"
283     fi
284     rm -f fake
285 else
286     printf "yes\n"
287     printf "Checking for mysql_config --cflags... "
288     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
289     if [ $? != 0 ]
290     then
291         CHECK_MYSQLCLIENT=no
292         printf "no\n"
293     else
294         printf "[$MYSQL_CFLAGS]\n"
295         printf "Checking for mysql_config --libs_r... "
296         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
297         if [ $? != 0 ]
298         then
299             CHECK_MYSQLCLIENT=no
300             printf "no\n"
301         else
302             CHECK_MYSQLCLIENT=yes
303             printf "[$MYSQL_LDFLAGS]\n"
304         fi
305     fi
306 fi
307
308 printf "Checking for pg_config... "
309 printf "#include <libpq-fe.h>\nint main() { return 0; }\n" > build_check.c
310 PG_VERSION=`pg_config --version 2> /dev/null`
311 if [ $? != 0 ]
312 then
313     printf "no\n";
314     printf "Checking for -lpq... "
315     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
316     if [ $? != 0 ]
317     then
318         CHECK_PQ=no
319         printf "no\n"
320     else
321         CHECK_PQ=yes
322         printf "yes\n"
323     fi
324     rm -f fake
325 else
326     printf "yes\n";
327     printf "Checking for pg_config --includedir... "
328     PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null`
329     if [ $? != 0 ]
330     then
331         CHECK_PQ=no
332         printf "no\n"
333     else
334         printf "[$PG_CFLAGS]\n"
335         printf "Checking for pg_config --libdir... "
336         PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null`
337         if [ $? != 0 ]
338         then
339             CHECK_PQ=no
340             printf "no\n"
341         else
342             CHECK_PQ=yes
343             printf "[$PG_LDFLAGS]\n"
344         fi
345     fi
346 fi
347
348 printf "Checking for xmlrpc-c-config... "
349 printf "#include <xmlrpc-c/base.hpp>\nint main() { return 0; }\n" > build_check.c
350 XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
351 if [ $? != 0 ]
352 then
353     printf "no\n";
354     printf "Checking for -lxmlrpc... "
355     $CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
356     if [ $? != 0 ]
357     then
358         CHECK_XMLRPC=no
359         printf "no\n"
360     else
361         CHECK_XMLRPC=yes
362         printf "yes\n"
363     fi
364     rm -f fake
365 elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
366 then
367     printf "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)\n";
368     CHECK_XMLRPC=no
369 else
370     printf "yes (version $XMLRPCC_VERSION)\n";
371     printf "Checking for xmlrpc-c-config --cflags... "
372     XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
373     if [ $? != 0 ]
374     then
375         CHECK_XMLRPC=no
376         printf "no\n"
377     else
378         printf "[$XMLRPC_CFLAGS]\n"
379         printf "Checking for xmlrpc-c-config --libs... "
380         XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
381         if [ $? != 0 ]
382         then
383             CHECK_XMLRPC=no
384             printf "no\n"
385         else
386             CHECK_XMLRPC=yes
387             printf "[$XMLRPC_LDFLAGS]\n"
388         fi
389     fi
390 fi
391
392 printf "Checking for -lpcap... "
393 printf "#include <pcap.h>\nint main() { return 0; }\n" > build_check.c
394 $CC $CFLAGS $LDFLAGS build_check.c -lpcap -o fake > /dev/null 2> /dev/null
395 if [ $? != 0 ]
396 then
397     CHECK_PCAP=no
398     printf "no\n"
399 else
400     CHECK_PCAP=yes
401     printf "yes\n"
402 fi
403 rm -f fake
404
405 printf "Checking for -lnfnetlink... "
406 printf "#include <stdint.h>\n#include <netinet/in.h>\n#include <linux/netfilter.h>\nint main() { return 0; }\n" > build_check.c
407 $CC $CFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null
408 if [ $? != 0 ]
409 then
410     CHECK_NFNETLINK=no
411     printf "no\n"
412 else
413     CHECK_NFNETLINK=yes
414     NETLINK_LDFLAGS="-lnfnetlink"
415     printf "yes\n"
416 fi
417 rm -f fake
418
419 printf "Checking for -lnetfilter_queue... "
420 printf "#include <stdint.h>\n#include <libnetfilter_queue/libnetfilter_queue.h>\nint main() { return 0; }\n" > build_check.c
421 $CC $CFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null
422 if [ $? != 0 ]
423 then
424     CHECK_NFQ=no
425     printf "no\n"
426 else
427     CHECK_NFQ=yes
428     NFQ_LDFLAGS="-lnetfilter_queue"
429     printf "yes\n"
430 fi
431 rm -f fake
432
433 printf "Checking for -lyajl... "
434 pkg-config --version > /dev/null 2> /dev/null
435 if [ "$?" = "0" ]
436 then
437     pkg-config --atleast-version=2.0.0 yajl
438     if [ "$?" != "0" ]
439     then
440         CHECK_YAJL=no
441         printf "no\n"
442     else
443         CHECK_YAJL=yes
444         printf `pkg-config --modversion yajl`"\n"
445     fi
446 else
447     printf "#include <stdio.h>\n" > build_check.c
448     printf "#include <yajl/yajl_version.h>\n" >> build_check.c
449     printf "int main() { printf(\"%%d\", yajl_version()); return 0; }\n" >> build_check.c
450     $CC $CFLAGS $LDFLAGS build_check.c -lyajl -o fake > /dev/null 2> /dev/null
451     if [ $? != 0 ]
452     then
453         CHECK_YAJL=no
454         printf "no\n"
455     else
456         YAJL_VERSION=`./fake`
457         if [ $YAJL_VERSION -ge 20000 ]
458         then
459             CHECK_YAJL=yes
460             printf "${YAJL_VERSION}\n"
461         else
462             CHECK_YAJL=no
463             printf "no. Need at least version 2.0.0, existing version is ${YAJL_VERSION}\n"
464         fi
465     fi
466     rm -f fake
467 fi
468
469 printf "Checking for boost::scoped_ptr... "
470 printf "#include <boost/scoped_ptr.hpp>\nint main() { boost::scoped_ptr<int> test(new int(1)); return 0; }\n" > build_check.cpp
471 $CXX $CXXFLAGS $LDFLAGS build_check.cpp -o fake # > /dev/null 2> /dev/null
472 if [ $? != 0 ]
473 then
474     CHECK_BOOST_SCOPED_PTR=no
475     printf "no\n"
476 else
477     CHECK_BOOST_SCOPED_PTR=yes
478     printf "yes\n"
479 fi
480 rm -f fake
481
482 if [ "$OS" = "linux" ]
483 then
484     printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
485     printf "#include <linux/types.h>\n" > build_check.c
486     printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
487     printf "int main() { return 0; }\n" >> build_check.c
488     $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
489     if [ $? != 0 ]
490     then
491         CHECK_IP_QUEUE_H=no
492         printf "no\n"
493     else
494         CHECK_IP_QUEUE_H=yes
495         DEFS="$DEFS -DHAS_IP_QUEUE_H"
496         PLUGINS="$PLUGINS
497                  capture/ipq_linux"
498         printf "yes\n"
499     fi
500     rm -f fake
501 fi
502
503 rm -f build_check.c
504 rm -f build_check.cpp
505
506 if [ "$CHECK_EXPAT" != "yes" ]
507 then
508     printf -- "-lexpat not found!\n"
509     exit 1
510 fi
511
512 if [ "$CHECK_FBCLIENT" = "yes" ]
513 then
514     STG_LIBS="$STG_LIBS
515               ibpp.lib"
516     PLUGINS="$PLUGINS
517              store/firebird"
518 fi
519
520 if [ "$CHECK_PQ" = "yes" ]
521 then
522     PLUGINS="$PLUGINS
523              store/postgresql"
524 fi
525
526 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
527 then
528     PLUGINS="$PLUGINS
529              store/mysql"
530 fi
531
532 if [ "$CHECK_XMLRPC" = "yes" ]
533 then
534     PLUGINS="$PLUGINS
535              configuration/rpcconfig"
536 fi
537
538 if [ "$CHECK_PCAP" = "yes" ]
539 then
540     PLUGINS="$PLUGINS
541              capture/pcap"
542 fi
543
544 if [ "$CHECK_NFNETLINK" = "yes" -a "$CHECK_NFQ" = "yes" ]
545 then
546     PLUGINS="$PLUGINS
547              capture/nfqueue"
548 fi
549
550 if [ "$CHECK_YAJL" = "yes" -a "$CHECK_BOOST_SCOPED_PTR" = "yes" ]
551 then
552     PLUGINS="$PLUGINS
553              other/radius"
554     STG_LIBS="$STG_LIBS
555               json.lib"
556 fi
557
558 printf "OS=$OS\n" > $CONFFILE
559 printf "STG_TIME=yes\n" >> $CONFFILE
560 printf "DEBUG=$DEBUG\n" >> $CONFFILE
561 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
562 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
563 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
564 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
565 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
566 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
567 printf "ARCH=$ARCH\n" >> $CONFFILE
568 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
569 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
570 if [ "$CHECK_FBCLIENT" = "yes" ]
571 then
572     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
573     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
574 fi
575 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
576 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
577 then
578     printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE
579     printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE
580 fi
581 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
582 if [ "$CHECK_PQ" = "yes" ]
583 then
584     printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE
585     printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE
586 fi
587 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
588 if [ "$CHECK_XMLRPC" = "yes" ]
589 then
590     printf "XMLRPC_CFLAGS=$XMLRPC_CFLAGS\n" >> $CONFFILE
591     printf "XMLRPC_LDFLAGS=$XMLRPC_LDFLAGS\n" >> $CONFFILE
592 fi
593 printf "CHECK_PCAP=$CHECK_PCAP\n" >> $CONFFILE
594 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
595 if [ "$CHECK_NFNETLINK" = "yes" ]
596 then
597     printf "NETLINK_LDFLAGS=$NETLINK_LDFLAGS\n" >> $CONFFILE
598 fi
599 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
600 if [ "$CHECK_NFQ" = "yes" ]
601 then
602     printf "NFQ_LDFLAGS=$NFQ_LDFLAGS\n" >> $CONFFILE
603 fi
604 printf "DEFS=$DEFS\n" >> $CONFFILE
605 printf "STG_LIBS=" >> $CONFFILE
606 for lib in $STG_LIBS
607 do
608     printf "$lib " >> $CONFFILE
609 done
610 printf "\n" >> $CONFFILE
611 printf "PLUGINS=" >> $CONFFILE
612 for plugin in $PLUGINS
613 do
614     printf "$plugin " >> $CONFFILE
615 done
616 printf "\n" >> $CONFFILE
617 printf "CC=$CC\n" >> $CONFFILE
618 printf "CXX=$CXX\n" >> $CONFFILE
619 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
620 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
621 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
622 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
623 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
624 printf "PREFIX=$PREFIX\n" >> $CONFFILE
625 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
626 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
627 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
628 printf "OWNER=$OWNER\n" >> $CONFFILE
629 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
630 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
631
632 mkdir -p modules
633
634 if [ "$1" != "debug" ]
635 then
636     $MAKE $MAKEOPTS
637 else
638     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
639 fi