]> git.stg.codes - stg.git/blob - projects/stargazer/build
754f83f77ffebd9f0e2a1a7b424aaa481f0a64aa
[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           locker.lib
96           crypto.lib
97           common.lib
98           scriptexecuter.lib
99           conffiles.lib
100           pinger.lib
101           dotconfpp.lib
102           smux.lib"
103
104 PLUGINS="authorization/ao
105          authorization/inetaccess
106          configuration/sgconfig
107          other/ping
108          other/rscript
109          other/radius
110          other/smux
111          store/files
112          capture/cap_nf"
113
114 if [ "$OS" = "linux" ]
115 then
116     DEFS="$DEFS -DLINUX"
117     PLUGINS="$PLUGINS
118              capture/ether_linux"
119     LIB_THREAD=-lpthread
120 else
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 "int 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 -lfbclient... "
213 $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
214 if [ $? != 0 ]
215 then
216     CHECK_FBCLIENT=no
217     printf "no\n"
218 else
219     CHECK_FBCLIENT=yes
220     printf "yes\n"
221 fi
222 rm -f fake
223
224 printf "Checking for mysql_config... "
225 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
226 if [ $? != 0 ]
227 then
228     printf "no\n";
229     printf "Checking for -lmysqlclient... "
230     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
231     if [ $? != 0 ]
232     then
233         CHECK_MYSQLCLIENT=no
234         printf "no\n"
235     else
236         CHECK_MYSQLCLIENT=yes
237         printf "yes\n"
238     fi
239     rm -f fake
240 else
241     printf "yes\n"
242     printf "Checking for mysql_config --cflags... "
243     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
244     if [ $? != 0 ]
245     then
246         CHECK_MYSQLCLIENT=no
247         printf "no\n"
248     else
249         printf "[$MYSQL_CFLAGS]\n"
250         printf "Checking for mysql_config --libs_r... "
251         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
252         if [ $? != 0 ]
253         then
254             CHECK_MYSQLCLIENT=no
255             printf "no\n"
256         else
257             CHECK_MYSQLCLIENT=yes
258             printf "[$MYSQL_LDFLAGS]\n"
259         fi
260     fi
261 fi
262
263 printf "Checking for pg_config... "
264 PG_VERSION=`pg_config --version 2> /dev/null`
265 if [ $? != 0 ]
266 then
267     printf "no\n";
268     printf "Checking for -lpq... "
269     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
270     if [ $? != 0 ]
271     then
272         CHECK_PQ=no
273         printf "no\n"
274     else
275         CHECK_PQ=yes
276         printf "yes\n"
277     fi
278     rm -f fake
279 else
280     printf "yes\n";
281     printf "Checking for pg_config --includedir... "
282     PG_CFLAGS=`pg_config --includedir 2> /dev/null`
283     if [ $? != 0 ]
284     then
285         CHECK_PQ=no
286         printf "no\n"
287     else
288         printf "[$PG_CFLAGS]\n"
289         printf "Checking for pg_config --libdir... "
290         PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
291         if [ $? != 0 ]
292         then
293             CHECK_PQ=no
294             printf "no\n"
295         else
296             CHECK_PQ=yes
297             printf "[$PG_LDFLAGS]\n"
298         fi
299     fi
300 fi
301
302 printf "Checking for xmlrpc-c-config... "
303 XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
304 if [ $? != 0 ]
305 then
306     printf "no\n";
307     printf "Checking for -lxmlrpc... "
308     $CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
309     if [ $? != 0 ]
310     then
311         CHECK_XMLRPC=no
312         printf "no\n"
313     else
314         CHECK_XMLRPC=yes
315         printf "yes\n"
316     fi
317     rm -f fake
318 elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
319 then
320     printf "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)\n";
321     CHECK_XMLRPC=no
322 else
323     printf "yes (version $XMLRPCC_VERSION)\n";
324     printf "Checking for xmlrpc-c-config --cflags... "
325     XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
326     if [ $? != 0 ]
327     then
328         CHECK_XMLRPC=no
329         printf "no\n"
330     else
331         printf "[$XMLRPC_CFLAGS]\n"
332         printf "Checking for xmlrpc-c-config --libs... "
333         XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
334         if [ $? != 0 ]
335         then
336             CHECK_XMLRPC=no
337             printf "no\n"
338         else
339             CHECK_XMLRPC=yes
340             printf "[$XMLRPC_LDFLAGS]\n"
341         fi
342     fi
343 fi
344
345 printf "Checking for -lpcap... "
346 $CC $CFLAGS $LDFLAGS build_check.c -lpcap -o fake > /dev/null 2> /dev/null
347 if [ $? != 0 ]
348 then
349     CHECK_PCAP=no
350     printf "no\n"
351 else
352     CHECK_PCAP=yes
353     printf "yes\n"
354 fi
355 rm -f fake
356
357 printf "Checking for -lnfnetlink "
358 $CC $CFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null
359 if [ $? != 0 ]
360 then
361     CHECK_NFNETLINK=no
362     printf "no\n"
363 else
364     CHECK_NFNETLINK=yes
365     printf "yes\n"
366 fi
367 rm -f fake
368
369 printf "Checking for -lnetfilter_queue "
370 $CC $CFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null
371 if [ $? != 0 ]
372 then
373     CHECK_NFQ=no
374     printf "no\n"
375 else
376     CHECK_NFQ=yes
377     printf "yes\n"
378 fi
379 rm -f fake
380
381 if [ "$OS" = "linux" ]
382 then
383     printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
384     printf "#include <linux/types.h>\n" > build_check.c
385     printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
386     printf "int main() { return 0; }\n" >> build_check.c
387     $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
388     if [ $? != 0 ]
389     then
390         CHECK_IP_QUEUE_H=no
391         printf "no\n"
392     else
393         CHECK_IP_QUEUE_H=yes
394         DEFS="$DEFS -DHAS_IP_QUEUE_H"
395         PLUGINS="$PLUGINS
396                  capture/ipq_linux"
397         printf "yes\n"
398     fi
399     rm -f fake
400 fi
401
402 rm -f build_check.c
403
404 if [ "$CHECK_EXPAT" != "yes" ]
405 then
406     printf "-lexpat not found!\n"
407     exit 1
408 fi
409
410 if [ "$CHECK_FBCLIENT" = "yes" ]
411 then
412     STG_LIBS="$STG_LIBS
413               ibpp.lib"
414     PLUGINS="$PLUGINS
415              store/firebird"
416 fi
417
418 if [ "$CHECK_PQ" = "yes" ]
419 then
420     PLUGINS="$PLUGINS
421              store/postgresql"
422 fi
423
424 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
425 then
426     PLUGINS="$PLUGINS
427              store/mysql"
428 fi
429
430 if [ "$CHECK_XMLRPC" = "yes" ]
431 then
432     PLUGINS="$PLUGINS
433              configuration/rpcconfig"
434 fi
435
436 if [ "$CHECK_PCAP" = "yes" ]
437 then
438     PLUGINS="$PLUGINS
439              capture/pcap"
440 fi
441
442 if [ "$CHECK_NFNETLINK" = "yes" -a "$CHECK_NFQ" = "yes" ]
443 then
444     PLUGINS="$PLUGINS
445              capture/nfqueue"
446     NFQ_LIBS="-lnfnetlink -lnetfilter_queue"
447 fi
448
449 printf "OS=$OS\n" > $CONFFILE
450 printf "STG_TIME=yes\n" >> $CONFFILE
451 printf "DEBUG=$DEBUG\n" >> $CONFFILE
452 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
453 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
454 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
455 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
456 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
457 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
458 printf "ARCH=$ARCH\n" >> $CONFFILE
459 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
460 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
461 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
462 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
463 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
464 printf "CHECK_PCAP=$CHECK_PCAP\n" >> $CONFFILE
465 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
466 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
467 printf "DEFS=$DEFS\n" >> $CONFFILE
468 printf "NFQ_LIBS=$NFQ_LIBS\n" >> $CONFFILE
469 printf "STG_LIBS=" >> $CONFFILE
470 for lib in $STG_LIBS
471 do
472     printf "$lib " >> $CONFFILE
473 done
474 printf "\n" >> $CONFFILE
475 printf "PLUGINS=" >> $CONFFILE
476 for plugin in $PLUGINS
477 do
478     printf "$plugin " >> $CONFFILE
479 done
480 printf "\n" >> $CONFFILE
481 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
482 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
483 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
484 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
485 printf "PREFIX=$PREFIX\n" >> $CONFFILE
486 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
487 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
488 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
489 printf "OWNER=$OWNER\n" >> $CONFFILE
490 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
491 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
492
493 mkdir -p modules
494
495 if [ "$1" != "debug" ]
496 then
497     $MAKE $MAKEOPTS
498 else
499     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
500 fi