]> git.stg.codes - stg.git/blob - projects/stargazer/build
Allow user-defined 'ar' and 'ranlib'.
[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="make"
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     LIBICONV="-liconv"
121     if [ "$OS" = "bsd" ]
122     then
123         DEFS="$DEFS -DFREE_BSD"
124         LIB_THREAD=-lc_r
125     else
126         if [ "$OS" = "bsd7" ]
127         then
128             DEFS="$DEFS -DFREE_BSD5"
129             LIB_THREAD=-lpthread
130         else
131             if [ "$OS" == "darwin" ]
132             then
133                 DEFS="$DEFS -DDARWIN"
134                 LIB_THREAD=-lpthread
135             else
136                 LIB_THREAD=-lc_r
137             fi
138         fi
139     fi
140     PLUGINS="$PLUGINS
141              capture/ether_freebsd
142              capture/divert_freebsd"
143 fi
144
145 if [ -z "$CC" ]
146 then
147     CC=gcc
148 fi
149
150 if [ -z "$CXX" ]
151 then
152     CXX=g++
153 fi
154
155 if [ -z "$AR" ]
156 then
157     AR=ar
158 fi
159
160 if [ -z "$RANLIB" ]
161 then
162     RANLIB=ranlib
163 fi
164
165 printf "Checking CC... "
166 $CC --version > /dev/null 2> /dev/null
167 if [ $? != 0 ]
168 then
169     printf "FAIL!\n"
170     printf "$CC not found\n"
171     exit;
172 fi
173 printf "found\n"
174 printf "Checking CXX... "
175 $CXX --version > /dev/null 2> /dev/null
176 if [ $? != 0 ]
177 then
178     printf "FAIL!\n"
179     printf "$CXX not found\n"
180     exit;
181 fi
182 printf "found\n"
183 printf "Checking AR... "
184 $AR --version > /dev/null 2> /dev/null
185 if [ $? != 0 ]
186 then
187     printf "FAIL!\n"
188     printf "$AR not found\n"
189     exit;
190 fi
191 printf "found\n"
192 printf "Checking RANLIB... "
193 $RANLIB --version > /dev/null 2> /dev/null
194 if [ $? != 0 ]
195 then
196     printf "FAIL!\n"
197     printf "$RANLIB not found\n"
198     exit;
199 fi
200 printf "found\n"
201
202 printf "Checking endianess... "
203 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
204 $CC $CFLAGS $LDFLAGS build_check.c -o fake
205 if [ $? != 0 ]
206 then
207     printf "FAIL!\n"
208     printf "Endianess checking failed\n"
209     exit;
210 else
211     ./fake
212     if [ $? = 1 ]
213     then
214         ARCH=le
215         CXXFLAGS="$CXXFLAGS -DARCH_LE"
216         CFLAGS="$CFLAGS -DARCH_LE"
217         printf "Little Endian\n"
218     else
219         ARCH=be
220         CXXFLAGS="$CXXFLAGS -DARCH_BE"
221         CFLAGS="$CFLAGS -DARCH_BE"
222         printf "Big Endian\n"
223     fi
224 fi
225 rm -f fake
226
227 printf "Checking for -lexpat... "
228 printf "#include <expat.h>\nint main() { return 0; }\n" > build_check.c
229 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
230 if [ $? != 0 ]
231 then
232     CHECK_EXPAT=no
233     printf "no\n"
234 else
235     CHECK_EXPAT=yes
236     printf "yes\n"
237 fi
238 rm -f fake
239
240 printf "Checking for iconv 2nd argument... "
241 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
242 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
243 if [ $? != 0 ]
244 then
245     printf "non-const\n"
246 else
247     DEFS="$DEFS -DCONST_ICONV"
248     printf "const\n"
249 fi
250 rm -f fake
251
252 printf "Checking for fb_config... "
253 FB_VERSION=`fb_config --version 2> /dev/null`
254 if [ "$?" != "0" ]
255 then
256     printf "no\n"
257     printf "Checking for -lfbclient... "
258     printf "int main() { return 0; }\n" > build_check.c
259     $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
260     if [ $? != 0 ]
261     then
262         CHECK_FBCLIENT=no
263         printf "no\n"
264     else
265         FB_CFLAGS=""
266         FB_LDFLAGS="-lfbclient"
267         CHECK_FBCLIENT=yes
268         printf "yes\n"
269     fi
270     rm -f fake
271 else
272     printf "yes\n"
273     printf "Checking for fb_config --cflags... "
274     FB_CFLAGS=`fb_config --cflags`
275     if [ "$?" != "0" ]
276     then
277         CHECK_FBCLIENT=no
278         printf "no\n"
279     else
280         printf "[$FB_CFLAGS]\n"
281         printf "Checking for fb_config --libs "
282         FB_LDFLAGS=`fb_config --libs`
283         if [ "$?" != "0" ]
284         then
285             CHECK_FBCLIENT=no
286             printf "no\n"
287         else
288             CHECK_FBCLIENT=yes
289             printf "[$FB_LDFLAGS]\n"
290         fi
291     fi
292 fi
293
294
295 printf "Checking for mysql_config... "
296 printf "#include <mysql.h>\nint main() { return 0; }\n" > build_check.c
297 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
298 if [ $? != 0 ]
299 then
300     printf "no\n";
301     printf "Checking for -lmysqlclient... "
302     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
303     if [ $? != 0 ]
304     then
305         CHECK_MYSQLCLIENT=no
306         printf "no\n"
307     else
308         CHECK_MYSQLCLIENT=yes
309         MYSQL_CFLAGS=""
310         MYSQL_LDFLAGS="-lmysqlclient_r"
311         printf "yes\n"
312     fi
313     rm -f fake
314 else
315     printf "yes\n"
316     printf "Checking for mysql_config --cflags... "
317     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
318     if [ $? != 0 ]
319     then
320         CHECK_MYSQLCLIENT=no
321         printf "no\n"
322     else
323         printf "[$MYSQL_CFLAGS]\n"
324         printf "Checking for mysql_config --libs_r... "
325         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
326         if [ $? != 0 ]
327         then
328             CHECK_MYSQLCLIENT=no
329             printf "no\n"
330         else
331             CHECK_MYSQLCLIENT=yes
332             printf "[$MYSQL_LDFLAGS]\n"
333         fi
334     fi
335 fi
336
337 printf "Checking for pg_config... "
338 printf "#include <libpq-fe.h>\nint main() { return 0; }\n" > build_check.c
339 PG_VERSION=`pg_config --version 2> /dev/null`
340 if [ $? != 0 ]
341 then
342     printf "no\n";
343     printf "Checking for -lpq... "
344     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
345     if [ $? != 0 ]
346     then
347         CHECK_PQ=no
348         printf "no\n"
349     else
350         CHECK_PQ=yes
351         printf "yes\n"
352     fi
353     rm -f fake
354 else
355     printf "yes\n";
356     printf "Checking for pg_config --includedir... "
357     PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null`
358     if [ $? != 0 ]
359     then
360         CHECK_PQ=no
361         printf "no\n"
362     else
363         printf "[$PG_CFLAGS]\n"
364         printf "Checking for pg_config --libdir... "
365         PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null`
366         if [ $? != 0 ]
367         then
368             CHECK_PQ=no
369             printf "no\n"
370         else
371             CHECK_PQ=yes
372             printf "[$PG_LDFLAGS]\n"
373         fi
374     fi
375 fi
376
377 printf "Checking for xmlrpc-c-config... "
378 printf "#include <xmlrpc-c/base.hpp>\nint main() { return 0; }\n" > build_check.c
379 XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
380 if [ $? != 0 ]
381 then
382     printf "no\n";
383     printf "Checking for -lxmlrpc... "
384     $CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
385     if [ $? != 0 ]
386     then
387         CHECK_XMLRPC=no
388         printf "no\n"
389     else
390         CHECK_XMLRPC=yes
391         printf "yes\n"
392     fi
393     rm -f fake
394 elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
395 then
396     printf "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)\n";
397     CHECK_XMLRPC=no
398 else
399     printf "yes (version $XMLRPCC_VERSION)\n";
400     printf "Checking for xmlrpc-c-config --cflags... "
401     XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
402     if [ $? != 0 ]
403     then
404         CHECK_XMLRPC=no
405         printf "no\n"
406     else
407         printf "[$XMLRPC_CFLAGS]\n"
408         printf "Checking for xmlrpc-c-config --libs... "
409         XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
410         if [ $? != 0 ]
411         then
412             CHECK_XMLRPC=no
413             printf "no\n"
414         else
415             CHECK_XMLRPC=yes
416             printf "[$XMLRPC_LDFLAGS]\n"
417         fi
418     fi
419 fi
420
421 printf "Checking for -lnfnetlink... "
422 printf "#include <stdint.h>\n#include <netinet/in.h>\n#include <linux/netfilter.h>\nint main() { return 0; }\n" > build_check.c
423 $CC $CFLAGS $LDFLAGS build_check.c -lnfnetlink -o fake > /dev/null 2> /dev/null
424 if [ $? != 0 ]
425 then
426     CHECK_NFNETLINK=no
427     printf "no\n"
428 else
429     CHECK_NFNETLINK=yes
430     NETLINK_LDFLAGS="-lnfnetlink"
431     printf "yes\n"
432 fi
433 rm -f fake
434
435 printf "Checking for -lnetfilter_queue... "
436 printf "#include <stdint.h>\n#include <libnetfilter_queue/libnetfilter_queue.h>\nint main() { return 0; }\n" > build_check.c
437 $CC $CFLAGS $LDFLAGS build_check.c -lnetfilter_queue -o fake > /dev/null 2> /dev/null
438 if [ $? != 0 ]
439 then
440     CHECK_NFQ=no
441     printf "no\n"
442 else
443     CHECK_NFQ=yes
444     NFQ_LDFLAGS="-lnetfilter_queue"
445     printf "yes\n"
446 fi
447 rm -f fake
448
449 if [ "$OS" = "linux" ]
450 then
451     printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
452     printf "#include <linux/types.h>\n" > build_check.c
453     printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
454     printf "int main() { return 0; }\n" >> build_check.c
455     $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
456     if [ $? != 0 ]
457     then
458         CHECK_IP_QUEUE_H=no
459         printf "no\n"
460     else
461         CHECK_IP_QUEUE_H=yes
462         DEFS="$DEFS -DHAS_IP_QUEUE_H"
463         PLUGINS="$PLUGINS
464                  capture/ipq_linux"
465         printf "yes\n"
466     fi
467     rm -f fake
468 fi
469
470 rm -f build_check.c
471
472 if [ "$CHECK_EXPAT" != "yes" ]
473 then
474     printf -- "-lexpat not found!\n"
475     exit 1
476 fi
477
478 if [ "$CHECK_FBCLIENT" = "yes" ]
479 then
480     STG_LIBS="$STG_LIBS
481               ibpp.lib"
482     PLUGINS="$PLUGINS
483              store/firebird"
484 fi
485
486 if [ "$CHECK_PQ" = "yes" ]
487 then
488     PLUGINS="$PLUGINS
489              store/postgresql"
490 fi
491
492 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
493 then
494     PLUGINS="$PLUGINS
495              store/mysql"
496 fi
497
498 if [ "$CHECK_XMLRPC" = "yes" ]
499 then
500     PLUGINS="$PLUGINS
501              configuration/rpcconfig"
502 fi
503
504 if [ "$CHECK_NFNETLINK" = "yes" -a "$CHECK_NFQ" = "yes" ]
505 then
506     PLUGINS="$PLUGINS
507              capture/nfqueue"
508 fi
509
510 printf "OS=$OS\n" > $CONFFILE
511 printf "STG_TIME=yes\n" >> $CONFFILE
512 printf "DEBUG=$DEBUG\n" >> $CONFFILE
513 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
514 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
515 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
516 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
517 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
518 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
519 printf "ARCH=$ARCH\n" >> $CONFFILE
520 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
521 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
522 if [ "$CHECK_FBCLIENT" = "yes" ]
523 then
524     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
525     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
526 fi
527 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
528 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
529 then
530     printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE
531     printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE
532 fi
533 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
534 if [ "$CHECK_PQ" = "yes" ]
535 then
536     printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE
537     printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE
538 fi
539 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
540 if [ "$CHECK_XMLRPC" = "yes" ]
541 then
542     printf "XMLRPC_CFLAGS=$XMLRPC_CFLAGS\n" >> $CONFFILE
543     printf "XMLRPC_LDFLAGS=$XMLRPC_LDFLAGS\n" >> $CONFFILE
544 fi
545 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
546 if [ "$CHECK_NFNETLINK" = "yes" ]
547 then
548     printf "NETLINK_LDFLAGS=$NETLINK_LDFLAGS\n" >> $CONFFILE
549 fi
550 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
551 if [ "$CHECK_NFQ" = "yes" ]
552 then
553     printf "NFQ_LDFLAGS=$NFQ_LDFLAGS\n" >> $CONFFILE
554 fi
555 printf "DEFS=$DEFS\n" >> $CONFFILE
556 printf "STG_LIBS=" >> $CONFFILE
557 for lib in $STG_LIBS
558 do
559     printf "$lib " >> $CONFFILE
560 done
561 printf "\n" >> $CONFFILE
562 printf "PLUGINS=" >> $CONFFILE
563 for plugin in $PLUGINS
564 do
565     printf "$plugin " >> $CONFFILE
566 done
567 printf "\n" >> $CONFFILE
568 printf "CC=$CC\n" >> $CONFFILE
569 printf "CXX=$CXX\n" >> $CONFFILE
570 printf "AR=$AR\n" >> $CONFFILE
571 printf "RANLIB=$RANLIB\n" >> $CONFFILE
572 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
573 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
574 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
575 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
576 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
577 printf "PREFIX=$PREFIX\n" >> $CONFFILE
578 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
579 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
580 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
581 printf "OWNER=$OWNER\n" >> $CONFFILE
582 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
583 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
584
585 mkdir -p modules
586
587 if [ "$1" != "debug" ]
588 then
589     $MAKE $MAKEOPTS
590 else
591     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
592 fi