source: trunk/configure @ 2604

Last change on this file since 2604 was 2604, checked in by charles, 15 years ago

ModeenF's configure fix for BeOS

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