Build support for Microsoft Windows.
This commit is contained in:
@@ -53,7 +53,13 @@ _initialize() {
|
||||
# By default, this will check for `automake` and `autoreconf`.
|
||||
initialize_needs() { _initialize_needs "$@"; }
|
||||
_initialize_needs() {
|
||||
needs automake autoreconf
|
||||
if [[ $platform = windows ]]; then
|
||||
needs cmd
|
||||
export VSINSTALLDIR="${VSINSTALLDIR:-$(cd "$(cygpath -F 0x002a)/Microsoft Visual Studio"/*/*/Common7/.. && pwd)}"
|
||||
[[ -e "$VSINSTALLDIR/Common7/Tools/VsMSBuildCmd.bat" ]] || { echo >&2 "Missing: msbuild. Please install 'Build Tools for Visual Studio'."; return 1; }
|
||||
else
|
||||
needs automake autoreconf
|
||||
fi
|
||||
}
|
||||
|
||||
# clean <prefix> <platform>
|
||||
@@ -64,6 +70,13 @@ _initialize_needs() {
|
||||
clean() { _clean "$@"; }
|
||||
_clean() {
|
||||
rm -rf "$prefix"
|
||||
|
||||
if [[ $platform = windows ]]; then
|
||||
printf '"%%VSINSTALLDIR%%\Common7\Tools\VsMSBuildCmd.bat" && msbuild /t:Clean' > .clean.bat
|
||||
cmd //c .clean.bat
|
||||
rm -f .clean.bat
|
||||
fi
|
||||
|
||||
[[ ! -e Makefile ]] || make -s distclean
|
||||
[[ ! -e .git ]] || git clean -fdx
|
||||
}
|
||||
@@ -103,6 +116,8 @@ prepare_config() { _prepare_config "$@"; }
|
||||
_prepare_config() {
|
||||
local prefix=$1 platform=$2; shift 2
|
||||
|
||||
[[ $platform = windows ]] && return
|
||||
|
||||
[[ -e configure ]] || autoreconf --verbose --install --symlink 2> >(sed 's/^\([^:]*\):[0-9]\{1,\}: /\1: /')
|
||||
}
|
||||
|
||||
@@ -127,6 +142,8 @@ target_prepare() { _target_prepare "$@"; }
|
||||
_target_prepare() {
|
||||
local prefix=$1 platform=$2 arch=$3; shift 3
|
||||
|
||||
[[ $platform = windows ]] && return
|
||||
|
||||
[[ ! -e Makefile ]] || make -s clean
|
||||
}
|
||||
|
||||
@@ -140,6 +157,9 @@ _target_configure() {
|
||||
local prefix=$1 platform=$2 arch=$3; shift 3
|
||||
|
||||
case "$platform" in
|
||||
'windows')
|
||||
return
|
||||
;;
|
||||
'android')
|
||||
host=( "$SDKROOT"/*-android* ) host=${host##*/}
|
||||
|
||||
@@ -164,10 +184,16 @@ _target_configure() {
|
||||
target_build() { _target_build "$@"; }
|
||||
_target_build() {
|
||||
local prefix=$1 platform=$2 arch=$3; shift 3
|
||||
#make -j3 check
|
||||
|
||||
cores=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null ||:)
|
||||
make -j"${cores:-3}" install
|
||||
if [[ $platform = windows ]]; then
|
||||
# I cannot for the life of me figure out how to pass this command directly into cmd.
|
||||
printf '"%%VSINSTALLDIR%%\Common7\Tools\VsMSBuildCmd.bat" && msbuild /t:Rebuild /p:Configuration=ReleaseDLL;Platform=%s;OutDir=%s' "$arch" "$(cygpath -w "${prefix##$PWD/}/$arch/")" > .build.bat
|
||||
cmd //c .build.bat
|
||||
rm -f .build.bat
|
||||
else
|
||||
local cores=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null ||:)
|
||||
make -j"${cores:-3}" install
|
||||
fi
|
||||
}
|
||||
|
||||
# finalize <prefix> <platform> [ <arch> ... ]
|
||||
@@ -189,10 +215,16 @@ finalize_merge() { _finalize_merge "$@"; }
|
||||
_finalize_merge() {
|
||||
local prefix=$1 platform=$2; shift 2
|
||||
|
||||
mv -f -- "$prefix/$1/include" "$prefix/out/"
|
||||
[[ -e "$prefix/$1/include" ]] && mv -f -- "$prefix/$1/include" "$prefix/out/"
|
||||
|
||||
mkdir -p "$prefix/out/lib"
|
||||
case "$platform" in
|
||||
'windows')
|
||||
for arch; do
|
||||
install -d "$prefix/out/lib/$arch"
|
||||
install -p "$prefix/Win32/"*.lib "$prefix/out/lib/"
|
||||
done
|
||||
;;
|
||||
'macos'|'ios')
|
||||
for lib in "$prefix/$1/lib/"*; do
|
||||
if lipo -info "$lib" >/dev/null 2>&1; then
|
||||
@@ -247,6 +279,7 @@ _build() {
|
||||
'macos') archs=( 'x86_64' ) ;;
|
||||
'ios') archs=( 'i386' 'x86_64' 'armv7' 'armv7s' 'arm64' ) ;;
|
||||
'android') archs=( 'arm' 'arm64' 'x86' 'x86_64' ) ;;
|
||||
'windows') archs=( 'Win32' 'x64' ) ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
@@ -270,6 +303,8 @@ _build() {
|
||||
|
||||
# Set up a base environment for the platform.
|
||||
case "$platform" in
|
||||
'windows')
|
||||
;;
|
||||
'macos')
|
||||
SDKROOT="$(xcrun --show-sdk-path --sdk macosx)"
|
||||
export PATH="$(xcrun --show-sdk-platform-path --sdk macosx)/usr/bin:$PATH"
|
||||
|
Reference in New Issue
Block a user