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