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