]> git.stg.codes - stg.git/blob - projects/stargazer/build
Reduced scopes plus graceful connection shutdown.
[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 | cut -b1`
31 BUILD_DIR=`pwd`
32 CONFFILE="../../Makefile.conf"
33 VAR_DIR="./inst/var/stargazer"
34 MIN_XMLRPCC_VERSION="1.06.27"
35 XMLRPC_FEATURES="c++2 abyss-server"
36
37
38 if [ "$1" = "debug" ]
39 then
40     DEFS="$DEFS -DDEBUG"
41     MAKEOPTS="$MAKEOPTS -j1"
42     CFLAGS="$CFLAGS -ggdb3 -W -Wall"
43     CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall"
44     DEBUG="yes"
45 else
46     DEFS="$DEFS -DNDEBUG"
47     DEBUG="no"
48 fi
49
50 CFLAGS="$CFLAGS -I/usr/local/include"
51 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
52 LDFLAGS="$LDFLAGS -L/usr/local/lib"
53
54 if [ "$sys" = "Linux" ]
55 then
56     OS=linux
57     release=""
58     ETC_DIR="./inst/linux/etc/stargazer"
59     MAKE="make"
60 fi
61
62 if [ "$sys" = "FreeBSD" ]
63 then
64     case $release 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 currently supported by Linux, FreeBSD 4.x, 5.x, 6.x  #\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     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 "int 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 -lfbclient... "
212 $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
213 if [ $? != 0 ]
214 then
215     CHECK_FBCLIENT=no
216     printf "no\n"
217 else
218     CHECK_FBCLIENT=yes
219     printf "yes\n"
220 fi
221 rm -f fake
222
223 printf "Checking for mysql_config... "
224 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
225 if [ $? != 0 ]
226 then
227     printf "no\n";
228     printf "Checking for -lmysqlclient... "
229     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
230     if [ $? != 0 ]
231     then
232         CHECK_MYSQLCLIENT=no
233         printf "no\n"
234     else
235         CHECK_MYSQLCLIENT=yes
236         printf "yes\n"
237     fi
238     rm -f fake
239 else
240     printf "yes\n"
241     printf "Checking for mysql_config --cflags... "
242     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
243     if [ $? != 0 ]
244     then
245         CHECK_MYSQLCLIENT=no
246         printf "no\n"
247     else
248         printf "[$MYSQL_CFLAGS]\n"
249         printf "Checking for mysql_config --libs_r... "
250         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
251         if [ $? != 0 ]
252         then
253             CHECK_MYSQLCLIENT=no
254             printf "no\n"
255         else
256             CHECK_MYSQLCLIENT=yes
257             printf "[$MYSQL_LDFLAGS]\n"
258         fi
259     fi
260 fi
261
262 printf "Checking for pg_config... "
263 PG_VERSION=`pg_config --version 2> /dev/null`
264 if [ $? != 0 ]
265 then
266     printf "no\n";
267     printf "Checking for -lpq... "
268     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
269     if [ $? != 0 ]
270     then
271         CHECK_PQ=no
272         printf "no\n"
273     else
274         CHECK_PQ=yes
275         printf "yes\n"
276     fi
277     rm -f fake
278 else
279     printf "yes\n";
280     printf "Checking for pg_config --includedir... "
281     PG_CFLAGS=`pg_config --includedir 2> /dev/null`
282     if [ $? != 0 ]
283     then
284         CHECK_PQ=no
285         printf "no\n"
286     else
287         printf "[$PG_CFLAGS]\n"
288         printf "Checking for pg_config --libdir... "
289         PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
290         if [ $? != 0 ]
291         then
292             CHECK_PQ=no
293             printf "no\n"
294         else
295             CHECK_PQ=yes
296             printf "[$PG_LDFLAGS]\n"
297         fi
298     fi
299 fi
300
301 printf "Checking for xmlrpc-c-config... "
302 XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
303 if [ $? != 0 ]
304 then
305     printf "no\n";
306     printf "Checking for -lxmlrpc... "
307     $CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
308     if [ $? != 0 ]
309     then
310         CHECK_XMLRPC=no
311         printf "no\n"
312     else
313         CHECK_XMLRPC=yes
314         printf "yes\n"
315     fi
316     rm -f fake
317 elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
318 then
319     printf "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)\n";
320     CHECK_XMLRPC=no
321 else
322     printf "yes (version $XMLRPCC_VERSION)\n";
323     printf "Checking for xmlrpc-c-config --cflags... "
324     XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
325     if [ $? != 0 ]
326     then
327         CHECK_XMLRPC=no
328         printf "no\n"
329     else
330         printf "[$XMLRPC_CFLAGS]\n"
331         printf "Checking for xmlrpc-c-config --libs... "
332         XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
333         if [ $? != 0 ]
334         then
335             CHECK_XMLRPC=no
336             printf "no\n"
337         else
338             CHECK_XMLRPC=yes
339             printf "[$XMLRPC_LDFLAGS]\n"
340         fi
341     fi
342 fi
343
344 printf "Checking for -lpcap... "
345 $CC $CFLAGS $LDFLAGS build_check.c -lpcap -o fake > /dev/null 2> /dev/null
346 if [ $? != 0 ]
347 then
348     CHECK_PCAP=no
349     printf "no\n"
350 else
351     CHECK_PCAP=yes
352     printf "yes\n"
353 fi
354 rm -f fake
355
356 printf "Checking for -lnfnetlink... "
357 $CC $CFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null
358 if [ $? != 0 ]
359 then
360     CHECK_NFNETLINK=no
361     printf "no\n"
362 else
363     CHECK_NFNETLINK=yes
364     printf "yes\n"
365 fi
366 rm -f fake
367
368 printf "Checking for -lnetfilter_queue... "
369 $CC $CFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null
370 if [ $? != 0 ]
371 then
372     CHECK_NFQ=no
373     printf "no\n"
374 else
375     CHECK_NFQ=yes
376     printf "yes\n"
377 fi
378 rm -f fake
379
380 if [ "$OS" = "linux" ]
381 then
382     printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
383     printf "#include <linux/types.h>\n" > build_check.c
384     printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
385     printf "int main() { return 0; }\n" >> build_check.c
386     $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
387     if [ $? != 0 ]
388     then
389         CHECK_IP_QUEUE_H=no
390         printf "no\n"
391     else
392         CHECK_IP_QUEUE_H=yes
393         DEFS="$DEFS -DHAS_IP_QUEUE_H"
394         PLUGINS="$PLUGINS
395                  capture/ipq_linux"
396         printf "yes\n"
397     fi
398     rm -f fake
399 fi
400
401 rm -f build_check.c
402
403 if [ "$CHECK_EXPAT" != "yes" ]
404 then
405     printf "-lexpat not found!\n"
406     exit 1
407 fi
408
409 if [ "$CHECK_FBCLIENT" = "yes" ]
410 then
411     STG_LIBS="$STG_LIBS
412               ibpp.lib"
413     PLUGINS="$PLUGINS
414              store/firebird"
415 fi
416
417 if [ "$CHECK_PQ" = "yes" ]
418 then
419     PLUGINS="$PLUGINS
420              store/postgresql"
421 fi
422
423 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
424 then
425     PLUGINS="$PLUGINS
426              store/mysql"
427 fi
428
429 if [ "$CHECK_XMLRPC" = "yes" ]
430 then
431     PLUGINS="$PLUGINS
432              configuration/rpcconfig"
433 fi
434
435 if [ "$CHECK_PCAP" = "yes" ]
436 then
437     PLUGINS="$PLUGINS
438              capture/pcap"
439 fi
440
441 if [ "$CHECK_NFNETLINK" = "yes" -a "$CHECK_NFQ" = "yes" ]
442 then
443     PLUGINS="$PLUGINS
444              capture/nfqueue"
445     NFQ_LIBS="-lnfnetlink -lnetfilter_queue"
446 fi
447
448 printf "OS=$OS\n" > $CONFFILE
449 printf "STG_TIME=yes\n" >> $CONFFILE
450 printf "DEBUG=$DEBUG\n" >> $CONFFILE
451 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
452 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
453 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
454 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
455 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
456 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
457 printf "ARCH=$ARCH\n" >> $CONFFILE
458 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
459 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
460 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
461 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
462 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
463 printf "CHECK_PCAP=$CHECK_PCAP\n" >> $CONFFILE
464 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
465 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
466 printf "DEFS=$DEFS\n" >> $CONFFILE
467 printf "NFQ_LIBS=$NFQ_LIBS\n" >> $CONFFILE
468 printf "STG_LIBS=" >> $CONFFILE
469 for lib in $STG_LIBS
470 do
471     printf "$lib " >> $CONFFILE
472 done
473 printf "\n" >> $CONFFILE
474 printf "PLUGINS=" >> $CONFFILE
475 for plugin in $PLUGINS
476 do
477     printf "$plugin " >> $CONFFILE
478 done
479 printf "\n" >> $CONFFILE
480 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
481 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
482 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
483 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
484 printf "PREFIX=$PREFIX\n" >> $CONFFILE
485 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
486 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
487 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
488 printf "OWNER=$OWNER\n" >> $CONFFILE
489 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
490 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
491
492 mkdir -p modules
493
494 if [ "$1" != "debug" ]
495 then
496     $MAKE $MAKEOPTS
497 else
498     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
499 fi