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