]> git.stg.codes - stg.git/blob - projects/rscriptd/build
convertor -> sgconv in docs.
[stg.git] / projects / rscriptd / build
1 #!/bin/sh
2
3 #   $Author: faust $
4 #   $Revision: 1.21 $
5 #   $Date: 2010/04/14 08:58:52 $
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     ETC_DIR="./inst/freebsd/etc/stargazer"
58     MAKE="make"
59 fi
60
61 if [ "$OS" = "unknown" ]
62 then
63     printf "#############################################################################\n"
64     printf "# Sorry, but rscriptd is currently supported by Linux, FreeBSD and Darwin.  #\n"
65     printf "#############################################################################\n"
66     exit 1
67 fi
68
69 printf "#############################################################################\n"
70 printf "       Building rscriptd for $sys $release\n"
71 printf "#############################################################################\n"
72
73 STG_LIBS="logger.lib
74           crypto.lib
75           common.lib
76           scriptexecuter.lib
77           conffiles.lib"
78
79 if [ "$OS" = "linux" ]
80 then
81     DEFS="$DEFS -DLINUX"
82     LIB_THREAD=-lpthread
83 else
84     LIBICONV="-liconv"
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 if [ -z "$AR" ]
116 then
117     AR=ar
118 fi
119
120 if [ -z "$RANLIB" ]
121 then
122     RANLIB=ranlib
123 fi
124
125 printf "Checking CC... "
126 $CC --version > /dev/null 2> /dev/null
127 if [ $? != 0 ]
128 then
129     printf "FAIL!\n"
130     printf "$CC not found\n"
131     exit;
132 fi
133 printf "found\n"
134 printf "Checking CXX... "
135 $CXX --version > /dev/null 2> /dev/null
136 if [ $? != 0 ]
137 then
138     printf "FAIL!\n"
139     printf "$CXX not found\n"
140     exit;
141 fi
142 printf "found\n"
143 printf "Checking AR... "
144 $AR --version > /dev/null 2> /dev/null
145 if [ $? != 0 ]
146 then
147     printf "FAIL!\n"
148     printf "$AR not found\n"
149     exit;
150 fi
151 printf "found\n"
152 printf "Checking RANLIB... "
153 $RANLIB --version > /dev/null 2> /dev/null
154 if [ $? != 0 ]
155 then
156     printf "FAIL!\n"
157     printf "$RANLIB not found\n"
158     exit;
159 fi
160 printf "found\n"
161
162 printf "Checking endianess... "
163 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
164 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
165 if [ $? != 0 ]
166 then
167     printf "FAIL!\n"
168     printf "Endianess checking failed\n"
169     exit;
170 else
171     ./fake
172     if [ $? = 1 ]
173     then
174         ARCH=le
175         CXXFLAGS="$CXXFLAGS -DARCH_LE"
176         CFLAGS="$CFLAGS -DARCH_LE"
177         printf "Little Endian\n"
178     else
179         ARCH=be
180         CXXFLAGS="$CXXFLAGS -DARCH_BE"
181         CFLAGS="$CFLAGS -DARCH_BE"
182         printf "Big Endian\n"
183     fi
184 fi
185 rm -f fake
186
187 printf "Checking for iconv 2nd argument... "
188 printf "#include <iconv.h>\nint main(){ const char** src = 0; iconv(0, src, 0, 0, 0); }\n" > build_check.c
189 $CC $CFLAGS $LDFLAGS -Werror build_check.c $LIBICONV -o fake > /dev/null 2> /dev/null
190 if [ $? != 0 ]
191 then
192     printf "non-const\n"
193 else
194     DEFS="$DEFS -DCONST_ICONV"
195     printf "const\n"
196 fi
197 rm -f fake
198
199 rm -f build_check.c
200
201 printf "OS=$OS\n" > $CONFFILE
202 printf "STG_TIME=yes\n" >> $CONFFILE
203 printf "DEBUG=$DEBUG\n" >> $CONFFILE
204 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
205 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
206 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
207 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
208 printf "ARCH=$ARCH\n" >> $CONFFILE
209 printf "DEFS=$DEFS\n" >> $CONFFILE
210 printf "STG_LIBS=" >> $CONFFILE
211 for lib in $STG_LIBS
212 do
213     printf "$lib " >> $CONFFILE
214 done
215 printf "\n" >> $CONFFILE
216 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
217 printf "CC=$CC\n" >> $CONFFILE
218 printf "CXX=$CXX\n" >> $CONFFILE
219 printf "AR=$AR\n" >> $CONFFILE
220 printf "RANLIB=$RANLIB\n" >> $CONFFILE
221 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
222 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
223 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
224 printf "LIBICONV=$LIBICONV\n" >> $CONFFILE
225 printf "PREFIX=$PREFIX\n" >> $CONFFILE
226 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
227 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
228 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
229 printf "OWNER=$OWNER\n" >> $CONFFILE
230
231 if [ "$1" != "debug" ]
232 then
233     $MAKE $MAKEOPTS
234 else
235     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
236 fi