From 85039a60332f7e0941ea3f02dc2b411f84020281 Mon Sep 17 00:00:00 2001 From: krcroft Date: Mon, 28 Oct 2019 12:57:54 -0700 Subject: [PATCH] Simplify package listing script and standardize workflows The commit makes the following changes: - The package listing script now requires the user specify which package manager they're using. This approach resolves the ambiguity if a system has more than one package manager (ie: macports & brew) - Adds packages for Fedora, RedHat/CentOS, Arch, and OpenSuse - Eliminates unecessary code in the package manager script (more can be eliminate at the expense of complexity) - Made a couple minor fixes to the build script - Tried to further "standardize" the workflows as follows: - names are Compiler Version (Environment) - Sorted them alphabetically in their respective YAMLs - Minor spacing adjustment to align values (where it makes sense) - Dropped quotes around some of the string values because I'd rather our YAML be consistent and propper instead of changing our YAML to suite the limitations of an editor (can a different plugin or better parser be used?) - Added macOS workflows for Homebrew and MacPorts, both ready to go and tested, but with the build step just commented out --- .github/workflows/linux.yml | 48 ++-- .github/workflows/macos.yml | 61 ++++- .github/workflows/static.yml | 19 +- .github/workflows/windows.yml | 190 +++++++-------- .gitignore | 1 + Makefile.am | 1 + scripts/build.md | 124 ++++++---- scripts/build.sh | 178 ++++++-------- scripts/list-build-dependencies.sh | 375 +++++++++++------------------ 9 files changed, 458 insertions(+), 539 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 29bec371..09145730 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -1,48 +1,48 @@ -name: "Linux builds" +name: Linux builds on: push jobs: - build_ubuntu_gcc9: - name: "GCC 9 (ubuntu-18.04)" + build_ubuntu_clang_8: + name: Clang 8 (ubuntu-18.04) runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v1 - - name: "Log environment" - run: ./scripts/log-env.sh + - name: Log environment + run: ./scripts/log-env.sh - name: Install dependencies - run: sudo apt-get update && sudo apt install -y $(./scripts/list-build-dependencies.sh --compiler-version 9) + run: sudo apt-get update && sudo apt install -y $(./scripts/list-build-dependencies.sh -p apt --compiler clang --compiler-version 8) - name: Build - run: ./scripts/build.sh --compiler-version 9 --lto - - name: "Summarize warnings" - run: ./scripts/count-warnings.py build.log + run: ./scripts/build.sh --compiler clang --compiler-version 8 --lto + - name: Summarize warnings" + run: ./scripts/count-warnings.py build.log - build_ubuntu_gcc_defaults: - name: "GCC" + build_ubuntu_matrix_gcc: + name: GCC runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-18.04, ubuntu-16.04] steps: - uses: actions/checkout@v1 - - name: "Log environment" - run: ./scripts/log-env.sh + - name: Log environment + run: ./scripts/log-env.sh - name: Install dependencies - run: sudo apt-get update && sudo apt install -y $(./scripts/list-build-dependencies.sh) + run: sudo apt-get update && sudo apt install -y $(./scripts/list-build-dependencies.sh -p apt) - name: Build run: ./scripts/build.sh - - name: "Summarize warnings" - run: ./scripts/count-warnings.py build.log + - name: Summarize warnings + run: ./scripts/count-warnings.py build.log - build_ubuntu_clang_8: - name: "Clang 8 (ubuntu-18.04)" + build_ubuntu_gcc9: + name: GCC 9 (ubuntu-18.04) runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v1 - - name: "Log environment" - run: ./scripts/log-env.sh + - name: Log environment + run: ./scripts/log-env.sh - name: Install dependencies - run: sudo apt-get update && sudo apt install -y $(./scripts/list-build-dependencies.sh --compiler clang --compiler-version 8) + run: sudo apt-get update && sudo apt install -y $(./scripts/list-build-dependencies.sh -p apt --compiler-version 9) - name: Build - run: ./scripts/build.sh --compiler clang --compiler-version 8 --lto - - name: "Summarize warnings" - run: ./scripts/count-warnings.py build.log + run: ./scripts/build.sh --compiler-version 9 --lto + - name: Summarize warnings + run: ./scripts/count-warnings.py build.log diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index f4ce4cfb..5c617543 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -1,16 +1,59 @@ -name: "macOS builds" +name: macOS builds on: push jobs: - build_macos_clang: - name: "Clang (macOS-10.14)" + build_macos_xcode_clang: + name: Clang 10 (Xcode) runs-on: macOS-10.14 steps: - uses: actions/checkout@v1 - - name: "Log environment" - run: ./scripts/log-env.sh + - name: Log environment + run: ./scripts/log-env.sh - name: Install dependencies - run: brew install $(./scripts/list-build-dependencies.sh --compiler clang) + run: brew install $(./scripts/list-build-dependencies.sh -p brew --compiler clang) - name: Build - run: ./scripts/build.sh --compiler clang --lto - - name: "Summarize warnings" - run: python3 ./scripts/count-warnings.py build.log + run: ./scripts/build.sh --compiler clang --lto + - name: Summarize warnings + run: python3 ./scripts/count-warnings.py build.log + + +# build_macos_brew_gcc9: +# name: GCC 9 (Homebrew) +# runs-on: macOS-10.14 +# steps: +# - uses: actions/checkout@v1 +# - name: Log environment +# run: ./scripts/log-env.sh +# - name: Install dependencies +# run: brew install $(./scripts/list-build-dependencies.sh -p brew --compiler-version 9) +# - name: Build +# run: echo ./scripts/build.sh --compiler-version 9 --lto +# - name: Summarize warnings +# run: echo python3 ./scripts/count-warnings.py build.log + + +# build_macos_macports_gcc9: +# name: GCC 9 (MacPorts) +# runs-on: macOS-10.14 +# steps: +# - uses: actions/checkout@v1 +# - name: Install MacPorts +# run: | +# # xcode-select --install || true +# # sudo xcodebuild -license || true +# git clone --quiet --depth=1 https://github.com/macports/macports-base.git +# cd macports-base +# ./configure +# make -j"$(sysctl -n hw.physicalcpu || echo 4)" +# sudo make install +# +# - name: Install dependencies +# run: | +# PATH="/opt/local/sbin:/opt/local/bin:${PATH}" +# sudo port -q selfupdate || true +# sudo port -q install $(./scripts/list-build-dependencies.sh -p macports --compiler-version 9) +# +# - name: Build +# run: echo ./scripts/build.sh --compiler-version mp-9 --bin-path /opt/local/bin +# - name: Summarize warnings +# run: echo python3 ./scripts/count-warnings.py build.log + diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 7817b808..c96bed5e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -3,19 +3,18 @@ name: Static code analysis on: [push] jobs: - build_clang_static_analyser: - name: "Clang static analyzer" + name: Clang static analyzer runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v1 - - name: "Log environment" - run: ./scripts/log-env.sh - - run: sudo apt update - - name: "Install packages" - run: sudo apt-get install libsdl1.2-dev libsdl-net1.2-dev libsdl-sound1.2-dev python3-setuptools - - name: "Install scan-build (Python version)" - run: sudo pip3 install scan-build beautifulsoup4 html5lib + - name: Log environment + run: ./scripts/log-env.sh + - run: sudo apt update + - name: Install packages + run: sudo apt-get install libsdl1.2-dev libsdl-net1.2-dev libsdl-sound1.2-dev python3-setuptools + - name: Install scan-build (Python version) + run: sudo pip3 install scan-build beautifulsoup4 html5lib - name: Build run: | # build steps @@ -25,7 +24,7 @@ jobs: ./configure intercept-build make -j "$(nproc)" - name: Analyze - run: analyze-build -v -o report --html-title="dosbox-staging (${GITHUB_SHA:0:8})" + run: analyze-build -v -o report --html-title="dosbox-staging (${GITHUB_SHA:0:8})" - uses: actions/upload-artifact@master with: name: report diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 22b43802..5f923104 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,23 +1,96 @@ # SPDX-License-Identifier: GPL-2.0-or-later -name: "Windows builds" +name: Windows builds on: push jobs: - build_msvc_debug: - name: "MSVC 14 Debug (win-2019)" + build_msys2_clang_32: + name: Clang 8 i686 (MSYS2) runs-on: windows-2019 + env: + CHERE_INVOKING: yes steps: - uses: actions/checkout@v1 - - name: "Log environment" + - name: Install msys2 environment + run: choco install msys2 --no-progress + - name: Log environment + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/log-env.sh" + - name: Install dependencies + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/list-build-dependencies.sh -p msys2 --compiler clang --bit-depth 32 | xargs pacman -S --noconfirm" + - name: Build + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/build.sh --compiler clang --bit-depth 32 --bin-path /mingw32/bin" + - name: Summarize warnings + run: .\scripts\count-warnings.py build.log + + build_msys2_clang_64: + name: Clang 8 x86_64 (MSYS2) + runs-on: windows-2019 + env: + CHERE_INVOKING: yes + steps: + - uses: actions/checkout@v1 + - name: Install msys2 environment + run: choco install msys2 --no-progress + - name: Log environment + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/log-env.sh" + - name: Install dependencies + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/list-build-dependencies.sh -p msys2 --compiler clang | xargs pacman -S --noconfirm" + - name: Build + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/build.sh --compiler clang --bin-path /mingw64/bin" + - name: Summarize warnings + run: .\scripts\count-warnings.py build.log + + build_msys2_gcc_32: + name: GCC 9 i686 (MSYS2) + runs-on: windows-2019 + env: + CHERE_INVOKING: yes + steps: + - uses: actions/checkout@v1 + - name: Install msys2 environment + run: choco install msys2 --no-progress + - name: Log environment + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/log-env.sh" + - name: Install dependencies + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/list-build-dependencies.sh -p msys2 --bit-depth 32 | xargs pacman -S --noconfirm" + - name: Build + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/build.sh --bit-depth 32 --bin-path /mingw32/bin" + - name: Summarize warnings + run: .\scripts\count-warnings.py build.log + + + build_msys2_gcc_64: + name: GCC 9 x86_64 (MSYS2) + runs-on: windows-2019 + env: + CHERE_INVOKING: yes + steps: + - uses: actions/checkout@v1 + - name: Install msys2 environment + run: choco install msys2 --no-progress + - name: Log environment + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/log-env.sh" + - name: Install dependencies + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/list-build-dependencies.sh -p msys2 | xargs pacman -S --noconfirm" + - name: Build + run: C:\tools\msys64\usr\bin\bash -lc "./scripts/build.sh --bin-path /mingw64/bin" + - name: Summarize warnings + run: .\scripts\count-warnings.py build.log + + build_msvc_debug: + name: MSVC Debug x86 (win-2019) + runs-on: windows-2019 + steps: + - uses: actions/checkout@v1 + - name: Log environment shell: pwsh - run: .\scripts\log-env.ps1 - - name: "Install packages" + run: .\scripts\log-env.ps1 + - name: Install packages shell: pwsh run: | vcpkg install libpng sdl1 sdl1-net vcpkg integrate install - - name: "Build" + - name: Build shell: pwsh env: PATH: '${env:PATH};C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\amd64' @@ -26,21 +99,20 @@ jobs: cd visualc_net MSBuild -m dosbox.sln -p:Configuration=Debug - build_msvc_release: - name: "MSVC 14 Release (win-2019)" + name: MSVC Release x86 (win-2019) runs-on: windows-2019 steps: - - uses: actions/checkout@v1 - - name: "Log environment" + - uses: actions/checkout@v1 + - name: Log environment shell: pwsh - run: .\scripts\log-env.ps1 - - name: "Install packages" + run: .\scripts\log-env.ps1 + - name: Install packages shell: pwsh run: | vcpkg install libpng sdl1 sdl1-net vcpkg integrate install - - name: "Build" + - name: Build shell: pwsh env: PATH: '${env:PATH};C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\amd64' @@ -50,93 +122,3 @@ jobs: MSBuild -m dosbox.sln -p:Configuration=Release - build_msys2_gcc_64: - name: MSYS2 GCC-9 x86_64 - runs-on: windows-2019 - env: - CHERE_INVOKING: yes - steps: - - uses: actions/checkout@v1 - - name: Install msys2 environment - run: choco install msys2 --no-progress - - - name: "Log environment" - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/log-env.sh" - - - name: Install dependencies - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/list-build-dependencies.sh | xargs pacman -S --noconfirm" - - - name: Build - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/build.sh --bin-path /mingw64/bin" - - - name: Summarize warnings - run: .\scripts\count-warnings.py build.log - - - build_msys2_gcc_32: - name: MSYS2 GCC-9 i686 - runs-on: windows-2019 - env: - CHERE_INVOKING: yes - steps: - - uses: actions/checkout@v1 - - name: Install msys2 environment - run: choco install msys2 --no-progress - - - name: "Log environment" - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/log-env.sh" - - - name: Install dependencies - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/list-build-dependencies.sh --bit-depth 32 | xargs pacman -S --noconfirm" - - - name: Build - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/build.sh --bit-depth 32 --bin-path /mingw32/bin" - - - name: Summarize warnings - run: .\scripts\count-warnings.py build.log - - - build_msys2_clang_64: - name: MSYS2 Clang-8 x86_64 - runs-on: windows-2019 - env: - CHERE_INVOKING: yes - steps: - - uses: actions/checkout@v1 - - name: Install msys2 environment - run: choco install msys2 --no-progress - - - name: "Log environment" - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/log-env.sh" - - - name: Install dependencies - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/list-build-dependencies.sh --compiler clang | xargs pacman -S --noconfirm" - - - name: Build - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/build.sh --compiler clang --bin-path /mingw64/bin" - - - name: Summarize warnings - run: .\scripts\count-warnings.py build.log - - - build_msys2_clang_32: - name: MSYS2 Clang-8 i686 - runs-on: windows-2019 - env: - CHERE_INVOKING: yes - steps: - - uses: actions/checkout@v1 - - name: Install msys2 environment - run: choco install msys2 --no-progress - - - name: "Log environment" - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/log-env.sh" - - - name: Install dependencies - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/list-build-dependencies.sh --compiler clang --bit-depth 32 | xargs pacman -S --noconfirm" - - - name: Build - run: C:\tools\msys64\usr\bin\bash -lc "./scripts/build.sh --compiler clang --bit-depth 32 --bin-path /mingw32/bin" - - - name: Summarize warnings - run: .\scripts\count-warnings.py build.log diff --git a/.gitignore b/.gitignore index eba0f52d..8357aa23 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ aclocal.m4 autom4te.cache config.h config.h.in +config.h.in~ config.log config.status config.guess diff --git a/Makefile.am b/Makefile.am index dee57177..b8408129 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,6 +21,7 @@ distclean-local: -rm compile -rm config.guess -rm config.h.in + -rm config.h.in~ -rm config.log -rm config.sub -rm configure diff --git a/scripts/build.md b/scripts/build.md index 6749915f..c2b85d73 100644 --- a/scripts/build.md +++ b/scripts/build.md @@ -1,33 +1,30 @@ -# DOSBox build script +# DOSBox Build Script -A helper-script that builds DOSBox with varying compilers, release types, and versions -on MacOS, Linux, and Windows. +A script that builds DOSBox with your choice of compiler, release types, and +additional optimization options on MacOS, Linux, and Windows. -A second script, **list-build-dependencies.sh** prints a list of package and library -dependencies used to build and link DOSBox, customized for your hardware, operating system, -and selected compiler and its version. You can use this script's output to install -those necessary packages. +If this is the first time you are attempting to build DOSBox, then you need to +first install the development tools and DOSBox's development packages prior to +building. To help in this regard, the **list-build-dependencies.sh** script +prints a list of packages that you can use to install these dependencies. + +Use of both scripts is described below. ## Requirements - **Windows newer than XP** - **NTFS-based C:**, because msys2 doesn't work on FAT filesystems - - **Chocolately**, to install msys2 - - **MacOS** 10.x - - **brew**, as the package manager - - **Ubuntu** 16.04 or newer - - **apt**, as the package manager - - **sudo**, to permit installation of depedencies (optional) - -- **Build dependencies (all operating systems)** - - Per those listed by the accompanying list-build-dependencies.sh script +- **Fedora** up-to-date +- **RedHat or CentOS** 7 or newer +- **Arch-based distribution** up-to-date +- **OpenSUSE Leap** 15 or newer ## Windows Installation and Usage 1. Download and install Chocolatey: https://chocolatey.org/install -1. Open a console and run Cholocatey's command line interface (CLI) to install msys2: +1. Open a console and run Cholocatey's command line interface (CLI) to install msys2 and git: `choco install msys2 git --no-progress` ``` @@ -47,48 +44,82 @@ those necessary packages. PATH environment variable does not have C:\tools\msys64 in it. Adding... ``` -1. Open a new console and clone the DOSBox staging repository: - `git clone https://github.com/dreamer/dosbox-staging.git` +1. Launch a new MSYS2 terminal (not a CMD prompt or Powershell window): + 1. Start Menu > Run ... `c:\tools\msys64\msys2_shell.cmd` + 1. Run all subsequent steps within this terminal. -1. [optional] Install the build tools and package dependencies, if not yet done so: - ``` shell - cd dosbox-staging - SET CWD=%cd% - bash -lc "pacman -S --noconfirm $($CWD/scripts/list-build-dependencies.sh)" - ``` +1. Clone and enter the repository's directory: + 1. `git clone https://github.com/dreamer/dosbox-staging.git` + 1. `cd dosbox-staging` + 1. Run all subsequent steps while residing in the repo's directory. + +1. (🏁 first-time-only) Install the build tools and package dependencies: + `./scripts/list-build-dependencies.sh -p msys2 | xargs pacman -S --noconfirm` + +1. Launch the build script with default settings: + `./scripts/build.sh --bin-path /mingw64/bin` -1. Launch the build script with default settings: - ``` shell - cd dosbox-staging - SET CWD=%cd% - bash -lc "$CWD/scripts/build.sh --bin-path /mingw64/bin --src-path $CWD" - ``` ## MacOS Installation and Usage -1. Download and install brew: https://brew.sh -1. Install git: `brew install git` +Builds on Mac can be performed with Clang or GCC. + +If you only plan on only building with Clang, then follow the Brew installation steps. +If you're interested in building with GCC, then either Brew or MacPorts will work. +Both can be installed without conflicting with eachother. + +Before installing either, the Xcode tools need to be installed and the license agreed to: + +### Xcode Installation +1. Install the command line tools: `xcode-select --install` +1. Accept the license agreement: `sudo xcodebuild -license` + + +### Brew Installation +1. Download and install brew per the instructions here: https://brew.sh +1. Update it with: `brew update` +1. Install git with: `brew install git` +1. Install DOSBox dependencies: `brew install $(./scripts/list-build-dependencies.sh -p brew)` + + +### MacPorts Installation + +1. Build and install MacPorts along with DOSBox dependencies with the following sequence: + + ``` shell + git clone --quiet --depth=1 https://github.com/macports/macports-base.git + cd macports-base + ./configure + make -j"$(sysctl -n hw.physicalcpu || echo 4)" + sudo make install + PREFIX="/opt/local" + PATH="${PREFIX}/sbin:${PREFIX}/bin:${PATH}" + sudo port -q selfupdate + sudo port -q install $(/scripts/list-build-dependencies.sh -p macports) + ``` + +### Build DOSBox (common for all of the above) + 1. Clone the repository: `git clone https://github.com/dreamer/dosbox-staging.git` 1. Change directories into the repo: `cd dosbox-staging` -1. [optional] Install the build tools and package dependencies, if not yet done so: - ``` shell - brew update - brew install $(./scripts/list-build-dependencies.sh) - ``` -1. Build DOSBox: `./scripts/build.sh` +1. Build DOSBox: + - Clang: `./scripts/build.sh --compiler clang --bin-path /usr/local/bin` + - GCC (brew): `./scripts/build.sh --compiler-version 9 --bin-path /usr/local/bin` + - GCC (macports): `./scripts/build.sh --compiler-version mp-9 --bin-path /opt/local/bin` -## Linux (Ubuntu/Debian-based) Installation and Usage +## Linux Installation + +1. (🏁 first-time-only) Install dependencies based on your package manager; apt in this example: + `sudo apt install -y $(./scripts/list-build-dependencies.sh -p apt)` + For other supported package managers, run: + `./scripts/list-build-dependencies.sh --help` 1. Install git: `sudo apt install -y git` 1. Clone the repository: `git clone https://github.com/dreamer/dosbox-staging.git` 1. Change directories into the repo: `cd dosbox-staging` -1. [optional] Install the build tools and package dependencies, if not yet done so: - ``` shell - sudo apt update -y - sudo apt install -y $(./scripts/list-build-dependencies.sh) - ``` 1. Build DOSBox: `./scripts/build.sh` + ## Additional Tips The compiler, version, and bit-depth can be selected by passing the following common @@ -97,7 +128,7 @@ options to the **list-build-dependencies.sh** and **build.sh** scripts: * `--compiler-version 8`, to use a specific version of compiler (if available in your package manager) * `--bit-depth 32`, to build a 32-bit binary instead of 64-bit -After building, your binary will reside inside the src/ directory. +After building, your `dosbox` or `dosbox.exe` binary will reside inside `./dosbox-staging/src/`. Build flags you might be interested in: * `--release debug`, to build a binary containing debug symbols (instead of **fast** or **small**) @@ -107,4 +138,3 @@ The above flags are othogonal and thus can be mixed-and-matched as desired. If you want to run multiple back-to-back builds from the same directory with different settings then add the `--clean` flag to ensure previous objects and binaries are removed. - diff --git a/scripts/build.sh b/scripts/build.sh index 7dc6e4db..e0045115 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -21,32 +21,33 @@ # set -euo pipefail -IFS=$'\n\t' +readonly INVOCATION="${0}" +readonly IFS=$'\n\t' function usage() { if [ -n "${1}" ]; then errcho "${1}" fi local script - script=$(basename "${0}") - echo "Usage: ${script} [-b 32|64] [-c gcc|clang] [-f linux|macos|msys2] [-d] [-l] \\" - echo " [-p /custom/bin] [-u #] [-r fast|small|debug] [-s /your/src] [-t #]" + script=$(basename "${INVOCATION}") + echo "Usage: ${script} [-b 32|64] [-c gcc|clang] [-f linux|macos|msys2] [-d] [-l]" + echo " [-p /custom/bin] [-u #] [-r fast|small|debug] [-s /your/src] [-t #]" echo "" - echo " FLAG Description Default" - echo " ----------------------- ----------------------------------------------------- -------" - echo " -b, --bit-depth Build a 64 or 32 bit binary [$(print_var "${BITS}")]" - echo " -c, --compiler Choose either gcc or clang [$(print_var "${COMPILER}")]" - echo " -f, --force-system Force the system to be linux, macos, or msys2 [$(print_var "${SYSTEM}")]" - echo " -d, --fdo Used feedback-Directed Optimization data [$(print_var "${FDO}")]" - echo " -l, --lto Perform link-time-optimization [$(print_var "${LTO}")]" - echo " -p, --bin-path Prepend PATH with the one provided to find executables [$(print_var "${BIN_PATH}")]" - echo " -u, --compiler-version # Use a specific compiler version (ie: 9 -> gcc-9) [$(print_var "${COMPILER_VERSION}")]" - echo " -r, --release Build a fast, small, or debug release [$(print_var "${RELEASE}")]" - echo " -s, --src-path Use a different source directory to build [$(print_var "${SRC_PATH}")]" - echo " -t, --threads # Override auto-detection of number of logical CPUs [$(print_var "${THREADS}")]" - echo " -v, --version Print the version of this script [$(print_var "${SCRIPT_VERSION}")]" - echo " -x, --clean Clean old object and build file before making [$(print_var "${CLEAN}")]" - echo " -h, --help Print this usage text" + echo " FLAG Description Default" + echo " ----------------------- ----------------------------------------------------- -------" + echo " -b, --bit-depth Build a 64 or 32 bit binary [$(print_var "${BITS}")]" + echo " -c, --compiler Choose either gcc or clang [$(print_var "${COMPILER}")]" + echo " -f, --force-system Force the system to be linux, macos, or msys2 [$(print_var "${SYSTEM}")]" + echo " -d, --fdo Use Feedback-Directed Optimization (FDO) data [$(print_var "${FDO}")]" + echo " -l, --lto Perform Link-Time-Optimizations (LTO) [$(print_var "${LTO}")]" + echo " -p, --bin-path Prepend PATH with the one provided to find executables [$(print_var "${BIN_PATH}")]" + echo " -u, --compiler-version Customize the compiler postfix (ie: 9 -> gcc-9) [$(print_var "${COMPILER_VERSION}")]" + echo " -r, --release Build a fast, small, or debug release [$(print_var "${RELEASE}")]" + echo " -s, --src-path Enter a different source directory before building [$(print_var "${SRC_PATH}")]" + echo " -t, --threads Override the number of threads with which to compile [$(print_var "${THREADS}")]" + echo " -v, --version Print the version of this script [$(print_var "${SCRIPT_VERSION}")]" + echo " -x, --clean Clean old objects prior to building [$(print_var "${CLEAN}")]" + echo " -h, --help Print this usage text" echo "" echo "Example: ${script} -b 32 --compiler clang -u 8 --bin-path /mingw64/bin -r small --lto" echo "" @@ -54,9 +55,8 @@ function usage() { exit 1 } -# parse params function parse_args() { - defaults + set_defaults while [[ "${#}" -gt 0 ]]; do case ${1} in -b|--bit-depth) BITS="${2}"; shift;shift;; -c|--compiler) COMPILER="${2}"; shift;shift;; @@ -75,7 +75,7 @@ function parse_args() { esac; done } -function defaults() { +function set_defaults() { # variables that are directly set via user arguments BITS="64" CLEAN="false" @@ -85,7 +85,7 @@ function defaults() { LTO="false" BIN_PATH="unset" RELEASE="fast" - SRC_PATH="$(dirname "$(dirname "$(realpath -s "$0")")")" + SRC_PATH="unset" SYSTEM="auto" THREADS="auto" @@ -100,7 +100,7 @@ function defaults() { CALL_CACHE=("") # read-only strings - readonly SCRIPT_VERSION="0.9" + readonly SCRIPT_VERSION="1.0" readonly REPO_URL="https://github.com/dreamer/dosbox-staging" # environment variables passed onto the build @@ -149,20 +149,32 @@ function print_var() { fi } +## +# Uses +# ---- +# Alows function to indicate which other functions they depend on. +# For example: "uses system" indicates a function needs the system +# to be defined prior to running. +# This uses function acts like a call cache, ensuring each used function +# is only actually called once. This allows all functions to thoroughly +# employ the 'uses' mechanism without the performance-hit of repeatedly +# executing the same function. Likely, functions that are 'used' are +# atomic in that they will only be called once per script invocation. +# function uses() { # assert if [[ "${#}" != 1 ]]; then bug "The 'uses' function was called without an argument" fi - # only handles function calls, so filter everything else + # only operate on functions in our call-scope, otherwise fail hard func="${1}" if [[ "$(type -t "${func}")" != "function" ]]; then bug "The 'uses' function was passed ${func}, which isn't a function" fi + # Check the call cache to see if the function has already been called local found_in_previous="false" - # has our function already been called? for previous_func in "${CALL_CACHE[@]}"; do if [[ "${previous_func}" == "${func}" ]]; then found_in_previous="true" @@ -170,7 +182,7 @@ function uses() { fi done - # if it hasn't, record it and run it + # if it hasn't been called then record it and run it if [[ "${found_in_previous}" == "false" ]]; then CALL_CACHE+=("${func}") "${func}" @@ -184,28 +196,14 @@ function print_version() { } function system() { - if [[ "${MACHINE}" == "unset" ]]; then - MACHINE="$(uname -m)" - fi - - if [[ "${SYSTEM}" == "auto" ]]; then - SYSTEM="$(uname -s)" - fi - if [[ "${SYSTEM}" == "Darwin" \ - || "${SYSTEM}" == "macos" ]]; then - SYSTEM="macos" - - elif [[ "${SYSTEM}" == "MSYS"* \ - || "${SYSTEM}" == "msys2" ]]; then - SYSTEM="msys2" - - elif [[ "${SYSTEM}" == "Linux" \ - || "${SYSTEM}" == "linux" ]]; then - SYSTEM="linux" - - else - error "Your system, ${SYSTEM}, is not currently supported" - fi + if [[ "${MACHINE}" == "unset" ]]; then MACHINE="$(uname -m)"; fi + if [[ "${SYSTEM}" == "auto" ]]; then SYSTEM="$(uname -s)"; fi + case "$SYSTEM" in + Darwin|macos) SYSTEM="macos" ;; + MSYS*|msys2) SYSTEM="msys2" ;; + Linux|linux) SYSTEM="linux" ;; + *) error "Your system, $SYSTEM, is not currently supported" ;; + esac } function bits() { @@ -234,14 +232,9 @@ function tools_and_flags() { # Prioritize versioned lib-tools over generics AR="gcc-ar${VERSION_POSTFIX}" - if ! exists "${AR}"; then - AR="ar" - fi - RANLIB="gcc-ranlib${VERSION_POSTFIX}" - if ! exists "${RANLIB}"; then - RANLIB="ranlib" - fi + if ! exists "${AR}"; then AR="ar"; fi + if ! exists "${RANLIB}"; then RANLIB="ranlib"; fi # CLANG universal elif [[ "${COMPILER}" == "clang" ]]; then @@ -256,14 +249,10 @@ function tools_and_flags() { RANLIB="llvm-ranlib${VERSION_POSTFIX}" # CLANG on MacOS - elif [[ "${SYSTEM}" == "macos" ]]; then - LD="ld" - fi + elif [[ "${SYSTEM}" == "macos" ]]; then LD="ld"; fi # CLANG and MSYS2 - if [[ "${SYSTEM}" == "msys2" ]]; then - CFLAGS_ARRAY+=("-DWIN32") - fi + if [[ "${SYSTEM}" == "msys2" ]]; then CFLAGS_ARRAY+=("-DWIN32"); fi fi # macOS universal @@ -278,7 +267,9 @@ function tools_and_flags() { } function src_path() { - if [[ ! -d "${SRC_PATH}" ]]; then + if [[ "${SRC_PATH}" == "unset" ]]; then + SRC_PATH="$(cd "$(dirname "${INVOCATION}")" && cd .. && pwd -P)" + elif [[ ! -d "${SRC_PATH}" ]]; then usage "The requested source directory (${SRC_PATH}) does not exist, is not a directory, or is not accessible" fi cd "${SRC_PATH}" @@ -321,8 +312,7 @@ function compiler_version() { function release_flags() { uses compiler_type - if [[ "${RELEASE}" == "fast" ]]; then - CFLAGS_ARRAY+=("-Ofast") + if [[ "${RELEASE}" == "fast" ]]; then CFLAGS_ARRAY+=("-Ofast") elif [[ "${RELEASE}" == "small" ]]; then CFLAGS_ARRAY+=("-Os") if [[ "${COMPILER}" == "gcc" ]]; then @@ -330,36 +320,20 @@ function release_flags() { # ld on MacOS doesn't understand --as-needed, so exclude it uses system - if [[ "${SYSTEM}" != "macos" ]]; then - LDFLAGS_ARRAY+=("-Wl,--as-needed") - fi + if [[ "${SYSTEM}" != "macos" ]]; then LDFLAGS_ARRAY+=("-Wl,--as-needed"); fi fi - elif [[ "${RELEASE}" == "debug" ]]; then - CFLAGS_ARRAY+=("-g" "-O1") - else - usage "The release type of ${RELEASE} is not allowed. Choose fast, small, or debug" + elif [[ "${RELEASE}" == "debug" ]]; then CFLAGS_ARRAY+=("-g" "-O1") + else usage "The release type of ${RELEASE} is not allowed. Choose fast, small, or debug" fi } function threads() { - uses system - - if [[ "${THREADS}" != "auto" ]]; then - if [[ "${THREADS}" -lt 1 || "${THREADS}" -gt 256 ]]; then - usage "The number of threads, ${THREADS}, needs to be between 1 and 256, or don't set it at all" - fi - else - if [[ -n "${NUMBER_OF_PROCESSORS:-}" && "${NUMBER_OF_PROCESSORS}" -gt 0 ]]; then - THREADS="${NUMBER_OF_PROCESSORS}" - elif [[ "${SYSTEM}" == "macos" ]]; then - THREADS="$(sysctl -n hw.physicalcpu || echo 4)" - elif exists nproc; then - THREADS="$(nproc)" - else - THREADS=4 # if auto-detection fails fallback to a reasonable - # number of logical CPUs for 2019 - fi + if [[ "${THREADS}" == "auto" ]]; then + if exists nproc; then THREADS="$(nproc)" + else THREADS="$(sysctl -n hw.physicalcpu || echo 4)"; fi fi + # make presents a descriptive error message in the scenario where the user overrides + # THREADS with an illegal value: the '-j' option requires a positive integer argument. } function fdo_flags() { @@ -368,13 +342,13 @@ function fdo_flags() { fi uses compiler_type + uses src_path local fdo_file="${SRC_PATH}/scripts/profile-data/${COMPILER}.profile" if [[ ! -f "${fdo_file}" ]]; then error "The Feedback-Directed Optimization file provided (${fdo_file}) does not exist or could not be accessed" fi if [[ "${COMPILER}" == "gcc" ]]; then - # Don't let GCC 6.x and under use both FDO and LTO uses compiler_version if [[ ( "${COMPILER_VERSION}" == "unset" @@ -384,6 +358,7 @@ function fdo_flags() { error "GCC versions 6 and under cannot handle FDO and LTO simultaneously; please change one or more these." fi CFLAGS_ARRAY+=("-fauto-profile=${fdo_file}") + elif [[ "${COMPILER}" == "clang" ]]; then CFLAGS_ARRAY+=("-fprofile-sample-use=${fdo_file}") fi @@ -463,14 +438,9 @@ function do_configure() { LDFLAGS=$( printf "%s " "${LDFLAGS_ARRAY[@]}") local lto_string="" - if [[ "${LTO}" == "true" ]]; then - lto_string="-LTO" - fi - local fdo_string="" - if [[ "${FDO}" == "true" ]]; then - fdo_string="-FDO" - fi + if [[ "${LTO}" == "true" ]]; then lto_string="-LTO"; fi + if [[ "${FDO}" == "true" ]]; then fdo_string="-FDO"; fi echo "" echo "Launching with:" @@ -503,10 +473,8 @@ function do_configure() { function executable() { uses src_path EXECUTABLE="src/" - if [[ "${SYSTEM}" == "msys2" ]]; then - EXECUTABLE+="dosbox.exe" - else - EXECUTABLE+="dosbox" + if [[ "${SYSTEM}" == "msys2" ]]; then EXECUTABLE+="dosbox.exe" + else EXECUTABLE+="dosbox" fi if [[ ! -f "${EXECUTABLE}" ]]; then @@ -542,15 +510,11 @@ function show_binary() { uses system uses executable - if [[ "$SYSTEM" == "macos" ]]; then - otool -L "${EXECUTABLE}" - else - ldd "${EXECUTABLE}" - fi + if [[ "$SYSTEM" == "macos" ]]; then otool -L "${EXECUTABLE}" + else ldd "${EXECUTABLE}"; fi ls -1lh "${EXECUTABLE}" } - function main() { parse_args "$@" build diff --git a/scripts/list-build-dependencies.sh b/scripts/list-build-dependencies.sh index cc5fe0d4..66d9b086 100755 --- a/scripts/list-build-dependencies.sh +++ b/scripts/list-build-dependencies.sh @@ -4,15 +4,15 @@ # Copyright (c) 2019 Kevin R. Croft # SPDX-License-Identifier: GPL-2.0-or-later # -# This script lists DOSBox package dependencies as determined by the runtime -# architecture, operating system, and selected compiler type and and its version. +# This script lists development packages and DOSBox dependencies needed to build DOSBox. +# This package names provided are tailor based on the provided package manager, +# choice of compiler, and optionally its bit-depth. # -# See the usage block below for details or run it with the -h or --help arguments. +# See the usage arguments below for details or run it with the -h or --help. # # In general, this script adheres to Google's shell scripting style guide # (https://google.github.io/styleguide/shell.xml), however some deviations (such as -# tab indents instead of two-spaces) are used to fit with DOSBox's in-practice" -# coding style. +# tab indents instead of two-spaces) are used to fit DOSBox's in-practice coding style. # set -euo pipefail @@ -24,55 +24,59 @@ function usage() { fi local script script=$(basename "${0}") - echo "Usage: ${script} [-b 32|64] [-c gcc|clang] [-f linux|macos|msys2] [-o FILE] [-u #]" + echo "Usage: ${script} -p apt|xcode|brew|macports|msys2|vcpkg [-b 32|64] [-c gcc|clang] [-o FILE] [-u #]" echo "" - echo " FLAG Description Default" - echo " ----------------------- ----------------------------------------------------- -------" - echo " -b, --bit-depth Build a 64 or 32 bit binary [$(print_var "${BITS}")]" - echo " -c, --compiler Choose either gcc or clang [$(print_var "${COMPILER}")]" - echo " -f, --force-system Force the system to be linux, macos, or msys2 [$(print_var "${SYSTEM}")]" - echo " -o, --output-file Write the packages to a text file instead of stdout [$(print_var "${OUTPUT_FILE}")]" - echo " -u, --compiler-version # Use a specific compiler version (ie: 9 -> gcc-9) [$(print_var "${COMPILER_VERSION}")]" - echo " -v, --version Print the version of this script [$(print_var "${SCRIPT_VERSION}")]" - echo " -h, --help Print this usage text" + echo " FLAG Description Default" + echo " ----------------------- --------------------------------------------------- -------" + echo " -b, --bit-depth Choose either a 64 or 32 bit compiler [$(print_var "${BITS}")]" + echo " -c, --compiler Choose either gcc or clang [$(print_var "${COMPILER}")]" + echo " -u, --compiler-version <#> Customize the compiler version (if available) [$(print_var "${COMPILER_VERSION}")]" + echo " -v, --version Print the version of this script [$(print_var "${SCRIPT_VERSION}")]" + echo " -h, --help Print this usage text" + echo " -p, --package-manager Choose one of the following:" + echo " - apt (Linux: Debian, Ubuntu, Raspbian)" + echo " - dnf (Linux: Fedora, RedHat, CentOS)" + echo " - pacman (Linux: Arch, Manjaro)" + echo " - zypper (Linux: SuSE, OpenSUSE)" + echo " - xcode (OS X: Apple-supported)" + echo " - brew (OS X: Homebrew community-supported)" + echo " - macports (OS X: MacPorts community-supported)" + echo " - msys2 (Windows: Cygwin-based, community-support)" + echo " - vcpkg (Windows: Visual Studio builds)" + echo " ----------------------- --------------------------------------------------- -------" echo "" - echo "Example: ${script} --bit-depth 32 --compiler clang --compiler-version 8" + echo "Example: ${script} --package-manager apt --compiler clang --compiler-version 8" echo "" echo "Note: the last value will take precendent if duplicate flags are provided." exit 1 } +function defaults() { + BITS="64" + COMPILER="gcc" + COMPILER_VERSION="" + PACKAGE_MANAGER="unset" + readonly SCRIPT_VERSION="0.2" + readonly REPO_URL="https://github.com/dreamer/dosbox-staging" +} + # parse params function parse_args() { defaults while [[ "${#}" -gt 0 ]]; do case ${1} in - -b|--bit-depth) BITS="${2}"; shift;shift;; - -c|--compiler) COMPILER="${2}"; shift;shift;; - -f|--force-system) SYSTEM="${2}"; shift;shift;; - -o|--output-file) OUTPUT_FILE="${2}"; shift;shift;; - -u|--compiler-version) COMPILER_VERSION="${2}";shift;shift;; - -v|--version) print_version; shift;; - -h|--help) usage "Show usage"; shift;; + -b|--bit-depth) BITS="${2}"; shift;shift;; + -c|--compiler) COMPILER="${2}"; shift;shift;; + -p|--package-manager) PACKAGE_MANAGER="${2}"; shift;shift;; + -u|--compiler-version) COMPILER_VERSION="${2}"; shift;shift;; + -v|--version) print_version; shift;; + -h|--help) usage "Show usage"; shift;; *) usage "Unknown parameter: ${1}"; shift;shift;; esac; done -} -function defaults() { - # variables that are directly set via user arguments - BITS="64" - COMPILER="gcc" - COMPILER_VERSION="unset" - OUTPUT_FILE="unset" - SYSTEM="auto" - - # derived variables with initial values - VERSION_POSTFIX="" - MACHINE="unset" - CALL_CACHE=("") - - # read-only strings - readonly SCRIPT_VERSION="0.1" - readonly REPO_URL="https://github.com/dreamer/dosbox-staging" + # Check mandatory arguments + if [[ "${PACKAGE_MANAGER}" == "unset" ]]; then + usage "A choice of package manager must be provided; use '-p ' or '--package-manager '" + fi } function errcho() { @@ -81,18 +85,6 @@ function errcho() { >&2 echo "" >&2 echo -e " ${RED}👉 ${*}${CLEAR}" "\\n" } -function bug() { - local CLEAR='\033[0m' - local YELLOW='\033[0;33m' - >&2 echo -e " ${YELLOW}Please report the following at ${REPO_URL}${CLEAR}" - errcho "${@}" - exit 1 -} - -function error() { - errcho "${@}" - exit 1 -} function print_var() { if [[ -z "${1}" ]]; then @@ -102,197 +94,104 @@ function print_var() { fi } -function uses() { - # assert - if [[ "${#}" != 1 ]]; then - bug "The 'uses' function was called without an argument" - fi - - # only handles function calls, so filter everything else - func="${1}" - if [[ "$(type -t "${func}")" != "function" ]]; then - bug "The 'uses' function was passed ${func}, which isn't a function" - fi - - local found_in_previous="false" - # has our function already been called? - for previous_func in "${CALL_CACHE[@]}"; do - if [[ "${previous_func}" == "${func}" ]]; then - found_in_previous="true" - break - fi - done - - # if it hasn't, record it and run it - if [[ "${found_in_previous}" == "false" ]]; then - CALL_CACHE+=("${func}") - "${func}" - fi -} - - -function print_version() { - echo "${SCRIPT_VERSION}" - exit 0 -} - -function packages() { - # only proceed if the user wants to install packages - uses system - if [[ "${OUTPUT_FILE}" != "unset" ]]; then - "packages_for_${SYSTEM}" > "${OUTPUT_FILE}" - else - "packages_for_${SYSTEM}" - fi -} - -function packages_for_macos() { - - uses compiler_type - uses compiler_version - local compiler_package="" # for brew, the clang package doesn't exist, so stay empty in this case (?) - if [[ "${COMPILER}" == "gcc" ]]; then - compiler_package="gcc" - if [[ "${COMPILER_VERSION}" != "unset" ]]; then - compiler_package+="@${COMPILER_VERSION}" - fi - fi - - # Typical installation: - # - brew update - # - brew install - - local packages=( - "${compiler_package}" - coreutils - autogen - autoconf - automake - pkg-config - libpng - sdl - sdl_net - opusfile - speexdsp ) - echo "${packages[@]}" -} - -function packages_for_msys2() { - uses bits - local pkg_type="" - if [[ "${BITS}" == 64 ]]; then - pkg_type="x86_64" - else - pkg_type="i686" - fi - - uses compiler_type - uses compiler_version - local compiler_package="${COMPILER}" - compiler_package+="${VERSION_POSTFIX}" - - # Typical installation step: - # pacman -S --noconfirm - local packages=( - autogen - autoconf - base-devel - automake-wrapper - "mingw-w64-${pkg_type}-pkg-config" - "mingw-w64-${pkg_type}-${compiler_package}" - "mingw-w64-${pkg_type}-libtool" - "mingw-w64-${pkg_type}-libpng" - "mingw-w64-${pkg_type}-zlib" - "mingw-w64-${pkg_type}-SDL" - "mingw-w64-${pkg_type}-SDL_net" - "mingw-w64-${pkg_type}-opusfile" - "mingw-w64-${pkg_type}-speexdsp" ) - echo "${packages[@]}" -} - -function packages_for_linux() { - - # TODO: - # Convert this into an associative map between package - # managers and the list of respective package names. We - # should have coverage for the major distribution types, - # such as: - # - RPM-based (RHEL/CentOS, Fedora, and openSUSE) - # - Debian-based (Debian, Ubuntu, and Raspbian) - # - pacman-based (Arch and Manjero) - # - uses compiler_type - local compiler_package="" - if [[ "${COMPILER}" == "gcc" ]]; then - compiler_package="g++" - else - compiler_package="clang" - fi - - uses compiler_version - compiler_package+="${VERSION_POSTFIX}" - - # Typically install step - # sudo apt update -y - # sudo apt install -y - local packages=( - "${compiler_package}" - libtool - build-essential - libsdl1.2-dev - libsdl-net1.2-dev - libopusfile-dev - libspeexdsp-dev ) - echo "${packages[@]}" -} - -function system() { - if [[ "${MACHINE}" == "unset" ]]; then - MACHINE="$(uname -m)" - fi - - if [[ "${SYSTEM}" == "auto" ]]; then - SYSTEM="$(uname -s)" - fi - if [[ "${SYSTEM}" == "Darwin" \ - || "${SYSTEM}" == "macos" ]]; then - SYSTEM="macos" - - elif [[ "${SYSTEM}" == "MSYS"* \ - || "${SYSTEM}" == "msys2" \ - || "${SYSTEM}" == "MINGW"* ]]; then - SYSTEM="msys2" - - elif [[ "${SYSTEM}" == "Linux" \ - || "${SYSTEM}" == "linux" ]]; then - SYSTEM="linux" - - else - error "Your system, ${SYSTEM}, is not currently supported" - fi -} - -function bits() { - if [[ "${BITS}" != 64 && "${BITS}" != 32 ]]; then - usage "A bit-depth of ${BITS} is not allowed; choose 64 or 32" - fi -} - -function compiler_type() { - if [[ "${COMPILER}" != "gcc" && "${COMPILER}" != "clang" ]]; then - usage "The choice of compiler (${COMPILER}) is not valid; choose gcc or clang" - fi -} - -function compiler_version() { - if [[ "${COMPILER_VERSION}" != "unset" ]]; then - VERSION_POSTFIX="-${COMPILER_VERSION}" +function list_packages() { + VERSION_DELIM="" + case "$1" in + + apt) + # Apt separates GCC into the gcc and g++ pacakges, the latter which depends on the prior. + # Therefore, we provide g++ in-place of gcc. + VERSION_DELIM="-" + if [[ "${COMPILER}" == "gcc" ]]; then + COMPILER="g++" + fi + PACKAGES=(libtool build-essential libsdl1.2-dev libsdl-net1.2-dev libopusfile-dev libspeexdsp-dev) + ;; + + dnf) + VERSION_DELIM="-" + PACKAGES=(libtool SDL SDL_net-devel opusfile-devel speexdsp-devel) + ;; + + pacman) + # Arch offers 32-bit versions of SDL and speexDSP (but not others) + PACKAGES=(libtool sdl_net opusfile) + if [[ "${BITS}" == 32 ]]; then + PACKAGES+=(lib32-sdl lib32-speexdsp) + else + PACKAGES+=(sdl speexdsp) + fi + ;; + + zypper) + # OpenSUSE offers 32-bit versions of SDL, SDL_net, and speexDSP (but not others) + PACKAGES=(devel_basis libtool opusfile) + if [[ "${BITS}" == 32 ]]; then + PACKAGES+=(libSDL-devel-32bit libSDL_net-devel-32bit libspeexdsp1-32bit) + else + PACKAGES+=(SDL SDL_net speexdsp) + fi + ;; + + xcode) + # If the user doesn't want to use Homebrew or MacPorts, then they are limited to + # Apple's Clang plus the provided command line development tools provided by Xcode. + COMPILER="" + echo "Execute the following:" + echo " xcode-select --install # to install command line development tools" + echo " sudo xcodebuild -license # to accept Apple's license agreement" + echo "" + echo "Now download, build, and install the following manually to avoid using Homebrew or MacPorts:" + echo " - coreutils autogen autoconf automake pkg-config libpng sdl sdl_net opusfile speexdsp" + ;; + + brew) + # If the user wants Clang, we knock it out because it's provided provided out-of-the-box + VERSION_DELIM="@" + if [[ "${COMPILER}" == "clang" ]]; then + COMPILER="" + fi + PACKAGES=(coreutils autogen autoconf automake pkg-config libpng sdl sdl_net opusfile speexdsp) + ;; + + macports) + PACKAGES=(coreutils autogen automake autoconf pkgconfig libpng libsdl libsdl_net opusfile speexDSP) + ;; + + msys2) + # MSYS2 only supports the current latest releases of Clang and GCC, so we disable version customization + COMPILER_VERSION="" + local pkg_type + pkg_type="x86_64" + if [[ "${BITS}" == 32 ]]; then + pkg_type="i686" + fi + PACKAGES=(autogen autoconf base-devel automake-wrapper) + for pkg in pkg-config libtool libpng zlib SDL SDL_net opusfile speexdsp; do + PACKAGES+=("mingw-w64-${pkg_type}-${pkg}") + done + COMPILER="mingw-w64-${pkg_type}-${COMPILER}" + ;; + + vcpkg) + # VCPKG doesn't provide Clang or GCC, so we knock out the compiler and just give packages + COMPILER="" + PACKAGES=(libpng sdl1 sdl1-net opusfile speexdsp) + ;; + *) + usage "Unknown package manager ${1}" + ;; + esac + + if [[ -n "${COMPILER_VERSION}" && -n "${COMPILER}" ]]; then + COMPILER+="${VERSION_DELIM}${COMPILER_VERSION}" fi + echo "${COMPILER} ${PACKAGES[*]}" } function main() { parse_args "$@" - packages + list_packages "${PACKAGE_MANAGER}" } main "$@"