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