Add initial chocpkg scripts.

This commit is contained in:
Simon Howard 2016-02-16 23:00:20 -05:00
commit 367c247f30
15 changed files with 355 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
build
install
packages

187
chocpkg/chocpkg Executable file
View file

@ -0,0 +1,187 @@
#!/bin/bash
set -eu
basic_setup() {
if [ "${CHOCPKG_ROOT:-}" = "" ]; then
echo "CHOCPKG_ROOT not configured - please source setup.sh." \
>> /dev/stderr
exit -1
fi
INSTALL_DIR="$CHOCPKG_ROOT/install"
PACKAGES_DIR="$CHOCPKG_ROOT/packages"
BUILD_DIR="$CHOCPKG_ROOT/build"
mkdir -p "$INSTALL_DIR" "$PACKAGES_DIR" "$BUILD_DIR"
}
basic_setup
. chocpkg_functions.sh
# Function that returns true if the package is installed.
check_installed() {
if [ "${PACKAGE_INSTALLED_TOOL:-}" != "" ]; then
have_tool "$PACKAGE_INSTALLED_TOOL"
elif [ "${PKGCONFIG_NAME:-}" != "" ]; then
if ! have_tool pkg-config; then
error_exit "pkg-config not installed; please run:" \
" chocpkg install pkg-config"
fi
pkg-config --exists "$PKGCONFIG_NAME"
else
false
fi
}
# Function invoked before a package is built to set up the build environment,
# if necessary. Can be overridden by pkgdef files.
prebuild_setup() {
true
}
# Given a package name, find the pkgdef file associated with it, source
# the contents of the file and set various variables.
configure_for_package() {
local package=$1
local pkg_file="$CHOCPKG_ROOT/pkgdef/$package.sh"
if [ ! -e "$pkg_file" ]; then
error_exit "Package file $package.sh not found."
fi
# Defaults for package unless overridden:
PACKAGE_NAME=$package
PACKAGE_TYPE=fetch
PACKAGE_CONFIGURE_OPTS=""
DEPENDENCIES=""
GIT_BRANCH=master
. "$pkg_file"
# After reading the package file, configure a few more variables:
case "$PACKAGE_TYPE" in
fetch)
PACKAGE_FILENAME="$PACKAGE_NAME-$PACKAGE_VERSION.tar.gz"
PACKAGE_BUILD_DIR="$BUILD_DIR/$PACKAGE_NAME-$PACKAGE_VERSION"
;;
git)
PACKAGE_BUILD_DIR="$BUILD_DIR/$PACKAGE_NAME"
;;
*)
error_exit "Unknown package type $PACKAGE_TYPE"
;;
esac
}
download_package_file() {
local dlfile="$PACKAGES_DIR/$PACKAGE_FILENAME"
if [ ! -e "$dlfile" ]; then
local tmpfile="$dlfile.part"
if ! chocurl "$PACKAGE_URL" > $tmpfile; then
error_exit "Failed to download $PACKAGE_URL"
fi
mv "$tmpfile" "$dlfile"
fi
}
extract_package_file() {
local dlfile="$PACKAGES_DIR/$PACKAGE_FILENAME"
(cd "$BUILD_DIR"; gunzip < "$dlfile" | tar -x) || (
mv "$dlfile" "$dlfile.bad"
error_exit "Failed to extract $PACKAGE_FILENAME: bad download?"
)
}
fetch_package() {
case "$PACKAGE_TYPE" in
fetch)
download_package_file
extract_package_file
;;
git)
if [ ! -e "$PACKAGE_BUILD_DIR" ]; then
git clone -b "$GIT_BRANCH" "$GIT_URL" "$PACKAGE_BUILD_DIR"
fi
;;
esac
}
setup_build_environment() {
CPPFLAGS="-I$INSTALL_DIR/include -I$INSTALL_DIR/include/SDL"
LDFLAGS="-L$INSTALL_DIR/lib $LDFLAGS"
ACLOCAL_PATH="$INSTALL_DIR/share/aclocal:$ACLOCAL_PATH"
export CPPFLAGS LDFLAGS ACLOCAL_PATH
if [ $(uname) = "Darwin" ]; then
CC="gcc -m32"
CXX="g++ -m32"
LDFLAGS="-lobjc $LDFLAGS"
MACOSX_DEPLOYMENT_TARGET=10.5
export CC CXX MACOSX_DEPLOYMENT_TARGET
else
LDFLAGS="-Wl,-rpath -Wl,$INSTALL_DIR/lib $LDFLAGS"
fi
}
build_package() {
if [ "$PACKAGE_NAME" != "pkg-config" ]; then
chocpkg install pkg-config
fi
for dep in $DEPENDENCIES; do
chocpkg install "$dep"
done
fetch_package "$PACKAGE_NAME"
echo =======================================================
echo "Building $PACKAGE_NAME..."
echo =======================================================
echo
cd "$PACKAGE_BUILD_DIR"
if ! prebuild_setup; then
error_exit "Failed pre-build setup step for $PACKAGE_NAME."
fi
./configure --prefix="$INSTALL_DIR" $PACKAGE_CONFIGURE_OPTS || (
error_exit "Failed to configure package $PACKAGE_NAME for build."
)
make || (
error_exit "Failed to build package $PACKAGE_NAME."
)
}
install_package() {
# Already installed?
if check_installed; then
return
fi
build_package "$PACKAGE_NAME"
cd "$PACKAGE_BUILD_DIR"
make install || (
error_exit "Failed to install package $PACKAGE_NAME."
)
}
if [ $# -lt 2 ]; then
echo "Usage: $0 [fetch|build|install|installed] <package name>"
exit -1
fi
cmd=$1; package=$2
configure_for_package "$package"
case "$cmd" in
fetch)
fetch_package
;;
build)
build_package
;;
install)
install_package
;;
installed)
check_installed
;;
esac

View file

@ -0,0 +1,44 @@
# Check if the specified string matches the glob pattern.
pattern_match() {
pattern="$1"
case "$2" in
$pattern)
true
;;
*)
false
;;
esac
}
# Determine if a given program is in the PATH.
have_tool() {
tool=$1
result=1
SAVE_IFS=$IFS
IFS=:
for dir in $PATH; do
if [ -e $dir/$tool ]; then
#echo $dir/$tool
result=0
break
fi
done
IFS=$SAVE_IFS
return $result
}
error_exit() {
(echo
for line in "$@"; do
echo "$line"
done) >&2
exit 1
}

25
chocpkg/chocurl Executable file
View file

@ -0,0 +1,25 @@
#!/bin/bash
. chocpkg_functions.sh
url=$1
if have_tool curl; then
exec curl $url
fi
if have_tool wget; then
exec wget $url -O -
fi
# Desperate?
for l in lynx links elinks; do
if have_tool $l; then
echo "Using $l to download $url..." >&2
exec $l -source $url
fi
done
error_exit "No tool available to retrieve URLs. Please install curl or wget."

10
pkgdef/SDL2.sh Normal file
View file

@ -0,0 +1,10 @@
PACKAGE_VERSION=2.0.3
PACKAGE_URL=http://www.libsdl.org/release/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz
PKGCONFIG_NAME=sdl2
# Many OS X systems have the Quartz X11 server installed, but
# we probably don't want to use it.
if [ $(uname) = "Darwin" ]; then
PACKAGE_CONFIGURE_OPTS=--disable-video-x11
fi

18
pkgdef/SDL2_mixer.sh Normal file
View file

@ -0,0 +1,18 @@
PACKAGE_VERSION=2.0.1
PACKAGE_URL=http://www.libsdl.org/projects/SDL_mixer/release/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz
PKGCONFIG_NAME=SDL2_mixer
# Disable dependencies on external libraries for sound file formats:
PACKAGE_CONFIGURE_OPTS="
--disable-music-mod --disable-music-mp3
--disable-music-flac-shared --disable-music-ogg-shared
"
# ...except ones we have installed:
if ! chocpkg installed flac; then
PACKAGE_CONFIGURE_OPTS="$PACKAGE_CONFIGURE_OPTS --disable-music-flac"
fi
if ! chocpkg installed libogg; then
PACKAGE_CONFIGURE_OPTS="$PACKAGE_CONFIGURE_OPTS --disable-music-ogg"
fi

4
pkgdef/SDL2_net.sh Normal file
View file

@ -0,0 +1,4 @@
PACKAGE_VERSION=2.0.1
PACKAGE_URL=http://www.libsdl.org/projects/SDL_net/release/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz
PKGCONFIG_NAME=SDL2_net

View file

@ -0,0 +1,14 @@
PACKAGE_TYPE=git
GIT_URL=https://github.com/fragglet/chocolate-doom.git
GIT_BRANCH=sdl2-branch
DEPENDENCIES="SDL2 SDL2_mixer SDL2_net"
prebuild_setup() {
mkdir -p autotools
aclocal -I "$INSTALL_DIR/share/aclocal"
autoheader
automake -a -c
autoconf
automake
}

4
pkgdef/flac.sh Normal file
View file

@ -0,0 +1,4 @@
PACKAGE_VERSION=1.2.1
PACKAGE_URL=http://www.chocolate-doom.org/depends/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz
PKGCONFIG_NAME=flac

4
pkgdef/libogg.sh Normal file
View file

@ -0,0 +1,4 @@
PACKAGE_VERSION=1.3.1
PACKAGE_URL=http://www.chocolate-doom.org/depends/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz
PKGCONFIG_NAME=ogg

4
pkgdef/libpng.sh Normal file
View file

@ -0,0 +1,4 @@
PACKAGE_VERSION=1.6.10
PACKAGE_URL=http://www.chocolate-doom.org/depends/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz
PKGCONFIG_NAME=libpng

4
pkgdef/libsamplerate.sh Normal file
View file

@ -0,0 +1,4 @@
PACKAGE_VERSION=0.1.8
PACKAGE_URL=http://www.chocolate-doom.org/depends/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz
PKGCONFIG_NAME=samplerate

5
pkgdef/libvorbis.sh Normal file
View file

@ -0,0 +1,5 @@
PACKAGE_VERSION=1.3.4
PACKAGE_URL=http://www.chocolate-doom.org/depends/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz
PKGCONFIG_NAME=vorbis
DEPENDENCIES="libogg"

5
pkgdef/pkg-config.sh Normal file
View file

@ -0,0 +1,5 @@
PACKAGE_VERSION=0.28
PACKAGE_URL=https://pkgconfig.freedesktop.org/releases/pkg-config-${PACKAGE_VERSION}.tar.gz
PACKAGE_INSTALLED_TOOL=pkg-config
PACKAGE_CONFIGURE_OPTS="--with-internal-glib"

24
setup.sh Normal file
View file

@ -0,0 +1,24 @@
CHOCPKG_ROOT=$HOME/chocolate-doom-build
export CHOCPKG_ROOT
# Build directory must not contain a space, or bad things happen:
case "$CHOCPKG_ROOT" in
*\ *)
cat <<END
The path to your home directory contains a space:
HOME=$HOME
This script will probably fail to build - reset HOME to point
somewhere else. For example, type:
mkdir /home/user
HOME=/home/user
END
exit -1
esac
# Set up various environment variables:
PATH="$CHOCPKG_ROOT/chocpkg:$CHOCPKG_ROOT/install/bin:$PATH"