]> git.stg.codes - stg.git/blob - projects/sgauthstress/build
Ticket 37. The changePolicy parameter added in the struct
[stg.git] / projects / sgauthstress / build
1 #!/bin/sh
2
3 #   $Author: faust $
4 #   $Revision: 1.24 $
5 #   $Date: 2010/04/14 08:59:02 $
6 ######################################################
7
8 OS=unknown
9 sys=`uname -s`
10 release=`uname -r`
11 major=`printf "%s" "$release" | cut -d. -f1`
12 BUILD_DIR=`pwd`
13 CONFFILE="../../Makefile.conf"
14 PREFIX="/"
15 BIN_MODE=0755
16 DATA_MODE=0644
17 DIR_MODE=0755
18 OWNER=root
19
20 if [ "$1" = "debug" ]
21 then
22    DEFS="$DEFS -DDEBUG"
23    MAKEOPTS="$MAKEOPTS -j1"
24    CFLAGS="$CFLAGS -ggdb3 -W -Wall -Wextra"
25    CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall -Wextra"
26    DEBUG="yes"
27 else
28    DEFS="$DEFS -DNDEBUG"
29    DEBUG="no"
30 fi
31
32 CFLAGS="$CFLAGS -I/usr/local/include"
33 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
34 LDFLAGS="$LDFLAGS -L/usr/local/lib"
35
36 if [ "$sys" = "Linux" ]
37 then
38     OS=linux
39     MAKE="make"
40 fi
41
42 if [ "$sys" = "FreeBSD" ]
43 then
44     case $major in
45         4) OS=bsd;;
46         5) OS=bsd5;;
47         6) OS=bsd5;;
48         7) OS=bsd7;;
49         *) OS=bsd7;;
50     esac
51     MAKE="gmake"
52 fi
53
54 if [ "$sys" = "Darwin" ]
55 then
56     OS=darwin
57     ETC_DIR="./inst/freebsd/etc/stargazer"
58     MAKE="gmake"
59     CFLAGS="$CFLAGS -I/opt/local/include"
60     CXXFLAGS="$CFLAGS -I/opt/local/include"
61     LDFLAGS="$LDFLAGS -L/opt/local/lib"
62 fi
63
64 if [ "$OS" = "unknown" ]
65 then
66     printf "################################################################################\n"
67     printf "# Sorry, but sgauthstress is currently supported by Linux, FreeBSD and Darwin. #\n"
68     printf "################################################################################\n"
69     exit 1
70 fi
71
72 printf "#############################################################################\n"
73 printf "       Building sgauthstress for $sys $release\n"
74 printf "#############################################################################\n"
75
76 STG_LIBS="logger.lib
77           crypto.lib
78           common.lib
79           conffiles.lib
80           dotconfpp.lib"
81
82 PLUGINS="store/files"
83
84 if [ "$OS" = "linux" ]
85 then
86     DEFS="$DEFS -DLINUX"
87     LIB_THREAD=-lpthread
88 else
89     LIBICONV="-liconv"
90     if [ "$OS" = "bsd" ]
91     then
92         DEFS="$DEFS -DFREE_BSD"
93         LIB_THREAD=-lc_r
94     else
95         DEFS="$DEFS -DFREE_BSD5"
96         if [ "$OS" = "bsd7" ]
97         then
98             LIB_THREAD=-lpthread
99         else
100             LIB_THREAD=-lc_r
101         fi
102     fi
103 fi
104
105 if [ -z "$CC" ]
106 then
107     CC=gcc
108 fi
109
110 if [ -z "$CXX" ]
111 then
112     CXX=g++
113 fi
114
115 printf "Checking CC... "
116 $CC --version > /dev/null 2> /dev/null
117 if [ $? != 0 ]
118 then
119     printf "FAIL!\n"
120     printf "$CC not found\n"
121     exit;
122 fi
123 printf "found\n"
124 printf "Checking CXX... "
125 $CXX --version > /dev/null 2> /dev/null
126 if [ $? != 0 ]
127 then
128     printf "FAIL!\n"
129     printf "$CXX not found\n"
130     exit;
131 fi
132 printf "found\n"
133
134 printf "Checking endianess... "
135 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
136 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
137 if [ $? != 0 ]
138 then
139     printf "FAIL!\n"
140     printf "Endianess checking failed\n"
141     exit;
142 else
143     ./fake
144     if [ $? = 1 ]
145     then
146         ARCH=le
147         CXXFLAGS="$CXXFLAGS -DARCH_LE"
148         CFLAGS="$CFLAGS -DARCH_LE"
149         printf "Little Endian\n"
150     else
151         ARCH=be
152         CXXFLAGS="$CXXFLAGS -DARCH_BE"
153         CFLAGS="$CFLAGS -DARCH_BE"
154         printf "Big Endian\n"
155     fi
156 fi
157 rm -f fake
158
159 printf "Checking for iconv 2nd argument... "
160 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
161 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
162 if [ $? != 0 ]
163 then
164     printf "non-const\n"
165 else
166     DEFS="$DEFS -DCONST_ICONV"
167     printf "const\n"
168 fi
169 rm -f fake
170
171 rm -f build_check.c
172
173 printf "Checking for fb_config... "
174 FB_VERSION=`fb_config --version 2> /dev/null`
175 if [ "$?" != "0" ]
176 then
177     printf "no\n"
178     printf "Checking for -lfbclient... "
179     printf "int main() { return 0; }\n" > build_check.c
180     $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
181     if [ $? != 0 ]
182     then
183         CHECK_FBCLIENT=no
184         printf "no\n"
185     else
186         FB_CFLAGS=""
187         FB_LDFLAGS="-lfbclient"
188         CHECK_FBCLIENT=yes
189         printf "yes\n"
190     fi
191     rm -f fake
192 else
193     printf "yes\n"
194     printf "Checking for fb_config --cflags... "
195     FB_CFLAGS=`fb_config --cflags`
196     if [ "$?" != "0" ]
197     then
198         CHECK_FBCLIENT=no
199         printf "no\n"
200     else
201         printf "[$FB_CFLAGS]\n"
202         printf "Checking for fb_config --libs "
203         FB_LDFLAGS=`fb_config --libs`
204         if [ "$?" != "0" ]
205         then
206             CHECK_FBCLIENT=no
207             printf "no\n"
208         else
209             CHECK_FBCLIENT=yes
210             printf "[$FB_LDFLAGS]\n"
211         fi
212     fi
213 fi
214
215 printf "Checking for mysql_config... "
216 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
217 if [ $? != 0 ]
218 then
219     printf "no\n";
220     printf "Checking for -lmysqlclient... "
221     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
222     if [ $? != 0 ]
223     then
224         CHECK_MYSQLCLIENT=no
225         printf "no\n"
226     else
227         CHECK_MYSQLCLIENT=yes
228         printf "yes\n"
229     fi
230     rm -f fake
231 else
232     printf "yes\n"
233     printf "Checking for mysql_config --cflags... "
234     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
235     if [ $? != 0 ]
236     then
237         CHECK_MYSQLCLIENT=no
238         printf "no\n"
239     else
240         printf "[$MYSQL_CFLAGS]\n"
241         printf "Checking for mysql_config --libs_r... "
242         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
243         if [ $? != 0 ]
244         then
245             CHECK_MYSQLCLIENT=no
246             printf "no\n"
247         else
248             CHECK_MYSQLCLIENT=yes
249             printf "[$MYSQL_LDFLAGS]\n"
250         fi
251     fi
252 fi
253
254 printf "Checking for pg_config... "
255 printf "#include <libpq-fe.h>\nint main() { return 0; }\n" > build_check.c
256 PG_VERSION=`pg_config --version 2> /dev/null`
257 if [ $? != 0 ]
258 then
259     printf "no\n";
260     printf "Checking for -lpq... "
261     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
262     if [ $? != 0 ]
263     then
264         CHECK_PQ=no
265         printf "no\n"
266     else
267         CHECK_PQ=yes
268         printf "yes\n"
269     fi
270     rm -f fake
271 else
272     printf "yes\n";
273     printf "Checking for pg_config --includedir... "
274     PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null`
275     if [ $? != 0 ]
276     then
277         CHECK_PQ=no
278         printf "no\n"
279     else
280         printf "[$PG_CFLAGS]\n"
281         printf "Checking for pg_config --libdir... "
282         PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null`
283         if [ $? != 0 ]
284         then
285             CHECK_PQ=no
286             printf "no\n"
287         else
288             CHECK_PQ=yes
289             printf "[$PG_LDFLAGS]\n"
290         fi
291     fi
292 fi
293
294 rm -f build_check.c
295
296 if [ "$CHECK_FBCLIENT" = "yes" ]
297 then
298     STG_LIBS="$STG_LIBS
299           ibpp.lib"
300     PLUGINS="$PLUGINS
301          store/firebird"
302 fi
303
304 if [ "$CHECK_PQ" = "yes" ]
305 then
306     PLUGINS="$PLUGINS
307              store/postgresql"
308 fi
309
310 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
311 then
312     PLUGINS="$PLUGINS
313          store/mysql"
314 fi
315
316 printf "OS=$OS\n" > $CONFFILE
317 printf "STG_TIME=yes\n" >> $CONFFILE
318 printf "DEBUG=$DEBUG\n" >> $CONFFILE
319 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
320 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
321 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
322 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
323 printf "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules\n" >> $CONFFILE
324 printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE
325 printf "ARCH=$ARCH\n" >> $CONFFILE
326 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
327 if [ "$CHECK_FBCLIENT" = "yes" ]
328 then
329     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
330     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
331 fi
332 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
333 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
334 then
335     printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE
336     printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE
337 fi
338 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
339 if [ "$CHECK_PQ" = "yes" ]
340 then
341     printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE
342     printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE
343 fi
344 printf "DEFS=$DEFS\n" >> $CONFFILE
345 printf "STG_LIBS=" >> $CONFFILE
346 for lib in $STG_LIBS
347 do
348     printf "$lib " >> $CONFFILE
349 done
350 printf "\n" >> $CONFFILE
351 printf "PLUGINS=" >> $CONFFILE
352 for plugin in $PLUGINS
353 do
354     printf "$plugin " >> $CONFFILE
355 done
356 printf "\n" >> $CONFFILE
357 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
358 printf "CC=$CC\n" >> $CONFFILE
359 printf "CXX=$CXX\n" >> $CONFFILE
360 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
361 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
362 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
363 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
364 printf "PREFIX=$PREFIX\n" >> $CONFFILE
365 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
366 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
367 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
368 printf "OWNER=$OWNER\n" >> $CONFFILE
369
370 if [ "$1" != "debug" ]
371 then
372     $MAKE $MAKEOPTS
373 else
374     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
375 fi