]> git.stg.codes - stg.git/blob - projects/rlm_stg/build
Added suboptions to tariffs and admins.
[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     if [ "$OS" = "bsd" ]
72     then
73         DEFS="$DEFS -DFREE_BSD"
74     else
75         DEFS="$DEFS -DFREE_BSD5"
76         if [ "$OS" = "bsd7" ]
77         then
78             LIB_THREAD=-lpthread
79         else
80             LIB_THREAD=-lc_r
81         fi
82     fi
83     CXXFLAGS="$CXXFLAGS -DHAVE_CLOSEFROM"
84 fi
85
86 if [ -z "$CC" ]
87 then
88     CC=gcc
89 fi
90
91 if [ -z "$CXX" ]
92 then
93     CXX=g++
94 fi
95
96 printf "Checking CC... "
97 $CC --version > /dev/null 2> /dev/null
98 if [ $? != 0 ]
99 then
100     printf "FAIL!\n"
101     printf "$CC not found\n"
102     exit;
103 fi
104 printf "found\n"
105 printf "Checking CXX... "
106 $CXX --version > /dev/null 2> /dev/null
107 if [ $? != 0 ]
108 then
109     printf "FAIL!\n"
110     printf "$CXX not found\n"
111     exit;
112 fi
113 printf "found\n"
114
115 printf "Checking endianess... "
116 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
117 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
118 if [ $? != 0 ]
119 then
120     printf "FAIL!\n"
121     printf "Endianess checking failed\n"
122     exit;
123 else
124     ./fake
125     if [ $? = 1 ]
126     then
127         ARCH=le
128         CXXFLAGS="$CXXFLAGS -DARCH_LE"
129         CFLAGS="$CFLAGS -DARCH_LE"
130         printf "Little Endian\n"
131     else
132         ARCH=be
133         CXXFLAGS="$CXXFLAGS -DARCH_BE"
134         CFLAGS="$CFLAGS -DARCH_BE"
135         printf "Big Endian\n"
136     fi
137 fi
138 rm -f fake
139
140 printf "OS=$OS\n" > $CONFFILE
141 printf "STG_TIME=yes\n" >> $CONFFILE
142 printf "DEBUG=$DEBUG\n" >> $CONFFILE
143 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
144 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
145 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
146 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
147 printf "ARCH=$ARCH\n" >> $CONFFILE
148 printf "DEFS=$DEFS\n" >> $CONFFILE
149 printf "STG_LIBS=" >> $CONFFILE
150 for lib in $STG_LIBS
151 do
152     printf "$lib " >> $CONFFILE
153 done
154 printf "\n" >> $CONFFILE
155 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
156 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
157 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
158 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
159 printf "PREFIX=$PREFIX\n" >> $CONFFILE
160 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
161 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
162 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
163 printf "OWNER=$OWNER\n" >> $CONFFILE
164 $MAKE $MAKEOPTS
165