Skip to content

Commit

Permalink
add cygwin cross build support
Browse files Browse the repository at this point in the history
Put shared code for linux cross builds and cygwin cross builds into
builder/mingw-cross.sh .

Call wxrc when the build platform is cygwin with files resolved via
`cygpath -m` in case the wxrc is a native binary.

Add -fpermissive to CXX/OBJCXX flags.

Reenable libzvbi support for ffmpeg.

Stop building ffmpeg and related dists by default until we fix game
recording.

Set CMAKE_PREFIX_PATH in cmake args as a FILEPATH type variable.

Support xml catalog made with native libxml2 using cygpath in related
commands, make cygpath a noop on non-cygwin platforms.

Remove gdb and zip from msys2 deps.

Add a cygwin installdeps routine using a copy of cyg-apt that it
fetches.

When creating symlinks in install_dist() fully resolve all symlinks in
path parts for the source file, so that host and target binaries are
correctly linked.

When cp -af fails to preserve permission related data, fall back to cp
-rf.

When installing libs with a cross suffix, make a symlink for the lib
without the cross suffix.

Make sure cygwin runs with CYGWIN=winsymlinks:native .

Add paths to host gettext executables to cmake args, otherwise it tries
to use the target executables and fails on paths.

For the pkgconfig bundled glib, turn off win32 platform for the cygwin
host build.

For gettext, remove --disable-auto-import from link flags.

Compile target freetype on cygwin with cmake and manually install the
pkgconfig .pc file using sed.

Other misc. minor tweaks and cleanups.
  • Loading branch information
rkitover committed Apr 29, 2018
1 parent 9933b6b commit aa852d9
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 116 deletions.
15 changes: 14 additions & 1 deletion src/wx/CMakeLists.txt
Expand Up @@ -399,7 +399,7 @@ SET(XRC_SOURCES
)

# wxrc does not support xrs files in -c output (> 10x compression)
# we do it using the bin2.c utility
# we do it using the bin2c.c utility

SET(BIN2C ${CMAKE_BINARY_DIR}/bin2c)

Expand All @@ -413,6 +413,19 @@ else()
set(WXRC wxrc)
endif()

if(CMAKE_HOST_SYSTEM_NAME STREQUAL CYGWIN)
# pass xrc sources through cygpath in case we only have native wxrc

set(new_xrc_sources)

foreach(xrc ${XRC_SOURCES})
execute_process(COMMAND cygpath -m ${xrc} OUTPUT_VARIABLE win_path OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND new_xrc_sources ${win_path})
endforeach()

set(XRC_SOURCES ${new_xrc_sources})
endif()

ADD_CUSTOM_COMMAND(OUTPUT wxvbam.xrs
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${WXRC} ${XRC_SOURCES} "--output=wxvbam.xrs"
Expand Down
169 changes: 139 additions & 30 deletions tools/builder/core.sh
Expand Up @@ -31,8 +31,8 @@ esac
export CPPFLAGS="$CPPFLAGS -I$BUILD_ROOT/root/include"
export CFLAGS="$CFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -Wno-error=all"
export CXXFLAGS="$CXXFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all"
export OBJCXXFLAGS="$OBJCXXFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all"
export CXXFLAGS="$CXXFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all -fpermissive"
export OBJCXXFLAGS="$OBJCXXFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all -fpermissive"
export LDFLAGS="$LDFLAGS -fPIC -L$BUILD_ROOT/root/lib -Wno-error=all"
if [ -z "\$OPENMP" ] && echo "\$CC" | grep -Eq gcc; then
Expand Down Expand Up @@ -195,24 +195,34 @@ DISTS=$DISTS'
libx265 https://bitbucket.org/multicoreware/x265/downloads/x265_2.5.tar.gz lib/libx265.a
libxavs https://github.com/Distrotech/xavs/archive/distrotech-xavs-git.tar.gz lib/libxavs.a
libzmq https://github.com/zeromq/libzmq/releases/download/v4.2.2/zeromq-4.2.2.tar.gz lib/libzmq.a
# libzvbi https://downloads.sourceforge.net/project/zapping/zvbi/0.2.35/zvbi-0.2.35.tar.bz2 lib/libzvbi.a
libzvbi https://downloads.sourceforge.net/project/zapping/zvbi/0.2.35/zvbi-0.2.35.tar.bz2 lib/libzvbi.a
ffmpeg https://github.com/ffmpeg/ffmpeg/archive/0c78b6a416c661afed745d44495b5194f714fb96.tar.gz lib/libavformat.a
'

# for now we don't build ffmpeg because game recording is broken
BUILD_FFMPEG=
PROJECT_ARGS="$PROJECT_ARGS -DENABLE_FFMPEG=NO"

FFMPEG_DISTS='
graphite2 xvidcore fribidi libgsm libmodplug libopencore-amrnb opus snappy
libsoxr speex libtheora vidstab libvo-amrwbenc mp3lame libass libbluray
libvpx libwavpack libx264 libx265 libxavs libzmq libzvbi ffmpeg
'

: ${PATH_SEP:=':'}

# these two can be set to always be included regardless of overrides
REQUIRED_CONFIGURE_ARGS="$REQUIRED_CONFIGURE_ARGS"
REQUIRED_CMAKE_ARGS="$REQUIRED_CMAKE_ARGS"

CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-shared --enable-static --prefix=/usr"

CMAKE_BASE_ARGS="$CMAKE_BASE_ARGS -DBUILD_SHARED_LIBS=NO -DENABLE_SHARED=NO -DCMAKE_PREFIX_PATH=\"\$CMAKE_PREFIX_PATH\" -DCMAKE_BUILD_TYPE=Release"
CMAKE_BASE_ARGS="$CMAKE_BASE_ARGS -DBUILD_SHARED_LIBS=NO -DENABLE_SHARED=NO -DCMAKE_PREFIX_PATH:FILEPATH=\"\$CMAKE_PREFIX_PATH\" -DCMAKE_BUILD_TYPE=Release"

CMAKE_ARGS="$CMAKE_BASE_ARGS $CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=/usr"

MESON_ARGS="--prefix /usr --buildtype release --default-library static -Dintrospection=false"

PROJECT_ARGS="$PROJECT_ARGS"

DIST_PATCHES=$DIST_PATCHES'
docbook2x https://gist.githubusercontent.com/rkitover/0b5dcc95a0703a9b0e0e7eb6d325a98e/raw/e256d2fad8d19633ac8abe02a0d1e119063d1fd9/docbook2x.patch
graphite2 https://gist.githubusercontent.com/rkitover/418600634d7cf19e2bf1c3708b50c042/raw/839b72d9cda545f2e3b640d743c1bd44b89861b9/graphite2-1.3.10-static.patch
Expand Down Expand Up @@ -269,12 +279,12 @@ DIST_PRE_BUILD="$DIST_PRE_BUILD
"

DIST_POST_BUILD="$DIST_POST_BUILD
harfbuzz rebuild_dist freetype --with-harfbuzz=yes;
harfbuzz rebuild_dist freetype;
flex-2.6.3 build_dist flex || :;
glib rebuild_dist gettext --without-included-glib --without-included-libxml;
graphviz (cd '$BUILD_ROOT/root/bin'; path_exists dot_static && ! path_exists dot && ln -sf '$BUILD_ROOT/root/bin/dot_static' ./dot || :)
libxml2 mkdir -p '$BUILD_ROOT/root/etc/xml'; \
xmlcatalog --noout --create '$BUILD_ROOT/root/etc/xml/catalog.xml' || :;
xmlcatalog --noout --create \"\$(cygpath -m \"$BUILD_ROOT/root/etc/xml/catalog.xml\")\" || :;
python2 pip2 install six;
python3 pip3 install six;
fontconfig mkdir -p '$BUILD_ROOT/root/etc/fonts'; \
Expand Down Expand Up @@ -343,14 +353,11 @@ DIST_ARGS="$DIST_ARGS
libx264 --enable-pic
libx265 -DHIGH_BIT_DEPTH=ON -DENABLE_ASSEMBLY=OFF -DENABLE_CLI=OFF
ffmpeg --pkg-config-flags=--static --enable-nonfree --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-version3 --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-openssl --enable-lzma --extra-cflags='-DMODPLUG_STATIC -DZMQ_STATIC' --extra-cxxflags='-DMODPLUG_STATIC -DZMQ_STATIC' --extra-objcflags='-DMODPLUG_STATIC -DZMQ_STATIC'
ffmpeg --pkg-config-flags=--static --enable-nonfree --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-version3 --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-libzvbi --enable-openssl --enable-lzma --extra-cflags='-DMODPLUG_STATIC -DZMQ_STATIC' --extra-cxxflags='-DMODPLUG_STATIC -DZMQ_STATIC' --extra-objcflags='-DMODPLUG_STATIC -DZMQ_STATIC'
#
# TODO: add these if possible (from brew) --enable-indev=qtkit --enable-securetransport --enable-chromaprint --enable-ffplay --enable-frei0r --enable-libbs2b --enable-libcaca --enable-libfdk-aac --enable-libgme --enable-libgsm --enable-librtmp --enable-librubberband --enable-libssh --enable-libtesseract --enable-libtwolame --enable-webp --enable-libzimg
#
# Possibly also: --enable-libzvbi
# I could not get libzvbi to build
#
# these require > 10.7:
# --enable-opencl # requires 10.8
# --enable-videotoolbox # requires 10.8
Expand Down Expand Up @@ -455,6 +462,12 @@ setup() {
done
cd "$OPWD"

if [ -z "$BUILD_FFMPEG" ]; then
for dist in $FFMPEG_DISTS; do
table_line_remove DISTS $dist
done
fi

DIST_NAMES=$( table_column DISTS 0 3)
DIST_URLS=$( table_column DISTS 1 3)
DIST_TARGETS=$(table_column DISTS 2 3)
Expand Down Expand Up @@ -622,10 +635,6 @@ windows_install_core_deps() {
fi
}

cygwin_install_core_deps() {
:
}

msys2_install_core_deps() {
case "$MSYSTEM" in
MINGW32)
Expand All @@ -642,13 +651,12 @@ msys2_install_core_deps() {
pacman -Sy

set --
for p in binutils curl crt-git gcc gcc-libs gdb headers-git tools-git windows-default-manifest libmangle-git; do
for p in binutils curl crt-git gcc gcc-libs headers-git tools-git windows-default-manifest libmangle-git; do
set -- "$@" "${target}-${p}"
done

# install
# TODO: remove zip and add to dists
pacman --noconfirm --needed -S make tar patch diffutils ccache zip perl m4 msys2-w32api-headers msys2-runtime-devel gcc gcc-libs mpfr windows-default-manifest python2 "$@"
pacman --noconfirm --needed -S make tar patch diffutils ccache perl msys2-w32api-headers msys2-runtime-devel gcc gcc-libs mpfr windows-default-manifest python2 "$@"

# make sure msys perl takes precedence over mingw perl if the latter is installed
mkdir -p "$BUILD_ROOT/root/bin"
Expand All @@ -663,6 +671,34 @@ msys2_install_core_deps() {
done_msg
}

cygwin_install_core_deps() {
installing_core_deps

target="mingw64-${target_cpu}"

curl -L rawgit.com/transcode-open/apt-cyg/master/apt-cyg > "$BUILD_ROOT/root/bin/apt-cyg"
chmod +x "$BUILD_ROOT/root/bin/apt-cyg"

hash -r

apt-cyg update

set --
for p in binutils gcc-core gcc-g++ headers windows-default-manifest; do
set -- "$@" "${target}-${p}"
done

apt-cyg install make tar patch diffutils ccache perl m4 cygwin32-w32api-headers gcc-core gcc-g++ mpfr windows-default-manifest python2 libncurses-devel "$@"

# alias python2 to python
ln -sf /usr/bin/python2.exe "$BUILD_ROOT/root/bin/python.exe"

# activate ccache
eval "$BUILD_ENV"

done_msg
}

mac_install_core_deps() {
if ! xcode-select -p >/dev/null 2>&1 && \
! pkgutil --pkg-info=com.apple.pkg.CLTools_Executables >/dev/null 2>&1 && \
Expand Down Expand Up @@ -1681,6 +1717,8 @@ EOF
;;
esac

link_dest=$(fully_resolve_link "$link_dest")

if [ -e "$link_dest" ]; then
echo_run ln -sf "$link_dest" "$dest_f"
else
Expand All @@ -1696,7 +1734,7 @@ ln -sf \"$link_dest\" \"$dest_f\"
# don''t relocate headers, man and info pages and docs
case "$dest_f" in
share/doc/*|share/man/*|share/info/*|include/*)
echo_run cp -af "$tmp_prefix/$f" "$dest_f"
echo_run cp -af "$tmp_prefix/$f" "$dest_f" || echo_run cp -rf "$tmp_prefix/$f" "$dest_f"
continue
;;
esac
Expand Down Expand Up @@ -1742,7 +1780,16 @@ ln -sf \"$link_dest\" \"$dest_f\"
continue
fi

echo_run cp -af "$tmp_prefix/$f" "$dest_f"
echo_run cp -af "$tmp_prefix/$f" "$dest_f" || echo_run cp -rf "$tmp_prefix/$f" "$dest_f"

# when cross-compiling, link arch-suffixed libs to their normal names
if [ -n "$target_arch" ]; then
case "$f" in
*/lib/*-${target_arch}.a)
echo_run ln -sf "$PWD/$dest_f" "${dest_f%%-${target_arch}.a}.a"
;;
esac
fi
done
IFS=$OIFS

Expand Down Expand Up @@ -2050,17 +2097,15 @@ install_docbook_dist() {

_dir="$BUILD_ROOT/root/share/xml/docbook/$_dir"

# on cygwin/msys write native POSIX paths to catalog
if command -v cygpath >/dev/null; then
_dir=$(cygpath -m "$_dir")
fi

echo_run mkdir -p "$_dir"
echo_run cp -af * "$_dir"
echo_run cp -af * "$_dir" || echo_run cp -rf * "$_dir"

# on cygwin/msys write native POSIX paths to catalog
_dir=$(cygpath -m "$_dir")

if [ -f "$_dir/catalog.xml" ]; then
echo_run xmlcatalog --noout --del "file://$_dir/catalog.xml" "$BUILD_ROOT/root/etc/xml/catalog.xml" || :
echo_run xmlcatalog --noout --add nextCatalog '' "file://$_dir/catalog.xml" "$BUILD_ROOT/root/etc/xml/catalog.xml"
echo_run xmlcatalog --noout --del "file://$_dir/catalog.xml" "$(cygpath -m "$BUILD_ROOT/root/etc/xml/catalog.xml")" || :
echo_run xmlcatalog --noout --add nextCatalog '' "file://$_dir/catalog.xml" "$(cygpath -m "$BUILD_ROOT/root/etc/xml/catalog.xml")"
fi
}

Expand Down Expand Up @@ -2296,7 +2341,7 @@ build_project() {
cd "$BUILD_ROOT/project"

# FIXME: turn LTO back on when everything works
echo_eval_run cmake "'$CHECKOUT'" $REQUIRED_CMAKE_ARGS -DVBAM_STATIC=ON -DENABLE_FFMPEG=OFF -DENABLE_LTO=OFF $PROJECT_ARGS $CMAKE_BASE_ARGS $@
echo_eval_run cmake "'$CHECKOUT'" $REQUIRED_CMAKE_ARGS -DVBAM_STATIC=ON -DENABLE_LTO=OFF $PROJECT_ARGS $CMAKE_BASE_ARGS $@
echo_run make -j$NUM_CPUS

if [ "$os" = mac ]; then
Expand Down Expand Up @@ -2471,5 +2516,69 @@ ln() {
command ln "$@"
}

cygpath() {
if /bin/command -v cygpath >/dev/null; then
command cygpath "$@"
else
case "$1" in
-*)
shift
;;
esac

echo "$@"
fi
}

fully_resolve_link() {
file=$1
# get initial part for non-absolute path, or blank for absolute
path=${file%%/*}
# and set $file to the rest
file=${file#*/}

OLDIFS=$IFS
IFS='/'
for part in $file; do
[ ! -z "$part" ] && path=$(resolve_link "$path/$part")
done
IFS=$OLDIFS

# remove 'foo/..' path parts
while :; do
case "$path" in
*/../*|*/..)
path=$(echo "$path" | sed 's,//*[^/][^/]*//*\.\./*,/,g')
;;
*)
break
;;
esac
done

# remove trailing /s
while [ "$path" != "${path%/}" ]; do
path=${path%/}
done

echo "$path"
}

resolve_link() {
file=$1

while [ -h "$file" ]; do
ls0=$(ls -ld "$file")
new_link=$(expr "$ls0" : '.* -> \(.*\)$')
if expr "$new_link" : '/.*' > /dev/null; then
file="$new_link"
else
file="${file%/*}"/"$new_link"
fi
done

echo "$file"
}

# this needs to run on source, not just after entry
setup

0 comments on commit aa852d9

Please sign in to comment.