]> git.stg.codes - stg.git/blob - projects/rscriptd/build
Parse admins list.
[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 | 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         *) 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="gmake"
59 fi
60
61 if [ "$OS" = "unknown" ]
62 then
63     printf "#############################################################################\n"
64     printf "# Sorry, but rscriptd 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 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     if [ "$OS" = "bsd" ]
85     then
86         DEFS="$DEFS -DFREE_BSD"
87     else
88         if [ "$OS" = "bsd7" ]
89         then
90             DEFS="$DEFS -DFREE_BSD5"
91             LIB_THREAD=-lpthread
92         else
93             if [ "$OS" == "darwin" ]
94             then
95                 DEFS="$DEFS -DDARWIN"
96                 LIB_THREAD=-lpthread
97             else
98                 LIB_THREAD=-lc_r
99             fi
100         fi
101     fi
102 fi
103
104 if [ -z "$CC" ]
105 then
106     CC=gcc
107 fi
108
109 if [ -z "$CXX" ]
110 then
111     CXX=g++
112 fi
113
114 printf "Checking CC... "
115 $CC --version > /dev/null 2> /dev/null
116 if [ $? != 0 ]
117 then
118     printf "FAIL!\n"
119     printf "$CC not found\n"
120     exit;
121 fi
122 printf "found\n"
123 printf "Checking CXX... "
124 $CXX --version > /dev/null 2> /dev/null
125 if [ $? != 0 ]
126 then
127     printf "FAIL!\n"
128     printf "$CXX not found\n"
129     exit;
130 fi
131 printf "found\n"
132
133 printf "Checking endianess... "
134 printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
135 $CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
136 if [ $? != 0 ]
137 then
138     printf "FAIL!\n"
139     printf "Endianess checking failed\n"
140     exit;
141 else
142     ./fake
143     if [ $? = 1 ]
144     then
145         ARCH=le
146         CXXFLAGS="$CXXFLAGS -DARCH_LE"
147         CFLAGS="$CFLAGS -DARCH_LE"
148         printf "Little Endian\n"
149     else
150         ARCH=be
151         CXXFLAGS="$CXXFLAGS -DARCH_BE"
152         CFLAGS="$CFLAGS -DARCH_BE"
153         printf "Big Endian\n"
154     fi
155 fi
156 rm -f fake
157 rm -f build_check.c
158
159 printf "OS=$OS\n" > $CONFFILE
160 printf "STG_TIME=yes\n" >> $CONFFILE
161 printf "DEBUG=$DEBUG\n" >> $CONFFILE
162 printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
163 printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
164 printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
165 printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
166 printf "ARCH=$ARCH\n" >> $CONFFILE
167 printf "DEFS=$DEFS\n" >> $CONFFILE
168 printf "STG_LIBS=" >> $CONFFILE
169 for lib in $STG_LIBS
170 do
171     printf "$lib " >> $CONFFILE
172 done
173 printf "\n" >> $CONFFILE
174 printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
175 printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
176 printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
177 printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
178 printf "PREFIX=$PREFIX\n" >> $CONFFILE
179 printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
180 printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
181 printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
182 printf "OWNER=$OWNER\n" >> $CONFFILE
183
184 if [ "$1" != "debug" ]
185 then
186     $MAKE $MAKEOPTS
187 else
188     printf "\n\n\nDebug build. Type $MAKE explicitly\n"
189 fi