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