]> git.stg.codes - stg.git/blob - projects/libs/build
More verbose debug.
[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="gmake"
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 printf "Checking CC... "
126 $CC --version > /dev/null 2> /dev/null
127 if [ $? != 0 ]
128 then
129     printf "FAIL!\n"
130     printf "$CC not found\n"
131     exit;
132 fi
133 printf "found\n"
134 printf "Checking CXX... "
135 $CXX --version > /dev/null 2> /dev/null
136 if [ $? != 0 ]
137 then
138     printf "FAIL!\n"
139     printf "$CXX not found\n"
140     exit;
141 fi
142 printf "found\n"
143
144 printf "Checking endianess... "
145 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
146 $CC $CFLAGS $LDFLAGS build_check.c -o fake
147 if [ $? != 0 ]
148 then
149     printf "FAIL!\n"
150     printf "Endianess checking failed\n"
151     exit;
152 else
153     ./fake
154     if [ $? = 1 ]
155     then
156         ARCH=le
157         CXXFLAGS="$CXXFLAGS -DARCH_LE"
158         CFLAGS="$CFLAGS -DARCH_LE"
159         printf "Little Endian\n"
160     else
161         ARCH=be
162         CXXFLAGS="$CXXFLAGS -DARCH_BE"
163         CFLAGS="$CFLAGS -DARCH_BE"
164         printf "Big Endian\n"
165     fi
166 fi
167 rm -f fake
168
169 printf "Checking for -lexpat... "
170 printf "#include <expat.h>\nint main() { return 0; }\n" > build_check.c
171 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
172 if [ $? != 0 ]
173 then
174     CHECK_EXPAT=no
175     printf "no\n"
176 else
177     CHECK_EXPAT=yes
178     printf "yes\n"
179 fi
180 rm -f fake
181
182 printf "Checking for iconv 2nd argument... "
183 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
184 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
185 if [ $? != 0 ]
186 then
187     printf "non-const\n"
188 else
189     DEFS="$DEFS -DCONST_ICONV"
190     printf "const\n"
191 fi
192 rm -f fake
193
194 printf "Checking for fb_config... "
195 FB_VERSION=`fb_config --version 2> /dev/null`
196 if [ "$?" != "0" ]
197 then
198     printf "no\n"
199     printf "Checking for -lfbclient... "
200     printf "int main() { return 0; }\n" > build_check.c
201     $CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
202     if [ $? != 0 ]
203     then
204         CHECK_FBCLIENT=no
205         printf "no\n"
206     else
207         FB_CFLAGS=""
208         FB_LDFLAGS="-lfbclient"
209         CHECK_FBCLIENT=yes
210         printf "yes\n"
211     fi
212     rm -f fake
213 else
214     printf "yes\n"
215     printf "Checking for fb_config --cflags... "
216     FB_CFLAGS=`fb_config --cflags`
217     if [ "$?" != "0" ]
218     then
219         CHECK_FBCLIENT=no
220         printf "no\n"
221     else
222         printf "[$FB_CFLAGS]\n"
223         printf "Checking for fb_config --libs "
224         FB_LDFLAGS=`fb_config --libs`
225         if [ "$?" != "0" ]
226         then
227             CHECK_FBCLIENT=no
228             printf "no\n"
229         else
230             CHECK_FBCLIENT=yes
231             printf "[$FB_LDFLAGS]\n"
232         fi
233     fi
234 fi
235
236 rm -f build_check.c
237
238 if [ "$CHECK_EXPAT" != "yes" ]
239 then
240     printf -- "-lexpat not found!\n"
241     exit 1
242 fi
243
244 if [ "$CHECK_FBCLIENT" = "yes" ]
245 then
246     STG_LIBS="$STG_LIBS
247               ibpp.lib"
248 fi
249
250 printf "OS=$OS\n" > $CONFFILE
251 printf "STG_TIME=yes\n" >> $CONFFILE
252 printf "DEBUG=$DEBUG\n" >> $CONFFILE
253 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
254 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
255 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
256 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
257 printf "ARCH=$ARCH\n" >> $CONFFILE
258 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
259 printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
260 if [ "$CHECK_FBCLIENT" = "yes" ]
261 then
262     printf "FB_CFLAGS=$FB_CFLAGS\n" >> $CONFFILE
263     printf "FB_LDFLAGS=$FB_LDFLAGS\n" >> $CONFFILE
264 fi
265 printf "DEFS=$DEFS\n" >> $CONFFILE
266 printf "STG_LIBS=" >> $CONFFILE
267 for lib in $STG_LIBS
268 do
269     printf "$lib " >> $CONFFILE
270 done
271 printf "\n" >> $CONFFILE
272 printf "CC=$CC\n" >> $CONFFILE
273 printf "CXX=$CXX\n" >> $CONFFILE
274 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
275 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
276 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
277 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
278 printf "PREFIX=$PREFIX\n" >> $CONFFILE
279 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
280 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
281 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
282 printf "OWNER=$OWNER\n" >> $CONFFILE
283
284 if [ "$1" != "debug" ]
285 then
286     $MAKE $MAKEOPTS
287 else
288     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
289 fi