]> git.stg.codes - stg.git/blob - projects/libs/build
228e1df27d113a2904bb50c870fa3a2572b2152b
[stg.git] / projects / libs / 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         *) 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 currently supported by Linux, FreeBSD 4.x, 5.x, 6.x  #\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           ia.lib
103           srvconf.lib"
104
105 if [ "$OS" = "linux" ]
106 then
107     DEFS="$DEFS -DLINUX"
108 else
109     if [ "$OS" = "bsd" ]
110     then
111         DEFS="$DEFS -DFREE_BSD"
112     else
113         if [ "$OS" = "bsd7" ]
114         then
115             DEFS="$DEFS -DFREE_BSD5"
116         else
117             if [ "$OS" == "darwin" ]
118             then
119                 DEFS="$DEFS -DDARWIN"
120             fi
121         fi
122     fi
123 fi
124
125 if [ -z "$CC" ]
126 then
127     CC=gcc
128 fi
129
130 if [ -z "$CXX" ]
131 then
132     CXX=g++
133 fi
134
135 printf "Checking CC... "
136 $CC --version > /dev/null 2> /dev/null
137 if [ $? != 0 ]
138 then
139     printf "FAIL!\n"
140     printf "$CC not found\n"
141     exit;
142 fi
143 printf "found\n"
144 printf "Checking CXX... "
145 $CXX --version > /dev/null 2> /dev/null
146 if [ $? != 0 ]
147 then
148     printf "FAIL!\n"
149     printf "$CXX not found\n"
150     exit;
151 fi
152 printf "found\n"
153
154 printf "Checking endianess... "
155 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
156 $CC $CFLAGS $LDFLAGS build_check.c -o fake
157 if [ $? != 0 ]
158 then
159     printf "FAIL!\n"
160     printf "Endianess checking failed\n"
161     exit;
162 else
163     ./fake
164     if [ $? = 1 ]
165     then
166         ARCH=le
167         CXXFLAGS="$CXXFLAGS -DARCH_LE"
168         CFLAGS="$CFLAGS -DARCH_LE"
169         printf "Little Endian\n"
170     else
171         ARCH=be
172         CXXFLAGS="$CXXFLAGS -DARCH_BE"
173         CFLAGS="$CFLAGS -DARCH_BE"
174         printf "Big Endian\n"
175     fi
176 fi
177 rm -f fake
178
179 printf "Checking for -lexpat... "
180 printf "#include <expat.h>\nint main() { return 0; }\n" > build_check.c
181 $CXX $CXXFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
182 if [ $? != 0 ]
183 then
184     CHECK_EXPAT=no
185     printf "no\n"
186 else
187     CHECK_EXPAT=yes
188     printf "yes\n"
189 fi
190 rm -f fake
191
192 printf "Checking for -lfbclient... "
193 printf "int main() { return 0; }\n" > build_check.c
194 $CXX $CXXFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
195 if [ $? != 0 ]
196 then
197     CHECK_FBCLIENT=no
198     printf "no\n"
199 else
200     CHECK_FBCLIENT=yes
201     printf "yes\n"
202 fi
203 rm -f fake
204
205 rm -f build_check.c
206
207 if [ "$CHECK_EXPAT" != "yes" ]
208 then
209     printf -- "-lexpat not found!\n"
210     exit 1
211 fi
212
213 if [ "$CHECK_FBCLIENT" = "yes" ]
214 then
215     STG_LIBS="$STG_LIBS
216               ibpp.lib"
217 fi
218
219 printf "OS=$OS\n" > $CONFFILE
220 printf "STG_TIME=yes\n" >> $CONFFILE
221 printf "DEBUG=$DEBUG\n" >> $CONFFILE
222 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
223 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
224 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
225 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
226 printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
227 printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
228 printf "ARCH=$ARCH\n" >> $CONFFILE
229 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
230 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
231 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
232 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
233 printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
234 printf "CHECK_PCAP=$CHECK_PCAP\n" >> $CONFFILE
235 printf "CHECK_NFNETLINK=$CHECK_NFNETLINK\n" >> $CONFFILE
236 printf "CHECK_NFQ=$CHECK_NFQ\n" >> $CONFFILE
237 printf "DEFS=$DEFS\n" >> $CONFFILE
238 printf "NFQ_LIBS=$NFQ_LIBS\n" >> $CONFFILE
239 printf "STG_LIBS=" >> $CONFFILE
240 for lib in $STG_LIBS
241 do
242     printf "$lib " >> $CONFFILE
243 done
244 printf "\n" >> $CONFFILE
245 printf "PLUGINS=" >> $CONFFILE
246 for plugin in $PLUGINS
247 do
248     printf "$plugin " >> $CONFFILE
249 done
250 printf "\n" >> $CONFFILE
251 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
252 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
253 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
254 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
255 printf "PREFIX=$PREFIX\n" >> $CONFFILE
256 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
257 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
258 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
259 printf "OWNER=$OWNER\n" >> $CONFFILE
260 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
261 printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
262
263 mkdir -p modules
264
265 if [ "$1" != "debug" ]
266 then
267     $MAKE $MAKEOPTS
268 else
269     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
270 fi