source: trunk/configure @ 2551

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

sync the two build systems w.r.t. dirname() and basename()

  • 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 2551 2007-07-30 14:31:03Z 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 runcmd $CC -o testconf testconf.c
233  then
234    CFLAGS="$CFLAGS -DHAVE_DIRNAME -DHAVE_BASENAME"
235  fi
236  rm -f testconf*
237}
238
239gettext_test()
240{
241  verbose gettext_test
242  cat > testconf.c <<EOF
243  #include <libintl.h>
244  int main()
245  {
246    gettext("");
247  }
248EOF
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
270gtk_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      }
283EOF
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
313libevent_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>
320int main()
321{
322    event_init();
323    return 0;
324}
325EOF
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#
355while [ $# -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
380done
381
382#
383# System-specific flags
384#
385SYSTEM=`uname -s`
386case $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
418You 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.
424EOF
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 ;;
440esac
441echo "System:  $SYSTEM"
442
443#
444# First things first, check to see if there's a compiler installed
445#
446cc_test
447
448#
449# OpenSSL settings
450#
451echo -n "OpenSSL: "
452if [ "$OPENSSL" = no ]; then
453  echo "disabled, using built-in SHA1 implementation"
454else
455  openssl_test
456fi
457if [ "$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
461fi
462
463#
464# GTK+ settings
465#
466echo -n "GTK+:    "
467if [ "x$GTK" = xno ]; then
468  echo "disabled"
469else
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.
480EOF
481  fi
482fi
483
484#
485# libevent settings
486#
487echo -n "Daemon:  "
488if [ "$LIBEVENT" = no ]; then
489  echo "disabled"
490else
491  if libevent_test; then
492      echo "yes"
493  else
494      echo "no (can't find libevent)"
495  fi
496fi
497
498#
499# Math functions
500#
501lm_test
502lrintf_test
503
504#
505# String functions
506#
507strlcpy_test
508strlcat_test
509asprintf_test
510snprintf_test
511libgen_test
512
513#
514# Generate config.mk
515#
516rm -f mk/config.mk
517cat > mk/config.mk << EOF
518SYSTEM         = $SYSTEM
519PREFIX         = $PREFIX
520LOCALEDIR      = $LOCALEDIR
521BEOS_NETSERVER = $BEOS_NETSERVER
522PTHREAD        = $PTHREAD
523OPENSSL        = $OPENSSL
524GTK            = $GTK
525DAEMON         = $LIBEVENT
526CC             = $CC
527CFLAGS         = $CFLAGS
528CXX            = $CXX
529CXXFLAGS       = $CXXFLAGS
530LDFLAGS        = $LDFLAGS
531CFLAGS_GTK     = $CFLAGS_GTK
532LDFLAGS_GTK    = $LDFLAGS_GTK
533CFLAGS_EVENT   = $CFLAGS_EVENT
534LDFLAGS_EVENT  = $LDFLAGS_EVENT
535EOF
536
537echo
538echo "Now use GNU make to build Transmission."
539echo "It may be called 'make' or 'gmake' depending on your system."
540
Note: See TracBrowser for help on using the repository browser.