]> git.stg.codes - stg.git/blob - projects/sgconv/build
580d515a8a9e51eb6764ff02a84214569a5de06f
[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         8) OS=bsd7;;
51         9) OS=bsd7;;
52         *) OS=unknown;;
53     esac
54     MAKE="gmake"
55 fi
56
57 if [ "$OS" = "unknown" ]
58 then 
59     printf "#############################################################################\n"
60     printf "# Sorry, but sgconv currently supported by Linux, FreeBSD 4.x, 5.x, 6.x     #\n"
61     printf "#############################################################################\n"
62     exit 1
63 fi
64
65 printf "#############################################################################\n"
66 printf "       Building sgconv for $sys $release\n"
67 printf "#############################################################################\n"
68
69 STG_LIBS="logger.lib 
70           locker.lib
71           crypto.lib 
72           common.lib 
73           conffiles.lib
74           dotconfpp.lib"
75
76 PLUGINS="store/files"
77
78 if [ "$OS" = "linux" ]
79 then
80     DEFS="$DEFS -DLINUX"
81     LIB_THREAD=-lpthread
82 else
83     if [ "$OS" = "bsd" ]
84     then
85         DEFS="$DEFS -DFREE_BSD"
86         LIB_THREAD=-lc_r
87     else
88         DEFS="$DEFS -DFREE_BSD5"
89         if [ "$OS" = "bsd7" ]
90         then
91             LIB_THREAD=-lpthread
92         else
93             LIB_THREAD=-lc_r
94         fi
95     fi
96 fi
97
98 if [ -z "$CC" ]
99 then
100     CC=gcc
101 fi
102
103 if [ -z "$CXX" ]
104 then
105     CXX=g++
106 fi
107
108 printf "Checking CC... "
109 $CC --version > /dev/null 2> /dev/null
110 if [ $? != 0 ]
111 then
112     printf "FAIL!\n"
113     printf "$CC not found\n"
114     exit;
115 fi
116 printf "found\n"
117 printf "Checking CXX... "
118 $CXX --version > /dev/null 2> /dev/null
119 if [ $? != 0 ]
120 then
121     printf "FAIL!\n"
122     printf "$CXX not found\n"
123     exit;
124 fi
125 printf "found\n"
126
127 printf "Checking endianess... "
128 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
129 $CC $CFLAGS $LDFLAGS -L/usr/lib/mysql -L/usr/local/lib/mysql build_check.c -o fake > /dev/null 2> /dev/null
130 if [ $? != 0 ]
131 then
132     printf "FAIL!\n"
133     printf "Endianess checking failed\n"
134     exit;
135 else
136     ./fake
137     if [ $? = 1 ]
138     then
139         ARCH=le
140         CXXFLAGS="$CXXFLAGS -DARCH_LE"
141         CFLAGS="$CFLAGS -DARCH_LE"
142         printf "Little Endian\n"
143     else
144         ARCH=be
145         CXXFLAGS="$CXXFLAGS -DARCH_BE"
146         CFLAGS="$CFLAGS -DARCH_BE"
147         printf "Big Endian\n"
148     fi
149 fi
150 rm -f fake
151
152 printf "Checking for -lfbclient... "
153 $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
154 if [ $? != 0 ]
155 then
156     CHECK_FBCLIENT=no
157     printf "no\n"
158 else
159     CHECK_FBCLIENT=yes
160     printf "yes\n"
161 fi
162 rm -f fake
163
164 printf "Checking for mysql_config... "
165 MYSQL_VERSION=`mysql_config --version 2> /dev/null`
166 if [ $? != 0 ]
167 then
168     printf "no\n";
169     printf "Checking for -lmysqlclient... "
170     $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
171     if [ $? != 0 ]
172     then
173         CHECK_MYSQLCLIENT=no
174         printf "no\n"
175     else
176         CHECK_MYSQLCLIENT=yes
177         printf "yes\n"
178     fi
179     rm -f fake
180 else
181     printf "yes\n"
182     printf "Checking for mysql_config --cflags... "
183     MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
184     if [ $? != 0 ]
185     then
186         CHECK_MYSQLCLIENT=no
187         printf "no\n"
188     else
189         printf "[$MYSQL_CFLAGS]\n"
190         printf "Checking for mysql_config --libs_r... "
191         MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
192         if [ $? != 0 ]
193         then
194             CHECK_MYSQLCLIENT=no
195             printf "no\n"
196         else
197             CHECK_MYSQLCLIENT=yes
198             printf "[$MYSQL_LDFLAGS]\n"
199         fi
200     fi
201 fi
202
203 printf "Checking for pg_config... "
204 PG_VERSION=`pg_config --version 2> /dev/null`
205 if [ $? != 0 ]
206 then
207     printf "no\n";
208     printf "Checking for -lpq... "
209     $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
210     if [ $? != 0 ]
211     then
212         CHECK_PQ=no
213         printf "no\n"
214     else
215         CHECK_PQ=yes
216         printf "yes\n"
217     fi
218     rm -f fake
219 else
220     printf "yes\n";
221     printf "Checking for pg_config --includedir... "
222     PG_CFLAGS=`pg_config --includedir 2> /dev/null`
223     if [ $? != 0 ]
224     then
225         CHECK_PQ=no
226         printf "no\n"
227     else
228         printf "[$PG_CFLAGS]\n"
229         printf "Checking for pg_config --libdir... "
230         PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
231         if [ $? != 0 ]
232         then
233             CHECK_PQ=no
234             printf "no\n"
235         else
236             CHECK_PQ=yes
237             printf "[$PG_LDFLAGS]\n"
238         fi
239     fi
240 fi
241
242 rm -f build_check.c
243
244 if [ "$CHECK_FBCLIENT" = "yes" ]
245 then
246     STG_LIBS="$STG_LIBS
247           ibpp.lib"
248     PLUGINS="$PLUGINS
249          store/firebird"
250 fi
251
252 if [ "$CHECK_PQ" = "yes" ]
253 then
254     PLUGINS="$PLUGINS
255              store/postgresql"
256 fi
257
258 if [ "$CHECK_MYSQLCLIENT" = "yes" ]
259 then
260     PLUGINS="$PLUGINS
261          store/mysql"
262 fi
263
264 printf "OS=$OS\n" > $CONFFILE
265 printf "STG_TIME=yes\n" >> $CONFFILE
266 printf "DEBUG=$DEBUG\n" >> $CONFFILE
267 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
268 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
269 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
270 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
271 printf "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules\n" >> $CONFFILE
272 printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE
273 printf "ARCH=$ARCH\n" >> $CONFFILE
274 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
275 printf "DEFS=$DEFS\n" >> $CONFFILE
276 printf "STG_LIBS=" >> $CONFFILE
277 for lib in $STG_LIBS
278 do
279     printf "$lib " >> $CONFFILE
280 done
281 printf "\n" >> $CONFFILE
282 printf "PLUGINS=" >> $CONFFILE
283 for plugin in $PLUGINS
284 do
285     printf "$plugin " >> $CONFFILE
286 done
287 printf "\n" >> $CONFFILE
288 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
289 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
290 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
291 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
292 printf "PREFIX=$PREFIX\n" >> $CONFFILE
293 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
294 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
295 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
296 printf "OWNER=$OWNER\n" >> $CONFFILE
297 printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
298
299 mkdir -p ../stargazer/modules
300
301 $MAKE $MAKEOPTS
302