]> git.stg.codes - stg.git/blob - projects/sgconf_xml/build
Rename parameter's names
[stg.git] / projects / sgconf_xml / build
1 #!/bin/sh
2
3 #   $Author: nobunaga $
4 #   $Revision: 1.2 $
5 #   $Date: 2008/01/05 12:11:02 $
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     echo "#############################################################################"
57     echo "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x  #"
58     echo "#############################################################################"
59     exit 1
60 fi
61
62 echo "#############################################################################"
63 echo "       Building sgconf for $sys $release"
64 echo "#############################################################################"
65
66 STG_LIBS="conffiles.lib
67           crypto.lib 
68           common.lib 
69           srvconf.lib"
70
71 if [ "$OS" = "linux" ]
72 then
73     DEFS="$DEFS -DLINUX"
74     LIB_THREAD=-lpthread
75 else
76     if [ "$OS" = "bsd" ]
77     then
78         DEFS="$DEFS -DFREE_BSD"
79     else
80         DEFS="$DEFS -DFREE_BSD5"
81         if [ "$OS" = "bsd7" ]
82         then
83             LIB_THREAD=-lpthread
84         else
85             LIB_THREAD=-lc_r
86         fi
87     fi
88 fi
89
90 if [ -z "$CC" ]
91 then
92     CC=gcc
93 fi
94
95 if [ -z "$CXX" ]
96 then
97     CXX=g++
98 fi
99
100 echo -n "Checking CC... "
101 $CC --version > /dev/null 2> /dev/null
102 if [ $? != 0 ]
103 then
104     echo "FAIL!"
105     echo "$CC not found"
106     exit;
107 fi
108 echo "found"
109 echo -n "Checking CXX... "
110 $CXX --version > /dev/null 2> /dev/null
111 if [ $? != 0 ]
112 then
113     echo "FAIL!"
114     echo "$CXX not found"
115     exit;
116 fi
117 echo "found"
118
119 echo -n "Checking endianess... "
120 echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
121 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
122 if [ $? != 0 ]
123 then
124     echo "FAIL!"
125     echo "Endianess checking failed"
126     exit;
127 else
128     ./fake
129     if [ $? = 1 ]
130     then
131         ARCH=le
132         CXXFLAGS="$CXXFLAGS -DARCH_LE"
133         CFLAGS="$CFLAGS -DARCH_LE"
134         echo "Little Endian"
135     else
136         ARCH=be
137         CXXFLAGS="$CXXFLAGS -DARCH_BE"
138         CFLAGS="$CFLAGS -DARCH_BE"
139         echo "Big Endian"
140     fi
141 fi
142 rm -f fake
143
144 echo -n "Checking for -lexpat... "
145 echo "int main() { return 0; }" > build_check.c
146 $CC $CXXFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
147 if [ $? != 0 ]
148 then
149     CHECK_EXPAT=no
150     echo "no"
151 else
152     CHECK_EXPAT=yes
153     echo "yes"
154 fi
155 rm -f fake
156 rm -f build_check.c
157
158 if [ "$CHECK_EXPAT" != "yes" ]
159 then
160     echo "-lexpat not found!"
161     exit 1
162 fi
163
164 echo "OS=$OS" > $CONFFILE
165 echo "STG_TIME=yes" >> $CONFFILE
166 echo "DEBUG=$DEBUG" >> $CONFFILE
167 echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE
168 echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE
169 echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE
170 echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE
171 echo "ARCH=$ARCH" >> $CONFFILE
172 echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE
173 echo "DEFS=$DEFS" >> $CONFFILE
174 echo -n "STG_LIBS=" >> $CONFFILE
175 for lib in $STG_LIBS
176 do
177     echo -n "$lib " >> $CONFFILE
178 done
179 echo "" >> $CONFFILE
180 echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
181 echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
182 echo "CFLAGS=$CFLAGS" >> $CONFFILE
183 echo "LDFLAGS=$LDFLAGS" >> $CONFFILE
184 echo "PREFIX=$PREFIX" >> $CONFFILE
185 echo "BIN_MODE=$BIN_MODE" >> $CONFFILE
186 echo "DATA_MODE=$DATA_MODE" >> $CONFFILE
187 echo "DIR_MODE=$DIR_MODE" >> $CONFFILE
188 echo "OWNER=$OWNER" >> $CONFFILE
189
190 $MAKE $MAKEOPTS
191