]> git.stg.codes - stg.git/blob - projects/rlm_stg/build
Ticket 37. UPDATE moved before DROP DEFAULT.
[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 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 "OS=$OS\n" > $CONFFILE
154 printf "STG_TIME=yes\n" >> $CONFFILE
155 printf "DEBUG=$DEBUG\n" >> $CONFFILE
156 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
157 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
158 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
159 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
160 printf "ARCH=$ARCH\n" >> $CONFFILE
161 printf "DEFS=$DEFS\n" >> $CONFFILE
162 printf "STG_LIBS=" >> $CONFFILE
163 for lib in $STG_LIBS
164 do
165     printf "$lib " >> $CONFFILE
166 done
167 printf "\n" >> $CONFFILE
168 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
169 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
170 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
171 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
172 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
173 printf "PREFIX=$PREFIX\n" >> $CONFFILE
174 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
175 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
176 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
177 printf "OWNER=$OWNER\n" >> $CONFFILE
178
179 if [ "$1" != "debug" ]
180 then
181     $MAKE $MAKEOPTS
182 else
183     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
184 fi