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