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