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