]> git.stg.codes - stg.git/blob - projects/sgconf/build
Change version in build messages.
[stg.git] / projects / sgconf / build
1 #!/bin/sh
2
3 #   $Author: faust $
4 #   $Revision: 1.21 $
5 #   $Date: 2010/04/14 08:59:11 $
6 ######################################################
7
8 OS=unknown
9 sys=`uname -s`
10 release=`uname -r`
11 major=`printf "%s" "$release" | cut -d. -f1`
12 BUILD_DIR=`pwd`
13 CONFFILE="../../Makefile.conf"
14 PREFIX="/"
15 BIN_MODE=0755
16 DATA_MODE=0644
17 DIR_MODE=0755
18 OWNER=root
19
20 if [ "$1" = "debug" ]
21 then
22    DEFS="$DEFS -DDEBUG"
23    MAKEOPTS="$MAKEOPTS -j1"
24    CFLAGS="$CFLAGS -ggdb3 -W -Wall -Wextra"
25    CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall -Wextra"
26    DEBUG="yes"
27 else
28    DEFS="$DEFS -DNDEBUG"
29    DEBUG="no"
30 fi
31
32 CFLAGS="$CFLAGS -I/usr/local/include"
33 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
34 LDFLAGS="$LDFLAGS -L/usr/local/lib"
35
36 if [ "$sys" = "Linux" ]
37 then
38     OS=linux
39     MAKE="make"
40 fi
41
42 if [ "$sys" = "FreeBSD" ]
43 then
44     case $major in
45         4) OS=bsd;;
46         5) OS=bsd5;;
47         6) OS=bsd5;;
48         7) OS=bsd7;;
49         *) OS=bsd7;;
50     esac
51     MAKE="gmake"
52 fi
53
54 if [ "$sys" = "Darwin" ]
55 then
56     OS=darwin
57     ETC_DIR="./inst/freebsd/etc/stargazer"
58     MAKE="make"
59 fi
60
61 if [ "$OS" = "unknown" ]
62 then
63     printf "#############################################################################\n"
64     printf "# Sorry, but sgconf is currently supported by Linux, FreeBSD and Darwin.    #\n"
65     printf "#############################################################################\n"
66     exit 1
67 fi
68
69 printf "#############################################################################\n"
70 printf "       Building sgconf for $sys $release\n"
71 printf "#############################################################################\n"
72
73 STG_LIBS="conffiles.lib
74           crypto.lib
75           common.lib
76           srvconf.lib"
77
78 if [ "$OS" = "linux" ]
79 then
80     DEFS="$DEFS -DLINUX"
81     LIB_THREAD=-lpthread
82 else
83     LIBICONV="-liconv"
84     if [ "$OS" = "bsd" ]
85     then
86         DEFS="$DEFS -DFREE_BSD"
87     else
88         if [ "$OS" = "bsd7" ]
89         then
90             DEFS="$DEFS -DFREE_BSD5"
91             LIB_THREAD=-lpthread
92         else
93             if [ "$OS" == "darwin" ]
94             then
95                 DEFS="$DEFS -DDARWIN"
96                 LIB_THREAD=-lpthread
97             else
98                 LIB_THREAD=-lc_r
99             fi
100         fi
101     fi
102 fi
103
104 if [ -z "$CC" ]
105 then
106     CC=gcc
107 fi
108
109 if [ -z "$CXX" ]
110 then
111     CXX=g++
112 fi
113
114 if [ -z "$AR" ]
115 then
116     AR=ar
117 fi
118
119 if [ -z "$RANLIB" ]
120 then
121     RANLIB=ranlib
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 printf "Checking AR... "
143 $AR --version > /dev/null 2> /dev/null
144 if [ $? != 0 ]
145 then
146     printf "FAIL!\n"
147     printf "$AR not found\n"
148     exit;
149 fi
150 printf "found\n"
151 printf "Checking RANLIB... "
152 $RANLIB --version > /dev/null 2> /dev/null
153 if [ $? != 0 ]
154 then
155     printf "FAIL!\n"
156     printf "$RANLIB not found\n"
157     exit;
158 fi
159 printf "found\n"
160
161 printf "Checking endianess... "
162 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
163 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
164 if [ $? != 0 ]
165 then
166     printf "FAIL!\n"
167     printf "Endianess checking failed\n"
168     exit;
169 else
170     ./fake
171     if [ $? = 1 ]
172     then
173         ARCH=le
174         CXXFLAGS="$CXXFLAGS -DARCH_LE"
175         CFLAGS="$CFLAGS -DARCH_LE"
176         printf "Little Endian\n"
177     else
178         ARCH=be
179         CXXFLAGS="$CXXFLAGS -DARCH_BE"
180         CFLAGS="$CFLAGS -DARCH_BE"
181         printf "Big Endian\n"
182     fi
183 fi
184 rm -f fake
185
186 printf "Checking for -lexpat... "
187 printf "int main() { return 0; }\n" > build_check.c
188 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
189 if [ $? != 0 ]
190 then
191     CHECK_EXPAT=no
192     printf "no\n"
193 else
194     CHECK_EXPAT=yes
195     printf "yes\n"
196 fi
197 rm -f fake
198
199 printf "Checking for iconv 2nd argument... "
200 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
201 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
202 if [ $? != 0 ]
203 then
204     printf "non-const\n"
205 else
206     DEFS="$DEFS -DCONST_ICONV"
207     printf "const\n"
208 fi
209 rm -f fake
210
211 rm -f build_check.c
212
213 if [ "$CHECK_EXPAT" != "yes" ]
214 then
215     printf "-lexpat not found!\n"
216     exit 1
217 fi
218
219 printf "OS=$OS\n" > $CONFFILE
220 printf "STG_TIME=yes\n" >> $CONFFILE
221 printf "DEBUG=$DEBUG\n" >> $CONFFILE
222 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
223 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
224 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
225 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
226 printf "ARCH=$ARCH\n" >> $CONFFILE
227 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
228 printf "DEFS=$DEFS\n" >> $CONFFILE
229 printf "STG_LIBS=" >> $CONFFILE
230 for lib in $STG_LIBS
231 do
232     printf "$lib " >> $CONFFILE
233 done
234 printf "\n" >> $CONFFILE
235 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
236 printf "CC=$CC\n" >> $CONFFILE
237 printf "CXX=$CXX\n" >> $CONFFILE
238 printf "AR=$AR\n" >> $CONFFILE
239 printf "RANLIB=$RANLIB\n" >> $CONFFILE
240 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
241 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
242 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
243 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
244 printf "PREFIX=$PREFIX\n" >> $CONFFILE
245 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
246 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
247 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
248 printf "OWNER=$OWNER\n" >> $CONFFILE
249
250 if [ "$1" != "debug" ]
251 then
252     $MAKE $MAKEOPTS
253 else
254     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
255 fi