]> git.stg.codes - stg.git/blob - projects/sgauthstress/build
Introduced SGCP library.
[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 rm -f build_check.c
158
159 printf "Checking for fb_config... "
160 FB_VERSION=`fb_config --version 2> /dev/null`
161 if [ "$?" != "0" ]
162 then
163     printf "no\n"
164     printf "Checking for -lfbclient... "
165     printf "int main() { return 0; }\n" > build_check.c
166     $CXX $CXXFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
167     if [ $? != 0 ]
168     then
169         CHECK_FBCLIENT=no
170         printf "no\n"
171     else
172         FB_CFLAGS=""
173         FB_LDFLAGS="-lfbclient"
174         CHECK_FBCLIENT=yes
175         printf "yes\n"
176     fi
177     rm -f fake
178 else
179     printf "yes\n"
180     printf "Checking for fb_config --cflags... "
181     FB_CFLAGS=`fb_config --cflags`
182     if [ "$?" != "0" ]
183     then
184         CHECK_FBCLIENT=no
185         printf "no\n"
186     else
187         printf "[$FB_CFLAGS]\n"
188         printf "Checking for fb_config --libs "
189         FB_LDFLAGS=`fb_config --libs`
190         if [ "$?" != "0" ]
191         then
192             CHECK_FBCLIENT=no
193             printf "no\n"
194         else
195             CHECK_FBCLIENT=yes
196             printf "[$FB_LDFLAGS]\n"
197         fi
198     fi
199 fi
200
201 printf "Checking for mysql_config... "
202 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
203 if [ $? != 0 ]
204 then
205     printf "no\n";
206     printf "Checking for -lmysqlclient... "
207     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
208     if [ $? != 0 ]
209     then
210         CHECK_MYSQLCLIENT=no
211         printf "no\n"
212     else
213         CHECK_MYSQLCLIENT=yes
214         printf "yes\n"
215     fi
216     rm -f fake
217 else
218     printf "yes\n"
219     printf "Checking for mysql_config --cflags... "
220     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
221     if [ $? != 0 ]
222     then
223         CHECK_MYSQLCLIENT=no
224         printf "no\n"
225     else
226         printf "[$MYSQL_CFLAGS]\n"
227         printf "Checking for mysql_config --libs_r... "
228         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
229         if [ $? != 0 ]
230         then
231             CHECK_MYSQLCLIENT=no
232             printf "no\n"
233         else
234             CHECK_MYSQLCLIENT=yes
235             printf "[$MYSQL_LDFLAGS]\n"
236         fi
237     fi
238 fi
239
240 printf "Checking for pg_config... "
241 printf "#include <libpq-fe.h>\nint main() { return 0; }\n" > build_check.c
242 PG_VERSION=`pg_config --version 2> /dev/null`
243 if [ $? != 0 ]
244 then
245     printf "no\n";
246     printf "Checking for -lpq... "
247     $CXX $CXXFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
248     if [ $? != 0 ]
249     then
250         CHECK_PQ=no
251         printf "no\n"
252     else
253         CHECK_PQ=yes
254         printf "yes\n"
255     fi
256     rm -f fake
257 else
258     printf "yes\n";
259     printf "Checking for pg_config --includedir... "
260     PG_CFLAGS="-I"`pg_config --includedir 2> /dev/null`
261     if [ $? != 0 ]
262     then
263         CHECK_PQ=no
264         printf "no\n"
265     else
266         printf "[$PG_CFLAGS]\n"
267         printf "Checking for pg_config --libdir... "
268         PG_LDFLAGS="-L"`pg_config --libdir 2> /dev/null`
269         if [ $? != 0 ]
270         then
271             CHECK_PQ=no
272             printf "no\n"
273         else
274             CHECK_PQ=yes
275             printf "[$PG_LDFLAGS]\n"
276         fi
277     fi
278 fi
279
280 rm -f build_check.c
281
282 if [ "$CHECK_FBCLIENT" = "yes" ]
283 then
284     STG_LIBS="$STG_LIBS
285           ibpp.lib"
286     PLUGINS="$PLUGINS
287          store/firebird"
288 fi
289
290 if [ "$CHECK_PQ" = "yes" ]
291 then
292     PLUGINS="$PLUGINS
293              store/postgresql"
294 fi
295
296 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
297 then
298     PLUGINS="$PLUGINS
299          store/mysql"
300 fi
301
302 printf "OS=$OS\n" > $CONFFILE
303 printf "STG_TIME=yes\n" >> $CONFFILE
304 printf "DEBUG=$DEBUG\n" >> $CONFFILE
305 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
306 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
307 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
308 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
309 printf "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules\n" >> $CONFFILE
310 printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE
311 printf "ARCH=$ARCH\n" >> $CONFFILE
312 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
313 if [ "$CHECK_FBCLIENT" = "yes" ]
314 then
315     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
316     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
317 fi
318 printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
319 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
320 then
321     printf "MYSQL_CFLAGS=$MYSQL_CFLAGS\n" >> $CONFFILE
322     printf "MYSQL_LDFLAGS=$MYSQL_LDFLAGS\n" >> $CONFFILE
323 fi
324 printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
325 if [ "$CHECK_PQ" = "yes" ]
326 then
327     printf "PG_CFLAGS=$PG_CFLAGS\n" >> $CONFFILE
328     printf "PG_LDFLAGS=$PG_LDFLAGS\n" >> $CONFFILE
329 fi
330 printf "DEFS=$DEFS\n" >> $CONFFILE
331 printf "STG_LIBS=" >> $CONFFILE
332 for lib in $STG_LIBS
333 do
334     printf "$lib " >> $CONFFILE
335 done
336 printf "\n" >> $CONFFILE
337 printf "PLUGINS=" >> $CONFFILE
338 for plugin in $PLUGINS
339 do
340     printf "$plugin " >> $CONFFILE
341 done
342 printf "\n" >> $CONFFILE
343 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
344 printf "CC=$CC\n" >> $CONFFILE
345 printf "CXX=$CXX\n" >> $CONFFILE
346 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
347 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
348 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
349 printf "PREFIX=$PREFIX\n" >> $CONFFILE
350 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
351 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
352 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
353 printf "OWNER=$OWNER\n" >> $CONFFILE
354
355 if [ "$1" != "debug" ]
356 then
357     $MAKE $MAKEOPTS
358 else
359     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
360 fi