2006-10-20 23:15:26 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Build script to automatically build Chocolate Doom. This will work
|
|
|
|
# on OSX and Linux, and hopefully Cygwin as well (havent tried)
|
|
|
|
#
|
|
|
|
# To build on OSX:
|
|
|
|
# 1. Install Xcode (available on your OSX DVDs or from the Apple
|
|
|
|
# website)
|
|
|
|
# 2. Type:
|
|
|
|
# curl http://www.chocolate-doom.org/build-chocolate-doom | sh
|
|
|
|
#
|
|
|
|
# To build on Linux:
|
|
|
|
# 1. Make sure gcc is installed (depends on your distribution).
|
|
|
|
# 2. Type:
|
|
|
|
# wget -O - http://www.chocolate-doom.org/build-chocolate-doom | sh
|
|
|
|
#
|
|
|
|
|
|
|
|
CHOCOLATE_DOOM_DIR=~/chocolate-doom
|
|
|
|
PACKAGES_DIR=$CHOCOLATE_DOOM_DIR/packages
|
|
|
|
BUILD_DIR=$CHOCOLATE_DOOM_DIR/build
|
|
|
|
|
2011-11-05 15:21:56 +00:00
|
|
|
# Check if the specified string matches the glob pattern.
|
|
|
|
|
|
|
|
pattern_match() {
|
|
|
|
pattern="$1"
|
|
|
|
|
|
|
|
case "$2" in
|
|
|
|
$pattern)
|
|
|
|
true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
false
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2006-10-20 23:15:26 +00:00
|
|
|
# Determine if a given program is in the PATH.
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
have_tool() {
|
2006-10-20 23:15:26 +00:00
|
|
|
tool=$1
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
result=1
|
2006-10-20 23:15:26 +00:00
|
|
|
SAVE_IFS=$IFS
|
|
|
|
IFS=:
|
|
|
|
|
|
|
|
for dir in $PATH; do
|
|
|
|
if [ -e $dir/$tool ]; then
|
2010-07-14 20:35:10 +00:00
|
|
|
# echo $dir/$tool
|
|
|
|
result=0
|
2006-10-20 23:15:26 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
IFS=$SAVE_IFS
|
|
|
|
|
|
|
|
return $result
|
|
|
|
}
|
|
|
|
|
|
|
|
# Download a given URL to stdout.
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
get_url() {
|
2006-10-20 23:15:26 +00:00
|
|
|
url=$1
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
if have_tool curl; then
|
2006-10-20 23:15:26 +00:00
|
|
|
curl $url
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
if have_tool wget; then
|
2006-10-20 23:15:26 +00:00
|
|
|
wget $url -O -
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2011-06-09 20:17:53 +00:00
|
|
|
# Desperate?
|
|
|
|
|
|
|
|
for l in lynx links elinks; do
|
|
|
|
if have_tool $l; then
|
|
|
|
echo "Using $l to download $url..." >&2
|
|
|
|
$l -source $url
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "No tool available to retrieve URLs. Please install curl or wget." >&2
|
|
|
|
|
|
|
|
exit -1
|
2006-10-20 23:15:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Extract a tar.gz file.
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
extract_targz() {
|
2006-10-20 23:15:26 +00:00
|
|
|
file=$1
|
|
|
|
|
|
|
|
gunzip < $1 | tar -x
|
|
|
|
}
|
|
|
|
|
|
|
|
# Download a file to the packages directory.
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
download_file() {
|
2006-10-20 23:15:26 +00:00
|
|
|
url=$1
|
|
|
|
file=$2
|
|
|
|
|
|
|
|
if get_url $url$file > $PACKAGES_DIR/$file.part; then
|
|
|
|
mv $PACKAGES_DIR/$file.part $PACKAGES_DIR/$file
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
echo "File $file failed to download! Please try again."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
# fetch_from_svn(svn_url, checkout_dir_name)
|
|
|
|
# Check module out from subversion.
|
|
|
|
|
|
|
|
fetch_from_svn() {
|
|
|
|
svn_url=$1
|
|
|
|
checkout_dir_name=$2
|
|
|
|
|
|
|
|
checkout_path="$BUILD_DIR/$checkout_dir_name"
|
|
|
|
|
|
|
|
if [ ! -e "$checkout_path" ]; then
|
|
|
|
|
|
|
|
if ! svn checkout "$svn_url" "$checkout_path"; then
|
|
|
|
echo "Failed to check out $checkout_dir_name from Subversion"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
svn update "$checkout_path"
|
|
|
|
fi
|
|
|
|
}
|
2006-10-20 23:15:26 +00:00
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
# fetch_module(base_url, module_name, version)
|
|
|
|
# Download the specified module.
|
|
|
|
|
|
|
|
fetch_module() {
|
2006-10-20 23:15:26 +00:00
|
|
|
url=$1
|
|
|
|
module=$2
|
|
|
|
version=$3
|
|
|
|
|
|
|
|
echo =======================================================
|
|
|
|
echo Building $module version $version
|
|
|
|
echo =======================================================
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [ ! -e $PACKAGES_DIR/$module-$version.tar.gz ]; then
|
|
|
|
echo Downloading tar file...
|
|
|
|
download_file $url $module-$version.tar.gz
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo Extracting...
|
|
|
|
cd $BUILD_DIR
|
|
|
|
|
|
|
|
if ! extract_targz $PACKAGES_DIR/$module-$version.tar.gz; then
|
|
|
|
rm -f $PACKAGES_DIR/$module-$version.tar.gz
|
|
|
|
|
|
|
|
echo Archive failed to extract and is possibly corrupted.
|
|
|
|
echo Please run this script again.
|
|
|
|
exit
|
|
|
|
fi
|
2010-07-14 20:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# build_module(module_dir, args)
|
|
|
|
# Build the specified module.
|
|
|
|
|
|
|
|
build_module() {
|
|
|
|
module=$1
|
|
|
|
args=$2
|
2006-10-20 23:15:26 +00:00
|
|
|
|
|
|
|
echo Building module...
|
2010-07-14 20:35:10 +00:00
|
|
|
cd "$BUILD_DIR/$module"
|
2006-10-20 23:15:26 +00:00
|
|
|
(./configure --with-sdl-prefix=$SDL_PREFIX --prefix=$INSTALL_DIR $args) || exit
|
|
|
|
make || exit
|
|
|
|
|
|
|
|
# Install the package
|
|
|
|
echo $INSTALL_MESSAGE
|
|
|
|
$INSTALL_COMMAND make install || exit
|
|
|
|
|
|
|
|
echo Build complete.
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
# fetch_and_build_module(base_url, module_name, version, args)
|
|
|
|
# Build a module, downloading from http:
|
|
|
|
|
|
|
|
fetch_and_build_module() {
|
|
|
|
url=$1
|
|
|
|
module=$2
|
|
|
|
version=$3
|
|
|
|
args=$4
|
|
|
|
|
|
|
|
fetch_module "$url" "$module" "$version"
|
|
|
|
build_module "$module-$version" "$args"
|
|
|
|
}
|
|
|
|
|
|
|
|
autogen_module() {
|
|
|
|
module=$1
|
|
|
|
|
|
|
|
cd "$BUILD_DIR/$module"
|
|
|
|
|
|
|
|
# This is what is normally found in the autogen.sh script. The
|
|
|
|
# commands are run here directly as some slight tweaks are needed.
|
|
|
|
|
|
|
|
mkdir autotools
|
2010-07-14 21:05:39 +00:00
|
|
|
|
|
|
|
aclocal -I "$SDL_PREFIX/share/aclocal" || exit
|
|
|
|
autoheader || exit
|
|
|
|
automake -a -c || exit
|
|
|
|
autoconf || exit
|
|
|
|
automake || exit
|
2010-07-14 20:35:10 +00:00
|
|
|
}
|
|
|
|
|
2006-10-20 23:15:26 +00:00
|
|
|
# Check if a given header file is in the standard include directory or
|
|
|
|
# SDL include directory.
|
|
|
|
|
2011-11-05 16:21:02 +00:00
|
|
|
have_header() {
|
2006-10-20 23:15:26 +00:00
|
|
|
headerfile=$1
|
|
|
|
|
2011-11-02 21:47:40 +00:00
|
|
|
echo "#include <$headerfile>" | cpp $SDL_CFLAGS $CPPFLAGS > /dev/null
|
2006-10-20 23:15:26 +00:00
|
|
|
|
|
|
|
result=$?
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
if [ $result = 0 ]; then
|
2006-10-20 23:15:26 +00:00
|
|
|
echo "Have $headerfile"
|
|
|
|
else
|
|
|
|
echo "Don't have $headerfile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
return $result
|
|
|
|
}
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
usage() {
|
2011-11-02 21:47:40 +00:00
|
|
|
echo
|
2006-10-20 23:15:26 +00:00
|
|
|
echo "Usage:"
|
|
|
|
echo "$0 : Install into home directory"
|
|
|
|
echo "$0 -su : Install globally onto system using 'su'"
|
|
|
|
echo "$0 -sudo : Install globally onto system using 'sudo'"
|
2011-11-02 21:47:40 +00:00
|
|
|
echo
|
|
|
|
echo "Extra options:"
|
2011-11-05 16:21:02 +00:00
|
|
|
echo "-v2 : Build v2-branch instead of trunk"
|
|
|
|
echo "-libsamplerate : Build libsamplerate"
|
|
|
|
echo "-host <spec> : Cross-compile for the specified target."
|
2011-11-02 21:47:40 +00:00
|
|
|
echo
|
|
|
|
|
2006-10-20 23:15:26 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2011-11-05 15:21:56 +00:00
|
|
|
if pattern_match "* *" "$HOME"; then
|
|
|
|
echo
|
|
|
|
echo "The path to your home directory contains a space:"
|
|
|
|
echo
|
|
|
|
echo " HOME=$HOME"
|
|
|
|
echo
|
|
|
|
echo "This script will probably fail to build - reset HOME to point"
|
|
|
|
echo "somewhere else. For example, type:"
|
|
|
|
echo
|
|
|
|
echo " mkdir /home/user"
|
|
|
|
echo " HOME=/home/user"
|
|
|
|
echo
|
|
|
|
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
if ! have_tool gcc; then
|
2006-10-20 23:15:26 +00:00
|
|
|
echo "No compiler found. Please install gcc!" >&2
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
2011-11-05 15:57:12 +00:00
|
|
|
# Parse command line arguments:
|
2006-10-20 23:15:26 +00:00
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
svn_build=false
|
2011-11-05 15:57:12 +00:00
|
|
|
force_build_sdl=false
|
2011-11-05 16:21:02 +00:00
|
|
|
build_libsamplerate=false
|
2011-11-05 15:57:12 +00:00
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
INSTALL_DIR=$CHOCOLATE_DOOM_DIR/install
|
|
|
|
INSTALL_COMMAND=
|
|
|
|
INSTALL_MESSAGE="Installing..."
|
2011-11-02 21:47:40 +00:00
|
|
|
SVN_PATH=/trunk/chocolate-doom
|
|
|
|
SVN_CO_NAME=chocolate-doom-svn
|
|
|
|
HOST_ARG=
|
2010-07-14 20:35:10 +00:00
|
|
|
|
|
|
|
for arg in "$@"; do
|
2011-11-02 21:47:40 +00:00
|
|
|
case "$arg" in
|
2010-07-14 20:35:10 +00:00
|
|
|
"-su")
|
|
|
|
INSTALL_DIR=/usr/local
|
|
|
|
INSTALL_COMMAND=su -c
|
|
|
|
INSTALL_MESSAGE="Type the root password:"
|
|
|
|
;;
|
|
|
|
"-sudo")
|
|
|
|
INSTALL_DIR=/usr/local
|
|
|
|
INSTALL_COMMAND=sudo
|
|
|
|
INSTALL_MESSAGE="Type your password:"
|
|
|
|
;;
|
2011-11-02 21:47:40 +00:00
|
|
|
-host=*)
|
|
|
|
HOST_ARG="-$arg"
|
2011-11-05 15:57:12 +00:00
|
|
|
# Build libraries from scratch when cross compiling:
|
|
|
|
force_build_sdl=true
|
2011-11-02 21:47:40 +00:00
|
|
|
;;
|
2011-11-05 16:21:02 +00:00
|
|
|
"-libsamplerate")
|
|
|
|
build_libsamplerate=true
|
|
|
|
;;
|
2010-07-14 20:35:10 +00:00
|
|
|
"-svn")
|
|
|
|
svn_build=true
|
|
|
|
;;
|
2011-11-02 21:47:40 +00:00
|
|
|
"-v2")
|
|
|
|
svn_build=true
|
|
|
|
SVN_PATH=/branches/v2-branch
|
|
|
|
SVN_CO_NAME=v2-branch-svn
|
|
|
|
;;
|
2010-07-14 20:35:10 +00:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2006-10-20 23:15:26 +00:00
|
|
|
|
|
|
|
# Make all our build directories etc
|
|
|
|
|
|
|
|
mkdir $CHOCOLATE_DOOM_DIR
|
|
|
|
mkdir $PACKAGES_DIR
|
|
|
|
mkdir $BUILD_DIR
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
MACOSX_DEPLOYMENT_TARGET=10.4
|
2010-07-14 21:05:39 +00:00
|
|
|
PATH="$INSTALL_DIR/bin:$PATH"
|
2011-11-02 21:47:40 +00:00
|
|
|
CPPFLAGS="-I$INSTALL_DIR/include -I$INSTALL_DIR/include/SDL"
|
2010-07-14 20:35:10 +00:00
|
|
|
LDFLAGS="-L$INSTALL_DIR/lib $LDFLAGS"
|
|
|
|
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET
|
2011-11-02 21:47:40 +00:00
|
|
|
export CPPFLAGS
|
2010-07-14 20:35:10 +00:00
|
|
|
export LDFLAGS
|
2006-10-20 23:15:26 +00:00
|
|
|
|
|
|
|
SDL_BUILD_OPTIONS=""
|
|
|
|
|
|
|
|
if [ `uname` = "Darwin" ]; then
|
|
|
|
SDL_BUILD_OPTIONS="--disable-video-x11 $SDL_BUILD_OPTIONS"
|
2011-01-02 02:36:46 +00:00
|
|
|
CC="gcc -m32"
|
|
|
|
export CC
|
2006-10-20 23:15:26 +00:00
|
|
|
else
|
2010-07-14 20:35:10 +00:00
|
|
|
LDFLAGS="-Wl,-rpath -Wl,$INSTALL_DIR/lib $LDFLAGS"
|
2006-10-20 23:15:26 +00:00
|
|
|
fi
|
|
|
|
|
2011-11-02 21:47:40 +00:00
|
|
|
# Windows build?
|
|
|
|
|
2011-11-05 15:21:56 +00:00
|
|
|
if [ `uname` = "Cygwin" ] || pattern_match "*mingw*" "$HOST_ARG"; then
|
2011-11-02 21:47:40 +00:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Windows build: installing supplementary DirectX headers."
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [ ! -e $PACKAGES_DIR/directx-devel.tar.gz ]; then
|
|
|
|
download_file http://www.libsdl.org/extras/win32/common/ \
|
|
|
|
directx-devel.tar.gz
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p $INSTALL_DIR
|
|
|
|
cd $INSTALL_DIR
|
|
|
|
extract_targz $PACKAGES_DIR/directx-devel.tar.gz
|
|
|
|
fi
|
|
|
|
|
2006-10-20 23:15:26 +00:00
|
|
|
SDL_CFLAGS=
|
|
|
|
SDL_PREFIX=`sdl-config --prefix`
|
|
|
|
|
2011-11-05 15:57:12 +00:00
|
|
|
if [ $? = 0 ] && ! $force_build_sdl; then
|
2006-10-20 23:15:26 +00:00
|
|
|
# SDL is installed on the system
|
|
|
|
|
|
|
|
SDL_CFLAGS=`sdl-config --cflags`
|
|
|
|
else
|
|
|
|
# SDL not installed; we must build it
|
|
|
|
|
|
|
|
SDL_PREFIX=$INSTALL_DIR
|
|
|
|
|
2011-11-02 21:47:40 +00:00
|
|
|
fetch_and_build_module http://www.libsdl.org/release/ SDL 1.2.14 \
|
|
|
|
"$SDL_BUILD_OPTIONS $HOST_ARG"
|
2006-10-20 23:15:26 +00:00
|
|
|
fi
|
|
|
|
|
2011-11-05 16:21:02 +00:00
|
|
|
if $force_build_sdl || ! have_header SDL_net.h; then
|
2006-10-20 23:15:26 +00:00
|
|
|
|
|
|
|
# SDL_net not installed; we must build it
|
|
|
|
|
2011-11-02 21:47:40 +00:00
|
|
|
fetch_and_build_module http://www.libsdl.org/projects/SDL_net/release/ \
|
|
|
|
SDL_net 1.2.6 "$HOST_ARG"
|
2006-10-20 23:15:26 +00:00
|
|
|
fi
|
|
|
|
|
2011-11-05 16:21:02 +00:00
|
|
|
if $force_build_sdl || ! have_header SDL_mixer.h; then
|
2006-10-20 23:15:26 +00:00
|
|
|
|
|
|
|
# SDL_mixer not installed; we must build it
|
2011-11-05 15:57:12 +00:00
|
|
|
# Disable dependencies on external libraries for sound file formats:
|
|
|
|
|
|
|
|
mixer_opts="--disable-music-mod --disable-music-ogg \
|
|
|
|
--disable-music-flac --disable-music-mp3"
|
2006-10-20 23:15:26 +00:00
|
|
|
|
2011-11-02 21:47:40 +00:00
|
|
|
fetch_and_build_module http://www.libsdl.org/projects/SDL_mixer/release/ \
|
2011-11-05 15:57:12 +00:00
|
|
|
SDL_mixer 1.2.11 "$HOST_ARG $mixer_opts"
|
2006-10-20 23:15:26 +00:00
|
|
|
fi
|
|
|
|
|
2011-11-05 16:21:02 +00:00
|
|
|
# Optional libsamplerate support:
|
|
|
|
|
2011-11-13 18:57:03 +00:00
|
|
|
if $build_libsamplerate; then
|
2011-11-05 16:21:02 +00:00
|
|
|
if $force_build_sdl || ! have_header libsamplerate.h; then
|
|
|
|
fetch_and_build_module http://www.mega-nerd.com/SRC/ \
|
|
|
|
libsamplerate 0.1.8 "$HOST_ARG"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
# Build Chocolate Doom. We can build the stable version or check out
|
|
|
|
# the latest code from Subversion.
|
|
|
|
|
|
|
|
if $svn_build; then
|
2011-11-02 21:47:40 +00:00
|
|
|
fetch_from_svn "http://chocolate-doom.svn.sourceforge.net/svnroot/chocolate-doom$SVN_PATH" \
|
|
|
|
"$SVN_CO_NAME"
|
2006-10-20 23:15:26 +00:00
|
|
|
|
2011-11-02 21:47:40 +00:00
|
|
|
autogen_module "$SVN_CO_NAME"
|
2010-07-14 20:35:10 +00:00
|
|
|
|
2011-11-02 21:47:40 +00:00
|
|
|
build_module "$SVN_CO_NAME" "$HOST_ARG"
|
2010-07-14 20:35:10 +00:00
|
|
|
else
|
2011-06-09 20:17:53 +00:00
|
|
|
# Build v1.6.0
|
2010-07-14 20:35:10 +00:00
|
|
|
|
2011-11-02 21:47:40 +00:00
|
|
|
fetch_and_build_module http://mesh.dl.sourceforge.net/project/chocolate-doom/chocolate-doom/1.6.0/ \
|
|
|
|
chocolate-doom 1.6.0 "$HOST_ARG"
|
2010-07-14 20:35:10 +00:00
|
|
|
fi
|
2006-10-20 23:15:26 +00:00
|
|
|
|
|
|
|
cd $CHOCOLATE_DOOM_DIR
|
|
|
|
ln -sf $INSTALL_DIR/games/chocolate-doom chocolate-doom
|
|
|
|
ln -sf $INSTALL_DIR/games/chocolate-server chocolate-server
|
|
|
|
ln -sf $INSTALL_DIR/games/chocolate-setup chocolate-setup
|
|
|
|
|