1 | #! /bin/sh |
---|
2 | # |
---|
3 | # $Id: configure 1621 2007-03-31 20:30:18Z joshe $ |
---|
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 | gettext_test() |
---|
144 | { |
---|
145 | verbose gettext_test |
---|
146 | cat > testconf.c <<EOF |
---|
147 | #include <libintl.h> |
---|
148 | int main() |
---|
149 | { |
---|
150 | gettext(""); |
---|
151 | } |
---|
152 | EOF |
---|
153 | |
---|
154 | if runcmd $CC $CFLAGS_GTK $LDFLAGS_GTK -o testconf testconf.c |
---|
155 | then |
---|
156 | rm -f testconf* |
---|
157 | return 0 |
---|
158 | fi |
---|
159 | |
---|
160 | for intl_testdir in $PREFIX/include \ |
---|
161 | /usr/local/include /usr/X11R6/include /usr/pkg/include |
---|
162 | do |
---|
163 | if runcmd $CC $CFLAGS_GTK -I$intl_testdir $LDFLAGS_GTK -o testconf testconf.c |
---|
164 | then |
---|
165 | CFLAGS_GTK="$CFLAGS_GTK -I$intl_testdir" |
---|
166 | rm -f testconf* |
---|
167 | return 0 |
---|
168 | fi |
---|
169 | done |
---|
170 | rm -f testconf* |
---|
171 | return 1 |
---|
172 | } |
---|
173 | |
---|
174 | gtk_test() |
---|
175 | { |
---|
176 | verbose gtk_test |
---|
177 | if runcmd pkg-config gtk+-2.0 |
---|
178 | then |
---|
179 | if runcmd pkg-config --exists gtk+-2.0 '>=' 2.6.0 |
---|
180 | then |
---|
181 | cat > testconf.c << EOF |
---|
182 | #include <gtk/gtk.h> |
---|
183 | int main() |
---|
184 | { |
---|
185 | gtk_main(); |
---|
186 | } |
---|
187 | EOF |
---|
188 | if runcmd $CC `pkg-config gtk+-2.0 --cflags --libs` -o testconf testconf.c |
---|
189 | then |
---|
190 | CFLAGS_GTK=`pkg-config gtk+-2.0 --cflags` |
---|
191 | LDFLAGS_GTK=`pkg-config gtk+-2.0 --libs` |
---|
192 | if gettext_test |
---|
193 | then |
---|
194 | echo "yes" |
---|
195 | GTK=yes |
---|
196 | LOCALEDIR="$PREFIX/share/locale" |
---|
197 | CFLAGS_GTK="$CFLAGS_GTK -DLOCALEDIR=\\"\""$LOCALEDIR\\"\" |
---|
198 | else |
---|
199 | echo "no (could not find gettext libintl.h)" |
---|
200 | GTK=no |
---|
201 | fi |
---|
202 | else |
---|
203 | echo "no" |
---|
204 | GTK=no |
---|
205 | fi |
---|
206 | rm -f testconf* |
---|
207 | else |
---|
208 | echo "no (2.6.0 or later is required)" |
---|
209 | GTK=no |
---|
210 | fi |
---|
211 | else |
---|
212 | echo "no" |
---|
213 | GTK=no |
---|
214 | fi |
---|
215 | } |
---|
216 | |
---|
217 | libevent_test() |
---|
218 | { |
---|
219 | verbose libevent_test |
---|
220 | cat > testconf.c <<EOF |
---|
221 | #include <sys/types.h> |
---|
222 | #include <sys/time.h> |
---|
223 | #include <event.h> |
---|
224 | int main() |
---|
225 | { |
---|
226 | event_init(); |
---|
227 | return 0; |
---|
228 | } |
---|
229 | EOF |
---|
230 | |
---|
231 | if runcmd $CC $CFLAGS -levent $LDFLAGS -o testconf testconf.c |
---|
232 | then |
---|
233 | LIBEVENT=yes |
---|
234 | LDFLAGS_EVENT="-levent" |
---|
235 | rm -f testconf* |
---|
236 | return 0 |
---|
237 | fi |
---|
238 | |
---|
239 | for event_testdir in $PREFIX /usr/local /usr/X11R6 /usr/pkg |
---|
240 | do |
---|
241 | if runcmd $CC $CFLAGS -I$event_testdir/include $LDFLAGS -levent \ |
---|
242 | -L$event_testdir/lib -o testconf testconf.c |
---|
243 | then |
---|
244 | LIBEVENT=yes |
---|
245 | CFLAGS_EVENT="-I$event_testdir/include" |
---|
246 | LDFLAGS_EVENT="-levent -L$event_testdir/lib" |
---|
247 | rm -f testconf* |
---|
248 | return 0 |
---|
249 | fi |
---|
250 | done |
---|
251 | LIBEVENT=no |
---|
252 | rm -f testconf* |
---|
253 | return 1 |
---|
254 | } |
---|
255 | |
---|
256 | # |
---|
257 | # Parse options |
---|
258 | # |
---|
259 | while [ $# -ne 0 ]; do |
---|
260 | param=`expr "opt$1" : 'opt[^=]*=\(.*\)'` |
---|
261 | |
---|
262 | case "x$1" in |
---|
263 | x--disable-openssl|x--without-openssl) |
---|
264 | OPENSSL=no |
---|
265 | ;; |
---|
266 | x--disable-daemon|x--without-daemon) |
---|
267 | LIBEVENT=no |
---|
268 | ;; |
---|
269 | x--disable-gtk|x--without-gtk) |
---|
270 | GTK=no |
---|
271 | ;; |
---|
272 | x--prefix=*) |
---|
273 | PREFIX="$param" |
---|
274 | ;; |
---|
275 | x--verbose) |
---|
276 | VERBOSE=yes |
---|
277 | ;; |
---|
278 | x--help) |
---|
279 | usage |
---|
280 | exit 0 |
---|
281 | ;; |
---|
282 | esac |
---|
283 | shift |
---|
284 | done |
---|
285 | |
---|
286 | # |
---|
287 | # System-specific flags |
---|
288 | # |
---|
289 | SYSTEM=`uname -s` |
---|
290 | case $SYSTEM in |
---|
291 | BeOS) |
---|
292 | RELEASE=`uname -r` |
---|
293 | case $RELEASE in |
---|
294 | 6.*|5.0.4) # Zeta or R5 / BONE beta 7 |
---|
295 | ;; |
---|
296 | 5.0*) # R5 / net_server |
---|
297 | BEOS_NETSERVER=yes |
---|
298 | ;; |
---|
299 | *) |
---|
300 | echo "Unsupported BeOS version" |
---|
301 | exit 1 |
---|
302 | ;; |
---|
303 | esac |
---|
304 | GCCVER=`$CC -dumpversion` |
---|
305 | case $GCCVER in |
---|
306 | 2.95.3*|3*|4*) |
---|
307 | ;; |
---|
308 | 2.9*) |
---|
309 | BEOS_OLDCC=yes |
---|
310 | ;; |
---|
311 | *) |
---|
312 | echo "Unsupported gcc version" |
---|
313 | exit 1 |
---|
314 | ;; |
---|
315 | esac |
---|
316 | ;; |
---|
317 | |
---|
318 | Darwin) |
---|
319 | # Make sure the Universal SDK is installed |
---|
320 | if [ ! -d /Developer/SDKs/MacOSX10.4u.sdk ]; then |
---|
321 | cat << EOF |
---|
322 | You need to install the Universal SDK in order to build Transmission: |
---|
323 | Get your Xcode CD or package |
---|
324 | Restart the install |
---|
325 | When it gets to "Installation Type", select "Customize" |
---|
326 | Select "Mac OS X 10.4 (Universal) SDK" under "Cross Development" |
---|
327 | Finish the install. |
---|
328 | EOF |
---|
329 | exit 1 |
---|
330 | fi |
---|
331 | PTHREAD=yes |
---|
332 | ;; |
---|
333 | |
---|
334 | FreeBSD|NetBSD|OpenBSD|Linux|skyos) |
---|
335 | PTHREAD=yes |
---|
336 | ;; |
---|
337 | |
---|
338 | CYGWIN*) |
---|
339 | ;; |
---|
340 | |
---|
341 | *) |
---|
342 | echo "Unsupported operating system" |
---|
343 | exit 1 ;; |
---|
344 | esac |
---|
345 | echo "System: $SYSTEM" |
---|
346 | |
---|
347 | # |
---|
348 | # First things first, check to see if there's a compiler installed |
---|
349 | # |
---|
350 | cc_test |
---|
351 | |
---|
352 | # |
---|
353 | # OpenSSL settings |
---|
354 | # |
---|
355 | echo -n "OpenSSL: " |
---|
356 | if [ "$OPENSSL" = no ]; then |
---|
357 | echo "disabled, using built-in SHA1 implementation" |
---|
358 | else |
---|
359 | openssl_test |
---|
360 | fi |
---|
361 | if [ "$OPENSSL" = no ] && [ "$BEOS_OLDCC" = yes ]; then |
---|
362 | echo "built-in SHA1 implementation not supported with your gcc version" |
---|
363 | echo "you must either install OpenSSL or gcc 2.95.3 or newer" |
---|
364 | exit 1 |
---|
365 | fi |
---|
366 | |
---|
367 | # |
---|
368 | # GTK+ settings |
---|
369 | # |
---|
370 | echo -n "GTK+: " |
---|
371 | if [ "$GTK" = no ]; then |
---|
372 | echo "disabled" |
---|
373 | else |
---|
374 | gtk_test |
---|
375 | fi |
---|
376 | |
---|
377 | # |
---|
378 | # libevent settings |
---|
379 | # |
---|
380 | echo -n "Daemon: " |
---|
381 | if [ "$LIBEVENT" = no ]; then |
---|
382 | echo "disabled" |
---|
383 | else |
---|
384 | if libevent_test; then |
---|
385 | echo "yes" |
---|
386 | else |
---|
387 | echo "no (can't find libevent)" |
---|
388 | fi |
---|
389 | fi |
---|
390 | |
---|
391 | # |
---|
392 | # Math functions |
---|
393 | # |
---|
394 | lm_test |
---|
395 | lrintf_test |
---|
396 | |
---|
397 | # |
---|
398 | # Generate config.mk |
---|
399 | # |
---|
400 | rm -f mk/config.mk |
---|
401 | cat > mk/config.mk << EOF |
---|
402 | SYSTEM = $SYSTEM |
---|
403 | PREFIX = $PREFIX |
---|
404 | LOCALEDIR = $LOCALEDIR |
---|
405 | BEOS_NETSERVER = $BEOS_NETSERVER |
---|
406 | PTHREAD = $PTHREAD |
---|
407 | OPENSSL = $OPENSSL |
---|
408 | GTK = $GTK |
---|
409 | DAEMON = $LIBEVENT |
---|
410 | CC = $CC |
---|
411 | CFLAGS = $CFLAGS |
---|
412 | CXX = $CXX |
---|
413 | CXXFLAGS = $CXXFLAGS |
---|
414 | LDFLAGS = $LDFLAGS |
---|
415 | CFLAGS_GTK = $CFLAGS_GTK |
---|
416 | LDFLAGS_GTK = $LDFLAGS_GTK |
---|
417 | CFLAGS_EVENT = $CFLAGS_EVENT |
---|
418 | LDFLAGS_EVENT = $LDFLAGS_EVENT |
---|
419 | EOF |
---|
420 | |
---|
421 | echo |
---|
422 | echo "Now use GNU make to build Transmission." |
---|
423 | echo "It may be called 'make' or 'gmake' depending on your system." |
---|