source: trunk/configure @ 240

Last change on this file since 240 was 240, checked in by joshe, 16 years ago

Show subversion revision number in version string.

  • Property svn:executable set to *
  • Property svn:keywords set to Rev
File size: 5.5 KB
Line 
1#! /bin/sh
2
3#
4# Default settings
5#
6SYSTEM=
7BEOS_NETSERVER=no
8MATH=no
9PTHREAD=no
10OPENSSL=
11GTK=
12PREFIX=/usr/local
13CC="${CC-cc}"
14CFLAGS="${CFLAGS}"
15CXX="${CXX-c++}"
16CXXFLAGS="${CXXFLAGS}"
17LDFLAGS="${LDFLAGS}"
18
19SVNREV="`echo '$Rev: 240 $' | sed 's/[^0-9]*//g'`"
20
21#
22# Functions
23#
24usage()
25{
26  cat << EOF
27
28Options:
29  --disable-openssl      Disable OpenSSL, use built-in SHA1 implementation
30  --disable-gtk          Don't build the GTK+ GUI
31  --prefix=PATH          Installation path
32
33Some influential environment variables:
34  CC          C compiler command
35  CFLAGS      C compiler flags
36  CXX         C++ compiler command
37  CXXFLAGS    C++ compiler flags
38  LDFLAGS     linker flags
39
40EOF
41}
42
43cc_test()
44{
45  cat > testconf.c <<EOF
46  int main()
47  {
48    return 0;
49  }
50EOF
51  if ! $CC -o testconf testconf.c > /dev/null 2>&1; then
52    rm -f testconf.c testconf
53    echo "Could not find a working compiler"
54    exit 1
55  fi
56  rm -f testconf.c testconf
57}
58
59openssl_test()
60{
61  cat > testconf.c << EOF
62  #include <stdio.h>
63  #include <openssl/sha.h>
64  int main()
65  {
66      SHA1( 0, 0, 0 );
67  }
68EOF
69  if $CC $CFLAGS $LDFLAGS -o testconf testconf.c -lcrypto > /dev/null 2>&1
70  then
71    echo "yes"
72    OPENSSL=yes
73  else
74    echo "missing, using built-in SHA1 implementation"
75    OPENSSL=no
76  fi
77  rm -f testconf.c testconf
78}
79
80lm_test()
81{
82  cat > testconf.c << EOF
83  int main()
84  {
85    return cos( 42 );
86  }
87EOF
88  if ! $CC -o testconf testconf.c > /dev/null 2>&1
89  then
90    if $CC -o testconf testconf.c -lm > /dev/null 2>&1
91    then
92      LDFLAGS="$LDFLAGS -lm"
93    fi
94  fi
95  rm -f testconf.c testconf
96}
97
98lrintf_test()
99{
100  cat > testconf.c << EOF
101  int main()
102  {
103    return ( lrintf( 3.14 ) != 3 );
104  }
105EOF
106  if ( $CC -o testconf testconf.c $LDFLAGS && ./testconf ) > /dev/null 2>&1
107  then
108    CFLAGS="$CFLAGS -DHAVE_LRINTF"
109  fi
110  rm -f testconf.c testconf
111}
112
113gettext_test()
114{
115  cat > testconf.c <<EOF
116  #include <libintl.h>
117  int main()
118  {
119    gettext("");
120  }
121EOF
122
123  if $CC $CFLAGS_GTK $LDFLAGS_GTK -o testconf testconf.c > /dev/null 2>&1
124  then
125    rm -f testconf.c testconf
126    return 0
127  fi
128
129  for intl_testdir in $PREFIX/include \
130      /usr/local/include /usr/X11R6/include /usr/pkg/include
131  do
132    if $CC $CFLAGS_GTK -I$intl_testdir $LDFLAGS_GTK -o testconf testconf.c > /dev/null 2>&1
133    then
134      CFLAGS_GTK="CFLAGS_GTK -I$intl_testdir"
135      rm -f testconf.c testconf
136      return 0
137    fi
138  done
139  rm -f testconf.c testconf
140  return 1
141}
142
143gtk_test()
144{
145  if pkg-config gtk+-2.0 > /dev/null 2>&1
146  then
147    if expr `pkg-config --modversion gtk+-2.0` '>=' 2.6.0 > /dev/null 2>&1
148    then
149      cat > testconf.c << EOF
150      #include <gtk/gtk.h>
151      int main()
152      {
153        gtk_main();
154      }
155EOF
156      if $CC `pkg-config gtk+-2.0 --cflags --libs` -o testconf testconf.c > /dev/null 2>&1
157      then
158        CFLAGS_GTK=`pkg-config gtk+-2.0 --cflags`
159        LDFLAGS_GTK=`pkg-config gtk+-2.0 --libs`
160        if gettext_test
161        then
162          echo "yes"
163          GTK=yes
164          GTKLOCALEDIR="$PREFIX/share/locale"
165        else
166          echo "no (could not find gettext libintl.h)"
167          GTK=no
168        fi
169      else
170        echo "no"
171        GTK=no
172      fi
173      rm -f testconf.c testconf
174    else
175      echo "no (2.6.0 or later is required)"
176      GTK=no
177    fi
178  else
179    echo "no"
180    GTK=no
181  fi
182}
183
184#
185# Parse options
186#
187while [ $# -ne 0 ]; do
188  param=`expr "opt$1" : 'opt[^=]*=\(.*\)'`
189
190  case "x$1" in
191    x--disable-openssl)
192      OPENSSL=no
193      ;;
194    x--disable-gtk)
195      GTK=no
196      ;;
197    x--help)
198      usage
199      exit 0
200      ;;
201  esac
202  shift
203done
204
205#
206# System-specific flags
207#
208SYSTEM=`uname -s`
209case $SYSTEM in
210  BeOS)
211    RELEASE=`uname -r`
212    case $RELEASE in
213      6.0*|5.0.4) # Zeta or R5 / BONE beta 7
214        ;;
215      5.0*)       # R5 / net_server
216        BEOS_NETSERVER=yes
217        ;;
218      *)
219        echo "Unsupported BeOS version"
220        exit 1
221        ;;
222    esac
223    ;;
224
225  Darwin)
226    # Make sure the Universal SDK is installed
227    if [ ! -d /Developer/SDKs/MacOSX10.4u.sdk ]; then
228      cat << EOF
229You need to install the Universal SDK in order to build Transmission:
230  Get your Xcode CD or package
231  Restart the install
232  When it gets to "Installation Type", select "Customize"
233  Select "Mac OS X 10.4 (Universal) SDL" under "Cross Development"
234  Finish the install.
235EOF
236      exit 1
237    fi
238    PTHREAD=yes
239    ;;
240
241  FreeBSD|NetBSD|OpenBSD|Linux)
242    PTHREAD=yes
243    ;;
244
245  *)
246    echo "Unsupported operating system"
247    exit 1 ;;
248esac
249echo "System:  $SYSTEM"
250
251#
252# First things first, check to see if there's a compiler installed
253#
254cc_test
255
256#
257# OpenSSL settings
258#
259echo -n "OpenSSL: "
260if [ "$OPENSSL" = no ]; then
261  echo "disabled, using built-in SHA1 implementation"
262else
263  openssl_test
264fi
265
266#
267# GTK+ settings
268#
269echo -n "GTK+:    "
270if [ "$GTK" = no ]; then
271  echo "disabled"
272else
273  gtk_test
274fi
275if [ "$GTK" = yes ]; then
276  rm -f gtk/defines.h
277  cat > gtk/defines.h << EOF
278#ifndef TG_DEFINES_H
279#define TG_DEFINES_H
280#define LOCALEDIR               "$GTKLOCALEDIR"
281#endif
282EOF
283fi
284
285#
286# Math functions
287#
288lm_test
289lrintf_test
290
291#
292# Generate Makefile.config
293#
294rm -f Makefile.config
295cat > Makefile.config << EOF
296CONFIGURE_RUN  = yes
297SVN_REVISION   = $SVNREV
298SYSTEM         = $SYSTEM
299BEOS_NETSERVER = $BEOS_NETSERVER
300PTHREAD        = $PTHREAD
301OPENSSL        = $OPENSSL
302GTK            = $GTK
303CC             = $CC
304CFLAGS         = $CFLAGS
305CXX            = $CXX
306CXXFLAGS       = $CXXFLAGS
307LDFLAGS        = $LDFLAGS
308CFLAGS_GTK     = $CFLAGS_GTK
309LDFLAGS_GTK    = $LDFLAGS_GTK
310EOF
311
312echo
313echo "Now use GNU make to build Transmission."
314echo "It may be called 'make' or 'gmake' depending on your system."
Note: See TracBrowser for help on using the repository browser.