2018-09-13 01:34:31 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-06-28 19:52:43 +00:00
|
|
|
|
|
|
|
set -e # exit if a command fails
|
|
|
|
set -o pipefail # Will return the exit status of make if it fails
|
2020-12-12 05:39:33 +00:00
|
|
|
set -o physical # Resolve symlinks when changing directory
|
|
|
|
|
|
|
|
project_source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
2018-06-28 19:52:43 +00:00
|
|
|
|
2020-05-25 19:54:51 +00:00
|
|
|
package_windows() {
|
|
|
|
rm -rf dist
|
2018-06-28 19:52:43 +00:00
|
|
|
mkdir -p dist
|
2021-04-19 08:07:38 +00:00
|
|
|
cp build/qemu-system-i386.exe dist/xemu.exe
|
|
|
|
cp build/qemu-system-i386w.exe dist/xemuw.exe
|
2020-12-12 06:04:17 +00:00
|
|
|
cp -r "${project_source_dir}/data" dist/
|
|
|
|
python3 "${project_source_dir}/get_deps.py" dist/xemu.exe dist
|
2020-03-12 08:04:33 +00:00
|
|
|
strip dist/xemu.exe
|
|
|
|
strip dist/xemuw.exe
|
2018-06-28 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 08:04:56 +00:00
|
|
|
package_macos() {
|
|
|
|
#
|
|
|
|
# Create bundle
|
|
|
|
#
|
|
|
|
rm -rf dist
|
|
|
|
|
|
|
|
# Copy in executable
|
|
|
|
mkdir -p dist/xemu.app/Contents/MacOS/
|
2021-04-19 08:07:38 +00:00
|
|
|
cp build/qemu-system-i386 dist/xemu.app/Contents/MacOS/xemu
|
2020-03-26 08:04:56 +00:00
|
|
|
|
|
|
|
# Copy in in executable dylib dependencies
|
|
|
|
mkdir -p dist/xemu.app/Contents/Frameworks
|
|
|
|
dylibbundler -cd -of -b -x dist/xemu.app/Contents/MacOS/xemu \
|
|
|
|
-d dist/xemu.app/Contents/Frameworks/ \
|
|
|
|
-p '@executable_path/../Frameworks/'
|
|
|
|
|
|
|
|
# Copy in runtime resources
|
|
|
|
mkdir -p dist/xemu.app/Contents/Resources
|
2020-12-12 06:04:17 +00:00
|
|
|
cp -r "${project_source_dir}/data" dist/xemu.app/Contents/Resources
|
2020-03-26 08:04:56 +00:00
|
|
|
|
|
|
|
# Generate icon file
|
|
|
|
mkdir -p xemu.iconset
|
2020-12-12 06:04:17 +00:00
|
|
|
for r in 16 32 128 256 512; do cp "${project_source_dir}/ui/icons/xemu_${r}x${r}.png" "xemu.iconset/icon_${r}x${r}.png"; done
|
2020-03-26 08:04:56 +00:00
|
|
|
iconutil --convert icns --output dist/xemu.app/Contents/Resources/xemu.icns xemu.iconset
|
|
|
|
|
|
|
|
# Generate Info.plist file
|
|
|
|
cat <<EOF > dist/xemu.app/Contents/Info.plist
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
|
|
|
<key>CFBundleDevelopmentRegion</key>
|
|
|
|
<string>en</string>
|
|
|
|
<key>CFBundleExecutable</key>
|
|
|
|
<string>xemu</string>
|
|
|
|
<key>CFBundleIconFile</key>
|
|
|
|
<string>xemu.icns</string>
|
|
|
|
<key>CFBundleIdentifier</key>
|
|
|
|
<string>xemu.app.0</string>
|
|
|
|
<key>CFBundleInfoDictionaryVersion</key>
|
|
|
|
<string>6.0</string>
|
|
|
|
<key>CFBundleName</key>
|
|
|
|
<string>xemu</string>
|
|
|
|
<key>CFBundlePackageType</key>
|
|
|
|
<string>APPL</string>
|
|
|
|
<key>CFBundleShortVersionString</key>
|
|
|
|
<string>1</string>
|
|
|
|
<key>CFBundleSignature</key>
|
|
|
|
<string>xemu</string>
|
|
|
|
<key>CFBundleVersion</key>
|
|
|
|
<string>1</string>
|
|
|
|
<key>LSApplicationCategoryType</key>
|
|
|
|
<string>public.app-category.games</string>
|
|
|
|
<key>LSMinimumSystemVersion</key>
|
|
|
|
<string>10.6</string>
|
|
|
|
<key>NSPrincipalClass</key>
|
|
|
|
<string>NSApplication</string>
|
|
|
|
<key>NSHighResolutionCapable</key>
|
|
|
|
<true/>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2020-05-25 19:54:51 +00:00
|
|
|
package_linux() {
|
|
|
|
rm -rf dist
|
|
|
|
mkdir -p dist
|
2021-04-19 08:07:38 +00:00
|
|
|
cp build/qemu-system-i386 dist/xemu
|
2020-12-12 06:04:17 +00:00
|
|
|
cp -r "${project_source_dir}/data" dist
|
2020-05-25 19:54:51 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 01:34:31 +00:00
|
|
|
postbuild=''
|
2020-03-12 08:04:33 +00:00
|
|
|
debug_opts=''
|
|
|
|
build_cflags='-O3'
|
2020-12-12 05:28:46 +00:00
|
|
|
default_job_count='12'
|
2020-05-31 01:43:20 +00:00
|
|
|
sys_ldflags=''
|
2018-09-13 01:34:31 +00:00
|
|
|
|
2020-12-12 05:28:46 +00:00
|
|
|
get_job_count () {
|
|
|
|
if command -v 'nproc' >/dev/null
|
|
|
|
then
|
|
|
|
nproc
|
|
|
|
else
|
|
|
|
case "$(uname -s)" in
|
|
|
|
'Linux')
|
|
|
|
egrep "^processor" /proc/cpuinfo | wc -l
|
|
|
|
;;
|
|
|
|
'FreeBSD')
|
|
|
|
sysctl -n hw.ncpu
|
|
|
|
;;
|
|
|
|
'Darwin')
|
|
|
|
sysctl -n hw.logicalcpu 2>/dev/null \
|
|
|
|
|| sysctl -n hw.ncpu
|
|
|
|
;;
|
|
|
|
'MSYS_NT-'*|'CYGWIN_NT-'*|'MINGW'*'_NT-'*)
|
|
|
|
if command -v 'wmic' >/dev/null
|
|
|
|
then
|
|
|
|
wmic cpu get NumberOfLogicalProcessors/Format:List \
|
|
|
|
| grep -m1 '=' | cut -f2 -d'='
|
|
|
|
else
|
|
|
|
echo "${NUMBER_OF_PROCESSORS:-${default_job_count}}"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "${default_job_count}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
job_count="$(get_job_count)" 2>/dev/null
|
|
|
|
job_count="${job_count:-${default_job_count}}"
|
2021-04-19 09:39:50 +00:00
|
|
|
debug=""
|
|
|
|
opts=""
|
2020-12-12 05:28:46 +00:00
|
|
|
|
2020-05-25 19:54:51 +00:00
|
|
|
while [ ! -z "${1}" ]
|
2018-09-13 01:34:31 +00:00
|
|
|
do
|
|
|
|
case "${1}" in
|
|
|
|
'-j'*)
|
|
|
|
job_count="${1:2}"
|
|
|
|
shift
|
|
|
|
;;
|
2020-03-12 08:04:33 +00:00
|
|
|
'--debug')
|
2021-04-19 09:39:50 +00:00
|
|
|
debug="y"
|
2018-09-13 01:34:31 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
2020-05-25 19:54:51 +00:00
|
|
|
break
|
2018-09-13 01:34:31 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-04-19 06:45:49 +00:00
|
|
|
target="qemu-system-i386"
|
2021-04-19 09:39:50 +00:00
|
|
|
if test ! -z "$debug"; then
|
|
|
|
build_cflags='-O0 -g -DXEMU_DEBUG_BUILD=1'
|
|
|
|
opts="--enable-debug"
|
|
|
|
else
|
|
|
|
opts="--enable-lto"
|
|
|
|
fi
|
2021-04-19 06:45:49 +00:00
|
|
|
|
2020-03-12 08:04:33 +00:00
|
|
|
case "$(uname -s)" in # Adjust compilation options based on platform
|
2018-06-28 19:52:43 +00:00
|
|
|
Linux)
|
2020-03-12 08:04:33 +00:00
|
|
|
echo 'Compiling for Linux...'
|
2020-05-25 19:54:51 +00:00
|
|
|
sys_cflags='-Wno-error=redundant-decls -Wno-error=unused-but-set-variable'
|
2021-04-19 09:39:50 +00:00
|
|
|
opts="$opts --disable-werror"
|
2020-05-25 19:54:51 +00:00
|
|
|
postbuild='package_linux'
|
2018-06-28 19:52:43 +00:00
|
|
|
;;
|
|
|
|
Darwin)
|
2020-03-12 08:04:33 +00:00
|
|
|
echo 'Compiling for MacOS...'
|
2020-03-26 08:04:56 +00:00
|
|
|
sys_cflags='-march=ivybridge'
|
2020-05-31 01:43:20 +00:00
|
|
|
sys_ldflags='-headerpad_max_install_names'
|
2021-04-19 09:39:50 +00:00
|
|
|
opts="$opts --disable-cocoa"
|
2019-06-28 00:11:18 +00:00
|
|
|
# necessary to find libffi, which is required by gobject
|
|
|
|
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}/usr/local/opt/libffi/lib/pkgconfig"
|
2020-04-27 23:44:53 +00:00
|
|
|
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig:${PKG_CONFIG_PATH}"
|
|
|
|
echo $PKG_CONFIG_PATH
|
2020-03-26 08:04:56 +00:00
|
|
|
postbuild='package_macos'
|
2018-06-28 19:52:43 +00:00
|
|
|
;;
|
|
|
|
CYGWIN*|MINGW*|MSYS*)
|
2020-03-12 08:04:33 +00:00
|
|
|
echo 'Compiling for Windows...'
|
2018-09-13 01:34:31 +00:00
|
|
|
sys_cflags='-Wno-error'
|
2021-04-19 09:39:50 +00:00
|
|
|
opts="$opts --disable-fortify-source"
|
2018-09-13 01:34:31 +00:00
|
|
|
postbuild='package_windows' # set the above function to be called after build
|
2021-04-19 06:45:49 +00:00
|
|
|
target="qemu-system-i386.exe qemu-system-i386w.exe"
|
2018-06-28 19:52:43 +00:00
|
|
|
;;
|
|
|
|
*)
|
2018-09-13 01:34:31 +00:00
|
|
|
echo "could not detect OS $(uname -s), aborting" >&2
|
2018-06-28 19:52:43 +00:00
|
|
|
exit -1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2018-09-13 01:34:31 +00:00
|
|
|
# find absolute path (and resolve symlinks) to build out of tree
|
2020-12-12 05:39:33 +00:00
|
|
|
configure="${project_source_dir}/configure"
|
2020-12-12 05:58:47 +00:00
|
|
|
build_cflags="${build_cflags} -I${project_source_dir}/ui/imgui"
|
2018-06-28 19:52:43 +00:00
|
|
|
|
2018-09-13 01:34:31 +00:00
|
|
|
set -x # Print commands from now on
|
2018-06-28 19:52:43 +00:00
|
|
|
|
2018-09-13 01:34:31 +00:00
|
|
|
"${configure}" \
|
|
|
|
--extra-cflags="-DXBOX=1 ${build_cflags} ${sys_cflags} ${CFLAGS}" \
|
2020-05-31 01:43:20 +00:00
|
|
|
--extra-ldflags="${sys_ldflags}" \
|
2018-09-13 01:34:31 +00:00
|
|
|
--target-list=i386-softmmu \
|
2021-04-19 09:39:50 +00:00
|
|
|
${opts} \
|
2020-05-25 19:54:51 +00:00
|
|
|
"$@"
|
2018-06-28 19:52:43 +00:00
|
|
|
|
2021-02-07 21:10:30 +00:00
|
|
|
# Force imgui update now to work around annoying make issue
|
2021-02-12 05:06:41 +00:00
|
|
|
if ! test -f "${project_source_dir}/ui/imgui/imgui.cpp"; then
|
|
|
|
./scripts/git-submodule.sh update ui/imgui
|
|
|
|
fi
|
2021-02-07 21:10:30 +00:00
|
|
|
|
2021-04-19 06:45:49 +00:00
|
|
|
time make -j"${job_count}" ${target} 2>&1 | tee build.log
|
2018-06-28 19:52:43 +00:00
|
|
|
|
2021-01-12 02:48:19 +00:00
|
|
|
"${postbuild}" # call post build functions
|