1 | #! /bin/sh |
---|
2 | # |
---|
3 | # $Id: configure 2551 2007-07-30 14:31:03Z charles $ |
---|
4 | |
---|
5 | # |
---|
6 | # Default settings |
---|
7 | # |
---|
8 | SYSTEM= |
---|
9 | BEOS_NETSERVER=no |
---|
10 | BEOS_OLDCC=no |
---|
11 | MATH=no |
---|
12 | PTHREAD=no |
---|
13 | OPENSSL= |
---|
14 | GTK= |
---|
15 | LIBEVENT= |
---|
16 | PREFIX=/usr/local |
---|
17 | CC="${CC-cc}" |
---|
18 | CFLAGS="${CFLAGS}" |
---|
19 | CXX="${CXX-c++}" |
---|
20 | CXXFLAGS="${CXXFLAGS}" |
---|
21 | LDFLAGS="${LDFLAGS}" |
---|
22 | VERBOSE=no |
---|
23 | |
---|
24 | # |
---|
25 | # Functions |
---|
26 | # |
---|
27 | usage() |
---|
28 | { |
---|
29 | cat << EOF |
---|
30 | |
---|
31 | Options: |
---|
32 | --disable-openssl Disable OpenSSL, use built-in SHA1 implementation |
---|
33 | --disable-gtk Don't build the GTK+ GUI |
---|
34 | --disable-daemon Don't build the daemon |
---|
35 | --prefix=PATH Installation path |
---|
36 | --verbose Display additional information for debugging |
---|
37 | |
---|
38 | Some influential environment variables: |
---|
39 | CC C compiler command |
---|
40 | CFLAGS C compiler flags |
---|
41 | CXX C++ compiler command |
---|
42 | CXXFLAGS C++ compiler flags |
---|
43 | LDFLAGS linker flags |
---|
44 | |
---|
45 | EOF |
---|
46 | } |
---|
47 | |
---|
48 | runcmd() |
---|
49 | { |
---|
50 | if [ "$VERBOSE" = yes ] |
---|
51 | then |
---|
52 | echo "$@" >&2 |
---|
53 | "$@" |
---|
54 | else |
---|
55 | "$@" > /dev/null 2>&1 |
---|
56 | fi |
---|
57 | return $! |
---|
58 | } |
---|
59 | |
---|
60 | verbose() |
---|
61 | { |
---|
62 | if [ "$VERBOSE" = yes ] |
---|
63 | then |
---|
64 | echo "$@" |
---|
65 | fi |
---|
66 | } |
---|
67 | |
---|
68 | cc_test() |
---|
69 | { |
---|
70 | verbose cc_test |
---|
71 | cat > testconf.c <<EOF |
---|
72 | int main() |
---|
73 | { |
---|
74 | return 0; |
---|
75 | } |
---|
76 | EOF |
---|
77 | if ! runcmd $CC -o testconf testconf.c |
---|
78 | then |
---|
79 | rm -f testconf* |
---|
80 | echo "Could not find a working compiler" |
---|
81 | exit 1 |
---|
82 | fi |
---|
83 | rm -f testconf* |
---|
84 | } |
---|
85 | |
---|
86 | openssl_test() |
---|
87 | { |
---|
88 | verbose openssl_test |
---|
89 | cat > testconf.c << EOF |
---|
90 | #include <stdio.h> |
---|
91 | #include <openssl/sha.h> |
---|
92 | int main() |
---|
93 | { |
---|
94 | SHA1( 0, 0, 0 ); |
---|
95 | } |
---|
96 | EOF |
---|
97 | if runcmd $CC $CFLAGS $LDFLAGS -o testconf testconf.c -lcrypto |
---|
98 | then |
---|
99 | echo "yes" |
---|
100 | OPENSSL=yes |
---|
101 | else |
---|
102 | echo "missing, using built-in SHA1 implementation" |
---|
103 | OPENSSL=no |
---|
104 | fi |
---|
105 | rm -f testconf* |
---|
106 | } |
---|
107 | |
---|
108 | lm_test() |
---|
109 | { |
---|
110 | verbose lm_test |
---|
111 | cat > testconf.c << EOF |
---|
112 | int main() |
---|
113 | { |
---|
114 | return cos( 42 ); |
---|
115 | } |
---|
116 | EOF |
---|
117 | if ! runcmd $CC -o testconf testconf.c |
---|
118 | then |
---|
119 | if runcmd $CC -o testconf testconf.c -lm |
---|
120 | then |
---|
121 | LDFLAGS="-lm $LDFLAGS" |
---|
122 | fi |
---|
123 | fi |
---|
124 | rm -f testconf* |
---|
125 | } |
---|
126 | |
---|
127 | lrintf_test() |
---|
128 | { |
---|
129 | verbose lrintf_test |
---|
130 | cat > testconf.c << EOF |
---|
131 | int main() |
---|
132 | { |
---|
133 | return ( lrintf( 3.14 ) != 3 ); |
---|
134 | } |
---|
135 | EOF |
---|
136 | if runcmd $CC -o testconf testconf.c $LDFLAGS && runcmd ./testconf |
---|
137 | then |
---|
138 | CFLAGS="$CFLAGS -DHAVE_LRINTF" |
---|
139 | fi |
---|
140 | rm -f testconf* |
---|
141 | } |
---|
142 | |
---|
143 | strlcpy_test() |
---|
144 | { |
---|
145 | verbose strlcpy_test |
---|
146 | cat > testconf.c << EOF |
---|
147 | #include <string.h> |
---|
148 | int main() |
---|
149 | { |
---|
150 | char buf[] = "1234:p"; |
---|
151 | strlcpy( buf, "foo", sizeof buf ); |
---|
152 | return ( 0 == memcmp( buf, "foo\0:p", 6 ) ? 0 : 1 ); |
---|
153 | } |
---|
154 | EOF |
---|
155 | if runcmd $CC -o testconf testconf.c && runcmd ./testconf |
---|
156 | then |
---|
157 | CFLAGS="$CFLAGS -DHAVE_STRLCPY" |
---|
158 | fi |
---|
159 | rm -f testconf* |
---|
160 | } |
---|
161 | |
---|
162 | strlcat_test() |
---|
163 | { |
---|
164 | verbose strlcat_test |
---|
165 | cat > testconf.c << EOF |
---|
166 | #include <string.h> |
---|
167 | int main() |
---|
168 | { |
---|
169 | char buf[] = "1234567:p"; |
---|
170 | buf[0] = '\0'; |
---|
171 | strlcat( buf, "foo", sizeof buf ); |
---|
172 | strlcat( buf, "bar", sizeof buf ); |
---|
173 | return ( 0 == memcmp( buf, "foobar\0:p", 6 ) ? 0 : 1 ); |
---|
174 | } |
---|
175 | EOF |
---|
176 | if runcmd $CC -o testconf testconf.c && runcmd ./testconf |
---|
177 | then |
---|
178 | CFLAGS="$CFLAGS -DHAVE_STRLCAT" |
---|
179 | fi |
---|
180 | rm -f testconf* |
---|
181 | } |
---|
182 | |
---|
183 | asprintf_test() |
---|
184 | { |
---|
185 | verbose asprintf_test |
---|
186 | cat > testconf.c <<EOF |
---|
187 | #define _GNU_SOURCE |
---|
188 | #include <stdio.h> |
---|
189 | int main() |
---|
190 | { |
---|
191 | asprintf( NULL, NULL ); |
---|
192 | return 0; |
---|
193 | } |
---|
194 | EOF |
---|
195 | if runcmd $CC -o testconf testconf.c |
---|
196 | then |
---|
197 | CFLAGS="$CFLAGS -DHAVE_ASPRINTF" |
---|
198 | fi |
---|
199 | rm -f testconf* |
---|
200 | } |
---|
201 | |
---|
202 | snprintf_test() |
---|
203 | { |
---|
204 | verbose snprintf_test |
---|
205 | cat > testconf.c <<EOF |
---|
206 | #include <stdio.h> |
---|
207 | int main() |
---|
208 | { |
---|
209 | char buf[] = "blueberry"; |
---|
210 | return ( 6 != snprintf( buf, 4, "%s%s", "foo", "bar" ) || |
---|
211 | 0 != memcmp( buf, "foo\0berry", 9 ) ); |
---|
212 | } |
---|
213 | EOF |
---|
214 | if ! runcmd $CC -o testconf testconf.c || ! runcmd ./testconf |
---|
215 | then |
---|
216 | echo "error: broken snprintf() found" |
---|
217 | exit 1 |
---|
218 | fi |
---|
219 | rm -f testconf* |
---|
220 | } |
---|
221 | |
---|
222 | libgen_test() |
---|
223 | { |
---|
224 | verbose libgen_test |
---|
225 | cat > testconf.c << EOF |
---|
226 | #include <libgen.h> |
---|
227 | int main() |
---|
228 | { |
---|
229 | return 0; |
---|
230 | } |
---|
231 | EOF |
---|
232 | if runcmd $CC -o testconf testconf.c |
---|
233 | then |
---|
234 | CFLAGS="$CFLAGS -DHAVE_DIRNAME -DHAVE_BASENAME" |
---|
235 | fi |
---|
236 | rm -f testconf* |
---|
237 | } |
---|
238 | |
---|
239 | gettext_test() |
---|
240 | { |
---|
241 | verbose gettext_test |
---|
242 | cat > testconf.c <<EOF |
---|
243 | #include <libintl.h> |
---|
244 | int main() |
---|
245 | { |
---|
246 | gettext(""); |
---|
247 | } |
---|
248 | EOF |
---|
249 | |
---|
250 | if runcmd $CC $CFLAGS_GTK $LDFLAGS_GTK -o testconf testconf.c |
---|
251 | then |
---|
252 | rm -f testconf* |
---|
253 | return 0 |
---|
254 | fi |
---|
255 | |
---|
256 | for intl_testdir in $PREFIX/include \ |
---|
257 | /usr/local/include /usr/X11R6/include /usr/pkg/include |
---|
258 | do |
---|
259 | if runcmd $CC $CFLAGS_GTK -I$intl_testdir $LDFLAGS_GTK -o testconf testconf.c |
---|
260 | then |
---|
261 | CFLAGS_GTK="$CFLAGS_GTK -I$intl_testdir" |
---|
262 | rm -f testconf* |
---|
263 | return 0 |
---|
264 | fi |
---|
265 | done |
---|
266 | rm -f testconf* |
---|
267 | return 1 |
---|
268 | } |
---|
269 | |
---|
270 | gtk_test() |
---|
271 | { |
---|
272 | verbose gtk_test |
---|
273 | if runcmd pkg-config gtk+-2.0 |
---|
274 | then |
---|
275 | if runcmd pkg-config --exists gtk+-2.0 '>=' 2.6.0 |
---|
276 | then |
---|
277 | cat > testconf.c << EOF |
---|
278 | #include <gtk/gtk.h> |
---|
279 | int main() |
---|
280 | { |
---|
281 | gtk_main(); |
---|
282 | } |
---|
283 | EOF |
---|
284 | if runcmd $CC `pkg-config gtk+-2.0 --cflags --libs` -o testconf testconf.c |
---|
285 | then |
---|
286 | CFLAGS_GTK=`pkg-config gtk+-2.0 --cflags` |
---|
287 | LDFLAGS_GTK=`pkg-config gtk+-2.0 --libs` |
---|
288 | if gettext_test |
---|
289 | then |
---|
290 | echo "yes" |
---|
291 | GTK=yes |
---|
292 | LOCALEDIR="$PREFIX/share/locale" |
---|
293 | CFLAGS_GTK="$CFLAGS_GTK -DLOCALEDIR=\\"\""$LOCALEDIR\\"\" |
---|
294 | else |
---|
295 | echo "no (could not find gettext libintl.h)" |
---|
296 | GTK=no |
---|
297 | fi |
---|
298 | else |
---|
299 | echo "no" |
---|
300 | GTK=no |
---|
301 | fi |
---|
302 | rm -f testconf* |
---|
303 | else |
---|
304 | echo "no (2.6.0 or later is required)" |
---|
305 | GTK=no |
---|
306 | fi |
---|
307 | else |
---|
308 | echo "no" |
---|
309 | GTK=no |
---|
310 | fi |
---|
311 | } |
---|
312 | |
---|
313 | libevent_test() |
---|
314 | { |
---|
315 | verbose libevent_test |
---|
316 | cat > testconf.c <<EOF |
---|
317 | #include <sys/types.h> |
---|
318 | #include <sys/time.h> |
---|
319 | #include <event.h> |
---|
320 | int main() |
---|
321 | { |
---|
322 | event_init(); |
---|
323 | return 0; |
---|
324 | } |
---|
325 | EOF |
---|
326 | |
---|
327 | if runcmd $CC $CFLAGS -levent $LDFLAGS -o testconf testconf.c |
---|
328 | then |
---|
329 | LIBEVENT=yes |
---|
330 | LDFLAGS_EVENT="-levent" |
---|
331 | rm -f testconf* |
---|
332 | return 0 |
---|
333 | fi |
---|
334 | |
---|
335 | for event_testdir in $PREFIX /usr/local /usr/X11R6 /usr/pkg |
---|
336 | do |
---|
337 | if runcmd $CC $CFLAGS -I$event_testdir/include $LDFLAGS -levent \ |
---|
338 | -L$event_testdir/lib -o testconf testconf.c |
---|
339 | then |
---|
340 | LIBEVENT=yes |
---|
341 | CFLAGS_EVENT="-I$event_testdir/include" |
---|
342 | LDFLAGS_EVENT="-levent -L$event_testdir/lib" |
---|
343 | rm -f testconf* |
---|
344 | return 0 |
---|
345 | fi |
---|
346 | done |
---|
347 | LIBEVENT=no |
---|
348 | rm -f testconf* |
---|
349 | return 1 |
---|
350 | } |
---|
351 | |
---|
352 | # |
---|
353 | # Parse options |
---|
354 | # |
---|
355 | while [ $# -ne 0 ]; do |
---|
356 | param=`expr "opt$1" : 'opt[^=]*=\(.*\)'` |
---|
357 | |
---|
358 | case "x$1" in |
---|
359 | x--disable-openssl|x--without-openssl) |
---|
360 | OPENSSL=no |
---|
361 | ;; |
---|
362 | x--disable-daemon|x--without-daemon) |
---|
363 | LIBEVENT=no |
---|
364 | ;; |
---|
365 | x--disable-gtk|x--without-gtk) |
---|
366 | GTK=no |
---|
367 | ;; |
---|
368 | x--prefix=*) |
---|
369 | PREFIX="$param" |
---|
370 | ;; |
---|
371 | x--verbose) |
---|
372 | VERBOSE=yes |
---|
373 | ;; |
---|
374 | x--help) |
---|
375 | usage |
---|
376 | exit 0 |
---|
377 | ;; |
---|
378 | esac |
---|
379 | shift |
---|
380 | done |
---|
381 | |
---|
382 | # |
---|
383 | # System-specific flags |
---|
384 | # |
---|
385 | SYSTEM=`uname -s` |
---|
386 | case $SYSTEM in |
---|
387 | BeOS) |
---|
388 | RELEASE=`uname -r` |
---|
389 | case $RELEASE in |
---|
390 | 6.*|5.0.4) # Zeta or R5 / BONE beta 7 |
---|
391 | ;; |
---|
392 | 5.0*) # R5 / net_server |
---|
393 | BEOS_NETSERVER=yes |
---|
394 | ;; |
---|
395 | *) |
---|
396 | echo "Unsupported BeOS version" |
---|
397 | exit 1 |
---|
398 | ;; |
---|
399 | esac |
---|
400 | GCCVER=`$CC -dumpversion` |
---|
401 | case $GCCVER in |
---|
402 | 2.95.3*|3*|4*) |
---|
403 | ;; |
---|
404 | 2.9*) |
---|
405 | BEOS_OLDCC=yes |
---|
406 | ;; |
---|
407 | *) |
---|
408 | echo "Unsupported gcc version" |
---|
409 | exit 1 |
---|
410 | ;; |
---|
411 | esac |
---|
412 | ;; |
---|
413 | |
---|
414 | Darwin) |
---|
415 | # Make sure the Universal SDK is installed |
---|
416 | if [ ! -d /Developer/SDKs/MacOSX10.4u.sdk ]; then |
---|
417 | cat << EOF |
---|
418 | You need to install the Universal SDK in order to build Transmission: |
---|
419 | Get your Xcode CD or package |
---|
420 | Restart the install |
---|
421 | When it gets to "Installation Type", select "Customize" |
---|
422 | Select "Mac OS X 10.4 (Universal) SDK" under "Cross Development" |
---|
423 | Finish the install. |
---|
424 | EOF |
---|
425 | exit 1 |
---|
426 | fi |
---|
427 | PTHREAD=yes |
---|
428 | ;; |
---|
429 | |
---|
430 | FreeBSD|NetBSD|OpenBSD|Linux|skyos) |
---|
431 | PTHREAD=yes |
---|
432 | ;; |
---|
433 | |
---|
434 | CYGWIN*) |
---|
435 | ;; |
---|
436 | |
---|
437 | *) |
---|
438 | echo "Unsupported operating system" |
---|
439 | exit 1 ;; |
---|
440 | esac |
---|
441 | echo "System: $SYSTEM" |
---|
442 | |
---|
443 | # |
---|
444 | # First things first, check to see if there's a compiler installed |
---|
445 | # |
---|
446 | cc_test |
---|
447 | |
---|
448 | # |
---|
449 | # OpenSSL settings |
---|
450 | # |
---|
451 | echo -n "OpenSSL: " |
---|
452 | if [ "$OPENSSL" = no ]; then |
---|
453 | echo "disabled, using built-in SHA1 implementation" |
---|
454 | else |
---|
455 | openssl_test |
---|
456 | fi |
---|
457 | if [ "$OPENSSL" = no ] && [ "$BEOS_OLDCC" = yes ]; then |
---|
458 | echo "built-in SHA1 implementation not supported with your gcc version" |
---|
459 | echo "you must either install OpenSSL or gcc 2.95.3 or newer" |
---|
460 | exit 1 |
---|
461 | fi |
---|
462 | |
---|
463 | # |
---|
464 | # GTK+ settings |
---|
465 | # |
---|
466 | echo -n "GTK+: " |
---|
467 | if [ "x$GTK" = xno ]; then |
---|
468 | echo "disabled" |
---|
469 | else |
---|
470 | gtk_test |
---|
471 | if [ "x$GTK" = xno ] && [ "x$SYSTEM" = xLinux ]; then |
---|
472 | cat <<EOF |
---|
473 | |
---|
474 | *** GTK+ was not found, transmission-gtk will *NOT* be built. If you |
---|
475 | *** wish to use the graphical version of Transmission then you will |
---|
476 | *** need to install GTK+ headers and libraries. Try using your |
---|
477 | *** distribution's package management utility to find a package called |
---|
478 | *** libgtk2.0-dev, gtk2-devel, or something similar; then install it |
---|
479 | *** and re-run this script. |
---|
480 | EOF |
---|
481 | fi |
---|
482 | fi |
---|
483 | |
---|
484 | # |
---|
485 | # libevent settings |
---|
486 | # |
---|
487 | echo -n "Daemon: " |
---|
488 | if [ "$LIBEVENT" = no ]; then |
---|
489 | echo "disabled" |
---|
490 | else |
---|
491 | if libevent_test; then |
---|
492 | echo "yes" |
---|
493 | else |
---|
494 | echo "no (can't find libevent)" |
---|
495 | fi |
---|
496 | fi |
---|
497 | |
---|
498 | # |
---|
499 | # Math functions |
---|
500 | # |
---|
501 | lm_test |
---|
502 | lrintf_test |
---|
503 | |
---|
504 | # |
---|
505 | # String functions |
---|
506 | # |
---|
507 | strlcpy_test |
---|
508 | strlcat_test |
---|
509 | asprintf_test |
---|
510 | snprintf_test |
---|
511 | libgen_test |
---|
512 | |
---|
513 | # |
---|
514 | # Generate config.mk |
---|
515 | # |
---|
516 | rm -f mk/config.mk |
---|
517 | cat > mk/config.mk << EOF |
---|
518 | SYSTEM = $SYSTEM |
---|
519 | PREFIX = $PREFIX |
---|
520 | LOCALEDIR = $LOCALEDIR |
---|
521 | BEOS_NETSERVER = $BEOS_NETSERVER |
---|
522 | PTHREAD = $PTHREAD |
---|
523 | OPENSSL = $OPENSSL |
---|
524 | GTK = $GTK |
---|
525 | DAEMON = $LIBEVENT |
---|
526 | CC = $CC |
---|
527 | CFLAGS = $CFLAGS |
---|
528 | CXX = $CXX |
---|
529 | CXXFLAGS = $CXXFLAGS |
---|
530 | LDFLAGS = $LDFLAGS |
---|
531 | CFLAGS_GTK = $CFLAGS_GTK |
---|
532 | LDFLAGS_GTK = $LDFLAGS_GTK |
---|
533 | CFLAGS_EVENT = $CFLAGS_EVENT |
---|
534 | LDFLAGS_EVENT = $LDFLAGS_EVENT |
---|
535 | EOF |
---|
536 | |
---|
537 | echo |
---|
538 | echo "Now use GNU make to build Transmission." |
---|
539 | echo "It may be called 'make' or 'gmake' depending on your system." |
---|
540 | |
---|