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