]> git.stg.codes - stg.git/blob - projects/stargazer/build
Merge branch 'naffanya-dev'
[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 -lnfnetlink "
346 $CC $CFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null
347 if [ $? != 0 ]
348 then
349     CHECK_NFNETLINK=no
350     printf "no\n"
351 else
352     CHECK_NFNETLINK=yes
353     printf "yes\n"
354 fi
355 rm -f fake
356
357 printf "Checking for -lnetfilter_queue "
358 $CC $CFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null
359 if [ $? != 0 ]
360 then
361     CHECK_NFQ=no
362     printf "no\n"
363 else
364     CHECK_NFQ=yes
365     printf "yes\n"
366 fi
367 rm -f fake
368
369 if [ "$OS" = "linux" ]
370 then
371     printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
372     printf "#include <linux/types.h>\n" > build_check.c
373     printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
374     printf "int main() { return 0; }\n" >> build_check.c
375     $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
376     if [ $? != 0 ]
377     then
378         CHECK_IP_QUEUE_H=no
379         printf "no\n"
380     else
381         CHECK_IP_QUEUE_H=yes
382         DEFS="$DEFS -DHAS_IP_QUEUE_H"
383         PLUGINS="$PLUGINS
384                  capture/ipq_linux"
385         printf "yes\n"
386     fi
387     rm -f fake
388 fi
389
390 rm -f build_check.c
391
392 if [ "$CHECK_EXPAT" != "yes" ]
393 then
394     printf "-lexpat not found!\n"
395     exit 1
396 fi
397
398 if [ "$CHECK_FBCLIENT" = "yes" ]
399 then
400     STG_LIBS="$STG_LIBS
401               ibpp.lib"
402     PLUGINS="$PLUGINS
403              store/firebird"
404 fi
405
406 if [ "$CHECK_PQ" = "yes" ]
407 then
408     PLUGINS="$PLUGINS
409              store/postgresql"
410 fi
411
412 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
413 then
414     PLUGINS="$PLUGINS
415              store/mysql"
416 fi
417
418 if [ "$CHECK_XMLRPC" = "yes" ]
419 then
420     PLUGINS="$PLUGINS
421              configuration/rpcconfig"
422 fi
423
424 if [ "$CHECK_NFNETLINK" = "yes" -a "$CHECK_NFQ" = "yes" ]
425 then
426     PLUGINS="$PLUGINS
427              capture/nfqueue"
428     NFQ_LIBS="-lnfnetlink -lnetfilter_queue"
429 fi
430
431 printf "OS=$OS\n" > $CONFFILE
432 printf "STG_TIME=yes\n" >> $CONFFILE
433 printf "DEBUG=$DEBUG\n" >> $CONFFILE
434 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
435 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
436 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
437 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
438 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
439 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
440 printf "ARCH=$ARCH\n" >> $CONFFILE
441 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
442 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
443 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
444 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
445 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
446 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
447 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
448 printf "DEFS=$DEFS\n" >> $CONFFILE
449 printf "NFQ_LIBS=$NFQ_LIBS\n" >> $CONFFILE
450 printf "STG_LIBS=" >> $CONFFILE
451 for lib in $STG_LIBS
452 do
453     printf "$lib " >> $CONFFILE
454 done
455 printf "\n" >> $CONFFILE
456 printf "PLUGINS=" >> $CONFFILE
457 for plugin in $PLUGINS
458 do
459     printf "$plugin " >> $CONFFILE
460 done
461 printf "\n" >> $CONFFILE
462 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
463 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
464 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
465 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
466 printf "PREFIX=$PREFIX\n" >> $CONFFILE
467 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
468 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
469 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
470 printf "OWNER=$OWNER\n" >> $CONFFILE
471 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
472 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
473
474 mkdir -p modules
475
476 if [ "$1" != "debug" ]
477 then
478     $MAKE $MAKEOPTS
479 else
480     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
481 fi