]> git.stg.codes - stg.git/blob - projects/sgauthstress/build
Added "smart" iconv 2nd arg const-ness detection.
[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     if [ "$OS" = "bsd" ]
90     then
91         DEFS="$DEFS -DFREE_BSD"
92         LIB_THREAD=-lc_r
93     else
94         DEFS="$DEFS -DFREE_BSD5"
95         if [ "$OS" = "bsd7" ]
96         then
97             LIB_THREAD=-lpthread
98         else
99             LIB_THREAD=-lc_r
100         fi
101     fi
102 fi
103
104 if [ -z "$CC" ]
105 then
106     CC=gcc
107 fi
108
109 if [ -z "$CXX" ]
110 then
111     CXX=g++
112 fi
113
114 printf "Checking CC... "
115 $CC --version > /dev/null 2> /dev/null
116 if [ $? != 0 ]
117 then
118     printf "FAIL!\n"
119     printf "$CC not found\n"
120     exit;
121 fi
122 printf "found\n"
123 printf "Checking CXX... "
124 $CXX --version > /dev/null 2> /dev/null
125 if [ $? != 0 ]
126 then
127     printf "FAIL!\n"
128     printf "$CXX not found\n"
129     exit;
130 fi
131 printf "found\n"
132
133 printf "Checking endianess... "
134 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
135 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
136 if [ $? != 0 ]
137 then
138     printf "FAIL!\n"
139     printf "Endianess checking failed\n"
140     exit;
141 else
142     ./fake
143     if [ $? = 1 ]
144     then
145         ARCH=le
146         CXXFLAGS="$CXXFLAGS -DARCH_LE"
147         CFLAGS="$CFLAGS -DARCH_LE"
148         printf "Little Endian\n"
149     else
150         ARCH=be
151         CXXFLAGS="$CXXFLAGS -DARCH_BE"
152         CFLAGS="$CFLAGS -DARCH_BE"
153         printf "Big Endian\n"
154     fi
155 fi
156 rm -f fake
157
158 printf "Checking for iconv 2nd argument... "
159 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
160 $CXX $CXXFLAGS $LDFLAGS -Werror build_check.c -o fake > /dev/null 2> /dev/null
161 if [ $? != 0 ]
162 then
163     printf "non-const\n"
164 else
165     DEFS="$DEFS -DCONST_ICONV"
166     printf "const\n"
167 fi
168 rm -f fake
169
170 rm -f build_check.c
171
172 printf "Checking for fb_config... "
173 FB_VERSION=`fb_config --version 2> /dev/null`
174 if [ "$?" != "0" ]
175 then
176     printf "no\n"
177     printf "Checking for -lfbclient... "
178     printf "int main() { return 0; }\n" > build_check.c
179     $CXX $CXXFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
180     if [ $? != 0 ]
181     then
182         CHECK_FBCLIENT=no
183         printf "no\n"
184     else
185         FB_CFLAGS=""
186         FB_LDFLAGS="-lfbclient"
187         CHECK_FBCLIENT=yes
188         printf "yes\n"
189     fi
190     rm -f fake
191 else
192     printf "yes\n"
193     printf "Checking for fb_config --cflags... "
194     FB_CFLAGS=`fb_config --cflags`
195     if [ "$?" != "0" ]
196     then
197         CHECK_FBCLIENT=no
198         printf "no\n"
199     else
200         printf "[$FB_CFLAGS]\n"
201         printf "Checking for fb_config --libs "
202         FB_LDFLAGS=`fb_config --libs`
203         if [ "$?" != "0" ]
204         then
205             CHECK_FBCLIENT=no
206             printf "no\n"
207         else
208             CHECK_FBCLIENT=yes
209             printf "[$FB_LDFLAGS]\n"
210         fi
211     fi
212 fi
213
214 printf "Checking for mysql_config... "
215 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
216 if [ $? != 0 ]
217 then
218     printf "no\n";
219     printf "Checking for -lmysqlclient... "
220     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
221     if [ $? != 0 ]
222     then
223         CHECK_MYSQLCLIENT=no
224         printf "no\n"
225     else
226         CHECK_MYSQLCLIENT=yes
227         printf "yes\n"
228     fi
229     rm -f fake
230 else
231     printf "yes\n"
232     printf "Checking for mysql_config --cflags... "
233     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
234     if [ $? != 0 ]
235     then
236         CHECK_MYSQLCLIENT=no
237         printf "no\n"
238     else
239         printf "[$MYSQL_CFLAGS]\n"
240         printf "Checking for mysql_config --libs_r... "
241         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
242         if [ $? != 0 ]
243         then
244             CHECK_MYSQLCLIENT=no
245             printf "no\n"
246         else
247             CHECK_MYSQLCLIENT=yes
248             printf "[$MYSQL_LDFLAGS]\n"
249         fi
250     fi
251 fi
252
253 printf "Checking for pg_config... "
254 printf "#include <libpq-fe.h>\nint main() { return 0; }\n" > build_check.c
255 PG_VERSION=`pg_config --version 2> /dev/null`
256 if [ $? != 0 ]
257 then
258     printf "no\n";
259     printf "Checking for -lpq... "
260     $CXX $CXXFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
261     if [ $? != 0 ]
262     then
263         CHECK_PQ=no
264         printf "no\n"
265     else
266         CHECK_PQ=yes
267         printf "yes\n"
268     fi
269     rm -f fake
270 else
271     printf "yes\n";
272     printf "Checking for pg_config --includedir... "
273     PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null`
274     if [ $? != 0 ]
275     then
276         CHECK_PQ=no
277         printf "no\n"
278     else
279         printf "[$PG_CFLAGS]\n"
280         printf "Checking for pg_config --libdir... "
281         PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null`
282         if [ $? != 0 ]
283         then
284             CHECK_PQ=no
285             printf "no\n"
286         else
287             CHECK_PQ=yes
288             printf "[$PG_LDFLAGS]\n"
289         fi
290     fi
291 fi
292
293 rm -f build_check.c
294
295 if [ "$CHECK_FBCLIENT" = "yes" ]
296 then
297     STG_LIBS="$STG_LIBS
298           ibpp.lib"
299     PLUGINS="$PLUGINS
300          store/firebird"
301 fi
302
303 if [ "$CHECK_PQ" = "yes" ]
304 then
305     PLUGINS="$PLUGINS
306              store/postgresql"
307 fi
308
309 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
310 then
311     PLUGINS="$PLUGINS
312          store/mysql"
313 fi
314
315 printf "OS=$OS\n" > $CONFFILE
316 printf "STG_TIME=yes\n" >> $CONFFILE
317 printf "DEBUG=$DEBUG\n" >> $CONFFILE
318 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
319 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
320 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
321 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
322 printf "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules\n" >> $CONFFILE
323 printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE
324 printf "ARCH=$ARCH\n" >> $CONFFILE
325 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
326 if [ "$CHECK_FBCLIENT" = "yes" ]
327 then
328     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
329     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
330 fi
331 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
332 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
333 then
334     printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE
335     printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE
336 fi
337 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
338 if [ "$CHECK_PQ" = "yes" ]
339 then
340     printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE
341     printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE
342 fi
343 printf "DEFS=$DEFS\n" >> $CONFFILE
344 printf "STG_LIBS=" >> $CONFFILE
345 for lib in $STG_LIBS
346 do
347     printf "$lib " >> $CONFFILE
348 done
349 printf "\n" >> $CONFFILE
350 printf "PLUGINS=" >> $CONFFILE
351 for plugin in $PLUGINS
352 do
353     printf "$plugin " >> $CONFFILE
354 done
355 printf "\n" >> $CONFFILE
356 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
357 printf "CC=$CC\n" >> $CONFFILE
358 printf "CXX=$CXX\n" >> $CONFFILE
359 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
360 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
361 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
362 printf "PREFIX=$PREFIX\n" >> $CONFFILE
363 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
364 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
365 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
366 printf "OWNER=$OWNER\n" >> $CONFFILE
367
368 if [ "$1" != "debug" ]
369 then
370     $MAKE $MAKEOPTS
371 else
372     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
373 fi