2021-11-23 16:11:43 +13:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-11-26 09:05:52 +13:00
|
|
|
set -e
|
2021-11-23 16:11:43 +13:00
|
|
|
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#
|
2022-09-10 18:04:16 -04:00
|
|
|
# Copyright (C) 2020-2022 Sherman Perry and the DOSBox Staging Team
|
2021-11-23 16:11:43 +13:00
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
printf "%s\n" "\
|
2021-11-26 17:04:53 +13:00
|
|
|
Usage: -p <platform> [-h -c <commit> -b <branch> -r <repo> -v <version> -f] BUILD_DIR PACKAGE_DIR
|
2021-11-23 16:11:43 +13:00
|
|
|
Where:
|
|
|
|
-h : Show this help message
|
2022-09-10 18:04:16 -04:00
|
|
|
-p : Build platform. Can be one of linux, macos, msys2, msvc
|
2021-11-23 16:11:43 +13:00
|
|
|
-c : Git commit
|
|
|
|
-b : Git branch
|
|
|
|
-r : Git repository
|
2022-09-10 18:04:16 -04:00
|
|
|
-v : DOSBox Staging version
|
|
|
|
-f : Force creation if PACKAGE_DIR is not empty
|
2021-11-23 16:11:43 +13:00
|
|
|
BUILD_DIR : Meson build directory
|
|
|
|
PACKAGE_DIR : Package directory
|
2022-03-25 15:32:01 -07:00
|
|
|
|
2021-11-23 16:11:43 +13:00
|
|
|
Note: On macos, '-v' must be set. On msvc, the environment variable VC_REDIST_DIR must be set."
|
|
|
|
}
|
|
|
|
|
|
|
|
create_parent_dir()
|
|
|
|
{
|
|
|
|
path=$1
|
|
|
|
dir=$(dirname "$path")
|
|
|
|
if [ "$dir" != "." ]; then
|
|
|
|
case $platform in
|
|
|
|
msvc) mkdir -p "$dir" ;;
|
|
|
|
macos) install -d "${dir}/"
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install_file()
|
|
|
|
{
|
|
|
|
src=$1
|
|
|
|
dest=$2
|
|
|
|
case $platform in
|
|
|
|
linux|msys2) install -DT -m 644 "$src" "$dest" ;;
|
|
|
|
msvc) create_parent_dir "$dest" && cp "$src" "$dest" ;;
|
|
|
|
macos) create_parent_dir "$dest" && install -m 644 "$src" "$dest" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
install_doc()
|
|
|
|
{
|
|
|
|
# Install common documentation files
|
|
|
|
case $platform in
|
|
|
|
linux)
|
|
|
|
install_file docs/README.template "${pkg_dir}/README"
|
|
|
|
install_file COPYING "${pkg_dir}/COPYING"
|
|
|
|
install_file README "${pkg_dir}/doc/manual.txt"
|
|
|
|
install_file docs/dosbox.1 "${pkg_dir}/man/dosbox.1"
|
|
|
|
readme_tmpl="${pkg_dir}/README"
|
|
|
|
;;
|
|
|
|
macos)
|
2022-12-14 16:05:11 +10:00
|
|
|
install_file docs/README.template "${macos_content_dir}/SharedSupport/README"
|
|
|
|
install_file COPYING "${macos_content_dir}/SharedSupport/COPYING"
|
|
|
|
install_file README "${macos_content_dir}/SharedSupport/manual.txt"
|
|
|
|
install_file docs/README.video "${macos_content_dir}/SharedSupport/video.txt"
|
|
|
|
readme_tmpl="${macos_content_dir}/SharedSupport/README"
|
2021-11-23 16:11:43 +13:00
|
|
|
;;
|
|
|
|
msys2|msvc)
|
|
|
|
install_file COPYING "${pkg_dir}/COPYING.txt"
|
|
|
|
install_file docs/README.template "${pkg_dir}/README.txt"
|
|
|
|
install_file docs/README.video "${pkg_dir}/doc/video.txt"
|
|
|
|
install_file README "${pkg_dir}/doc/manual.txt"
|
|
|
|
readme_tmpl="${pkg_dir}/README.txt"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
# Fill template variables in README.template
|
2022-09-10 18:04:16 -04:00
|
|
|
if [[ "$git_branch" == "refs/tags/"* ]] && [[ "$git_branch" != *"-"* ]]; then
|
|
|
|
version_tag=`echo $git_branch | awk '{print substr($0,11);exit}'`
|
|
|
|
package_information="release $version_tag"
|
2022-09-26 21:43:06 -04:00
|
|
|
elif [[ "$git_branch" == "release/"* ]]; then
|
|
|
|
version_tag=`git describe --tags | cut -f1 -d"-"`
|
2022-09-26 21:46:41 -04:00
|
|
|
package_information="release $version_tag"
|
2022-09-10 18:04:16 -04:00
|
|
|
elif [ -n "$git_branch" ] && [ -n "$git_commit" ]; then
|
|
|
|
package_information="a development branch named $git_branch with commit $git_commit"
|
|
|
|
else
|
|
|
|
package_information="a development branch"
|
2021-11-26 09:05:52 +13:00
|
|
|
fi
|
2022-09-10 18:04:16 -04:00
|
|
|
if [ -n "$package_information" ]; then
|
|
|
|
sed -i -e "s|%PACKAGE_INFORMATION%|$package_information|" "$readme_tmpl"
|
2021-11-26 09:05:52 +13:00
|
|
|
fi
|
|
|
|
if [ -n "$git_repo" ]; then
|
|
|
|
sed -i -e "s|%GITHUB_REPO%|$git_repo|" "$readme_tmpl"
|
|
|
|
fi
|
2021-11-23 16:11:43 +13:00
|
|
|
}
|
|
|
|
|
2022-03-25 15:30:45 -07:00
|
|
|
install_resources()
|
2021-11-23 16:11:43 +13:00
|
|
|
{
|
2022-03-25 15:30:45 -07:00
|
|
|
case "$platform" in
|
|
|
|
"macos")
|
|
|
|
local src_dir=${build_dir}/../Resources
|
2022-12-14 16:05:11 +10:00
|
|
|
local dest_dir=${macos_content_dir}/Resources
|
2022-03-25 15:30:45 -07:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
local src_dir=${build_dir}/resources
|
|
|
|
local dest_dir=${pkg_dir}/resources
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
find $src_dir -type f |
|
2021-11-26 20:02:39 +13:00
|
|
|
while IFS= read -r src; do
|
2022-03-25 15:30:45 -07:00
|
|
|
install_file "$src" "$dest_dir/${src#*$src_dir/}"
|
2021-11-26 20:02:39 +13:00
|
|
|
done
|
2021-11-23 16:11:43 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_linux()
|
|
|
|
{
|
|
|
|
# Print shared object dependencies
|
2022-01-10 22:08:16 -08:00
|
|
|
# ldd crashes with a malloc error on the s390x platform, so always pass
|
|
|
|
ldd "${build_dir}/dosbox" || true
|
2021-11-23 16:11:43 +13:00
|
|
|
install -DT "${build_dir}/dosbox" "${pkg_dir}/dosbox"
|
|
|
|
|
|
|
|
install -DT contrib/linux/dosbox-staging.desktop "${pkg_dir}/desktop/dosbox-staging.desktop"
|
|
|
|
DESTDIR="$(realpath "$pkg_dir")" make -C contrib/icons/ install datadir=
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_macos()
|
|
|
|
{
|
2021-12-14 09:38:12 -08:00
|
|
|
# Note, this script assumes macos builds have x86_64 and arm64 subdirectories
|
2021-11-23 16:11:43 +13:00
|
|
|
|
|
|
|
# Print shared object dependencies
|
2021-12-14 09:38:12 -08:00
|
|
|
for arch in x86_64 arm64; do
|
|
|
|
echo "Checking shared object dependencies for $arch:"
|
|
|
|
otool -L "${build_dir}/dosbox-$arch/dosbox"
|
|
|
|
python3 scripts/verify-macos-dylibs.py "${build_dir}/dosbox-$arch/dosbox"
|
|
|
|
echo ""
|
|
|
|
done
|
2021-11-23 16:11:43 +13:00
|
|
|
|
|
|
|
# Create universal binary from both architectures
|
|
|
|
mkdir dosbox-universal
|
|
|
|
lipo dosbox-x86_64/dosbox dosbox-arm64/dosbox -create -output dosbox-universal/dosbox
|
|
|
|
|
|
|
|
# Generate icon
|
|
|
|
make -C contrib/icons/ dosbox-staging.icns
|
|
|
|
|
2022-12-14 16:05:11 +10:00
|
|
|
install -d "${macos_content_dir}/MacOS/"
|
|
|
|
install dosbox-universal/dosbox "${macos_content_dir}/MacOS/"
|
|
|
|
install_file contrib/macos/Info.plist.template "${macos_content_dir}/Info.plist"
|
|
|
|
install_file contrib/macos/PkgInfo "${macos_content_dir}/PkgInfo"
|
|
|
|
install_file contrib/icons/dosbox-staging.icns "${macos_content_dir}/Resources/"
|
2021-11-23 16:11:43 +13:00
|
|
|
|
2022-12-14 16:05:11 +10:00
|
|
|
sed -i -e "s|%VERSION%|${dbox_version}|" "${macos_content_dir}/Info.plist"
|
|
|
|
|
|
|
|
# Install "Start DOSBox Staging" command
|
|
|
|
start_command="Start DOSBox Staging.command"
|
|
|
|
install -m 755 "contrib/macos/${start_command}" "${macos_dist_dir}/${start_command}"
|
|
|
|
|
|
|
|
# Hide extension in Finder
|
|
|
|
xattr -x -w com.apple.FinderInfo "00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" "${macos_dist_dir}/${start_command}"
|
|
|
|
|
|
|
|
# Set up visual appearance of the root folder of the DMG image
|
|
|
|
install_file contrib/macos/background/background.tiff "${macos_dist_dir}/.hidden/background.tiff"
|
|
|
|
install_file contrib/macos/DS_Store "${macos_dist_dir}/.DS_Store"
|
2021-11-23 16:11:43 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_msys2()
|
|
|
|
{
|
|
|
|
install -DT "${build_dir}/dosbox.exe" "${pkg_dir}/dosbox.exe"
|
|
|
|
|
|
|
|
# Discover and copy required dll files
|
|
|
|
ntldd -R "${pkg_dir}/dosbox.exe" \
|
|
|
|
| sed -e 's/^[[:blank:]]*//g' \
|
|
|
|
| cut -d ' ' -f 3 \
|
|
|
|
| grep -E -i '(mingw|clang)(32|64)' \
|
|
|
|
| sed -e 's|\\|/|g' \
|
|
|
|
| xargs cp --target-directory="${pkg_dir}/"
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_msvc()
|
|
|
|
{
|
|
|
|
# Get the release dir name from $build_dir
|
2021-11-26 19:35:57 +13:00
|
|
|
release_dir=$(basename -- "$(dirname -- "${build_dir}")")/$(basename -- "${build_dir}")
|
2021-11-23 16:11:43 +13:00
|
|
|
|
|
|
|
# Copy binary
|
|
|
|
cp "${build_dir}/dosbox.exe" "${pkg_dir}/dosbox.exe"
|
|
|
|
|
|
|
|
# Copy dll files
|
|
|
|
cp "${build_dir}"/*.dll "${pkg_dir}/"
|
|
|
|
cp "src/libs/zmbv/${release_dir}"/*.dll "${pkg_dir}/"
|
|
|
|
|
2021-11-23 09:08:14 -08:00
|
|
|
# Copy MSVC C++ redistributable files
|
|
|
|
cp docs/vc_redist.txt "${pkg_dir}/doc/vc_redist.txt"
|
|
|
|
cp "$VC_REDIST_DIR"/*.dll "${pkg_dir}/"
|
2021-11-23 16:11:43 +13:00
|
|
|
}
|
|
|
|
|
2021-11-25 10:37:56 +13:00
|
|
|
# Get GitHub CI environment variables if available. The CLI options
|
|
|
|
# '-c', '-b', '-r' will override these if set.
|
2022-03-25 15:31:44 -07:00
|
|
|
if [ -n "${GITHUB_REPOSITORY:-}" ]; then
|
2022-09-10 18:04:16 -04:00
|
|
|
git_commit=`echo ${GITHUB_SHA} | awk '{print substr($0,1,9);exit}'`
|
2022-03-25 15:31:44 -07:00
|
|
|
git_branch=${GITHUB_REF#refs/heads/}
|
|
|
|
git_repo=${GITHUB_REPOSITORY}
|
|
|
|
else
|
|
|
|
git_commit=$(git rev-parse --short HEAD || echo '')
|
|
|
|
git_branch=$(git rev-parse --abbrev-ref HEAD || echo '')
|
|
|
|
git_repo=$(basename "$(git rev-parse --show-toplevel)" || echo '')
|
|
|
|
fi
|
2021-11-25 10:37:56 +13:00
|
|
|
|
2022-03-25 15:31:44 -07:00
|
|
|
print_usage="false"
|
2021-11-26 17:04:53 +13:00
|
|
|
while getopts 'p:c:b:r:v:hf' c
|
2021-11-23 16:11:43 +13:00
|
|
|
do
|
|
|
|
case $c in
|
|
|
|
h) print_usage="true" ;;
|
2021-11-26 17:04:53 +13:00
|
|
|
f) force_pkg="true" ;;
|
2021-11-23 16:11:43 +13:00
|
|
|
p) platform=$OPTARG ;;
|
|
|
|
c) git_commit=$OPTARG ;;
|
|
|
|
b) git_branch=$OPTARG ;;
|
|
|
|
r) git_repo=$OPTARG ;;
|
|
|
|
v) dbox_version=$OPTARG ;;
|
|
|
|
*) true ;; # keep shellcheck happy
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift "$((OPTIND - 1))"
|
|
|
|
|
|
|
|
build_dir=$1
|
|
|
|
pkg_dir=$2
|
|
|
|
|
|
|
|
if [ "$print_usage" = "true" ]; then
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
p=$platform
|
|
|
|
case $p in
|
|
|
|
linux|macos|msys2|msvc) true ;;
|
|
|
|
*) platform="unsupported" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "$platform" = "unsupported" ]; then
|
|
|
|
echo "Platform not set or unsupported"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$build_dir" ]; then
|
|
|
|
echo "Build directory not set, or does not exist"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$pkg_dir" ]; then
|
|
|
|
echo "Package directory not set"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-03-25 15:32:01 -07:00
|
|
|
if [ "$platform" = "macos" ]; then
|
2021-11-23 16:11:43 +13:00
|
|
|
if [ -z "$dbox_version" ]; then
|
2022-09-10 18:04:16 -04:00
|
|
|
echo "DOSBox Staging version required on macOS"
|
2021-11-23 16:11:43 +13:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-12-14 16:05:11 +10:00
|
|
|
macos_dist_dir="${pkg_dir}/dist"
|
|
|
|
macos_content_dir="${macos_dist_dir}/DOSBox Staging.app/Contents"
|
2021-11-23 16:11:43 +13:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$platform" = "msvc" ] && [ -z "$VC_REDIST_DIR" ]; then
|
|
|
|
echo "VC_REDIST_DIR environment variable not set"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-11-26 17:04:53 +13:00
|
|
|
|
|
|
|
if [ -f "$pkg_dir" ]; then
|
|
|
|
echo "PACKAGE_DIR must not be a file"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-11-23 16:11:43 +13:00
|
|
|
|
|
|
|
mkdir -p "$pkg_dir"
|
2021-11-26 17:04:53 +13:00
|
|
|
|
2021-11-26 20:02:39 +13:00
|
|
|
if [ -z "$(find "${pkg_dir}" -maxdepth 0 -empty)" ] && [ "$force_pkg" != "true" ]; then
|
|
|
|
echo "PACKAGE_DIR must be empty. Use '-f' to force creation anyway"
|
2021-11-26 17:04:53 +13:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
2021-11-23 16:11:43 +13:00
|
|
|
install_doc
|
2022-03-25 15:30:45 -07:00
|
|
|
install_resources
|
2021-11-23 16:11:43 +13:00
|
|
|
|
|
|
|
case $platform in
|
|
|
|
linux) pkg_linux ;;
|
|
|
|
macos) pkg_macos ;;
|
|
|
|
msys2) pkg_msys2 ;;
|
|
|
|
msvc) pkg_msvc ;;
|
|
|
|
*) echo "Oops."; usage; exit 1 ;;
|
2021-11-26 09:05:52 +13:00
|
|
|
esac
|