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