# License: CC0

# Cross Build #

## Using openSUSE Build Service ##

As of December 2023, Viking is available on https://openbuildservice.org/

https://build.opensuse.org/package/show/windows:mingw:win32/mingw32-viking

https://build.opensuse.org/package/show/windows:mingw:win64/mingw64-viking

Thus cross-building is supported using the 'osc' command in varieties of SUSE and other Linuxes
 e.g. Debian (as preferred by this author) *locally*;
So https://openbuildservice.org/ might not be used or may get updated some time after the main formal release.

See https://openbuildservice.org/help/manuals/obs-user-guide/ for details on setup and usage of 'osc'.
Generally it is a case of:
          1. Ensuring "Setting Up Your Home Project for the First Time".
          2. Then "Creating a New Package Within Your Home Project".

then e.g.:
          cd ~/Code/home:$USER/mingw64-viking/
          osc build --local-package --no-verify
          # Ideally would want to simply get viking.exe directly from this build environment;
          #  but as the BUILDROOT gets wiped, and unfortunately osc / obs-build is severely outdated on Debian at time of writing
          #  and doesn't support '--buildopts=--noclean'
          # So either install the RPM somewhere, or extract from the RPM:
          # rpm2cpio mingw64-viking-1.*.rpm | cpio -idv *viking.exe

ATM, although the compiling build can be performed under 'osc', creating the Windows Installer is a little more bespoke;
and so remains doing under the VM method detailed below.

## Using OpenSUSE Tumbleweed in a VM ##

This is for 32 bit version, but very similar for 64 version.
Just use mingw64-viking.spec file instead, install the appropriate 64bit dependencies and it produce a viking-win64-*.exe file.

### Host Preparation ###

On the host need to ensure the viking-1.X.tar.gz file is available:
	cd code/viking
	make dist

Generate help PDF
	dblatex help/C/index.docbook -o viking.pdf
This could be done in the VM but installing dblatex requires ~650Mb install (so a waste if already available on the host).

### Guest Preparation (root) ###

In the guest ensure availability of build dependent mingw32 / mingw64 packages (not in standard Tumbleweed repo ATM)
	# As root
	zypper ar -f http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Tumbleweed windows
	zypper ar -f http://download.opensuse.org/repositories/windows:/mingw:/win64/openSUSE_Tumbleweed windows64
	# Ensure a standard user account is available for the build e.g:
	#useradd -m build
	#passwd build

Install build packages as listed in the .spec file or when running the rpmbuild it will tell you what packages are required
	zypper install mingw32-cross-gcc
	#etc...

For the MSI generation you will need
	zypper install mingw32-cross-nsis

And ensure FindProcDLL is available for NSIS
if [ ! -e /usr/share/nsis/Plugins/FindProcDLL.dll ];
	wget http://nsis.sourceforge.net/mediawiki/images/3/3c/FindProc.zip
	unzip FindProc.zip FindProcDLL.dll -d /usr/share/nsis/Plugins/
fi

Make code accessible via a shared folder
So add a suitable Shared Folder to the virtual machine
Remember the build user will need mount access priviledges - if using VirtualBox then:
	##As root: Enable shared folder - often needing to run guest additions (insert/add disk .iso image)
	#zypper install kernel-source kernel-syms
	#mount /dev/cdrom /media/cdrom
	#cd /media/cdrom/
	#./VBoxLinuxAdditions.run
	## Allow access
	#usermod -a -G vboxsf <builduser>

### Guest Preparation (builduser) ###

Go to the code location
	cd /media/sf_Code/viking

Copy source package as generated by make dist on the host to the package build area, or even just link to it e.g.:
	ln -s /media/sf_Code/viking/viking-1.6.1.tar.gz /home/build/rpmbuild/SOURCES/viking-1.6.1.tar.gz

### Build on Guest ###

Now perform the build (32bit):
	rpmbuild -ba mingw32-viking.spec
# or for the 64bit build:
#   rpmbuild -ba mingw64-viking.spec

Install locally
	sudo rpm -i /home/build/rpmbuild/RPMS/noarch/ming*-viking-*.noarch.rpm

Generate .msi
	cd windows
	./installer-mingw.sh
	cd -

### Install + Run on Host (or guest) ###
Install the appropriate 64bit or 32bit executable:
	wine windows/installer/viking-win64-*.exe

Run viking.exe with wine
	cd ~/.wine/drive_c/Program\ Files/Viking/
	wine viking.exe

#########################################################################

# Native Build #

The build under Windows follows the same process as the traditional Linux build:

    cd ../src
    sh configure <options>
    make

There is a separate installer method using NSIS to generate the viking-1.X.Y.Z.exe installer file.

To generate the installer (once the code has been compiled as above) run the installer.bat

For further details (especially about how to set up the development dependencies) see:
http://sourceforge.net/apps/mediawiki/viking/index.php?title=WindowsBuildInstructions

These instructions have now been turned turned into a series of scripts to produce the Viking installer:

1. prepare.bat
2a. configure_and_make.bat
2b. make.bat
3. installer.bat

The scripts are aimed at a pristine Windows XP installation.
Using *prepare.bat* will attempt to *download* and *install* various Open Source software to aid this process.
An administrator level account is needed to run this which will *modify* your system.

The other scripts simply make use of these (assumed) available system programs.

This setup is for dedicated usage to build Viking, primarily under Wine with:

 ./generate_install.sh

Such that any Windows system (or of course a Virtual Machine) can be simply deleted (e.g. rm -rf /.wine) and recreated fully via the scripts.

From Viking 1.4 to 1.6.X this was how the Windows viking-W.X.Y.Z.exe installer file was produced.

Notionally the standard configure + make stages should still work, but the Cross build is now the supported method.
Thus the prepare + installer scripts are no longer maintained and are for reference only.
