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