******************************************************************************
***            Cross-compiling Avidemux on Linux for Windows               ***
***                                                                        ***
***          Description of the default build environment setup            ***
******************************************************************************


1. Install MXE (M cross environment) dependencies as described in

    http://mxe.cc/#requirements

for your respective Linux distribution then clone the git repository as
described in

    http://mxe.cc/#download

to /opt:

    cd /opt
    git clone https://github.com/mxe/mxe.git

(make /opt temporarily writable by the user or clone as root / using sudo).
Change the owner and the group of /opt/mxe to those of the user. In the
exemplary setup the 'mxe' folder has been subsequently moved elsewhere and
then bind-mounted to /opt/mxe to save write cycles of an SSD where /opt
resides. This has been done purely for convenience and is not required.


2. Create /opt/mxe/settings.mk with

MXE_TARGETS :=  i686-w64-mingw32.shared x86_64-w64-mingw32.shared

as content to build both 32 bit and 64 bit environments. Optionally, you can
set the variable MXE_TMP which determines where intermediate files are created
(e.g. to /tmp) by adding

MXE_TMP := /tmp

to the settings.mk file.


3. Build required MXE packages for the targets specified above with

    cd /opt/mxe
    make qtwinextras sdl2 ogg vorbis lame a52dec faad2 fdk-aac libmad opus fribidi libass xvidcore x264

This pulls in all the dependencies and can take a couple of hours. The final
total size of the /opt/mxe folder may be about 2.2G. Please note that twolame
is not available as a shared library and x265 has not been packaged for MXE as
of this writing.


4. Download x265_2.1.tar.gz from

    https://bitbucket.org/multicoreware/x265/downloads

extract the content of the tarball, enter the 'x265_2.1/build' directory,
create a new subdirectory, e.g. 'mingw-w32', enter this subdirectory, create
a 'build.cmake' file there with

SET(CMAKE_SYSTEM_NAME Windows)
SET(CMAKE_C_COMPILER i686-w64-mingw32.shared-gcc)
SET(CMAKE_CXX_COMPILER i686-w64-mingw32.shared-g++)
SET(CMAKE_RC_COMPILER i686-w64-mingw32.shared-windres)
SET(CMAKE_ASM_YASM_COMPILER yasm)

as content, ensure that /opt/mxe/usr/bin is in $PATH and run

    cmake -DCMAKE_TOOLCHAIN_FILE=build.cmake -DCMAKE_INSTALL_PREFIX=/opt/mxe/usr/i686-w64-mingw32.shared -DENABLE_CLI=OFF ../../source
    make -j $(nproc)
    make install

(the last command has to be run as root or using sudo if the directory
'/opt/mxe/usr/i686-w64-mingw32.shared' is not writable by the user).

To build and install 64 bit x265, create e.g. 'mingw-w64' as a subdirectory of
'x265_2.1/build', enter this subdirectory, create a 'build.cmake' file there
with

SET(CMAKE_SYSTEM_NAME Windows)
SET(CMAKE_C_COMPILER x86_64-w64-mingw32.shared-gcc)
SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32.shared-g++)
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32.shared-windres)
SET(CMAKE_ASM_YASM_COMPILER yasm)

as content, again ensure that /opt/mxe/usr/bin is in $PATH  and run

    cmake -DCMAKE_TOOLCHAIN_FILE=build.cmake -DCMAKE_INSTALL_PREFIX=/opt/mxe/usr/x86_64-w64-mingw32.shared -DENABLE_CLI=OFF ../../source
    make -j $(nproc)
    make install

(the last command has to be run as root or using sudo if the directory
'/opt/mxe/usr/x86_64-w64-mingw32.shared' is not writable by the user).

Please note that you need yasm >= 1.3 to build a 64 bit x265 library, this
requirement is not met on Debian 8.


5. Create a user-writable directory 'out' in '/opt/mxe/usr/x86_64-w64-mingw32.shared'
and in '/opt/mxe/usr/i686-w64-mingw32.shared' respectively.


6. Enter the Avidemux top source directory and run

    bash bootStrapCrossMingwQt5_mxe.sh

to cross-compile a 32 bit Avidemux version or

    bash bootStrapCrossMingwQt5_mxe.sh --64

to cross-compile a 64 bit version. Run

    bash bootStrapCrossMingwQt5_mxe.sh -h

to see the list of all available options. It is assumed that 'zip' utility is
installed and in $PATH. Copy the 'avidemux_rYYMMDD-hhmmss_win{32,64}Qt5.zip'
file from the 'packaged_mingw_build_YYMMDD-hhmmss' directory to a Windows
partition, extract it on Windows and run 'avidemux.exe' from there.


7. Issues:

The build of the subtitle plugin and subsequently of the entire Avidemux
package fails as of this writing unless the '--with-system-libass' option is
added.

As of this writing, twolame, aften, vapoursynth and avsproxy are not available.

2016-12-13 UTC 09:02
