1 | #! /bin/sh |
---|
2 | |
---|
3 | # |
---|
4 | # Functions |
---|
5 | # |
---|
6 | usage() |
---|
7 | { |
---|
8 | cat << EOF |
---|
9 | |
---|
10 | OpenSSL options: |
---|
11 | --disable-openssl Disable OpenSSL, use built-in SHA1 implementation |
---|
12 | --openssl-prefix=PATH Location of OpenSSL headers and library |
---|
13 | --gettext-prefix=PATH Location of the Gettext header and library |
---|
14 | --disable-gtk Don't build the GTK+ GUI |
---|
15 | --prefix=PATH Install here instead of $INSTALL_PREFIX |
---|
16 | |
---|
17 | Some influential environment variables: |
---|
18 | CC C compiler command (default "cc") |
---|
19 | CFLAGS C compiler flags (default "-g -Wall -W") |
---|
20 | |
---|
21 | EOF |
---|
22 | } |
---|
23 | |
---|
24 | openssl_test() |
---|
25 | { |
---|
26 | cat > testconf.c << EOF |
---|
27 | #include <stdio.h> |
---|
28 | #include <openssl/sha.h> |
---|
29 | int main() |
---|
30 | { |
---|
31 | SHA1( 0, 0, 0 ); |
---|
32 | } |
---|
33 | EOF |
---|
34 | if [ -n "$OPENSSL_PREFIX" ]; then |
---|
35 | TMPFLAGS="-I$OPENSSL_PREFIX/include -L$OPENSSL_PREFIX/lib" |
---|
36 | fi |
---|
37 | if $CC $TMPFLAGS -o testconf testconf.c -lcrypto > /dev/null 2>&1 |
---|
38 | then |
---|
39 | echo "OpenSSL: yes" |
---|
40 | DEFINES="$DEFINES HAVE_OPENSSL" |
---|
41 | LINKLIBS="$LINKLIBS -lcrypto" |
---|
42 | else |
---|
43 | echo "OpenSSL: no, using built-in SHA1 implementation" |
---|
44 | fi |
---|
45 | rm -f testconf.c testconf |
---|
46 | } |
---|
47 | |
---|
48 | lm_test() |
---|
49 | { |
---|
50 | cat > testconf.c << EOF |
---|
51 | int main() |
---|
52 | { |
---|
53 | sqrt( 42 ); |
---|
54 | } |
---|
55 | EOF |
---|
56 | if ! $CC -o testconf testconf.c > /dev/null 2>&1 |
---|
57 | then |
---|
58 | if $CC -o testconf testconf.c -lm > /dev/null 2>&1 |
---|
59 | then |
---|
60 | LINKLIBS="$LINKLIBS -lm" |
---|
61 | fi |
---|
62 | fi |
---|
63 | rm -f testconf.c testconf |
---|
64 | } |
---|
65 | |
---|
66 | lrintf_test() |
---|
67 | { |
---|
68 | cat > testconf.c << EOF |
---|
69 | int main() |
---|
70 | { |
---|
71 | return ( lrintf( 3.14 ) != 3 ); |
---|
72 | } |
---|
73 | EOF |
---|
74 | if ( $CC -o testconf testconf.c $LINKLIBS && ./testconf ) > /dev/null 2>&1 |
---|
75 | then |
---|
76 | DEFINES="$DEFINES HAVE_LRINTF" |
---|
77 | fi |
---|
78 | rm -f testconf.c testconf |
---|
79 | } |
---|
80 | |
---|
81 | gettext_test() |
---|
82 | { |
---|
83 | cat > testconf.c <<EOF |
---|
84 | #include <libintl.h> |
---|
85 | int main() |
---|
86 | { |
---|
87 | gettext(""); |
---|
88 | } |
---|
89 | EOF |
---|
90 | |
---|
91 | if [ -n "$GETTEXT_PREFIX" ] && $CC "-I$GETTEXT_PREFIX/include" "-Wl,-R$GETTEXT_PREFIX/lib" "-L$GETTEXT_PREFIX/lib" -lintl -liconv -o testconf testconf.c >/dev/null 2>&1 |
---|
92 | then |
---|
93 | GTKCCFLAGS="-I$GETTEXT_PREFIX/include $GTKCCFLAGS" |
---|
94 | GTKLINKLIBS="-Wl,-R$GETTEXT_PREFIX/lib -L$GETTEXT_PREFIX/lib -lintl -liconv $GTKLINKLIBS" |
---|
95 | rm -f testconf.c testconf |
---|
96 | return 0 |
---|
97 | fi |
---|
98 | |
---|
99 | if $CC $GTKCCFLAGS $GTKLINKLIBS -o testconf testconf.c > /dev/null 2>&1 |
---|
100 | then |
---|
101 | rm -f testconf.c testconf |
---|
102 | return 0 |
---|
103 | fi |
---|
104 | |
---|
105 | for intl_testdir in $INSTALL_PREFIX/include \ |
---|
106 | /usr/local/include /usr/X11R6/include /usr/pkg/include |
---|
107 | do |
---|
108 | if $CC $GTKCCFLAGS -I$intl_testdir $GTKLINKLIBS -o testconf testconf.c > /dev/null 2>&1 |
---|
109 | then |
---|
110 | GTKCCFLAGS="$GTKCCFLAGS -I$intl_testdir" |
---|
111 | rm -f testconf.c testconf |
---|
112 | return 0 |
---|
113 | fi |
---|
114 | done |
---|
115 | rm -f testconf.c testconf |
---|
116 | return 1 |
---|
117 | } |
---|
118 | |
---|
119 | gtk_test() |
---|
120 | { |
---|
121 | if pkg-config gtk+-2.0 > /dev/null 2>&1 |
---|
122 | then |
---|
123 | if expr `pkg-config --modversion gtk+-2.0` '>=' 2.6.0 > /dev/null 2>&1 |
---|
124 | then |
---|
125 | cat > testconf.c << EOF |
---|
126 | #include <gtk/gtk.h> |
---|
127 | int main() |
---|
128 | { |
---|
129 | gtk_main(); |
---|
130 | } |
---|
131 | EOF |
---|
132 | if $CC `pkg-config gtk+-2.0 --cflags --libs` -o testconf testconf.c > /dev/null 2>&1 |
---|
133 | then |
---|
134 | GTKCCFLAGS=`pkg-config gtk+-2.0 --cflags` |
---|
135 | GTKLINKLIBS=`pkg-config gtk+-2.0 --libs` |
---|
136 | if gettext_test |
---|
137 | then |
---|
138 | GTKLOCALEDIR="$INSTALL_PREFIX/share/locale" |
---|
139 | GTK=yes |
---|
140 | echo "GTK+: yes" |
---|
141 | else |
---|
142 | GTKCCFLAGS= |
---|
143 | GTKLINKLIBS= |
---|
144 | echo "GTK+: no, could not find gettext libintl.h" |
---|
145 | GTK=no |
---|
146 | fi |
---|
147 | else |
---|
148 | echo "GTK+: no" |
---|
149 | GTK=no |
---|
150 | fi |
---|
151 | rm -f testconf.c testconf |
---|
152 | else |
---|
153 | echo "GTK+: no (2.6.0 or later is required)" |
---|
154 | GTK=no |
---|
155 | fi |
---|
156 | else |
---|
157 | echo "GTK+: no" |
---|
158 | GTK=no |
---|
159 | fi |
---|
160 | } |
---|
161 | |
---|
162 | # |
---|
163 | # Defaults settings |
---|
164 | # |
---|
165 | CC="${CC-cc}" |
---|
166 | CFLAGS="${CFLAGS--g -Wall -W}" |
---|
167 | # For > 2 GB files |
---|
168 | DEFINES="_FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE" |
---|
169 | # For asprintf |
---|
170 | DEFINES="$DEFINES _GNU_SOURCE" |
---|
171 | openssl_disable=0 |
---|
172 | gtk_disable=0 |
---|
173 | GTK=no |
---|
174 | GTKCCFLAGS= |
---|
175 | GTKLINKLIBS= |
---|
176 | GTKLOCALEDIR= |
---|
177 | if [ -n "$PREFIX" ]; then |
---|
178 | INSTALL_PREFIX=$PREFIX |
---|
179 | else |
---|
180 | INSTALL_PREFIX=/usr/local |
---|
181 | fi |
---|
182 | |
---|
183 | # |
---|
184 | # Parse options |
---|
185 | # |
---|
186 | while [ $# -ne 0 ]; do |
---|
187 | param=`expr "opt$1" : 'opt[^=]*=\(.*\)'` |
---|
188 | |
---|
189 | case "x$1" in |
---|
190 | x--disable-openssl) |
---|
191 | openssl_disable="1"; |
---|
192 | ;; |
---|
193 | x--openssl-prefix=*) |
---|
194 | OPENSSL_PREFIX="$param"; |
---|
195 | ;; |
---|
196 | x--gettext-prefix=*) |
---|
197 | GETTEXT_PREFIX="$param"; |
---|
198 | ;; |
---|
199 | x--disable-gtk) |
---|
200 | gtk_disable="1"; |
---|
201 | ;; |
---|
202 | x--prefix=*) |
---|
203 | INSTALL_PREFIX="$param"; |
---|
204 | ;; |
---|
205 | x--help) |
---|
206 | usage |
---|
207 | exit 0 |
---|
208 | ;; |
---|
209 | esac |
---|
210 | shift |
---|
211 | done |
---|
212 | |
---|
213 | # |
---|
214 | # System-specific flags |
---|
215 | # |
---|
216 | SYSTEM=`uname -s` |
---|
217 | case $SYSTEM in |
---|
218 | BeOS) |
---|
219 | DEFINES="$DEFINES SYS_BEOS" |
---|
220 | |
---|
221 | CC="gcc" |
---|
222 | MACHINE=`uname -m` |
---|
223 | case $MACHINE in |
---|
224 | BePC) # BeOS on x86 |
---|
225 | CPU="x86" |
---|
226 | ;; |
---|
227 | *) |
---|
228 | CPU="ppc" |
---|
229 | ;; |
---|
230 | esac |
---|
231 | SYSTEM="$SYSTEM / $CPU" |
---|
232 | |
---|
233 | RELEASE=`uname -r` |
---|
234 | case $RELEASE in |
---|
235 | 6.0*|5.0.4) # Zeta or R5 / BONE beta 7 |
---|
236 | SYSTEM="$SYSTEM / BONE" |
---|
237 | LINKLIBS="$LINKLIBS -lbind -lsocket" |
---|
238 | ;; |
---|
239 | 5.0*) # R5 / net_server |
---|
240 | SYSTEM="$SYSTEM / net_server" |
---|
241 | DEFINES="$DEFINES BEOS_NETSERVER" |
---|
242 | LINKLIBS="$LINKLIBS -lnet" |
---|
243 | ;; |
---|
244 | *) |
---|
245 | echo "Unsupported BeOS version" |
---|
246 | exit 1 |
---|
247 | ;; |
---|
248 | esac |
---|
249 | ;; |
---|
250 | |
---|
251 | Darwin) |
---|
252 | DEFINES="$DEFINES SYS_DARWIN" |
---|
253 | LINKLIBS="$LINKLIBS -lpthread" |
---|
254 | ;; |
---|
255 | |
---|
256 | FreeBSD) |
---|
257 | DEFINES="$DEFINES SYS_FREEBSD" |
---|
258 | LINKLIBS="$LINKLIBS -pthread" |
---|
259 | ;; |
---|
260 | |
---|
261 | NetBSD) |
---|
262 | DEFINES="$DEFINES SYS_NETBSD" |
---|
263 | LINKLIBS="$LINKLIBS -lpthread" |
---|
264 | ;; |
---|
265 | |
---|
266 | OpenBSD) |
---|
267 | DEFINES="$DEFINES SYS_OPENBSD" |
---|
268 | LINKLIBS="$LINKLIBS -lpthread" |
---|
269 | ;; |
---|
270 | |
---|
271 | Linux) |
---|
272 | DEFINES="$DEFINES SYS_LINUX" |
---|
273 | LINKLIBS="$LINKLIBS -lpthread" |
---|
274 | ;; |
---|
275 | |
---|
276 | *) |
---|
277 | echo "Unsupported operating system" |
---|
278 | exit 1 ;; |
---|
279 | esac |
---|
280 | echo "System: $SYSTEM" |
---|
281 | |
---|
282 | # |
---|
283 | # Mac OS X check for the Universal SDK |
---|
284 | # |
---|
285 | if [ "$SYSTEM" = Darwin -a ! -d /Developer/SDKs/MacOSX10.4u.sdk ]; then |
---|
286 | echo |
---|
287 | echo "You need to install the Universal SDK in order to build Transmission:" |
---|
288 | echo " Get your Xcode CD or package" |
---|
289 | echo " Restart the install" |
---|
290 | echo " When it gets to \"Installation Type\", select \"Customize\"" |
---|
291 | echo " Select \"Mac OS X 10.4 (Universal) SDL\" under \"Cross Development\"" |
---|
292 | echo " Finish the install." |
---|
293 | exit 1 |
---|
294 | fi |
---|
295 | |
---|
296 | # |
---|
297 | # OpenSSL settings |
---|
298 | # |
---|
299 | if [ ${openssl_disable} = 1 ]; then |
---|
300 | echo "OpenSSL: no, using built-in SHA1 implementation" |
---|
301 | else |
---|
302 | openssl_test |
---|
303 | fi |
---|
304 | |
---|
305 | # |
---|
306 | # GTK settings |
---|
307 | # |
---|
308 | if [ ${gtk_disable} = 1 ]; then |
---|
309 | echo "GTK+: no" |
---|
310 | else |
---|
311 | gtk_test |
---|
312 | fi |
---|
313 | |
---|
314 | # |
---|
315 | # Math functions |
---|
316 | # |
---|
317 | lm_test |
---|
318 | lrintf_test |
---|
319 | |
---|
320 | # |
---|
321 | # Generate config.jam |
---|
322 | # |
---|
323 | rm -f config.jam |
---|
324 | cat > config.jam << EOF |
---|
325 | CC = $CC ; |
---|
326 | LINK = $CC ; |
---|
327 | CCFLAGS = $CFLAGS ; |
---|
328 | DEFINES = $DEFINES ; |
---|
329 | LINKLIBS = $LINKLIBS ; |
---|
330 | GTK = $GTK ; |
---|
331 | GTKCCFLAGS = $GTKCCFLAGS ; |
---|
332 | GTKLINKLIBS = $GTKLINKLIBS ; |
---|
333 | EOF |
---|
334 | if [ -n "$OPENSSL_PREFIX" ]; then |
---|
335 | cat >> config.jam << EOF |
---|
336 | HDRS += $OPENSSL_PREFIX/include ; |
---|
337 | LINKFLAGS += -L$OPENSSL_PREFIX/lib ; |
---|
338 | EOF |
---|
339 | fi |
---|
340 | if [ -n "$CPU" ]; then |
---|
341 | cat >> config.jam << EOF |
---|
342 | CPU = $CPU ; |
---|
343 | EOF |
---|
344 | fi |
---|
345 | |
---|
346 | if [ xyes = "x$GTK" ]; then |
---|
347 | rm -f gtk/defines.h |
---|
348 | cat > gtk/defines.h << EOF |
---|
349 | #ifndef TG_DEFINES_H |
---|
350 | #define TG_DEFINES_H |
---|
351 | #define LOCALEDIR "$GTKLOCALEDIR" |
---|
352 | #endif |
---|
353 | EOF |
---|
354 | fi |
---|
355 | |
---|
356 | echo |
---|
357 | echo "To build Transmission, run 'jam'." |
---|