1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00
transmission/configure

541 lines
9.4 KiB
Text
Raw Normal View History

2006-07-16 19:39:23 +00:00
#! /bin/sh
#
# $Id$
2006-07-16 19:39:23 +00:00
#
# Default settings
#
SYSTEM=
BEOS_NETSERVER=no
BEOS_OLDCC=no
MATH=no
PTHREAD=no
OPENSSL=
GTK=
LIBEVENT=
PREFIX=/usr/local
CC="${CC-cc}"
CFLAGS="${CFLAGS}"
CXX="${CXX-c++}"
CXXFLAGS="${CXXFLAGS}"
LDFLAGS="${LDFLAGS}"
VERBOSE=no
2006-07-16 19:39:23 +00:00
#
# Functions
2006-07-16 19:39:23 +00:00
#
usage()
{
cat << EOF
2006-07-16 19:39:23 +00:00
Options:
--disable-openssl Disable OpenSSL, use built-in SHA1 implementation
--disable-gtk Don't build the GTK+ GUI
--disable-daemon Don't build the daemon
--prefix=PATH Installation path
--verbose Display additional information for debugging
2006-07-16 19:39:23 +00:00
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
CXX C++ compiler command
CXXFLAGS C++ compiler flags
LDFLAGS linker flags
2006-07-16 19:39:23 +00:00
EOF
}
2006-07-16 19:39:23 +00:00
runcmd()
{
if [ "$VERBOSE" = yes ]
then
echo "$@" >&2
"$@"
else
"$@" > /dev/null 2>&1
fi
return $!
}
2006-07-16 19:39:23 +00:00
verbose()
{
if [ "$VERBOSE" = yes ]
then
echo "$@"
fi
}
2006-07-16 19:39:23 +00:00
cc_test()
{
verbose cc_test
cat > testconf.c <<EOF
int main()
{
return 0;
}
EOF
if ! runcmd $CC -o testconf testconf.c
then
rm -f testconf*
echo "Could not find a working compiler"
exit 1
fi
rm -f testconf*
}
2006-07-16 19:39:23 +00:00
openssl_test()
{
verbose openssl_test
cat > testconf.c << EOF
#include <stdio.h>
#include <openssl/sha.h>
int main()
{
SHA1( 0, 0, 0 );
}
EOF
if runcmd $CC $CFLAGS $LDFLAGS -o testconf testconf.c -lcrypto
then
echo "yes"
OPENSSL=yes
else
echo "missing, using built-in SHA1 implementation"
OPENSSL=no
fi
rm -f testconf*
}
2006-07-16 19:39:23 +00:00
lm_test()
2006-07-16 19:39:23 +00:00
{
verbose lm_test
cat > testconf.c << EOF
int main()
{
return cos( 42 );
}
EOF
if ! runcmd $CC -o testconf testconf.c
then
if runcmd $CC -o testconf testconf.c -lm
then
LDFLAGS="-lm $LDFLAGS"
fi
fi
rm -f testconf*
2006-07-16 19:39:23 +00:00
}
lrintf_test()
{
verbose lrintf_test
cat > testconf.c << EOF
int main()
{
return ( lrintf( 3.14 ) != 3 );
}
EOF
if runcmd $CC -o testconf testconf.c $LDFLAGS && runcmd ./testconf
then
CFLAGS="$CFLAGS -DHAVE_LRINTF"
fi
rm -f testconf*
}
2006-07-16 19:39:23 +00:00
strlcpy_test()
{
verbose strlcpy_test
cat > testconf.c << EOF
#include <string.h>
int main()
2007-04-18 16:39:10 +00:00
{
char buf[] = "1234:p";
strlcpy( buf, "foo", sizeof buf );
return ( 0 == memcmp( buf, "foo\0:p", 6 ) ? 0 : 1 );
}
EOF
if runcmd $CC -o testconf testconf.c && runcmd ./testconf
then
CFLAGS="$CFLAGS -DHAVE_STRLCPY"
fi
rm -f testconf*
}
strlcat_test()
2007-04-18 16:39:10 +00:00
{
verbose strlcat_test
cat > testconf.c << EOF
#include <string.h>
int main()
2007-04-18 16:39:10 +00:00
{
char buf[] = "1234567:p";
buf[0] = '\0';
strlcat( buf, "foo", sizeof buf );
strlcat( buf, "bar", sizeof buf );
return ( 0 == memcmp( buf, "foobar\0:p", 6 ) ? 0 : 1 );
}
EOF
if runcmd $CC -o testconf testconf.c && runcmd ./testconf
then
CFLAGS="$CFLAGS -DHAVE_STRLCAT"
fi
rm -f testconf*
2007-04-18 16:39:10 +00:00
}
asprintf_test()
{
verbose asprintf_test
cat > testconf.c <<EOF
#define _GNU_SOURCE
#include <stdio.h>
int main()
{
asprintf( NULL, NULL );
return 0;
}
EOF
if runcmd $CC -o testconf testconf.c
then
CFLAGS="$CFLAGS -DHAVE_ASPRINTF"
fi
rm -f testconf*
}
snprintf_test()
{
verbose snprintf_test
cat > testconf.c <<EOF
#include <stdio.h>
int main()
{
char buf[] = "blueberry";
return ( 6 != snprintf( buf, 4, "%s%s", "foo", "bar" ) ||
0 != memcmp( buf, "foo\0berry", 9 ) );
}
EOF
if ! runcmd $CC -o testconf testconf.c || ! runcmd ./testconf
then
echo "error: broken snprintf() found"
exit 1
fi
rm -f testconf*
}
libgen_test()
{
verbose libgen_test
cat > testconf.c << EOF
#include <libgen.h>
int main()
{
return 0;
}
EOF
if runcmd $CC -o testconf testconf.c
then
CFLAGS="$CFLAGS -DHAVE_LIBGEN"
fi
rm -f testconf*
}
gettext_test()
{
verbose gettext_test
cat > testconf.c <<EOF
#include <libintl.h>
int main()
{
gettext("");
}
EOF
2006-07-16 19:39:23 +00:00
if runcmd $CC $CFLAGS_GTK $LDFLAGS_GTK -o testconf testconf.c
then
rm -f testconf*
return 0
fi
2006-07-16 19:39:23 +00:00
for intl_testdir in $PREFIX/include \
/usr/local/include /usr/X11R6/include /usr/pkg/include
do
if runcmd $CC $CFLAGS_GTK -I$intl_testdir $LDFLAGS_GTK -o testconf testconf.c
then
CFLAGS_GTK="$CFLAGS_GTK -I$intl_testdir"
rm -f testconf*
return 0
2006-07-16 19:39:23 +00:00
fi
done
rm -f testconf*
return 1
}
2006-07-16 19:39:23 +00:00
gtk_test()
{
verbose gtk_test
if runcmd pkg-config gtk+-2.0
then
if runcmd pkg-config --exists gtk+-2.0 '>=' 2.6.0
then
cat > testconf.c << EOF
#include <gtk/gtk.h>
int main()
{
gtk_main();
}
EOF
if runcmd $CC `pkg-config gtk+-2.0 --cflags --libs` -o testconf testconf.c
then
CFLAGS_GTK=`pkg-config gtk+-2.0 --cflags`
LDFLAGS_GTK=`pkg-config gtk+-2.0 --libs`
if gettext_test
then
echo "yes"
GTK=yes
LOCALEDIR="$PREFIX/share/locale"
CFLAGS_GTK="$CFLAGS_GTK -DLOCALEDIR=\\"\""$LOCALEDIR\\"\"
else
echo "no (could not find gettext libintl.h)"
GTK=no
fi
else
echo "no"
GTK=no
fi
rm -f testconf*
else
echo "no (2.6.0 or later is required)"
GTK=no
fi
else
echo "no"
GTK=no
fi
}
libevent_test()
{
verbose libevent_test
cat > testconf.c <<EOF
#include <sys/types.h>
#include <sys/time.h>
#include <event.h>
int main()
{
event_init();
return 0;
}
EOF
if runcmd $CC $CFLAGS -levent $LDFLAGS -o testconf testconf.c
then
LIBEVENT=yes
LDFLAGS_EVENT="-levent"
rm -f testconf*
return 0
fi
for event_testdir in $PREFIX /usr/local /usr/X11R6 /usr/pkg
do
if runcmd $CC $CFLAGS -I$event_testdir/include $LDFLAGS -levent \
-L$event_testdir/lib -o testconf testconf.c
then
LIBEVENT=yes
CFLAGS_EVENT="-I$event_testdir/include"
LDFLAGS_EVENT="-levent -L$event_testdir/lib"
rm -f testconf*
return 0
fi
done
LIBEVENT=no
rm -f testconf*
return 1
}
2006-07-16 19:39:23 +00:00
#
# Parse options
#
while [ $# -ne 0 ]; do
param=`expr "opt$1" : 'opt[^=]*=\(.*\)'`
2006-07-16 19:39:23 +00:00
case "x$1" in
x--disable-openssl|x--without-openssl)
OPENSSL=no
;;
x--disable-daemon|x--without-daemon)
LIBEVENT=no
;;
x--disable-gtk|x--without-gtk)
GTK=no
;;
x--prefix=*)
PREFIX="$param"
;;
x--verbose)
VERBOSE=yes
;;
x--help)
usage
exit 0
;;
esac
shift
done
2006-07-16 19:39:23 +00:00
#
# System-specific flags
#
SYSTEM=`uname -s`
case $SYSTEM in
BeOS)
RELEASE=`uname -r`
case $RELEASE in
6.*|5.0.4) # Zeta or R5 / BONE beta 7
;;
5.0*) # R5 / net_server
BEOS_NETSERVER=yes
;;
*)
echo "Unsupported BeOS version"
exit 1
;;
esac
GCCVER=`$CC -dumpversion`
case $GCCVER in
2.95.3*|3*|4*)
;;
2.9*)
BEOS_OLDCC=yes
;;
*)
echo "Unsupported gcc version"
exit 1
;;
esac
;;
Darwin)
# Make sure the Universal SDK is installed
if [ ! -d /Developer/SDKs/MacOSX10.4u.sdk ]; then
cat << EOF
You need to install the Universal SDK in order to build Transmission:
Get your Xcode CD or package
Restart the install
When it gets to "Installation Type", select "Customize"
Select "Mac OS X 10.4 (Universal) SDK" under "Cross Development"
Finish the install.
EOF
exit 1
fi
PTHREAD=yes
;;
FreeBSD|NetBSD|OpenBSD|Linux|skyos)
PTHREAD=yes
;;
CYGWIN*)
;;
*)
echo "Unsupported operating system"
exit 1 ;;
esac
echo "System: $SYSTEM"
2006-07-16 19:39:23 +00:00
2007-04-18 16:39:10 +00:00
#
# First things first, check to see if there's a compiler installed
2007-04-18 16:39:10 +00:00
#
cc_test
#
# OpenSSL settings
#
echo -n "OpenSSL: "
if [ "$OPENSSL" = no ]; then
echo "disabled, using built-in SHA1 implementation"
2007-04-18 16:39:10 +00:00
else
openssl_test
fi
if [ "$OPENSSL" = no ] && [ "$BEOS_OLDCC" = yes ]; then
echo "built-in SHA1 implementation not supported with your gcc version"
echo "you must either install OpenSSL or gcc 2.95.3 or newer"
exit 1
fi
#
# GTK+ settings
#
echo -n "GTK+: "
if [ "x$GTK" = xno ]; then
echo "disabled"
else
gtk_test
if [ "x$GTK" = xno ] && [ "x$SYSTEM" = xLinux ]; then
cat <<EOF
*** GTK+ was not found, transmission-gtk will *NOT* be built. If you
*** wish to use the graphical version of Transmission then you will
*** need to install GTK+ headers and libraries. Try using your
*** distribution's package management utility to find a package called
*** libgtk2.0-dev, gtk2-devel, or something similar; then install it
*** and re-run this script.
EOF
fi
fi
#
# libevent settings
#
echo -n "Daemon: "
if [ "$LIBEVENT" = no ]; then
echo "disabled"
else
if libevent_test; then
echo "yes"
2007-04-18 16:39:10 +00:00
else
echo "no (can't find libevent)"
2007-04-18 16:39:10 +00:00
fi
fi
#
# Math functions
#
lm_test
lrintf_test
2006-07-16 19:39:23 +00:00
#
# String functions
#
strlcpy_test
strlcat_test
asprintf_test
snprintf_test
libgen_test
2007-04-18 16:39:10 +00:00
#
# Generate config.mk
#
rm -f mk/config.mk
cat > mk/config.mk << EOF
SYSTEM = $SYSTEM
PREFIX = $PREFIX
LOCALEDIR = $LOCALEDIR
BEOS_NETSERVER = $BEOS_NETSERVER
PTHREAD = $PTHREAD
OPENSSL = $OPENSSL
GTK = $GTK
DAEMON = $LIBEVENT
CC = $CC
CFLAGS = $CFLAGS
CXX = $CXX
CXXFLAGS = $CXXFLAGS
LDFLAGS = $LDFLAGS
CFLAGS_GTK = $CFLAGS_GTK
LDFLAGS_GTK = $LDFLAGS_GTK
CFLAGS_EVENT = $CFLAGS_EVENT
LDFLAGS_EVENT = $LDFLAGS_EVENT
EOF
echo
echo "Now use GNU make to build Transmission."
echo "It may be called 'make' or 'gmake' depending on your system."
2006-07-16 19:39:23 +00:00