]> git.stg.codes - stg.git/blob - projects/stargazer/build
Ticket 26. The SETTINGS_IMPL & operator() declaration added.
[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 -lnfnetlink... "
395 printf "#include <stdint.h>\n#include <netinet/in.h>\n#include <linux/netfilter.h>\nint main() { return 0; }\n" > build_check.c
396 $CC $CFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null
397 if [ $? != 0 ]
398 then
399     CHECK_NFNETLINK=no
400     printf "no\n"
401 else
402     CHECK_NFNETLINK=yes
403     NETLINK_LDFLAGS="-lnfnetlink"
404     printf "yes\n"
405 fi
406 rm -f fake
407
408 printf "Checking for -lnetfilter_queue... "
409 printf "#include <stdint.h>\n#include <libnetfilter_queue/libnetfilter_queue.h>\nint main() { return 0; }\n" > build_check.c
410 $CC $CFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null
411 if [ $? != 0 ]
412 then
413     CHECK_NFQ=no
414     printf "no\n"
415 else
416     CHECK_NFQ=yes
417     NFQ_LDFLAGS="-lnetfilter_queue"
418     printf "yes\n"
419 fi
420 rm -f fake
421
422 if [ "$OS" = "linux" ]
423 then
424     printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
425     printf "#include <linux/types.h>\n" > build_check.c
426     printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
427     printf "int main() { return 0; }\n" >> build_check.c
428     $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
429     if [ $? != 0 ]
430     then
431         CHECK_IP_QUEUE_H=no
432         printf "no\n"
433     else
434         CHECK_IP_QUEUE_H=yes
435         DEFS="$DEFS -DHAS_IP_QUEUE_H"
436         PLUGINS="$PLUGINS
437                  capture/ipq_linux"
438         printf "yes\n"
439     fi
440     rm -f fake
441 fi
442
443 rm -f build_check.c
444
445 if [ "$CHECK_EXPAT" != "yes" ]
446 then
447     printf -- "-lexpat not found!\n"
448     exit 1
449 fi
450
451 if [ "$CHECK_FBCLIENT" = "yes" ]
452 then
453     STG_LIBS="$STG_LIBS
454               ibpp.lib"
455     PLUGINS="$PLUGINS
456              store/firebird"
457 fi
458
459 if [ "$CHECK_PQ" = "yes" ]
460 then
461     PLUGINS="$PLUGINS
462              store/postgresql"
463 fi
464
465 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
466 then
467     PLUGINS="$PLUGINS
468              store/mysql"
469 fi
470
471 if [ "$CHECK_XMLRPC" = "yes" ]
472 then
473     PLUGINS="$PLUGINS
474              configuration/rpcconfig"
475 fi
476
477 if [ "$CHECK_NFNETLINK" = "yes" -a "$CHECK_NFQ" = "yes" ]
478 then
479     PLUGINS="$PLUGINS
480              capture/nfqueue"
481 fi
482
483 printf "OS=$OS\n" > $CONFFILE
484 printf "STG_TIME=yes\n" >> $CONFFILE
485 printf "DEBUG=$DEBUG\n" >> $CONFFILE
486 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
487 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
488 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
489 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
490 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
491 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
492 printf "ARCH=$ARCH\n" >> $CONFFILE
493 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
494 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
495 if [ "$CHECK_FBCLIENT" = "yes" ]
496 then
497     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
498     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
499 fi
500 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
501 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
502 then
503     printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE
504     printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE
505 fi
506 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
507 if [ "$CHECK_PQ" = "yes" ]
508 then
509     printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE
510     printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE
511 fi
512 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
513 if [ "$CHECK_XMLRPC" = "yes" ]
514 then
515     printf "XMLRPC_CFLAGS=$XMLRPC_CFLAGS\n" >> $CONFFILE
516     printf "XMLRPC_LDFLAGS=$XMLRPC_LDFLAGS\n" >> $CONFFILE
517 fi
518 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
519 if [ "$CHECK_NFNETLINK" = "yes" ]
520 then
521     printf "NETLINK_LDFLAGS=$NETLINK_LDFLAGS\n" >> $CONFFILE
522 fi
523 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
524 if [ "$CHECK_NFQ" = "yes" ]
525 then
526     printf "NFQ_LDFLAGS=$NFQ_LDFLAGS\n" >> $CONFFILE
527 fi
528 printf "DEFS=$DEFS\n" >> $CONFFILE
529 printf "STG_LIBS=" >> $CONFFILE
530 for lib in $STG_LIBS
531 do
532     printf "$lib " >> $CONFFILE
533 done
534 printf "\n" >> $CONFFILE
535 printf "PLUGINS=" >> $CONFFILE
536 for plugin in $PLUGINS
537 do
538     printf "$plugin " >> $CONFFILE
539 done
540 printf "\n" >> $CONFFILE
541 printf "CC=$CC\n" >> $CONFFILE
542 printf "CXX=$CXX\n" >> $CONFFILE
543 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
544 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
545 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
546 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
547 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
548 printf "PREFIX=$PREFIX\n" >> $CONFFILE
549 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
550 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
551 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
552 printf "OWNER=$OWNER\n" >> $CONFFILE
553 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
554 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
555
556 mkdir -p modules
557
558 if [ "$1" != "debug" ]
559 then
560     $MAKE $MAKEOPTS
561 else
562     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
563 fi