]> git.stg.codes - stg.git/blob - projects/stargazer/build
Fixes due to stupid behaviour of BSD-like install.
[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`
31 major=`printf "%s" "$release" | cut -d. -f1`
32 BUILD_DIR=`pwd`
33 CONFFILE="../../Makefile.conf"
34 VAR_DIR="./inst/var/stargazer"
35 MIN_XMLRPCC_VERSION="1.06.27"
36 XMLRPC_FEATURES="c++2 abyss-server"
37
38
39 if [ "$1" = "debug" ]
40 then
41     DEFS="$DEFS -DDEBUG"
42     MAKEOPTS="$MAKEOPTS -j1"
43     CFLAGS="$CFLAGS -ggdb3 -W -Wall"
44     CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall"
45     DEBUG="yes"
46 else
47     DEFS="$DEFS -DNDEBUG"
48     DEBUG="no"
49 fi
50
51 CFLAGS="$CFLAGS -I/usr/local/include"
52 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
53 LDFLAGS="$LDFLAGS -L/usr/local/lib"
54
55 if [ "$sys" = "Linux" ]
56 then
57     OS=linux
58     ETC_DIR="./inst/linux/etc/stargazer"
59     MAKE="make"
60 fi
61
62 if [ "$sys" = "FreeBSD" ]
63 then
64     case $major in
65         4) OS=bsd;;
66         5) OS=bsd5;;
67         6) OS=bsd5;;
68         7) OS=bsd7;;
69         *) OS=bsd7;;
70     esac
71     ETC_DIR="./inst/freebsd/etc/stargazer"
72     MAKE="gmake"
73 fi
74
75 if [ "$sys" = "Darwin" ]
76 then
77     OS=darwin
78     ETC_DIR="./inst/freebsd/etc/stargazer"
79     MAKE="gmake"
80 fi
81
82 if [ "$OS" = "unknown" ]
83 then
84     printf "#############################################################################\n"
85     printf "# Sorry, but stargazer is currently supported by Linux, FreeBSD and Darwin. #\n"
86     printf "#############################################################################\n"
87     exit 1
88 fi
89
90 printf "#############################################################################\n"
91 printf "       Building STG 2.4 for $sys $release\n"
92 printf "#############################################################################\n"
93
94 STG_LIBS="logger.lib
95           crypto.lib
96           common.lib
97           scriptexecuter.lib
98           conffiles.lib
99           pinger.lib
100           dotconfpp.lib
101           smux.lib"
102
103 PLUGINS="authorization/ao
104          authorization/inetaccess
105          configuration/sgconfig
106          other/ping
107          other/rscript
108          other/radius
109          other/smux
110          store/files
111          capture/cap_nf"
112
113 if [ "$OS" = "linux" ]
114 then
115     DEFS="$DEFS -DLINUX"
116     PLUGINS="$PLUGINS
117              capture/ether_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         if [ "$OS" = "bsd7" ]
126         then
127             DEFS="$DEFS -DFREE_BSD5"
128             LIB_THREAD=-lpthread
129         else
130             if [ "$OS" == "darwin" ]
131             then
132                 DEFS="$DEFS -DDARWIN"
133                 LIB_THREAD=-lpthread
134             else
135                 LIB_THREAD=-lc_r
136             fi
137         fi
138     fi
139     PLUGINS="$PLUGINS
140              capture/ether_freebsd
141              capture/divert_freebsd"
142 fi
143
144 if [ -z "$CC" ]
145 then
146     CC=gcc
147 fi
148
149 if [ -z "$CXX" ]
150 then
151     CXX=g++
152 fi
153
154 printf "Checking CC... "
155 $CC --version > /dev/null 2> /dev/null
156 if [ $? != 0 ]
157 then
158     printf "FAIL!\n"
159     printf "$CC not found\n"
160     exit;
161 fi
162 printf "found\n"
163 printf "Checking CXX... "
164 $CXX --version > /dev/null 2> /dev/null
165 if [ $? != 0 ]
166 then
167     printf "FAIL!\n"
168     printf "$CXX not found\n"
169     exit;
170 fi
171 printf "found\n"
172
173 printf "Checking endianess... "
174 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
175 $CC $CFLAGS $LDFLAGS build_check.c -o fake
176 if [ $? != 0 ]
177 then
178     printf "FAIL!\n"
179     printf "Endianess checking failed\n"
180     exit;
181 else
182     ./fake
183     if [ $? = 1 ]
184     then
185         ARCH=le
186         CXXFLAGS="$CXXFLAGS -DARCH_LE"
187         CFLAGS="$CFLAGS -DARCH_LE"
188         printf "Little Endian\n"
189     else
190         ARCH=be
191         CXXFLAGS="$CXXFLAGS -DARCH_BE"
192         CFLAGS="$CFLAGS -DARCH_BE"
193         printf "Big Endian\n"
194     fi
195 fi
196 rm -f fake
197
198 printf "Checking for -lexpat... "
199 printf "#include <expat.h>\nint main() { return 0; }\n" > build_check.c
200 $CXX $CXXFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
201 if [ $? != 0 ]
202 then
203     CHECK_EXPAT=no
204     printf "no\n"
205 else
206     CHECK_EXPAT=yes
207     printf "yes\n"
208 fi
209 rm -f fake
210
211 printf "Checking for fb_config... "
212 FB_VERSION=`fb_config --version 2> /dev/null`
213 if [ "$?" != "0" ]
214 then
215     printf "no\n"
216     printf "Checking for -lfbclient... "
217     printf "int main() { return 0; }\n" > build_check.c
218     $CXX $CXXFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
219     if [ $? != 0 ]
220     then
221         CHECK_FBCLIENT=no
222         printf "no\n"
223     else
224         FB_CFLAGS=""
225         FB_LDFLAGS="-lfbclient"
226         CHECK_FBCLIENT=yes
227         printf "yes\n"
228     fi
229     rm -f fake
230 else
231     printf "yes\n"
232     printf "Checking for fb_config --cflags... "
233     FB_CFLAGS=`fb_config --cflags`
234     if [ "$?" != "0" ]
235     then
236         CHECK_FBCLIENT=no
237         printf "no\n"
238     else
239         printf "[$FB_CFLAGS]\n"
240         printf "Checking for fb_config --libs "
241         FB_LDFLAGS=`fb_config --libs`
242         if [ "$?" != "0" ]
243         then
244             CHECK_FBCLIENT=no
245             printf "no\n"
246         else
247             CHECK_FBCLIENT=yes
248             printf "[$FB_LDFLAGS]\n"
249         fi
250     fi
251 fi
252
253
254 printf "Checking for mysql_config... "
255 printf "#include <mysql.h>\nint main() { return 0; }\n" > build_check.c
256 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
257 if [ $? != 0 ]
258 then
259     printf "no\n";
260     printf "Checking for -lmysqlclient... "
261     $CXX $CXXFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
262     if [ $? != 0 ]
263     then
264         CHECK_MYSQLCLIENT=no
265         printf "no\n"
266     else
267         CHECK_MYSQLCLIENT=yes
268         MYSQL_CFLAGS=""
269         MYSQL_LDFLAGS="-lmysqlclient_r"
270         printf "yes\n"
271     fi
272     rm -f fake
273 else
274     printf "yes\n"
275     printf "Checking for mysql_config --cflags... "
276     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
277     if [ $? != 0 ]
278     then
279         CHECK_MYSQLCLIENT=no
280         printf "no\n"
281     else
282         printf "[$MYSQL_CFLAGS]\n"
283         printf "Checking for mysql_config --libs_r... "
284         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
285         if [ $? != 0 ]
286         then
287             CHECK_MYSQLCLIENT=no
288             printf "no\n"
289         else
290             CHECK_MYSQLCLIENT=yes
291             printf "[$MYSQL_LDFLAGS]\n"
292         fi
293     fi
294 fi
295
296 printf "Checking for pg_config... "
297 printf "#include <libpq-fe.h>\nint main() { return 0; }\n" > build_check.c
298 PG_VERSION=`pg_config --version 2> /dev/null`
299 if [ $? != 0 ]
300 then
301     printf "no\n";
302     printf "Checking for -lpq... "
303     $CXX $CXXFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
304     if [ $? != 0 ]
305     then
306         CHECK_PQ=no
307         printf "no\n"
308     else
309         CHECK_PQ=yes
310         printf "yes\n"
311     fi
312     rm -f fake
313 else
314     printf "yes\n";
315     printf "Checking for pg_config --includedir... "
316     PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null`
317     if [ $? != 0 ]
318     then
319         CHECK_PQ=no
320         printf "no\n"
321     else
322         printf "[$PG_CFLAGS]\n"
323         printf "Checking for pg_config --libdir... "
324         PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null`
325         if [ $? != 0 ]
326         then
327             CHECK_PQ=no
328             printf "no\n"
329         else
330             CHECK_PQ=yes
331             printf "[$PG_LDFLAGS]\n"
332         fi
333     fi
334 fi
335
336 printf "Checking for xmlrpc-c-config... "
337 printf "#include <xmlrpc-c/base.hpp>\nint main() { return 0; }\n" > build_check.c
338 XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
339 if [ $? != 0 ]
340 then
341     printf "no\n";
342     printf "Checking for -lxmlrpc... "
343     $CXX $CXXFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
344     if [ $? != 0 ]
345     then
346         CHECK_XMLRPC=no
347         printf "no\n"
348     else
349         CHECK_XMLRPC=yes
350         printf "yes\n"
351     fi
352     rm -f fake
353 elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
354 then
355     printf "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)\n";
356     CHECK_XMLRPC=no
357 else
358     printf "yes (version $XMLRPCC_VERSION)\n";
359     printf "Checking for xmlrpc-c-config --cflags... "
360     XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
361     if [ $? != 0 ]
362     then
363         CHECK_XMLRPC=no
364         printf "no\n"
365     else
366         printf "[$XMLRPC_CFLAGS]\n"
367         printf "Checking for xmlrpc-c-config --libs... "
368         XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
369         if [ $? != 0 ]
370         then
371             CHECK_XMLRPC=no
372             printf "no\n"
373         else
374             CHECK_XMLRPC=yes
375             printf "[$XMLRPC_LDFLAGS]\n"
376         fi
377     fi
378 fi
379
380 printf "Checking for -lnfnetlink... "
381 printf "#include <stdint.h>\n#include <netinet/in.h>\n#include <linux/netfilter.h>\nint main() { return 0; }\n" > build_check.c
382 $CXX $CXXFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null
383 if [ $? != 0 ]
384 then
385     CHECK_NFNETLINK=no
386     printf "no\n"
387 else
388     CHECK_NFNETLINK=yes
389     NETLINK_LDFLAGS="-lnfnetlink"
390     printf "yes\n"
391 fi
392 rm -f fake
393
394 printf "Checking for -lnetfilter_queue... "
395 printf "#include <stdint.h>\n#include <libnetfilter_queue/libnetfilter_queue.h>\nint main() { return 0; }\n" > build_check.c
396 $CXX $CXXFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null
397 if [ $? != 0 ]
398 then
399     CHECK_NFQ=no
400     printf "no\n"
401 else
402     CHECK_NFQ=yes
403     NFQ_LDFLAGS="-lnetfilter_queue"
404     printf "yes\n"
405 fi
406 rm -f fake
407
408 if [ "$OS" = "linux" ]
409 then
410     printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
411     printf "#include <linux/types.h>\n" > build_check.c
412     printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
413     printf "int main() { return 0; }\n" >> build_check.c
414     $CXX $CXXFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
415     if [ $? != 0 ]
416     then
417         CHECK_IP_QUEUE_H=no
418         printf "no\n"
419     else
420         CHECK_IP_QUEUE_H=yes
421         DEFS="$DEFS -DHAS_IP_QUEUE_H"
422         PLUGINS="$PLUGINS
423                  capture/ipq_linux"
424         printf "yes\n"
425     fi
426     rm -f fake
427 fi
428
429 rm -f build_check.c
430
431 if [ "$CHECK_EXPAT" != "yes" ]
432 then
433     printf -- "-lexpat not found!\n"
434     exit 1
435 fi
436
437 if [ "$CHECK_FBCLIENT" = "yes" ]
438 then
439     STG_LIBS="$STG_LIBS
440               ibpp.lib"
441     PLUGINS="$PLUGINS
442              store/firebird"
443 fi
444
445 if [ "$CHECK_PQ" = "yes" ]
446 then
447     PLUGINS="$PLUGINS
448              store/postgresql"
449 fi
450
451 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
452 then
453     PLUGINS="$PLUGINS
454              store/mysql"
455 fi
456
457 if [ "$CHECK_XMLRPC" = "yes" ]
458 then
459     PLUGINS="$PLUGINS
460              configuration/rpcconfig"
461 fi
462
463 if [ "$CHECK_NFNETLINK" = "yes" -a "$CHECK_NFQ" = "yes" ]
464 then
465     PLUGINS="$PLUGINS
466              capture/nfqueue"
467 fi
468
469 printf "OS=$OS\n" > $CONFFILE
470 printf "STG_TIME=yes\n" >> $CONFFILE
471 printf "DEBUG=$DEBUG\n" >> $CONFFILE
472 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
473 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
474 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
475 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
476 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
477 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
478 printf "ARCH=$ARCH\n" >> $CONFFILE
479 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
480 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
481 if [ "$CHECK_FBCLIENT" = "yes" ]
482 then
483     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
484     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
485 fi
486 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
487 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
488 then
489     printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE
490     printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE
491 fi
492 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
493 if [ "$CHECK_PQ" = "yes" ]
494 then
495     printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE
496     printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE
497 fi
498 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
499 if [ "$CHECK_XMLRPC" = "yes" ]
500 then
501     printf "XMLRPC_CFLAGS=$XMLRPC_CFLAGS\n" >> $CONFFILE
502     printf "XMLRPC_LDFLAGS=$XMLRPC_LDFLAGS\n" >> $CONFFILE
503 fi
504 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
505 if [ "$CHECK_NFNETLINK" = "yes" ]
506 then
507     printf "NETLINK_LDFLAGS=$NETLINK_LDFLAGS\n" >> $CONFFILE
508 fi
509 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
510 if [ "$CHECK_NFQ" = "yes" ]
511 then
512     printf "NFQ_LDFLAGS=$NFQ_LDFLAGS\n" >> $CONFFILE
513 fi
514 printf "DEFS=$DEFS\n" >> $CONFFILE
515 printf "STG_LIBS=" >> $CONFFILE
516 for lib in $STG_LIBS
517 do
518     printf "$lib " >> $CONFFILE
519 done
520 printf "\n" >> $CONFFILE
521 printf "PLUGINS=" >> $CONFFILE
522 for plugin in $PLUGINS
523 do
524     printf "$plugin " >> $CONFFILE
525 done
526 printf "\n" >> $CONFFILE
527 printf "CC=$CC\n" >> $CONFFILE
528 printf "CXX=$CXX\n" >> $CONFFILE
529 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
530 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
531 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
532 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
533 printf "PREFIX=$PREFIX\n" >> $CONFFILE
534 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
535 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
536 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
537 printf "OWNER=$OWNER\n" >> $CONFFILE
538 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
539 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
540
541 mkdir -p modules
542
543 if [ "$1" != "debug" ]
544 then
545     $MAKE $MAKEOPTS
546 else
547     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
548 fi