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