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