]> git.stg.codes - stg.git/blob - projects/libs/build
Allow user-defined 'ar' and 'ranlib'.
[stg.git] / projects / libs / build
1 #!/bin/sh
2
3 # Installation path prefix
4
5 #PREFIX=""
6
7 # Binaries access bits
8
9 BIN_MODE=0755
10
11 # Data files access bits
12
13 DATA_MODE=0644
14
15 # Dir access bits
16
17 DIR_MODE=0755
18
19 # Binaries and data files owner
20
21 OWNER=root
22
23 OS=unknown
24 sys=`uname -s`
25 release=`uname -r`
26 major=`printf "%s" "$release" | cut -d. -f1`
27 BUILD_DIR=`pwd`
28 CONFFILE="../../Makefile.conf"
29
30
31 if [ "$1" = "debug" ]
32 then
33     DEFS="$DEFS -DDEBUG"
34     MAKEOPTS="$MAKEOPTS -j1"
35     CFLAGS="$CFLAGS -ggdb3 -W -Wall"
36     CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall"
37     DEBUG="yes"
38 else
39     DEFS="$DEFS -DNDEBUG"
40     DEBUG="no"
41 fi
42
43 CFLAGS="$CFLAGS -I/usr/local/include"
44 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
45 LDFLAGS="$LDFLAGS -L/usr/local/lib"
46
47 if [ "$sys" = "Linux" ]
48 then
49     OS=linux
50     MAKE="make"
51 fi
52
53 if [ "$sys" = "FreeBSD" ]
54 then
55     case $major in
56         4) OS=bsd;;
57         5) OS=bsd5;;
58         6) OS=bsd5;;
59         7) OS=bsd7;;
60         *) OS=bsd7;;
61     esac
62     MAKE="gmake"
63 fi
64
65 if [ "$sys" = "Darwin" ]
66 then
67     OS=darwin
68     MAKE="make"
69 fi
70
71 if [ "$OS" = "unknown" ]
72 then
73     printf "#############################################################################\n"
74     printf "# Sorry, but we currently support Linux, FreeBSD and Darwin.                #\n"
75     printf "#############################################################################\n"
76     exit 1
77 fi
78
79 printf "#############################################################################\n"
80 printf "       Building STG 2.4 libs for $sys $release\n"
81 printf "#############################################################################\n"
82
83 STG_LIBS="logger.lib
84           crypto.lib
85           common.lib
86           scriptexecuter.lib
87           conffiles.lib
88           pinger.lib
89           dotconfpp.lib
90           smux.lib
91           ia.lib
92           srvconf.lib"
93
94 if [ "$OS" = "linux" ]
95 then
96     DEFS="$DEFS -DLINUX"
97 else
98     LIBICONV="-liconv"
99     if [ "$OS" = "bsd" ]
100     then
101         DEFS="$DEFS -DFREE_BSD"
102     else
103         if [ "$OS" = "bsd7" ]
104         then
105             DEFS="$DEFS -DFREE_BSD5"
106         else
107             if [ "$OS" == "darwin" ]
108             then
109                 DEFS="$DEFS -DDARWIN"
110             fi
111         fi
112     fi
113 fi
114
115 if [ -z "$CC" ]
116 then
117     CC=gcc
118 fi
119
120 if [ -z "$CXX" ]
121 then
122     CXX=g++
123 fi
124
125 if [ -z "$AR" ]
126 then
127     AR=ar
128 fi
129
130 if [ -z "$RANLIB" ]
131 then
132     RANLIB=ranlib
133 fi
134
135 printf "Checking CC... "
136 $CC --version > /dev/null 2> /dev/null
137 if [ $? != 0 ]
138 then
139     printf "FAIL!\n"
140     printf "$CC not found\n"
141     exit;
142 fi
143 printf "found\n"
144 printf "Checking CXX... "
145 $CXX --version > /dev/null 2> /dev/null
146 if [ $? != 0 ]
147 then
148     printf "FAIL!\n"
149     printf "$CXX not found\n"
150     exit;
151 fi
152 printf "found\n"
153 printf "Checking AR... "
154 $AR --version > /dev/null 2> /dev/null
155 if [ $? != 0 ]
156 then
157     printf "FAIL!\n"
158     printf "$AR not found\n"
159     exit;
160 fi
161 printf "found\n"
162 printf "Checking RANLIB... "
163 $RANLIB --version > /dev/null 2> /dev/null
164 if [ $? != 0 ]
165 then
166     printf "FAIL!\n"
167     printf "$RANLIB not found\n"
168     exit;
169 fi
170 printf "found\n"
171
172 printf "Checking endianess... "
173 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
174 $CC $CFLAGS $LDFLAGS build_check.c -o fake
175 if [ $? != 0 ]
176 then
177     printf "FAIL!\n"
178     printf "Endianess checking failed\n"
179     exit;
180 else
181     ./fake
182     if [ $? = 1 ]
183     then
184         ARCH=le
185         CXXFLAGS="$CXXFLAGS -DARCH_LE"
186         CFLAGS="$CFLAGS -DARCH_LE"
187         printf "Little Endian\n"
188     else
189         ARCH=be
190         CXXFLAGS="$CXXFLAGS -DARCH_BE"
191         CFLAGS="$CFLAGS -DARCH_BE"
192         printf "Big Endian\n"
193     fi
194 fi
195 rm -f fake
196
197 printf "Checking for -lexpat... "
198 printf "#include <expat.h>\nint main() { return 0; }\n" > build_check.c
199 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
200 if [ $? != 0 ]
201 then
202     CHECK_EXPAT=no
203     printf "no\n"
204 else
205     CHECK_EXPAT=yes
206     printf "yes\n"
207 fi
208 rm -f fake
209
210 printf "Checking for iconv 2nd argument... "
211 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
212 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
213 if [ $? != 0 ]
214 then
215     printf "non-const\n"
216 else
217     DEFS="$DEFS -DCONST_ICONV"
218     printf "const\n"
219 fi
220 rm -f fake
221
222 printf "Checking for fb_config... "
223 FB_VERSION=`fb_config --version 2> /dev/null`
224 if [ "$?" != "0" ]
225 then
226     printf "no\n"
227     printf "Checking for -lfbclient... "
228     printf "int main() { return 0; }\n" > build_check.c
229     $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
230     if [ $? != 0 ]
231     then
232         CHECK_FBCLIENT=no
233         printf "no\n"
234     else
235         FB_CFLAGS=""
236         FB_LDFLAGS="-lfbclient"
237         CHECK_FBCLIENT=yes
238         printf "yes\n"
239     fi
240     rm -f fake
241 else
242     printf "yes\n"
243     printf "Checking for fb_config --cflags... "
244     FB_CFLAGS=`fb_config --cflags`
245     if [ "$?" != "0" ]
246     then
247         CHECK_FBCLIENT=no
248         printf "no\n"
249     else
250         printf "[$FB_CFLAGS]\n"
251         printf "Checking for fb_config --libs "
252         FB_LDFLAGS=`fb_config --libs`
253         if [ "$?" != "0" ]
254         then
255             CHECK_FBCLIENT=no
256             printf "no\n"
257         else
258             CHECK_FBCLIENT=yes
259             printf "[$FB_LDFLAGS]\n"
260         fi
261     fi
262 fi
263
264 rm -f build_check.c
265
266 if [ "$CHECK_EXPAT" != "yes" ]
267 then
268     printf -- "-lexpat not found!\n"
269     exit 1
270 fi
271
272 if [ "$CHECK_FBCLIENT" = "yes" ]
273 then
274     STG_LIBS="$STG_LIBS
275               ibpp.lib"
276 fi
277
278 printf "OS=$OS\n" > $CONFFILE
279 printf "STG_TIME=yes\n" >> $CONFFILE
280 printf "DEBUG=$DEBUG\n" >> $CONFFILE
281 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
282 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
283 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
284 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
285 printf "ARCH=$ARCH\n" >> $CONFFILE
286 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
287 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
288 if [ "$CHECK_FBCLIENT" = "yes" ]
289 then
290     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
291     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
292 fi
293 printf "DEFS=$DEFS\n" >> $CONFFILE
294 printf "STG_LIBS=" >> $CONFFILE
295 for lib in $STG_LIBS
296 do
297     printf "$lib " >> $CONFFILE
298 done
299 printf "\n" >> $CONFFILE
300 printf "CC=$CC\n" >> $CONFFILE
301 printf "CXX=$CXX\n" >> $CONFFILE
302 printf "AR=$AR\n" >> $CONFFILE
303 printf "RANLIB=$RANLIB\n" >> $CONFFILE
304 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
305 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
306 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
307 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
308 printf "PREFIX=$PREFIX\n" >> $CONFFILE
309 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
310 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
311 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
312 printf "OWNER=$OWNER\n" >> $CONFFILE
313
314 if [ "$1" != "debug" ]
315 then
316     $MAKE $MAKEOPTS
317 else
318     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
319 fi