]> git.stg.codes - stg.git/blob - projects/stargazer/build
ff2269e125396821a7a0dbe247607e63c44ee253
[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 [ -z "$1" ]
39 then
40     DEFS="$DEFS -DNDEBUG"
41     MAKEOPTS="-j1"
42 else
43     if [ "$1" = "debug" ]
44     then
45         DEFS="$DEFS -DDEBUG"
46         MAKEOPTS="-j1"
47         CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall"
48     else
49         DEFS="$DEFS -DNDEBUG"
50         MAKEOPTS="-j1"
51     fi
52 fi
53
54 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
55 LDFLAGS="$LDFLAGS -L/usr/local/lib"
56
57 if [ "$sys" = "Linux" ]
58 then
59     OS=linux
60     release=""
61     ETC_DIR="./inst/linux/etc/stargazer"
62     MAKE="make"
63 fi
64
65 if [ "$sys" = "FreeBSD" ]
66 then
67     case $release in
68         4) OS=bsd;;
69         5) OS=bsd5;;
70         6) OS=bsd5;;
71         7) OS=bsd7;;
72         8) OS=bsd7;;
73         9) OS=bsd7;;
74         *) OS=unknown;;
75     esac
76     ETC_DIR="./inst/freebsd/etc/stargazer"
77     MAKE="gmake"
78 fi
79
80 if [ "$OS" = "unknown" ]
81 then 
82     echo "#############################################################################"
83     echo "# Sorry, but stargazer currently supported by Linux, FreeBSD 4.x, 5.x, 6.x  #"
84     echo "#############################################################################"
85     exit 1
86 fi
87
88 echo "#############################################################################"
89 echo "       Building STG 2.4 for $sys $release"
90 echo "#############################################################################"
91
92 STG_LIBS="logger.lib 
93           locker.lib
94           crypto.lib 
95           common.lib 
96           scriptexecuter.lib 
97           conffiles.lib
98           pinger.lib 
99           dotconfpp.lib
100           smux.lib"
101
102 PLUGINS="authorization/ao
103          authorization/inetaccess
104          configuration/sgconfig
105          other/ping
106          other/rscript
107          other/radius
108          other/smux
109          store/files
110          capture/cap_nf"
111
112 if [ "$OS" = "linux" ]
113 then
114     DEFS="$DEFS -DLINUX"
115     PLUGINS="$PLUGINS
116              capture/ether_linux
117              capture/ipq_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         DEFS="$DEFS -DFREE_BSD5"
126         if [ "$OS" = "bsd7" ]
127         then
128             LIB_THREAD=-lpthread
129         else
130             LIB_THREAD=-lc_r
131         fi
132     fi
133     PLUGINS="$PLUGINS
134              capture/ether_freebsd
135              capture/divert_freebsd"
136 fi
137
138 if [ -z "$CC" ]
139 then
140     CC=gcc
141 fi
142
143 if [ -z "$CXX" ]
144 then
145     CXX=g++
146 fi
147
148 echo -n "Checking CC... "
149 $CC --version > /dev/null 2> /dev/null
150 if [ $? != 0 ]
151 then
152     echo "FAIL!"
153     echo "$CC not found"
154     exit;
155 fi
156 echo "found"
157 echo -n "Checking CXX... "
158 $CXX --version > /dev/null 2> /dev/null
159 if [ $? != 0 ]
160 then
161     echo "FAIL!"
162     echo "$CXX not found"
163     exit;
164 fi
165 echo "found"
166
167 echo -n "Checking endianess... "
168 echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
169 $CC $CFLAGS $LDFLAGS build_check.c -o fake
170 if [ $? != 0 ]
171 then
172     echo "FAIL!"
173     echo "Endianess checking failed"
174     exit;
175 else
176     ./fake
177     if [ $? = 1 ]
178     then
179         ARCH=le
180         CXXFLAGS="$CXXFLAGS -DARCH_LE"
181         CFLAGS="$CFLAGS -DARCH_LE"
182         echo "Little Endian"
183     else
184         ARCH=be
185         CXXFLAGS="$CXXFLAGS -DARCH_BE"
186         CFLAGS="$CFLAGS -DARCH_BE"
187         echo "Big Endian"
188     fi
189 fi
190 rm -f fake
191
192 echo -n "Checking for -lexpat... "
193 echo "int main() { return 0; }" > build_check.c
194 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
195 if [ $? != 0 ]
196 then
197     CHECK_EXPAT=no
198     echo "no"
199 else
200     CHECK_EXPAT=yes
201     echo "yes"
202 fi
203 rm -f fake
204
205 echo -n "Checking for -lfbclient... "
206 $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
207 if [ $? != 0 ]
208 then
209     CHECK_FBCLIENT=no
210     echo "no"
211 else
212     CHECK_FBCLIENT=yes
213     echo "yes"
214 fi
215 rm -f fake
216
217 echo -n "Checking for mysql_config... "
218 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
219 if [ $? != 0 ]
220 then
221     echo "no";
222     echo -n "Checking for -lmysqlclient... "
223     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
224     if [ $? != 0 ]
225     then
226         CHECK_MYSQLCLIENT=no
227         echo "no"
228     else
229         CHECK_MYSQLCLIENT=yes
230         echo "yes"
231     fi
232     rm -f fake
233 else
234     echo "yes"
235     echo -n "Checking for mysql_config --cflags... "
236     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
237     if [ $? != 0 ]
238     then
239         CHECK_MYSQLCLIENT=no
240         echo "no"
241     else
242         echo "[$MYSQL_CFLAGS]"
243         echo -n "Checking for mysql_config --libs_r... "
244         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
245         if [ $? != 0 ]
246         then
247             CHECK_MYSQLCLIENT=no
248             echo "no"
249         else
250             CHECK_MYSQLCLIENT=yes
251             echo "[$MYSQL_LDFLAGS]"
252         fi
253     fi
254 fi
255
256 echo -n "Checking for pg_config... "
257 PG_VERSION=`pg_config --version 2> /dev/null`
258 if [ $? != 0 ]
259 then
260     echo "no";
261     echo -n "Checking for -lpq... "
262     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
263     if [ $? != 0 ]
264     then
265         CHECK_PQ=no
266         echo "no"
267     else
268         CHECK_PQ=yes
269         echo "yes"
270     fi
271     rm -f fake
272 else
273     echo "yes";
274     echo -n "Checking for pg_config --includedir... "
275     PG_CFLAGS=`pg_config --includedir 2> /dev/null`
276     if [ $? != 0 ]
277     then
278         CHECK_PQ=no
279         echo "no"
280     else
281         echo "[$PG_CFLAGS]"
282         echo -n "Checking for pg_config --libdir... "
283         PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
284         if [ $? != 0 ]
285         then
286             CHECK_PQ=no
287             echo "no"
288         else
289             CHECK_PQ=yes
290             echo "[$PG_LDFLAGS]"
291         fi
292     fi
293 fi
294
295 echo -n "Checking for xmlrpc-c-config... "
296 XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
297 if [ $? != 0 ]
298 then
299     echo "no";
300     echo -n "Checking for -lxmlrpc... "
301     $CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
302     if [ $? != 0 ]
303     then
304         CHECK_XMLRPC=no
305         echo "no"
306     else
307         CHECK_XMLRPC=yes
308         echo "yes"
309     fi
310     rm -f fake
311 elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
312 then
313     echo "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)";
314     CHECK_XMLRPC=no
315 else
316     echo "yes (version $XMLRPCC_VERSION)";
317     echo -n "Checking for xmlrpc-c-config --cflags... "
318     XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
319     if [ $? != 0 ]
320     then
321         CHECK_XMLRPC=no
322         echo "no"
323     else
324         echo "[$XMLRPC_CFLAGS]"
325         echo -n "Checking for xmlrpc-c-config --libs... "
326         XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
327         if [ $? != 0 ]
328         then
329             CHECK_XMLRPC=no
330             echo "no"
331         else
332             CHECK_XMLRPC=yes
333             echo "[$XMLRPC_LDFLAGS]"
334         fi
335     fi
336 fi
337
338 echo -n "Checking for linux/netfilter_ipv4/ip_queue.h... "
339 echo "#include <linux/types.h>" > build_check.c
340 echo "#include <linux/netfilter_ipv4/ip_queue.h>" >> build_check.c
341 echo "int main() { return 0; }" >> build_check.c
342 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
343 if [ $? != 0 ]
344 then
345     CHECK_IP_QUEUE_H=no
346     echo "no"
347 else
348     CHECK_IP_QUEUE_H=yes
349     DEFS="$DEFS HAS_IP_QUEUE_H"
350     echo "yes"
351 fi
352 rm -f fake
353
354 rm -f build_check.c
355
356 if [ "$CHECK_EXPAT" != "yes" ]
357 then
358     echo "-lexpat not found!"
359     exit 1
360 fi
361
362 if [ "$CHECK_FBCLIENT" = "yes" ]
363 then
364     STG_LIBS="$STG_LIBS
365               ibpp.lib"
366     PLUGINS="$PLUGINS
367              store/firebird"
368 fi
369
370 if [ "$CHECK_PQ" = "yes" ]
371 then
372     PLUGINS="$PLUGINS
373              store/postgresql"
374 fi
375
376 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
377 then
378     PLUGINS="$PLUGINS
379              store/mysql"
380 fi
381
382 if [ "$CHECK_XMLRPC" = "yes" ]
383 then
384     PLUGINS="$PLUGINS
385              configuration/rpcconfig"
386 fi
387
388 echo "OS=$OS" > $CONFFILE
389 echo "STG_TIME=yes" >> $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