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