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