]> git.stg.codes - stg.git/blob - projects/sgconv/build
Fixed compilation under CLang/FreeBSD10.
[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 | cut -b1`
11 BUILD_DIR=`pwd`
12 CONFFILE="../../Makefile.conf"
13 PREFIX="/"
14 BIN_MODE=0755
15 DATA_MODE=0644
16 DIR_MODE=0755
17 OWNER=root
18 VAR_DIR="./inst/var/stargazer"
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 -ggdb3 -W -Wall -I/usr/local/include"
33 CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall -I/usr/local/include"
34 LDFLAGS="$LDFLAGS -L/usr/local/lib"
35
36 if [ "$sys" = "Linux" ]
37 then
38     OS=linux
39     release=""
40     MAKE="make"
41 fi
42
43 if [ "$sys" = "FreeBSD" ]
44 then
45     case $release 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 currently supported by Linux, FreeBSD 4.x, 5.x, 6.x     #\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 -lfbclient... "
164 $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
165 if [ $? != 0 ]
166 then
167     CHECK_FBCLIENT=no
168     printf "no\n"
169 else
170     CHECK_FBCLIENT=yes
171     printf "yes\n"
172 fi
173 rm -f fake
174
175 printf "Checking for mysql_config... "
176 printf "#include <mysql.h>\nint main() { return 0; }\n" > build_check.c
177 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
178 if [ $? != 0 ]
179 then
180     printf "no\n";
181     printf "Checking for -lmysqlclient... "
182     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
183     if [ $? != 0 ]
184     then
185         CHECK_MYSQLCLIENT=no
186         printf "no\n"
187     else
188         CHECK_MYSQLCLIENT=yes
189         printf "yes\n"
190     fi
191     rm -f fake
192 else
193     printf "yes\n"
194     printf "Checking for mysql_config --cflags... "
195     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
196     if [ $? != 0 ]
197     then
198         CHECK_MYSQLCLIENT=no
199         printf "no\n"
200     else
201         printf "[$MYSQL_CFLAGS]\n"
202         printf "Checking for mysql_config --libs_r... "
203         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
204         if [ $? != 0 ]
205         then
206             CHECK_MYSQLCLIENT=no
207             printf "no\n"
208         else
209             CHECK_MYSQLCLIENT=yes
210             printf "[$MYSQL_LDFLAGS]\n"
211         fi
212     fi
213 fi
214
215 printf "Checking for pg_config... "
216 printf "#include <libpq-fe.h>\nint main() { return 0; }\n" > build_check.c
217 PG_VERSION=`pg_config --version 2> /dev/null`
218 if [ $? != 0 ]
219 then
220     printf "no\n";
221     printf "Checking for -lpq... "
222     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
223     if [ $? != 0 ]
224     then
225         CHECK_PQ=no
226         printf "no\n"
227     else
228         CHECK_PQ=yes
229         printf "yes\n"
230     fi
231     rm -f fake
232 else
233     printf "yes\n";
234     printf "Checking for pg_config --includedir... "
235     PG_CFLAGS=`pg_config --includedir 2> /dev/null`
236     if [ $? != 0 ]
237     then
238         CHECK_PQ=no
239         printf "no\n"
240     else
241         printf "[$PG_CFLAGS]\n"
242         printf "Checking for pg_config --libdir... "
243         PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
244         if [ $? != 0 ]
245         then
246             CHECK_PQ=no
247             printf "no\n"
248         else
249             CHECK_PQ=yes
250             printf "[$PG_LDFLAGS]\n"
251         fi
252     fi
253 fi
254
255 rm -f build_check.c
256
257 if [ "$CHECK_FBCLIENT" = "yes" ]
258 then
259     STG_LIBS="$STG_LIBS
260           ibpp.lib"
261     PLUGINS="$PLUGINS
262          store/firebird"
263 fi
264
265 if [ "$CHECK_PQ" = "yes" ]
266 then
267     PLUGINS="$PLUGINS
268              store/postgresql"
269 fi
270
271 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
272 then
273     PLUGINS="$PLUGINS
274          store/mysql"
275 fi
276
277 printf "OS=$OS\n" > $CONFFILE
278 printf "STG_TIME=yes\n" >> $CONFFILE
279 printf "DEBUG=$DEBUG\n" >> $CONFFILE
280 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
281 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
282 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
283 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
284 printf "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules\n" >> $CONFFILE
285 printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE
286 printf "ARCH=$ARCH\n" >> $CONFFILE
287 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
288 printf "DEFS=$DEFS\n" >> $CONFFILE
289 printf "STG_LIBS=" >> $CONFFILE
290 for lib in $STG_LIBS
291 do
292     printf "$lib " >> $CONFFILE
293 done
294 printf "\n" >> $CONFFILE
295 printf "PLUGINS=" >> $CONFFILE
296 for plugin in $PLUGINS
297 do
298     printf "$plugin " >> $CONFFILE
299 done
300 printf "\n" >> $CONFFILE
301 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
302 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
303 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
304 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
305 printf "PREFIX=$PREFIX\n" >> $CONFFILE
306 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
307 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
308 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
309 printf "OWNER=$OWNER\n" >> $CONFFILE
310 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
311
312 mkdir -p ../stargazer/modules
313
314 $MAKE $MAKEOPTS
315