]> git.stg.codes - stg.git/blob - projects/sgconf/build
Added support of Darwin platform.
[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 [ "$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 sgconf 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 sgconf for $sys $release\n"
64 printf "#############################################################################\n"
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 printf "Checking CC... "
101 $CC --version > /dev/null 2> /dev/null
102 if [ $? != 0 ]
103 then
104     printf "FAIL!\n"
105     printf "$CC not found\n"
106     exit;
107 fi
108 printf "found\n"
109 printf "Checking CXX... "
110 $CXX --version > /dev/null 2> /dev/null
111 if [ $? != 0 ]
112 then
113     printf "FAIL!\n"
114     printf "$CXX not found\n"
115     exit;
116 fi
117 printf "found\n"
118
119 printf "Checking endianess... "
120 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
121 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
122 if [ $? != 0 ]
123 then
124     printf "FAIL!\n"
125     printf "Endianess checking failed\n"
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         printf "Little Endian\n"
135     else
136         ARCH=be
137         CXXFLAGS="$CXXFLAGS -DARCH_BE"
138         CFLAGS="$CFLAGS -DARCH_BE"
139         printf "Big Endian\n"
140     fi
141 fi
142 rm -f fake
143
144 printf "Checking for -lexpat... "
145 printf "int main() { return 0; }\n" > build_check.c
146 $CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
147 if [ $? != 0 ]
148 then
149     CHECK_EXPAT=no
150     printf "no\n"
151 else
152     CHECK_EXPAT=yes
153     printf "yes\n"
154 fi
155 rm -f fake
156 rm -f build_check.c
157
158 if [ "$CHECK_EXPAT" != "yes" ]
159 then
160     printf "-lexpat not found!\n"
161     exit 1
162 fi
163
164 printf "OS=$OS\n" > $CONFFILE
165 printf "STG_TIME=yes\n" >> $CONFFILE
166 printf "DEBUG=$DEBUG\n" >> $CONFFILE
167 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
168 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
169 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
170 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
171 printf "ARCH=$ARCH\n" >> $CONFFILE
172 printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
173 printf "DEFS=$DEFS\n" >> $CONFFILE
174 printf "STG_LIBS=" >> $CONFFILE
175 for lib in $STG_LIBS
176 do
177     printf "$lib " >> $CONFFILE
178 done
179 printf "\n" >> $CONFFILE
180 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
181 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
182 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
183 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
184 printf "PREFIX=$PREFIX\n" >> $CONFFILE
185 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
186 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
187 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
188 printf "OWNER=$OWNER\n" >> $CONFFILE
189
190 $MAKE $MAKEOPTS
191