]> git.stg.codes - stg.git/blob - projects/rlm_stg/build
Added ability to optionally transfer resetable value to a real var.
[stg.git] / projects / rlm_stg / build
1 #!/bin/sh
2
3 #   $Author: faust $
4 #   $Revision: 1.13 $
5 #   $Date: 2010/04/14 08:58:44 $
6 ######################################################
7
8 OS=unknown
9 sys=`uname -s`
10 release=`uname -r | cut -b1`
11 BUILD_DIR=`pwd`
12 CONFFILE="../../Makefile.conf"
13 PREFIX="/"
14 BIN_MODE=0755
15 DATA_MODE=0644
16 DIR_MODE=0755
17 OWNER=root
18
19 if [ "$1" = "debug" ]
20 then
21    DEFS="$DEFS -DDEBUG"
22    MAKEOPTS="$MAKEOPTS -j1"
23    CFLAGS="$CFLAGS -ggdb3 -W -Wall -Wextra"
24    CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall -Wextra"
25    DEBUG="yes"
26 else
27    DEFS="$DEFS -DNDEBUG"
28    DEBUG="no"
29 fi
30
31 CFLAGS="$CFLAGS -I/usr/local/include"
32 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
33 LDFLAGS="$LDFLAGS -L/usr/local/lib"
34
35 if [ "$sys" = "Linux" ]
36 then
37     OS=linux
38     release=""
39     MAKE="make"
40 fi
41
42 if [ "$sys" = "FreeBSD" ]
43 then
44     case $release 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 [ "$OS" = "unknown" ]
55 then
56     printf "#############################################################################\n"
57     printf "# Sorry, but rlm_stg currently supported by Linux, FreeBSD 4.x, 5.x, 6.x  #\n"
58     printf "#############################################################################\n"
59     exit 1
60 fi
61
62 printf "#############################################################################\n"
63 printf "       Building rlm_stg for $sys $release\n"
64 printf "#############################################################################\n"
65
66 STG_LIBS="crypto.lib common.lib json.lib"
67
68 if [ "$OS" = "linux" ]
69 then
70     DEFS="$DEFS -DLINUX"
71     LIB_THREAD=-lpthread
72 else
73     LIBICONV="-liconv"
74     if [ "$OS" = "bsd" ]
75     then
76         DEFS="$DEFS -DFREE_BSD"
77     else
78         DEFS="$DEFS -DFREE_BSD5"
79         if [ "$OS" = "bsd7" ]
80         then
81             LIB_THREAD=-lpthread
82         else
83             LIB_THREAD=-lc_r
84         fi
85     fi
86     CXXFLAGS="$CXXFLAGS -DHAVE_CLOSEFROM"
87 fi
88
89 if [ -z "$CC" ]
90 then
91     CC=gcc
92 fi
93
94 if [ -z "$CXX" ]
95 then
96     CXX=g++
97 fi
98
99 printf "Checking CC... "
100 $CC --version > /dev/null 2> /dev/null
101 if [ $? != 0 ]
102 then
103     printf "FAIL!\n"
104     printf "$CC not found\n"
105     exit;
106 fi
107 printf "found\n"
108 printf "Checking CXX... "
109 $CXX --version > /dev/null 2> /dev/null
110 if [ $? != 0 ]
111 then
112     printf "FAIL!\n"
113     printf "$CXX not found\n"
114     exit;
115 fi
116 printf "found\n"
117
118 printf "Checking endianess... "
119 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
120 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
121 if [ $? != 0 ]
122 then
123     printf "FAIL!\n"
124     printf "Endianess checking failed\n"
125     exit;
126 else
127     ./fake
128     if [ $? = 1 ]
129     then
130         ARCH=le
131         CXXFLAGS="$CXXFLAGS -DARCH_LE"
132         CFLAGS="$CFLAGS -DARCH_LE"
133         printf "Little Endian\n"
134     else
135         ARCH=be
136         CXXFLAGS="$CXXFLAGS -DARCH_BE"
137         CFLAGS="$CFLAGS -DARCH_BE"
138         printf "Big Endian\n"
139     fi
140 fi
141 rm -f fake
142
143 printf "Checking for iconv 2nd argument... "
144 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
145 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
146 if [ $? != 0 ]
147 then
148     printf "non-const\n"
149 else
150     DEFS="$DEFS -DCONST_ICONV"
151     printf "const\n"
152 fi
153 rm -f fake
154
155 printf "Checking for -lyajl... "
156 pkg-config --version > /dev/null 2> /dev/null
157 if [ "$?" = "0" ]
158 then
159     pkg-config --atleast-version=2.0.0 yajl
160     if [ "$?" != "0" ]
161     then
162         CHECK_YAJL=no
163         printf "no\n"
164         exit;
165     else
166         CHECK_YAJL=yes
167         printf `pkg-config --modversion yajl`"\n"
168     fi
169 else
170     printf "#include <stdio.h>\n" > build_check.c
171     printf "#include <yajl/yajl_version.h>\n" >> build_check.c
172     printf "int main() { printf(\"%%d\", yajl_version()); return 0; }\n" >> build_check.c
173     $CC $CFLAGS $LDFLAGS build_check.c -lyajl -o fake > /dev/null 2> /dev/null
174     if [ $? != 0 ]
175     then
176         CHECK_YAJL=no
177         printf "no\n"
178         exit;
179     else
180         YAJL_VERSION=`./fake`
181         if [ $YAJL_VERSION -ge 20000 ]
182         then
183             CHECK_YAJL=yes
184             printf "${YAJL_VERSION}\n"
185         else
186             CHECK_YAJL=no
187             printf "no. Need at least version 2.0.0, existing version is ${YAJL_VERSION}\n"
188             exit;
189         fi
190     fi
191     rm -f fake
192 fi
193
194 printf "Checking for boost::scoped_ptr... "
195 printf "#include <boost/scoped_ptr.hpp>\nint main() { boost::scoped_ptr<int> test(new int(1)); return 0; }\n" > build_check.cpp
196 $CXX $CXXFLAGS $LDFLAGS build_check.cpp -o fake # > /dev/null 2> /dev/null
197 if [ $? != 0 ]
198 then
199     CHECK_BOOST_SCOPED_PTR=no
200     printf "no\n"
201     exit;
202 else
203     CHECK_BOOST_SCOPED_PTR=yes
204     printf "yes\n"
205 fi
206 rm -f fake
207
208 rm -f build_check.c
209 rm -f build_check.cpp
210
211 if [ "$CHECK_YAJL" = "yes" -a "$CHECK_BOOST_SCOPED_PTR" = "yes" ]
212 then
213     STG_LIBS="$STG_LIBS
214               json.lib"
215 fi
216
217 printf "OS=$OS\n" > $CONFFILE
218 printf "STG_TIME=yes\n" >> $CONFFILE
219 printf "DEBUG=$DEBUG\n" >> $CONFFILE
220 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
221 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
222 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
223 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
224 printf "ARCH=$ARCH\n" >> $CONFFILE
225 printf "DEFS=$DEFS\n" >> $CONFFILE
226 printf "STG_LIBS=" >> $CONFFILE
227 for lib in $STG_LIBS
228 do
229     printf "$lib " >> $CONFFILE
230 done
231 printf "\n" >> $CONFFILE
232 printf "CC=$CC\n" >> $CONFFILE
233 printf "CXX=$CXX\n" >> $CONFFILE
234 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
235 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
236 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
237 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
238 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
239 printf "PREFIX=$PREFIX\n" >> $CONFFILE
240 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
241 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
242 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
243 printf "OWNER=$OWNER\n" >> $CONFFILE
244
245 if [ "$1" != "debug" ]
246 then
247     $MAKE $MAKEOPTS
248 else
249     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
250 fi