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