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