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