]> git.stg.codes - stg.git/blob - projects/stargazer/build
Fixed "always online" parameter.
[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     CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall"
43     DEBUG="yes"
44 else
45     DEFS="$DEFS -DNDEBUG"
46     DEBUG="no"
47 fi
48
49 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
50 LDFLAGS="$LDFLAGS -L/usr/local/lib"
51
52 if [ "$sys" = "Linux" ]
53 then
54     OS=linux
55     release=""
56     ETC_DIR="./inst/linux/etc/stargazer"
57     MAKE="make"
58 fi
59
60 if [ "$sys" = "FreeBSD" ]
61 then
62     case $release in
63         4) OS=bsd;;
64         5) OS=bsd5;;
65         6) OS=bsd5;;
66         7) OS=bsd7;;
67         8) OS=bsd7;;
68         9) OS=bsd7;;
69         *) OS=unknown;;
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 if [ "$OS" = "linux" ]
346 then
347     printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
348     printf "#include <linux/types.h>\n" > build_check.c
349     printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
350     printf "int main() { return 0; }\n" >> build_check.c
351     $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
352     if [ $? != 0 ]
353     then
354         CHECK_IP_QUEUE_H=no
355         printf "no\n"
356     else
357         CHECK_IP_QUEUE_H=yes
358         DEFS="$DEFS -DHAS_IP_QUEUE_H"
359         PLUGINS="$PLUGINS
360                  capture/ipq_linux"
361         printf "yes\n"
362     fi
363     rm -f fake
364 fi
365
366 rm -f build_check.c
367
368 if [ "$CHECK_EXPAT" != "yes" ]
369 then
370     printf "-lexpat not found!\n"
371     exit 1
372 fi
373
374 if [ "$CHECK_FBCLIENT" = "yes" ]
375 then
376     STG_LIBS="$STG_LIBS
377               ibpp.lib"
378     PLUGINS="$PLUGINS
379              store/firebird"
380 fi
381
382 if [ "$CHECK_PQ" = "yes" ]
383 then
384     PLUGINS="$PLUGINS
385              store/postgresql"
386 fi
387
388 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
389 then
390     PLUGINS="$PLUGINS
391              store/mysql"
392 fi
393
394 if [ "$CHECK_XMLRPC" = "yes" ]
395 then
396     PLUGINS="$PLUGINS
397              configuration/rpcconfig"
398 fi
399
400 printf "OS=$OS\n" > $CONFFILE
401 printf "STG_TIME=yes\n" >> $CONFFILE
402 printf "DEBUG=$DEBUG\n" >> $CONFFILE
403 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
404 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
405 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
406 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
407 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
408 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
409 printf "ARCH=$ARCH\n" >> $CONFFILE
410 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
411 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
412 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
413 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
414 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
415 printf "DEFS=$DEFS\n" >> $CONFFILE
416 printf "STG_LIBS=" >> $CONFFILE
417 for lib in $STG_LIBS
418 do
419     printf "$lib " >> $CONFFILE
420 done
421 printf "\n" >> $CONFFILE
422 printf "PLUGINS=" >> $CONFFILE
423 for plugin in $PLUGINS
424 do
425     printf "$plugin " >> $CONFFILE
426 done
427 printf "\n" >> $CONFFILE
428 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
429 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
430 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
431 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
432 printf "PREFIX=$PREFIX\n" >> $CONFFILE
433 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
434 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
435 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
436 printf "OWNER=$OWNER\n" >> $CONFFILE
437 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
438 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
439
440 mkdir -p modules
441
442 if [ "$1" != "debug" ]
443 then
444     $MAKE $MAKEOPTS
445 else
446     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
447 fi