]> git.stg.codes - stg.git/blob - projects/stargazer/build
Code deduplication (plugin creation via template PLUGIN_CREATOR)
[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 -g3 -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
124 PLUGINS="authorization/ao
125          authorization/inetaccess
126          configuration/sgconfig
127          other/ping
128          other/rscript
129          other/radius
130          other/smux
131          store/files
132          capture/cap_nf"
133
134 if [ "$OS" = "linux" ]
135 then
136     DEFS="$DEFS -DLINUX"
137     PLUGINS="$PLUGINS
138              capture/ether_linux
139              capture/ipq_linux"
140     SHELL="/bin/bash"
141     LIB_THREAD=-lpthread
142 else
143     if [ "$OS" = "bsd" ]
144     then
145         DEFS="$DEFS -DFREE_BSD"
146         LIB_THREAD=-lc_r
147     else
148         DEFS="$DEFS -DFREE_BSD5"
149         if [ "$OS" = "bsd7" ]
150         then
151             LIB_THREAD=-lpthread
152         else
153             LIB_THREAD=-lc_r
154         fi
155     fi
156     PLUGINS="$PLUGINS
157              capture/ether_freebsd
158              capture/divert_freebsd"
159     SHELL="/usr/local/bin/bash"
160 fi
161
162 if [ -z "$CC" ]
163 then
164     CC=gcc
165 fi
166
167 if [ -z "$CXX" ]
168 then
169     CXX=g++
170 fi
171
172 echo -n "Checking CC... "
173 $CC --version > /dev/null 2> /dev/null
174 if [ $? != 0 ]
175 then
176     echo "FAIL!"
177     echo "$CC not found"
178     exit;
179 fi
180 echo "found"
181 echo -n "Checking CXX... "
182 $CXX --version > /dev/null 2> /dev/null
183 if [ $? != 0 ]
184 then
185     echo "FAIL!"
186     echo "$CXX not found"
187     exit;
188 fi
189 echo "found"
190
191 echo -n "Checking endianess... "
192 echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
193 $CC $CXXFLAGS $LDFLAGS build_check.c -o fake
194 if [ $? != 0 ]
195 then
196     echo "FAIL!"
197     echo "Endianess checking failed"
198     exit;
199 else
200     ./fake
201     if [ $? = 1 ]
202     then
203         ARCH=le
204         CXXFLAGS="$CXXFLAGS -DARCH_LE"
205         echo "Little Endian"
206     else
207         ARCH=be
208         CXXFLAGS="$CXXFLAGS -DARCH_BE"
209         echo "Big Endian"
210     fi
211 fi
212 rm -f fake
213
214 echo -n "Checking for -lexpat... "
215 echo "int main() { return 0; }" > build_check.c
216 $CC $CXXFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
217 if [ $? != 0 ]
218 then
219     CHECK_EXPAT=no
220     echo "no"
221 else
222     CHECK_EXPAT=yes
223     echo "yes"
224 fi
225 rm -f fake
226
227 echo -n "Checking for -lfbclient... "
228 $CC $CXXFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
229 if [ $? != 0 ]
230 then
231     CHECK_FBCLIENT=no
232     echo "no"
233 else
234     CHECK_FBCLIENT=yes
235     echo "yes"
236 fi
237 rm -f fake
238
239 echo -n "Checking for mysql_config... "
240 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
241 if [ $? != 0 ]
242 then
243     echo "no";
244     echo -n "Checking for -lmysqlclient... "
245     $CC $CXXFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
246     if [ $? != 0 ]
247     then
248         CHECK_MYSQLCLIENT=no
249         echo "no"
250     else
251         CHECK_MYSQLCLIENT=yes
252         echo "yes"
253     fi
254     rm -f fake
255 else
256     echo "yes"
257     echo -n "Checking for mysql_config --cflags... "
258     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
259     if [ $? != 0 ]
260     then
261         CHECK_MYSQLCLIENT=no
262         echo "no"
263     else
264         #CXXFLAGS="$CXXFLAGS $MYSQL_CFLAGS"
265         echo "[$MYSQL_CFLAGS]"
266         echo -n "Checking for mysql_config --libs_r... "
267         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
268         if [ $? != 0 ]
269         then
270             CHECK_MYSQLCLIENT=no
271             echo "no"
272         else
273             CHECK_MYSQLCLIENT=yes
274             #LDFLAGS="$LDFLAGS $MYSQL_LDFLAGS"
275             echo "[$MYSQL_LDFLAGS]"
276         fi
277     fi
278 fi
279
280 echo -n "Checking for pg_config... "
281 PG_VERSION=`pg_config --version 2> /dev/null`
282 if [ $? != 0 ]
283 then
284     echo "no";
285     echo -n "Checking for -lpq... "
286     $CC $CXXFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
287     if [ $? != 0 ]
288     then
289         CHECK_PQ=no
290         echo "no"
291     else
292         CHECK_PQ=yes
293         echo "yes"
294     fi
295     rm -f fake
296 else
297     echo "yes";
298     echo -n "Checking for pg_config --includedir... "
299     PG_CFLAGS=`pg_config --includedir 2> /dev/null`
300     if [ $? != 0 ]
301     then
302         CHECK_PQ=no
303         echo "no"
304     else
305         echo "[$PG_CFLAGS]"
306         echo -n "Checking for pg_config --libdir... "
307         PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
308         if [ $? != 0 ]
309         then
310             CHECK_PQ=no
311             echo "no"
312         else
313             CHECK_PQ=yes
314             echo "[$PG_LDFLAGS]"
315         fi
316     fi
317 fi
318
319 echo -n "Checking for xmlrpc-c-config... "
320 XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
321 if [ $? != 0 ]
322 then
323     echo "no";
324     echo -n "Checking for -lxmlrpc... "
325     $CC $CXXFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
326     if [ $? != 0 ]
327     then
328         CHECK_XMLRPC=no
329         echo "no"
330     else
331         CHECK_XMLRPC=yes
332         echo "yes"
333     fi
334     rm -f fake
335 elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
336 then
337     echo "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)";
338     CHECK_XMLRPC=no
339 else
340     echo "yes (version $XMLRPCC_VERSION)";
341     echo -n "Checking for xmlrpc-c-config --cflags... "
342     XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
343     if [ $? != 0 ]
344     then
345         CHECK_XMLRPC=no
346         echo "no"
347     else
348         echo "[$XMLRPC_CFLAGS]"
349         echo -n "Checking for xmlrpc-c-config --libs... "
350         XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
351         if [ $? != 0 ]
352         then
353             CHECK_XMLRPC=no
354             echo "no"
355         else
356             CHECK_XMLRPC=yes
357             echo "[$XMLRPC_LDFLAGS]"
358         fi
359     fi
360 fi
361
362 rm -f build_check.c
363
364 if [ "$CHECK_EXPAT" != "yes" ]
365 then
366     echo "-lexpat not found!"
367     exit 1
368 fi
369
370 if [ "$CHECK_FBCLIENT" = "yes" ]
371 then
372     STG_LIBS="$STG_LIBS
373               ibpp.lib"
374     PLUGINS="$PLUGINS
375              store/firebird"
376 fi
377
378 if [ "$CHECK_PQ" = "yes" ]
379 then
380     PLUGINS="$PLUGINS
381              store/postgresql"
382 fi
383
384 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
385 then
386     PLUGINS="$PLUGINS
387              store/mysql"
388 fi
389
390 if [ "$CHECK_XMLRPC" = "yes" ]
391 then
392     PLUGINS="$PLUGINS
393              configuration/rpcconfig"
394 fi
395
396 echo "OS=$OS" > $CONFFILE
397 echo "STG_TIME=yes" >> $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 "SHELL=$SHELL" >> $CONFFILE
424 echo "CXXFLAGS=$CXXFLAGS" >> $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 echo "DB_ADDRESS=$DB_ADDRESS" >> $CONFFILE
435 echo "DB_USER=$DB_USER" >> $CONFFILE
436 echo "DB_PASSWORD=$DB_PASSWORD" >> $CONFFILE
437 echo "FIREBIRD_ISQL=$FIREBIRD_ISQL" >> $CONFFILE
438 echo "FIREBIRD_GROUP=$FIREBIRD_GROUP" >> $CONFFILE
439
440 mkdir -p modules
441
442 if [ "$1" != "debug" ]
443 then
444     $MAKE $MAKEOPTS
445 else
446     echo -e "\n\n\nDebug build. Type $MAKE explicitly"
447 fi