#!/bin/sh main() { cd "$(dirname $0)" while [ $# -gt 0 ]; do case "$1" in -h|--help|--usage) usage quit 0 ;; *) break ;; esac done if [ $# -gt 1 ]; then usage quit 1 fi target=$1 mktmp case "$(uname -s)" in Linux) linux_installdeps ;; Darwin) osx_installdeps ;; MINGW*|MSYS*) msys2_installdeps ;; *) error "Don't know how to install deps on your OS" ;; esac quit 0 } mktmp() { tmp="/tmp/installdeps_$$" mkdir "$tmp" || quit 1 chmod 700 "$tmp" 2>/dev/null trap "quit 1" PIPE HUP INT QUIT ILL TRAP KILL BUS TERM } quit() { [ -n "$tmp" ] && rm -rf "$tmp" 2>/dev/null exit ${1:-0} } usage() { cat <<'EOF' Usage: ./installdeps [TARGET] Try to install the dependencies needed for this project appropriately on the host OS. This program may require sudo. A cross-compile target may be specified as the only parameter, of either MinGW-w64-i686 or MinGW-w64-x86_64. This is only supported on Arch Linux and MSYS2. OPn MSYS2 dependencies are installed for both 32 and 64 bit native Windows targets by default, unless you specify one or the other. MSYS2 layer builds are not supported. -h, --help, --usage Show this help screen and exit. Examples: ./installdeps # install dependencies for a host build ./installdeps MinGW-w64-i686 # cross-compile for 32 bit windows (Arch Linux or MSYS2) ./installdeps MinGW-w64-x86_64 # cross-compile for 64 bit windows (Arch Linux or MSYS2) EOF } error() { printf '\nERROR: %s.\n\n' "$1" >&2 [ -z "$2" ] && quit 1 } warning() { printf '\nWARNING: %s.\n\n' "$1" >&2 } info_msg() { printf '\nINFO: %s.\n\n' "$1" >&2 } installing() { echo 'Installing deps....' echo } check() { "$@" if [ $? -ne 0 ]; then error 'command failed' NOQUIT printf '%s:\n' 'The failing command was' echo "$@" quit 1 fi } countdown() { secs=$1 echo while [ "$secs" -ne 0 ]; do printf '%s\r' "Starting in $secs seconds..." sleep 1 secs=$((secs-1)) done printf '\n\n' } linux_installdeps() { if [ -f /etc/debian_version ]; then debian_installdeps elif [ -f /etc/arch-release ]; then archlinux_installdeps else error "Don't know how to install deps on your version of Linux" fi } check_cross() { [ -z "$target" ] && return if [ -z "$arch_linux" -a -z "$msys2" ]; then error 'cross compiling targets are only supported on Arch Linux and MSYS2 at the moment' fi target=$(echo "$target" | tr 'A-Z' 'a-z') case "$target" in mingw-w64-x86_64) ;; mingw-w64-i686) ;; *) error "target must be one of 'MinGW-w64-i686' or 'MinGW-w64-x86_64'" ;; esac } debian_installdeps() { check_cross installing check sudo apt-get -y update check sudo apt-get -y install build-essential g++ zlib1g-dev libgl1-mesa-dev cmake libavcodec-dev libavformat-dev libswscale-dev libavutil-dev libgettextpo-dev libjpeg-dev libpng16-dev libtiff5-dev libsdl2-dev libsfml-dev libopenal-dev libwxgtk3.0-dev generic_build_instructions } archlinux_installdeps() { arch_linux=1 pacman='sudo pacman' command -v pacaur >/dev/null && pacman='pacaur --noedit' command -v yaourt >/dev/null && pacman='yaourt --aur --m-arg=--skipinteg' check_cross installing # check for gcc-multilib gcc_pkg=gcc if $pacman -Q gcc-multilib >/dev/null 2>&1; then gcc_pkg=gcc-multilib fi # update catalogs check $pacman -Sy if [ -z "$target" ]; then # native build check $pacman --noconfirm --needed -S base-devel "$gcc_pkg" nasm zlib mesa cairo cmake ffmpeg gettext libpng libtiff pkg-config sdl2 sfml openal wxgtk else # windows cross build case "$target" in *i686*) cmake_flags='-DCMAKE_TOOLCHAIN_FILE=../CMakeScripts/Toolchain-cross-MinGW-w64-i686.cmake -DENABLE_LINK=NO' ;; *x86_64*) cmake_flags='-DCMAKE_TOOLCHAIN_FILE=../CMakeScripts/Toolchain-cross-MinGW-w64-x86_64.cmake -DENABLE_LINK=NO' ;; *) # this will never be reached, it's checked in check_cross() error 'unknown cross target' ;; esac # base devel packages check $pacman --noconfirm --needed -S base-devel "$gcc_pkg" nasm cmake git # now install yaourt if we don't have it if ! command -v yaourt >/dev/null; then ( cd "$tmp" git clone https://aur.archlinux.org/package-query.git cd package-query makepkg --noconfirm -si cd .. git clone https://aur.archlinux.org/yaourt.git cd yaourt makepkg --noconfirm -si ) [ $? -ne 0 ] && error 'could not install yaourt' fi pacman='yaourt --aur --m-arg=--skipinteg' pkg_prefix='mingw-w64-' # cross toolchain (without headers and crt, we'll use -git versions) set -- for p in binutils gcc winpthreads; do set -- "$@" "${pkg_prefix}${p}" done check $pacman --noconfirm --needed -S "$@" # build library deps from AUR info_msg 'We will now build dependencies from AUR, this will take quite a while and has a high probability of failure. In fact, it is definitely broken at the time of this writing. Press CTRL-C now to abort' countdown 16 # pass appropriate make -jX flag through makepkg export MAKEPKG_CONF=${MAKEPKG_CONF:-/etc/makepkg.conf} grep -Ev '^[ ]*MAKEFLAGS=' "$MAKEPKG_CONF" > "$tmp/makepkg.conf" export MAKEFLAGS="-j$(($(cat /proc/cpuinfo | grep -E '^processor ' | wc -l)+1))" echo "MAKEFLAGS=\"$MAKEFLAGS\"" >> "$tmp/makepkg.conf" export MAKEPKG_CONF="$tmp/makepkg.conf" # now do the AUR builds # first we need -headers-git and -crt-git (unless the non-git packages are installed) for p in "${pkg_prefix}headers" "${pkg_prefix}crt"; do if ! $pacman -Q "$p" >/dev/null 2>&1; then check $pacman --noconfirm --needed -S "${p}-git" else warning "${pkg_prefix}headers-git and ${pkg_prefix}crt-git are recommended over the regular versions, if you have build failures try to install them" fi done # and the actual deps for p in zlib gettext libpng libtiff pkg-config sdl2 openal wxmsw; do pkg="${pkg_prefix}${p}" # check if already installed if ! $pacman -Q "$pkg" >/dev/null 2>&1; then set -- "$@" "${pkg_prefix}${p}" fi done [ $# -gt 0 ] && check $pacman --noconfirm --needed -S "$@" warning 'SFML is required for LINK support, the SFML package in AUR is currently broken, if you want LINK support you will need to install it manually' fi generic_build_instructions } msys2_installdeps() { msys2=1 check_cross installing # update catalogs check pacman -Sy set -- for p in SDL2 cairo ffmpeg openal sfml wxWidgets zlib binutils cmake crt-git extra-cmake-modules gcc gcc-libs gdb headers-git make pkg-config tools-git windows-default-manifest libmangle-git nasm; do if [ -n "$target" ]; then if ! pacman -Q "${target}-${p}" >/dev/null 2>&1; then set -- "$@" "${target}-${p}" fi else # install both 32 and 64 bit versions for p_ in "mingw-w64-x86_64-$p" "mingw-w64-i686-$p"; do if ! pacman -Q "$p_" >/dev/null 2>&1; then set -- "$@" "$p_" fi done fi done # install check pacman --noconfirm --needed -S git make zip "$@" check git submodule update --init --recursive cmake_flags="-G 'MSYS Makefiles'" generic_build_instructions } osx_installdeps() { if ! xcode-select -p >/dev/null 2>&1 && \ ! pkgutil --pkg-info=com.apple.pkg.CLTools_Executables >/dev/null 2>&1 && \ ! pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI >/dev/null 2>&1; then error 'Please install XCode and the XCode Command Line Tools, then run this script again. On newer systems this can be done with: xcode-select --install ' fi if command -v brew >/dev/null; then brew_installdeps elif command -v port >/dev/null; then macports_installdeps elif command -v fink >/dev/null; then fink_installdeps else error 'You have no package manager, please install homebrew, macports or fink' fi } brew_installdeps() { check_cross installing check brew -v update set -- for f in cairo cmake ffmpeg gettext jpeg libpng libtiff pkg-config sdl2 sfml wxmac; do if brew info "$f" | grep -Eq '^Not installed$'; then set -- "$@" "$f" fi done [ $# -gt 0 ] && check brew -v install "$@" brew -v cleanup generic_build_instructions } macports_installdeps() { check_cross installing check sudo port -v selfupdate check sudo port -v install cairo cmake ffmpeg gettext jpeg libpng tiff pkgconfig libsdl2 sfml wxWidgets-3.0 libiconv check sudo port select wxWidgets wxWidgets-3.0 generic_build_instructions } fink_installdeps() { check_cross installing check sudo fink -vy selfupdate check sudo fink -vy install cairo cmake ffmpeg libgettext8-dev libjpeg9 libpng16 libtiff5 pkgconfig sdl2 wxwidgets300-osxcocoa libiconv-dev warning 'SFML is required for LINK support, there is currently no SFML package for Fink, if you want LINK support you will need to install it manually' cmake_flags='-DENABLE_LINK=NO' generic_build_instructions } generic_build_instructions() { cat <