]> git.stg.codes - stg.git/blob - projects/rlm_stg/build
Add tariff change policy description.
[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"
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 if [ -z "$AR" ]
98 then
99     AR=ar
100 fi
101
102 if [ -z "$RANLIB" ]
103 then
104     RANLIB=ranlib
105 fi
106
107 printf "Checking CC... "
108 $CC --version > /dev/null 2> /dev/null
109 if [ $? != 0 ]
110 then
111     printf "FAIL!\n"
112     printf "$CC not found\n"
113     exit;
114 fi
115 printf "found\n"
116 printf "Checking CXX... "
117 $CXX --version > /dev/null 2> /dev/null
118 if [ $? != 0 ]
119 then
120     printf "FAIL!\n"
121     printf "$CXX not found\n"
122     exit;
123 fi
124 printf "found\n"
125 printf "Checking AR... "
126 $AR --version > /dev/null 2> /dev/null
127 if [ $? != 0 ]
128 then
129     printf "FAIL!\n"
130     printf "$AR not found\n"
131     exit;
132 fi
133 printf "found\n"
134 printf "Checking RANLIB... "
135 $RANLIB --version > /dev/null 2> /dev/null
136 if [ $? != 0 ]
137 then
138     printf "FAIL!\n"
139     printf "$RANLIB not found\n"
140     exit;
141 fi
142 printf "found\n"
143
144 printf "Checking endianess... "
145 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
146 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
147 if [ $? != 0 ]
148 then
149     printf "FAIL!\n"
150     printf "Endianess checking failed\n"
151     exit;
152 else
153     ./fake
154     if [ $? = 1 ]
155     then
156         ARCH=le
157         CXXFLAGS="$CXXFLAGS -DARCH_LE"
158         CFLAGS="$CFLAGS -DARCH_LE"
159         printf "Little Endian\n"
160     else
161         ARCH=be
162         CXXFLAGS="$CXXFLAGS -DARCH_BE"
163         CFLAGS="$CFLAGS -DARCH_BE"
164         printf "Big Endian\n"
165     fi
166 fi
167 rm -f fake
168
169 printf "Checking for iconv 2nd argument... "
170 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
171 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
172 if [ $? != 0 ]
173 then
174     printf "non-const\n"
175 else
176     DEFS="$DEFS -DCONST_ICONV"
177     printf "const\n"
178 fi
179 rm -f fake
180
181 printf "OS=$OS\n" > $CONFFILE
182 printf "STG_TIME=yes\n" >> $CONFFILE
183 printf "DEBUG=$DEBUG\n" >> $CONFFILE
184 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
185 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
186 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
187 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
188 printf "ARCH=$ARCH\n" >> $CONFFILE
189 printf "DEFS=$DEFS\n" >> $CONFFILE
190 printf "STG_LIBS=" >> $CONFFILE
191 for lib in $STG_LIBS
192 do
193     printf "$lib " >> $CONFFILE
194 done
195 printf "\n" >> $CONFFILE
196 printf "CC=$CC\n" >> $CONFFILE
197 printf "CXX=$CXX\n" >> $CONFFILE
198 printf "AR=$AR\n" >> $CONFFILE
199 printf "RANLIB=$RANLIB\n" >> $CONFFILE
200 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
201 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
202 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
203 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
204 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
205 printf "PREFIX=$PREFIX\n" >> $CONFFILE
206 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
207 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
208 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
209 printf "OWNER=$OWNER\n" >> $CONFFILE
210
211 if [ "$1" != "debug" ]
212 then
213     $MAKE $MAKEOPTS
214 else
215     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
216 fi