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
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
echo No tool available to retrieve URLs. Please install curl or wget. >2
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
check_header() {
|
2006-10-20 23:15:26 +00:00
|
|
|
headerfile=$1
|
|
|
|
|
|
|
|
echo "#include <$headerfile>" | cpp $SDL_CFLAGS $CFLAGS > /dev/null
|
|
|
|
|
|
|
|
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() {
|
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'"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# Decide on how to install things
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
svn_build=false
|
|
|
|
INSTALL_DIR=$CHOCOLATE_DOOM_DIR/install
|
|
|
|
INSTALL_COMMAND=
|
|
|
|
INSTALL_MESSAGE="Installing..."
|
|
|
|
|
|
|
|
for arg in "$@"; do
|
|
|
|
case "$1" in
|
|
|
|
"-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:"
|
|
|
|
;;
|
|
|
|
|
|
|
|
"-svn")
|
|
|
|
svn_build=true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
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"
|
2010-07-14 20:35:10 +00:00
|
|
|
CFLAGS="-I$INSTALL_DIR/include/SDL $CFLAGS"
|
|
|
|
LDFLAGS="-L$INSTALL_DIR/lib $LDFLAGS"
|
|
|
|
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET
|
|
|
|
export CFLAGS
|
|
|
|
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"
|
|
|
|
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
|
|
|
|
|
|
|
|
SDL_CFLAGS=
|
|
|
|
SDL_PREFIX=`sdl-config --prefix`
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
if [ $? = 0 ]; 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
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
fetch_and_build_module http://www.libsdl.org/release/ SDL 1.2.14 "$SDL_BUILD_OPTIONS"
|
2006-10-20 23:15:26 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! check_header SDL_net.h; then
|
|
|
|
|
|
|
|
# SDL_net not installed; we must build it
|
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
fetch_and_build_module http://www.libsdl.org/projects/SDL_net/release/ SDL_net 1.2.6 ""
|
2006-10-20 23:15:26 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! check_header SDL_mixer.h; then
|
|
|
|
|
|
|
|
# SDL_mixer not installed; we must build it
|
|
|
|
|
2010-11-26 17:49:42 +00:00
|
|
|
fetch_and_build_module http://www.libsdl.org/projects/SDL_mixer/release/ SDL_mixer 1.2.11 ""
|
2006-10-20 23:15:26 +00:00
|
|
|
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
|
|
|
|
fetch_from_svn http://chocolate-doom.svn.sourceforge.net/svnroot/chocolate-doom/trunk/chocolate-doom chocolate-doom-svn
|
2006-10-20 23:15:26 +00:00
|
|
|
|
2010-07-14 20:35:10 +00:00
|
|
|
autogen_module chocolate-doom-svn
|
|
|
|
|
|
|
|
build_module chocolate-doom-svn ""
|
|
|
|
else
|
|
|
|
# Build v1.4.0
|
|
|
|
|
|
|
|
fetch_and_build_module http://mesh.dl.sourceforge.net/project/chocolate-doom/chocolate-doom/1.4.0/ chocolate-doom 1.4.0 ""
|
|
|
|
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
|
|
|
|
|