]> git.stg.codes - stg.git/blob - projects/stargazer/build
Merge branch 'master' into full-month-stats
[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 rm -f build_check.c
339
340 if [ "$CHECK_EXPAT" != "yes" ]
341 then
342     echo "-lexpat not found!"
343     exit 1
344 fi
345
346 if [ "$CHECK_FBCLIENT" = "yes" ]
347 then
348     STG_LIBS="$STG_LIBS
349               ibpp.lib"
350     PLUGINS="$PLUGINS
351              store/firebird"
352 fi
353
354 if [ "$CHECK_PQ" = "yes" ]
355 then
356     PLUGINS="$PLUGINS
357              store/postgresql"
358 fi
359
360 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
361 then
362     PLUGINS="$PLUGINS
363              store/mysql"
364 fi
365
366 if [ "$CHECK_XMLRPC" = "yes" ]
367 then
368     PLUGINS="$PLUGINS
369              configuration/rpcconfig"
370 fi
371
372 echo "OS=$OS" > $CONFFILE
373 echo "STG_TIME=yes" >> $CONFFILE
374 echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE
375 echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE
376 echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE
377 echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE
378 echo "DIR_MOD=\$(DIR_BUILD)/modules" >> $CONFFILE
379 echo "DIR_PLUGINS=\$(DIR_BUILD)/plugins" >> $CONFFILE
380 echo "ARCH=$ARCH" >> $CONFFILE
381 echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE
382 echo "CHECK_FBCLIENT=$CHECK_FBCLIENT" >> $CONFFILE
383 echo "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT" >> $CONFFILE
384 echo "CHECK_PQ=$CHECK_PQ" >> $CONFFILE
385 echo "CHECK_XMLRPC=$CHECK_XMLRPC" >> $CONFFILE
386 echo "DEFS=$DEFS" >> $CONFFILE
387 echo -n "STG_LIBS=" >> $CONFFILE
388 for lib in $STG_LIBS
389 do
390     echo -n "$lib " >> $CONFFILE
391 done
392 echo "" >> $CONFFILE
393 echo -n "PLUGINS=" >> $CONFFILE
394 for plugin in $PLUGINS
395 do
396     echo -n "$plugin " >> $CONFFILE
397 done
398 echo "" >> $CONFFILE
399 echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
400 echo "CFLAGS=$CFLAGS" >> $CONFFILE
401 echo "LDFLAGS=$LDFLAGS" >> $CONFFILE
402 echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
403 echo "PREFIX=$PREFIX" >> $CONFFILE
404 echo "BIN_MODE=$BIN_MODE" >> $CONFFILE
405 echo "DATA_MODE=$DATA_MODE" >> $CONFFILE
406 echo "DIR_MODE=$DIR_MODE" >> $CONFFILE
407 echo "OWNER=$OWNER" >> $CONFFILE
408 echo "VAR_DIR=$VAR_DIR" >> $CONFFILE
409 echo "ETC_DIR=$ETC_DIR" >> $CONFFILE
410
411 mkdir -p modules
412
413 if [ "$1" != "debug" ]
414 then
415     $MAKE $MAKEOPTS
416 else
417     echo -e "\n\n\nDebug build. Type $MAKE explicitly"
418 fi