331 lines
7.6 KiB
Bash
Executable file
331 lines
7.6 KiB
Bash
Executable file
#!/bin/bash -e
|
|
|
|
#
|
|
# JoeyLib
|
|
# Copyright (C) 2018-2019 Scott Duensing <scott@kangaroopunch.com>
|
|
#
|
|
# This software is provided 'as-is', without any express or implied
|
|
# warranty. In no event will the authors be held liable for any damages
|
|
# arising from the use of this software.
|
|
#
|
|
# Permission is granted to anyone to use this software for any purpose,
|
|
# including commercial applications, and to alter it and redistribute it
|
|
# freely, subject to the following restrictions:
|
|
#
|
|
# 1. The origin of this software must not be misrepresented; you must not
|
|
# claim that you wrote the original software. If you use this software
|
|
# in a product, an acknowledgment in the product documentation would be
|
|
# appreciated but is not required.
|
|
# 2. Altered source versions must be plainly marked as such, and must not be
|
|
# misrepresented as being the original software.
|
|
# 3. This notice may not be removed or altered from any source distribution.
|
|
#
|
|
|
|
|
|
#
|
|
# Global variables
|
|
#
|
|
G_TITLE="JoeyLib Installer"
|
|
G_PARENT=
|
|
|
|
|
|
function buildPCDeps() {
|
|
local DIST=$1
|
|
local PREFIX=$2
|
|
local CROSS=$3
|
|
local CC_EXPORT=$4
|
|
local CXX_EXPORT=$5
|
|
local CC_OLD=$CC
|
|
local CXX_OLD=$CXX
|
|
local SRC="${G_PARENT}/joeylib/joeylib/src"
|
|
local G_CFLAGS="-Wall -D_REENTRANT_ -I${SRC} -c"
|
|
|
|
echo ""
|
|
tBoldBox tCYAN "NOTE: If an error is encountered, installer will exit!"
|
|
|
|
# Clear any existing built libraries
|
|
if [[ -d ${PREFIX} ]]; then
|
|
rm -rf ${PREFIX}
|
|
fi
|
|
mkdir -p ${PREFIX}
|
|
|
|
pushd deps >& /dev/null
|
|
|
|
export CC="${CC_EXPORT}"
|
|
export CXX="${CXX_EXPORT}"
|
|
|
|
# SDL2
|
|
if [[ ! -d SDL ]]; then
|
|
echo ""
|
|
tBoldBox tPURPLE "Building SDL2"
|
|
echo ""
|
|
hg clone http://hg.libsdl.org/SDL
|
|
clearPCDepsBuild
|
|
pushd build >& /dev/null
|
|
../SDL/configure \
|
|
--target="${CROSS}" \
|
|
--host="${CROSS}" \
|
|
--build=x86_64-linux \
|
|
--enable-static \
|
|
--disable-shared \
|
|
--prefix=${PREFIX}
|
|
make
|
|
make install
|
|
popd >& /dev/null
|
|
fi
|
|
|
|
# libModPlug
|
|
if [[ ! -d libmodplug ]]; then
|
|
echo ""
|
|
tBoldBox tPURPLE "Building libModPlug"
|
|
echo ""
|
|
git clone https://github.com/Konstanty/libmodplug.git
|
|
pushd libmodplug >& /dev/null
|
|
libtoolize --force
|
|
aclocal
|
|
autoheader
|
|
automake --force-missing --add-missing
|
|
autoconf
|
|
popd >& /dev/null
|
|
clearPCDepsBuild
|
|
pushd build >& /dev/null
|
|
../libmodplug/configure \
|
|
--target="${CROSS}" \
|
|
--host="${CROSS}" \
|
|
--build=x86_64-linux \
|
|
--enable-static \
|
|
--disable-shared \
|
|
--prefix=${PREFIX}
|
|
make
|
|
make install
|
|
popd >& /dev/null
|
|
fi
|
|
|
|
# SDL_mixer
|
|
if [[ ! -d SDL_mixer ]]; then
|
|
echo ""
|
|
tBoldBox tPURPLE "Building SDL_mixer"
|
|
echo ""
|
|
hg clone http://hg.libsdl.org/SDL_mixer
|
|
clearPCDepsBuild
|
|
pushd build >& /dev/null
|
|
MODPLUG_CFLAGS="-I${PREFIX}/include -DMODPLUG_STATIC" \
|
|
MODPLUG_LIBS="-L${PREFIX}/lib -lmodplug -lstdc++ -lm" \
|
|
../SDL_mixer/configure \
|
|
--target="${CROSS}" \
|
|
--host="${CROSS}" \
|
|
--build=x86_64-linux \
|
|
--enable-static \
|
|
--disable-shared \
|
|
--prefix=${PREFIX} \
|
|
--with-sdl-prefix=${PREFIX} \
|
|
--disable-music-cmd \
|
|
--disable-music-wave \
|
|
--enable-music-mod-modplug \
|
|
--disable-music-mod-modplug-shared \
|
|
--disable-music-mod-mikmod \
|
|
--disable-music-midi \
|
|
--disable-music-ogg \
|
|
--disable-music-flac \
|
|
--disable-music-opus \
|
|
--disable-music-mp3 \
|
|
--disable-music-mp3-mpg123
|
|
make
|
|
make install
|
|
popd >& /dev/null
|
|
fi
|
|
|
|
export CC="${CC_OLD}"
|
|
export CXX="${CXX_OLD}"
|
|
|
|
# JoeyLib
|
|
echo ""
|
|
tBoldBox tPURPLE "Building JoeyLib"
|
|
echo ""
|
|
if [[ -d "${DIST}" ]]; then
|
|
rm -rf "${DIST}"
|
|
fi
|
|
mkdir -p "${DIST}"
|
|
clearPCDepsBuild
|
|
pushd build >& /dev/null
|
|
${CC_EXPORT} ${G_CFLAGS} -o jPC.o ${SRC}/jPC.c
|
|
${CC_EXPORT} ${G_CFLAGS} -o joey.o ${SRC}/joey.c
|
|
ar x ${PREFIX}/lib/libSDL2.a
|
|
ar x ${PREFIX}/lib/libSDL2_mixer.a
|
|
ar x ${PREFIX}/lib/libmodplug.a
|
|
ar rcs ${DIST}/libjoeylib.a *.o
|
|
cp -f ${SRC}/joey.h ${DIST}/../..
|
|
cp -f ${SRC}/../joey.pri ${DIST}/../..
|
|
popd >& /dev/null
|
|
|
|
popd >& /dev/null
|
|
}
|
|
|
|
|
|
function clearPCDepsBuild() {
|
|
if [[ -d $(pwd)/build ]]; then
|
|
rm -rf $(pwd)/build
|
|
fi
|
|
mkdir -p $(pwd)/build
|
|
}
|
|
|
|
|
|
function installLinux32() {
|
|
buildPCDeps \
|
|
"$(pwd)/../dist/linux/i386" \
|
|
"$(pwd)/deps/installed/linux/i386" \
|
|
"x86_64-linux-gnu" \
|
|
"x86_64-linux-gnu-gcc -m32" \
|
|
"x86_64-linux-gnu-g++ -m32"
|
|
}
|
|
|
|
|
|
function installLinux64() {
|
|
buildPCDeps \
|
|
"$(pwd)/../dist/linux/x64" \
|
|
"$(pwd)/deps/installed/linux/x64" \
|
|
"x86_64-linux-gnu" \
|
|
"x86_64-linux-gnu-gcc" \
|
|
"x86_64-linux-gnu-g++"
|
|
}
|
|
|
|
|
|
function installWin32() {
|
|
buildPCDeps \
|
|
"$(pwd)/../dist/windows/i386" \
|
|
"$(pwd)/deps/installed/windows/i386" \
|
|
"i686-w64-mingw32" \
|
|
"i686-w64-mingw32-gcc -static-libgcc" \
|
|
""
|
|
}
|
|
|
|
|
|
function installWin64() {
|
|
buildPCDeps \
|
|
"$(pwd)/../dist/windows/x64" \
|
|
"$(pwd)/deps/installed/windows/x64" \
|
|
"x86_64-w64-mingw32" \
|
|
"x86_64-w64-mingw32-gcc -static-libgcc" \
|
|
"x86_64-w64-mingw32-g++ -static-libstdc++"
|
|
}
|
|
|
|
|
|
function mainMenu() {
|
|
local ITEMS=(
|
|
# "IIgs" "Amiga" "ST"
|
|
"Linux32" "Linux64"
|
|
"Win32" "Win64"
|
|
# "macOS32" "macOS64"
|
|
# "Android" "iOS"
|
|
)
|
|
local DESC=(
|
|
# "Apple IIgs 16" "Commodore Amiga 16" "Atari ST 16"
|
|
"Linux 32" "Linux 64"
|
|
"Windows 32" "Windows 64"
|
|
# "macOS 32" "macOS 64"
|
|
# "Android 32" "iOS 64"
|
|
)
|
|
local TOTAL=${#ITEMS[*]}
|
|
local MENU=()
|
|
local X=
|
|
local CHOICE="x"
|
|
|
|
while [[ "${CHOICE}" != "" ]]; do
|
|
MENU=()
|
|
for (( X=0; X<=$(( ${TOTAL}-1 )); X++ )); do
|
|
MENU+=( "${ITEMS[$X]}" )
|
|
MENU+=( "Install ${DESC[$X]} Bit JoeyLib Library" )
|
|
done
|
|
CHOICE=$(
|
|
set e+
|
|
whiptail --title "${G_TITLE}" --cancel-button "Exit" --menu "" $(( ${TOTAL}+7 )) 65 ${TOTAL} "${MENU[@]}" 3>&2 2>&1 1>&3
|
|
set e-
|
|
)
|
|
if [[ "${CHOICE}" != "" ]]; then
|
|
CHOICE="install${CHOICE}"
|
|
${CHOICE}
|
|
fi
|
|
done
|
|
}
|
|
|
|
|
|
# --- START
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "The installer must be run as root."
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p installerWork
|
|
|
|
# Do we have Towel yet?
|
|
if [[ ! -f installerWork/towel/towel.sh ]]; then
|
|
# Do we have GIT?
|
|
if [[ "$(which git || true)" == "" ]]; then
|
|
echo "Installing git..."
|
|
apt-get -y install git >& /dev/null
|
|
fi
|
|
echo "Downloading towel.sh support library..."
|
|
git clone https://skunkworks.kangaroopunch.com/skunkworks/towel.git installerWork/towel >& /dev/null
|
|
fi
|
|
|
|
# Load Towel
|
|
source installerWork/towel/towel.sh
|
|
|
|
# Remember where we live.
|
|
G_PARENT=$(pwd)
|
|
|
|
# Don't change directories until Towel is loaded.
|
|
pushd installerWork >& /dev/null
|
|
|
|
:<<'SKIP'
|
|
# See if all the packages we need are installed
|
|
echo ""
|
|
tBoldBox tBLUE "Examining system..."
|
|
tCheckPackages MISSING cmake ragel hfsplus hfsutils hfsprogs libreadline-dev libedit-dev \
|
|
build-essential git mercurial texinfo libtool autoconf automake \
|
|
gcc-multilib g++-multilib mingw-w64 gdb-mingw-w64 clang llvm-dev libxml2-dev \
|
|
uuid-dev libssl-dev bash patch make tar xz-utils bzip2 gzip sed cpio \
|
|
libpulse-dev{,:i386} libasound-dev{,:i386} \
|
|
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libfreetype6-dev libpcap0.8-dev \
|
|
php-cli
|
|
|
|
if [[ "${MISSING}" != "" ]]; then
|
|
if (whiptail --title "${G_TITLE}" --yesno "Some required packages are missing.\n\nInstall them now?" 9 40); then
|
|
TEMP=" ${MISSING//[^ ]}"
|
|
TOTAL=${#TEMP}
|
|
COUNT=0
|
|
{
|
|
for PACKAGE in ${MISSING}; do
|
|
PERCENT=$(( 100*(++COUNT)/TOTAL ))
|
|
echo ${PERCENT}
|
|
apt-get -y install ${PACAKGE} >& /dev/null
|
|
done
|
|
} | whiptail --title "${G_TITLE}" --gauge "\nInstalling packages..." 7 50 0
|
|
else
|
|
tBoldBox tRED "Canceled!"
|
|
echo ""
|
|
echo "Installation cannot continue without the following pacakges:"
|
|
echo ""
|
|
echo ${MISSING}
|
|
echo ""
|
|
exit 1
|
|
fi
|
|
fi
|
|
SKIP
|
|
|
|
# Do we have JoeyLib yet?
|
|
if [[ ! -f ${G_PARENT}/joeylib/LICENSE ]]; then
|
|
echo ""
|
|
tBoldBox tBLUE "Downloading JoeyLib source..."
|
|
git clone https://skunkworks.kangaroopunch.com/skunkworks/joeylib.git ${G_PARENT}/joeylib >& /dev/null
|
|
fi
|
|
|
|
mainMenu
|
|
|
|
clear
|
|
tBoldBox tBLUE "Goodbye!"
|
|
echo ""
|
|
|
|
# --- EXIT
|
|
popd >& /dev/null
|