]> git.stg.codes - stg.git/blob - projects/stargazer/build
Patch from SpiderX <spiderx@spiderx.dp.ua> - build in debug mode.
[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 [ "$OS" = "unknown" ]
76 then 
77     echo "#############################################################################"
78     echo "# Sorry, but stargazer currently supported by Linux, FreeBSD 4.x, 5.x, 6.x  #"
79     echo "#############################################################################"
80     exit 1
81 fi
82
83 echo "#############################################################################"
84 echo "       Building STG 2.4 for $sys $release"
85 echo "#############################################################################"
86
87 STG_LIBS="logger.lib 
88           locker.lib
89           crypto.lib 
90           common.lib 
91           scriptexecuter.lib 
92           conffiles.lib
93           pinger.lib 
94           dotconfpp.lib
95           smux.lib"
96
97 PLUGINS="authorization/ao
98          authorization/inetaccess
99          configuration/sgconfig
100          other/ping
101          other/rscript
102          other/radius
103          other/smux
104          store/files
105          capture/cap_nf"
106
107 if [ "$OS" = "linux" ]
108 then
109     DEFS="$DEFS -DLINUX"
110     PLUGINS="$PLUGINS
111              capture/ether_linux"
112     LIB_THREAD=-lpthread
113 else
114     if [ "$OS" = "bsd" ]
115     then
116         DEFS="$DEFS -DFREE_BSD"
117         LIB_THREAD=-lc_r
118     else
119         DEFS="$DEFS -DFREE_BSD5"
120         if [ "$OS" = "bsd7" ]
121         then
122             LIB_THREAD=-lpthread
123         else
124             LIB_THREAD=-lc_r
125         fi
126     fi
127     PLUGINS="$PLUGINS
128              capture/ether_freebsd
129              capture/divert_freebsd"
130 fi
131
132 if [ -z "$CC" ]
133 then
134     CC=gcc
135 fi
136
137 if [ -z "$CXX" ]
138 then
139     CXX=g++
140 fi
141
142 echo -n "Checking CC... "
143 $CC --version > /dev/null 2> /dev/null
144 if [ $? != 0 ]
145 then
146     echo "FAIL!"
147     echo "$CC not found"
148     exit;
149 fi
150 echo "found"
151 echo -n "Checking CXX... "
152 $CXX --version > /dev/null 2> /dev/null
153 if [ $? != 0 ]
154 then
155     echo "FAIL!"
156     echo "$CXX not found"
157     exit;
158 fi
159 echo "found"
160
161 echo -n "Checking endianess... "
162 echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
163 $CC $CFLAGS $LDFLAGS build_check.c -o fake
164 if [ $? != 0 ]
165 then
166     echo "FAIL!"
167     echo "Endianess checking failed"
168     exit;
169 else
170     ./fake
171     if [ $? = 1 ]
172     then
173         ARCH=le
174         CXXFLAGS="$CXXFLAGS -DARCH_LE"
175         CFLAGS="$CFLAGS -DARCH_LE"
176         echo "Little Endian"
177     else
178         ARCH=be
179         CXXFLAGS="$CXXFLAGS -DARCH_BE"
180         CFLAGS="$CFLAGS -DARCH_BE"
181         echo "Big Endian"
182     fi
183 fi
184 rm -f fake
185
186 echo -n "Checking for -lexpat... "
187 echo "int main() { return 0; }" > build_check.c
188 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
189 if [ $? != 0 ]
190 then
191     CHECK_EXPAT=no
192     echo "no"
193 else
194     CHECK_EXPAT=yes
195     echo "yes"
196 fi
197 rm -f fake
198
199 echo -n "Checking for -lfbclient... "
200 $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
201 if [ $? != 0 ]
202 then
203     CHECK_FBCLIENT=no
204     echo "no"
205 else
206     CHECK_FBCLIENT=yes
207     echo "yes"
208 fi
209 rm -f fake
210
211 echo -n "Checking for mysql_config... "
212 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
213 if [ $? != 0 ]
214 then
215     echo "no";
216     echo -n "Checking for -lmysqlclient... "
217     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
218     if [ $? != 0 ]
219     then
220         CHECK_MYSQLCLIENT=no
221         echo "no"
222     else
223         CHECK_MYSQLCLIENT=yes
224         echo "yes"
225     fi
226     rm -f fake
227 else
228     echo "yes"
229     echo -n "Checking for mysql_config --cflags... "
230     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
231     if [ $? != 0 ]
232     then
233         CHECK_MYSQLCLIENT=no
234         echo "no"
235     else
236         echo "[$MYSQL_CFLAGS]"
237         echo -n "Checking for mysql_config --libs_r... "
238         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
239         if [ $? != 0 ]
240         then
241             CHECK_MYSQLCLIENT=no
242             echo "no"
243         else
244             CHECK_MYSQLCLIENT=yes
245             echo "[$MYSQL_LDFLAGS]"
246         fi
247     fi
248 fi
249
250 echo -n "Checking for pg_config... "
251 PG_VERSION=`pg_config --version 2> /dev/null`
252 if [ $? != 0 ]
253 then
254     echo "no";
255     echo -n "Checking for -lpq... "
256     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
257     if [ $? != 0 ]
258     then
259         CHECK_PQ=no
260         echo "no"
261     else
262         CHECK_PQ=yes
263         echo "yes"
264     fi
265     rm -f fake
266 else
267     echo "yes";
268     echo -n "Checking for pg_config --includedir... "
269     PG_CFLAGS=`pg_config --includedir 2> /dev/null`
270     if [ $? != 0 ]
271     then
272         CHECK_PQ=no
273         echo "no"
274     else
275         echo "[$PG_CFLAGS]"
276         echo -n "Checking for pg_config --libdir... "
277         PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
278         if [ $? != 0 ]
279         then
280             CHECK_PQ=no
281             echo "no"
282         else
283             CHECK_PQ=yes
284             echo "[$PG_LDFLAGS]"
285         fi
286     fi
287 fi
288
289 echo -n "Checking for xmlrpc-c-config... "
290 XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
291 if [ $? != 0 ]
292 then
293     echo "no";
294     echo -n "Checking for -lxmlrpc... "
295     $CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
296     if [ $? != 0 ]
297     then
298         CHECK_XMLRPC=no
299         echo "no"
300     else
301         CHECK_XMLRPC=yes
302         echo "yes"
303     fi
304     rm -f fake
305 elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
306 then
307     echo "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)";
308     CHECK_XMLRPC=no
309 else
310     echo "yes (version $XMLRPCC_VERSION)";
311     echo -n "Checking for xmlrpc-c-config --cflags... "
312     XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
313     if [ $? != 0 ]
314     then
315         CHECK_XMLRPC=no
316         echo "no"
317     else
318         echo "[$XMLRPC_CFLAGS]"
319         echo -n "Checking for xmlrpc-c-config --libs... "
320         XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
321         if [ $? != 0 ]
322         then
323             CHECK_XMLRPC=no
324             echo "no"
325         else
326             CHECK_XMLRPC=yes
327             echo "[$XMLRPC_LDFLAGS]"
328         fi
329     fi
330 fi
331
332 if [ "$OS" = "linux" ]
333 then
334     echo -n "Checking for linux/netfilter_ipv4/ip_queue.h... "
335     echo "#include <linux/types.h>" > build_check.c
336     echo "#include <linux/netfilter_ipv4/ip_queue.h>" >> build_check.c
337     echo "int main() { return 0; }" >> build_check.c
338     $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
339     if [ $? != 0 ]
340     then
341         CHECK_IP_QUEUE_H=no
342         echo "no"
343     else
344         CHECK_IP_QUEUE_H=yes
345         DEFS="$DEFS -DHAS_IP_QUEUE_H"
346         PLUGINS="$PLUGINS
347                  capture/ipq_linux"
348         echo "yes"
349     fi
350     rm -f fake
351 fi
352
353 rm -f build_check.c
354
355 if [ "$CHECK_EXPAT" != "yes" ]
356 then
357     echo "-lexpat not found!"
358     exit 1
359 fi
360
361 if [ "$CHECK_FBCLIENT" = "yes" ]
362 then
363     STG_LIBS="$STG_LIBS
364               ibpp.lib"
365     PLUGINS="$PLUGINS
366              store/firebird"
367 fi
368
369 if [ "$CHECK_PQ" = "yes" ]
370 then
371     PLUGINS="$PLUGINS
372              store/postgresql"
373 fi
374
375 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
376 then
377     PLUGINS="$PLUGINS
378              store/mysql"
379 fi
380
381 if [ "$CHECK_XMLRPC" = "yes" ]
382 then
383     PLUGINS="$PLUGINS
384              configuration/rpcconfig"
385 fi
386
387 echo "OS=$OS" > $CONFFILE
388 echo "STG_TIME=yes" >> $CONFFILE
389 echo "DEBUG=$DEBUG" >> $CONFFILE
390 echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE
391 echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE
392 echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE
393 echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE
394 echo "DIR_MOD=\$(DIR_BUILD)/modules" >> $CONFFILE
395 echo "DIR_PLUGINS=\$(DIR_BUILD)/plugins" >> $CONFFILE
396 echo "ARCH=$ARCH" >> $CONFFILE
397 echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE
398 echo "CHECK_FBCLIENT=$CHECK_FBCLIENT" >> $CONFFILE
399 echo "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT" >> $CONFFILE
400 echo "CHECK_PQ=$CHECK_PQ" >> $CONFFILE
401 echo "CHECK_XMLRPC=$CHECK_XMLRPC" >> $CONFFILE
402 echo "DEFS=$DEFS" >> $CONFFILE
403 echo -n "STG_LIBS=" >> $CONFFILE
404 for lib in $STG_LIBS
405 do
406     echo -n "$lib " >> $CONFFILE
407 done
408 echo "" >> $CONFFILE
409 echo -n "PLUGINS=" >> $CONFFILE
410 for plugin in $PLUGINS
411 do
412     echo -n "$plugin " >> $CONFFILE
413 done
414 echo "" >> $CONFFILE
415 echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
416 echo "CFLAGS=$CFLAGS" >> $CONFFILE
417 echo "LDFLAGS=$LDFLAGS" >> $CONFFILE
418 echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
419 echo "PREFIX=$PREFIX" >> $CONFFILE
420 echo "BIN_MODE=$BIN_MODE" >> $CONFFILE
421 echo "DATA_MODE=$DATA_MODE" >> $CONFFILE
422 echo "DIR_MODE=$DIR_MODE" >> $CONFFILE
423 echo "OWNER=$OWNER" >> $CONFFILE
424 echo "VAR_DIR=$VAR_DIR" >> $CONFFILE
425 echo "ETC_DIR=$ETC_DIR" >> $CONFFILE
426
427 mkdir -p modules
428
429 if [ "$1" != "debug" ]
430 then
431     $MAKE $MAKEOPTS
432 else
433     echo -e "\n\n\nDebug build. Type $MAKE explicitly"
434 fi