]> git.stg.codes - stg.git/blob - projects/sgconf/build
44f6e617c944dd7d10cc7303769a83a681955a1d
[stg.git] / projects / sgconf / build
1 #!/bin/sh
2
3 #   $Author: faust $
4 #   $Revision: 1.21 $
5 #   $Date: 2010/04/14 08:59:11 $
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 [ -z $1 ]
20 then
21     MAKEOPTS="-j1"
22 else
23     if [ "$1" = "debug" ]
24     then
25         DEFS="-DDEBUG"
26         MAKEOPTS="-j1"
27         CXXFLAGS="$CXXFLAGS -g3 -W -Wall"
28     else
29         MAKEOPTS="-j1"
30     fi
31 fi
32
33 CXXFLAGS="$CXXFLAGS -I/usr/local/include"
34 LDFLAGS="$LDFLAGS -L/usr/local/lib"
35
36 if [ "$sys" = "Linux" ]
37 then
38     OS=linux
39     release=""
40     MAKE="make"
41 fi
42
43 if [ "$sys" = "FreeBSD" ]
44 then
45     case $release in
46         4) OS=bsd;;
47         5) OS=bsd5;;
48         6) OS=bsd5;;
49         7) OS=bsd7;;
50         8) OS=bsd7;;
51         *) OS=unknown;;
52     esac
53     MAKE="gmake"
54 fi
55
56 if [ "$OS" = "unknown" ]
57 then 
58     echo "#############################################################################"
59     echo "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x  #"
60     echo "#############################################################################"
61     exit 1
62 fi
63
64 echo "#############################################################################"
65 echo "       Building sgconf for $sys $release"
66 echo "#############################################################################"
67
68 STG_LIBS="conffiles.lib
69           crypto.lib 
70           common.lib 
71           srvconf.lib"
72
73 if [ "$OS" = "linux" ]
74 then
75     DEFS="$DEFS -DLINUX"
76     LIB_THREAD=-lpthread
77     SHELL="/bin/bash"
78 else
79     if [ "$OS" = "bsd" ]
80     then
81         DEFS="$DEFS -DFREE_BSD"
82     else
83         DEFS="$DEFS -DFREE_BSD5"
84         if [ "$OS" = "bsd7" ]
85         then
86             LIB_THREAD=-lpthread
87         else
88             LIB_THREAD=-lc_r
89         fi
90     fi
91     SHELL="/usr/local/bin/bash"
92 fi
93
94 if [ -z "$CC" ]
95 then
96     CC=gcc
97 fi
98
99 if [ -z "$CXX" ]
100 then
101     CXX=g++
102 fi
103
104 echo -n "Checking CC... "
105 $CC --version > /dev/null 2> /dev/null
106 if [ $? != 0 ]
107 then
108     echo "FAIL!"
109     echo "$CC not found"
110     exit;
111 fi
112 echo "found"
113 echo -n "Checking CXX... "
114 $CXX --version > /dev/null 2> /dev/null
115 if [ $? != 0 ]
116 then
117     echo "FAIL!"
118     echo "$CXX not found"
119     exit;
120 fi
121 echo "found"
122
123 echo -n "Checking endianess... "
124 echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
125 $CC $CXXFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
126 if [ $? != 0 ]
127 then
128     echo "FAIL!"
129     echo "Endianess checking failed"
130     exit;
131 else
132     ./fake
133     if [ $? = 1 ]
134     then
135         ARCH=le
136         CXXFLAGS="$CXXFLAGS -DARCH_LE"
137         echo "Little Endian"
138     else
139         ARCH=be
140         CXXFLAGS="$CXXFLAGS -DARCH_BE"
141         echo "Big Endian"
142     fi
143 fi
144 rm -f fake
145
146 echo -n "Checking for -lexpat... "
147 echo "int main() { return 0; }" > build_check.c
148 $CC $CXXFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
149 if [ $? != 0 ]
150 then
151     CHECK_EXPAT=no
152     echo "no"
153 else
154     CHECK_EXPAT=yes
155     echo "yes"
156 fi
157 rm -f fake
158 rm -f build_check.c
159
160 if [ "$CHECK_EXPAT" != "yes" ]
161 then
162     echo "-lexpat not found!"
163     exit 1
164 fi
165
166 echo "OS=$OS" > $CONFFILE
167 echo "STG_TIME=yes" >> $CONFFILE
168 echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE
169 echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE
170 echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE
171 echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE
172 echo "ARCH=$ARCH" >> $CONFFILE
173 echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE
174 echo "DEFS=$DEFS" >> $CONFFILE
175 echo -n "STG_LIBS=" >> $CONFFILE
176 for lib in $STG_LIBS
177 do
178     echo -n "$lib " >> $CONFFILE
179 done
180 echo "" >> $CONFFILE
181 echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
182 echo "SHELL=$SHELL" >> $CONFFILE
183 echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
184 echo "LDFLAGS=$LDFLAGS" >> $CONFFILE
185 echo "PREFIX=$PREFIX" >> $CONFFILE
186 echo "BIN_MODE=$BIN_MODE" >> $CONFFILE
187 echo "DATA_MODE=$DATA_MODE" >> $CONFFILE
188 echo "DIR_MODE=$DIR_MODE" >> $CONFFILE
189 echo "OWNER=$OWNER" >> $CONFFILE
190
191 $MAKE $MAKEOPTS
192