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