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