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