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
|
|
|
|
2021-05-30 22:50:01 +00:00
|
|
|
target_arch=$(uname -m)
|
|
|
|
|
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-05-24 08:20:41 +00:00
|
|
|
cp build/qemu-system-i386w.exe dist/xemu.exe
|
2020-12-12 06:04:17 +00:00
|
|
|
python3 "${project_source_dir}/get_deps.py" dist/xemu.exe dist
|
2018-06-28 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 00:25:51 +00:00
|
|
|
package_wincross() {
|
|
|
|
rm -rf dist
|
|
|
|
mkdir -p dist
|
2021-05-24 08:20:41 +00:00
|
|
|
cp build/qemu-system-i386w.exe dist/xemu.exe
|
2021-05-24 11:25:29 +00:00
|
|
|
python3 ./scripts/gen-license.py --platform windows > dist/LICENSE.txt
|
2021-05-21 00:25:51 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 08:04:56 +00:00
|
|
|
package_macos() {
|
|
|
|
rm -rf dist
|
|
|
|
|
|
|
|
# Copy in executable
|
|
|
|
mkdir -p dist/xemu.app/Contents/MacOS/
|
2021-05-30 22:50:01 +00:00
|
|
|
exe_path=dist/xemu.app/Contents/MacOS/xemu
|
|
|
|
lib_path=dist/xemu.app/Contents/Libraries/${target_arch}
|
|
|
|
lib_rpath=../Libraries/${target_arch}
|
|
|
|
cp build/qemu-system-i386 ${exe_path}
|
2020-03-26 08:04:56 +00:00
|
|
|
|
|
|
|
# Copy in in executable dylib dependencies
|
|
|
|
dylibbundler -cd -of -b -x dist/xemu.app/Contents/MacOS/xemu \
|
2021-05-30 22:50:01 +00:00
|
|
|
-d ${lib_path}/ \
|
|
|
|
-p "@executable_path/${lib_rpath}/" \
|
2021-10-13 20:52:49 +00:00
|
|
|
-s ${PWD}/macos-libs/${target_arch}/opt/local/libexec/openssl11/lib/ \
|
2021-05-30 22:50:01 +00:00
|
|
|
-s ${PWD}/macos-libs/${target_arch}/opt/local/lib/
|
|
|
|
|
|
|
|
# Fixup some paths dylibbundler missed
|
|
|
|
for dep in $(otool -L "$exe_path" | grep -e '/opt/local/' | cut -d' ' -f1); do
|
|
|
|
dep_basename="$(basename $dep)"
|
|
|
|
new_path="@executable_path/${lib_rpath}/${dep_basename}"
|
|
|
|
echo "Fixing $exe_path dependency $dep_basename -> $new_path"
|
|
|
|
install_name_tool -change "$dep" "$new_path" "$exe_path"
|
|
|
|
done
|
2021-12-29 00:08:49 +00:00
|
|
|
|
2021-05-30 22:50:01 +00:00
|
|
|
for lib_path in ${lib_path}/*.dylib; do
|
|
|
|
for dep in $(otool -L "$lib_path" | grep -e '/opt/local/' | cut -d' ' -f1); do
|
|
|
|
dep_basename="$(basename $dep)"
|
|
|
|
new_path="@rpath/${dep_basename}"
|
|
|
|
echo "Fixing $lib_path dependency $dep_basename -> $new_path"
|
|
|
|
install_name_tool -change "$dep" "$new_path" "$lib_path"
|
2021-12-29 00:08:49 +00:00
|
|
|
codesign -s - -f "${lib_path}"
|
2021-05-30 22:50:01 +00:00
|
|
|
done
|
|
|
|
done
|
2020-03-26 08:04:56 +00:00
|
|
|
|
|
|
|
# Copy in runtime resources
|
|
|
|
mkdir -p dist/xemu.app/Contents/Resources
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2021-05-30 22:50:01 +00:00
|
|
|
cp Info.plist dist/xemu.app/Contents/
|
2021-12-29 00:08:49 +00:00
|
|
|
|
2023-03-31 22:05:03 +00:00
|
|
|
plutil -replace CFBundleShortVersionString -string $(cat ${project_source_dir}/XEMU_VERSION | cut -f1 -d-) dist/xemu.app/Contents/Info.plist
|
|
|
|
plutil -replace CFBundleVersion -string $(cat ${project_source_dir}/XEMU_VERSION | cut -f1 -d-) dist/xemu.app/Contents/Info.plist
|
|
|
|
|
2021-12-29 00:08:49 +00:00
|
|
|
codesign --force --deep --preserve-metadata=entitlements,requirements,flags,runtime --sign - "${exe_path}"
|
2021-05-30 22:50:01 +00:00
|
|
|
python3 ./scripts/gen-license.py --version-file=macos-libs/$target_arch/INSTALLED > dist/LICENSE.txt
|
2020-03-26 08:04:56 +00:00
|
|
|
}
|
|
|
|
|
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
|
2021-05-25 05:42:07 +00:00
|
|
|
if test -e "${project_source_dir}/XEMU_LICENSE"; then
|
|
|
|
cp "${project_source_dir}/XEMU_LICENSE" dist/LICENSE.txt
|
|
|
|
else
|
|
|
|
python3 ./scripts/gen-license.py > dist/LICENSE.txt
|
|
|
|
fi
|
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=''
|
2022-02-02 06:58:32 +00:00
|
|
|
build_cflags=''
|
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=""
|
2021-05-21 00:25:51 +00:00
|
|
|
platform="$(uname -s)"
|
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
|
|
|
|
;;
|
2021-05-21 00:25:51 +00:00
|
|
|
'-p'*)
|
|
|
|
platform="${2}"
|
|
|
|
shift 2
|
|
|
|
;;
|
2021-05-30 22:50:01 +00:00
|
|
|
'-a'*)
|
|
|
|
target_arch="${2}"
|
|
|
|
shift 2
|
|
|
|
;;
|
2018-09-13 01:34:31 +00:00
|
|
|
*)
|
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
|
2022-02-02 06:58:32 +00:00
|
|
|
build_cflags='-DXEMU_DEBUG_BUILD=1'
|
2022-02-01 05:23:15 +00:00
|
|
|
opts="--enable-debug --enable-trace-backends=log"
|
2021-04-19 09:39:50 +00:00
|
|
|
else
|
|
|
|
opts="--enable-lto"
|
|
|
|
fi
|
2021-04-19 06:45:49 +00:00
|
|
|
|
2023-06-04 16:49:31 +00:00
|
|
|
most_recent_macosx_sdk_ver () {
|
|
|
|
local min_ver="${1}"
|
|
|
|
local macos_sdk_base=/Library/Developer/CommandLineTools/SDKs
|
|
|
|
local sdks=("${macos_sdk_base}"/MacOSX[0-9]*.[0-9]*.sdk)
|
|
|
|
for i in "${!sdks[@]}"; do
|
|
|
|
local newval="${sdks[i]##${macos_sdk_base}/MacOSX}"
|
|
|
|
sdks[$i]="${newval%%.sdk}"
|
|
|
|
done
|
|
|
|
|
|
|
|
IFS=$'\n' sdks=($(sort -nr <<<"${sdks[*]}"))
|
|
|
|
unset IFS
|
|
|
|
|
|
|
|
local newest_sdk_ver="${sdks[0]}"
|
|
|
|
|
|
|
|
local sdk_path="${macos_sdk_base}/MacOSX${newest_sdk_ver}.sdk"
|
|
|
|
if ! test -d "${sdk_path}"; then
|
|
|
|
echo ""
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! LC_ALL=C awk 'BEGIN {exit ('${newest_sdk_ver}' < '${min_ver}')}'; then
|
|
|
|
echo ""
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo "${sdk_path}"
|
|
|
|
}
|
2021-05-21 00:25:51 +00:00
|
|
|
|
|
|
|
case "$platform" 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...'
|
2021-05-20 03:45:58 +00:00
|
|
|
sys_cflags='-Wno-error=redundant-decls'
|
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)
|
2021-05-30 22:50:01 +00:00
|
|
|
echo "Compiling for MacOS for $target_arch..."
|
|
|
|
if [ "$target_arch" == "arm64" ]; then
|
2024-07-14 19:45:33 +00:00
|
|
|
macos_min_ver=12.7.5
|
2021-05-30 22:50:01 +00:00
|
|
|
elif [ "$target_arch" == "x86_64" ]; then
|
2024-07-14 19:45:33 +00:00
|
|
|
macos_min_ver=12.7.5
|
2021-05-30 22:50:01 +00:00
|
|
|
else
|
|
|
|
echo "Unsupported arch $target_arch"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-06-04 16:49:31 +00:00
|
|
|
|
|
|
|
sdk="$(most_recent_macosx_sdk_ver ${macos_min_ver})"
|
|
|
|
if [[ -z "${sdk}" ]]; then
|
|
|
|
echo "SDK >= ${macos_min_ver} not found. Install Xcode Command Line Tools"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-05-30 22:50:01 +00:00
|
|
|
python3 ./scripts/download-macos-libs.py ${target_arch}
|
|
|
|
lib_prefix=${PWD}/macos-libs/${target_arch}/opt/local
|
|
|
|
export CFLAGS="-arch ${target_arch} \
|
|
|
|
-target ${target_arch}-apple-macos${macos_min_ver} \
|
|
|
|
-isysroot ${sdk} \
|
|
|
|
-I${lib_prefix}/include \
|
|
|
|
-mmacosx-version-min=$macos_min_ver"
|
|
|
|
export LDFLAGS="-arch ${target_arch} \
|
|
|
|
-isysroot ${sdk}"
|
|
|
|
if [ "$target_arch" == "x86_64" ]; then
|
|
|
|
sys_cflags='-march=ivybridge'
|
|
|
|
fi
|
2020-05-31 01:43:20 +00:00
|
|
|
sys_ldflags='-headerpad_max_install_names'
|
2021-05-30 22:50:01 +00:00
|
|
|
export PKG_CONFIG_PATH="${lib_prefix}/lib/pkgconfig"
|
2021-10-13 20:52:49 +00:00
|
|
|
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${lib_prefix}/libexec/openssl11/lib/pkgconfig"
|
2021-05-30 22:50:01 +00:00
|
|
|
opts="$opts --disable-cocoa --cross-prefix="
|
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'
|
2024-03-15 14:07:55 +00:00
|
|
|
CFLAGS="${CFLAGS} -lIphlpapi -lCrypt32" # workaround for linking libs on mingw
|
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-05-24 08:20:41 +00:00
|
|
|
target="qemu-system-i386w.exe"
|
2018-06-28 19:52:43 +00:00
|
|
|
;;
|
2021-05-21 00:25:51 +00:00
|
|
|
win64-cross)
|
|
|
|
echo 'Cross-compiling for Windows...'
|
|
|
|
export AR=${AR:-$CROSSAR}
|
|
|
|
sys_cflags='-Wno-error'
|
|
|
|
opts="$opts --cross-prefix=$CROSSPREFIX --static --disable-fortify-source"
|
|
|
|
postbuild='package_wincross' # set the above function to be called after build
|
2021-05-24 08:20:41 +00:00
|
|
|
target="qemu-system-i386w.exe"
|
2021-05-21 00:25:51 +00:00
|
|
|
;;
|
2018-06-28 19:52:43 +00:00
|
|
|
*)
|
2021-05-21 00:25:51 +00:00
|
|
|
echo "Unsupported platform $platform, 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"
|
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-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
|