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