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