source: branches/daemon/configure @ 1621

Last change on this file since 1621 was 1621, checked in by joshe, 15 years ago

Build on osx.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 7.2 KB
Line 
1#! /bin/sh
2#
3# $Id: configure 1621 2007-03-31 20:30:18Z joshe $
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
143gettext_test()
144{
145  verbose gettext_test
146  cat > testconf.c <<EOF
147  #include <libintl.h>
148  int main()
149  {
150    gettext("");
151  }
152EOF
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
174gtk_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      }
187EOF
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
217libevent_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>
224int main()
225{
226    event_init();
227    return 0;
228}
229EOF
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#
259while [ $# -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
284done
285
286#
287# System-specific flags
288#
289SYSTEM=`uname -s`
290case $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
322You 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.
328EOF
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 ;;
344esac
345echo "System:  $SYSTEM"
346
347#
348# First things first, check to see if there's a compiler installed
349#
350cc_test
351
352#
353# OpenSSL settings
354#
355echo -n "OpenSSL: "
356if [ "$OPENSSL" = no ]; then
357  echo "disabled, using built-in SHA1 implementation"
358else
359  openssl_test
360fi
361if [ "$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
365fi
366
367#
368# GTK+ settings
369#
370echo -n "GTK+:    "
371if [ "$GTK" = no ]; then
372  echo "disabled"
373else
374  gtk_test
375fi
376
377#
378# libevent settings
379#
380echo -n "Daemon:  "
381if [ "$LIBEVENT" = no ]; then
382  echo "disabled"
383else
384  if libevent_test; then
385      echo "yes"
386  else
387      echo "no (can't find libevent)"
388  fi
389fi
390
391#
392# Math functions
393#
394lm_test
395lrintf_test
396
397#
398# Generate config.mk
399#
400rm -f mk/config.mk
401cat > mk/config.mk << EOF
402SYSTEM         = $SYSTEM
403PREFIX         = $PREFIX
404LOCALEDIR      = $LOCALEDIR
405BEOS_NETSERVER = $BEOS_NETSERVER
406PTHREAD        = $PTHREAD
407OPENSSL        = $OPENSSL
408GTK            = $GTK
409DAEMON         = $LIBEVENT
410CC             = $CC
411CFLAGS         = $CFLAGS
412CXX            = $CXX
413CXXFLAGS       = $CXXFLAGS
414LDFLAGS        = $LDFLAGS
415CFLAGS_GTK     = $CFLAGS_GTK
416LDFLAGS_GTK    = $LDFLAGS_GTK
417CFLAGS_EVENT   = $CFLAGS_EVENT
418LDFLAGS_EVENT  = $LDFLAGS_EVENT
419EOF
420
421echo
422echo "Now use GNU make to build Transmission."
423echo "It may be called 'make' or 'gmake' depending on your system."
Note: See TracBrowser for help on using the repository browser.