From ed293325236b4f5f569629138c0e9a917ea06f44 Mon Sep 17 00:00:00 2001
From: Marty Plummer <ntzrmtthihu777@gmail.com>
Date: Tue, 18 Jul 2017 06:24:21 -0500
Subject: [PATCH] Added meson build files and manifests for dlls.

Works, builds both native linux and cross-compiles mingw-w64 variants.
Need to work out copying appropriate dlls into the mkxp runtime folder.

Signed-off-by: Marty Plummer <ntzrmtthihu777@gmail.com>
---
 assets/mkxp.manifest.in             |  33 +++++++++
 assets/runtime.manifest.in          |  30 ++++++++
 binding-mri/meson.build             |  27 ++++++++
 binding-mruby/meson.build           |  28 ++++++++
 binding-null/meson.build            |   5 ++
 cross/gentoo-i686-w64-mingw32.txt   |  16 +++++
 cross/gentoo-x86_64-w64-mingw32.txt |  16 +++++
 meson.build                         | 102 ++++++++++++++++++++++++++++
 meson_options.txt                   |   5 ++
 src/meson.build                     |  45 ++++++++++++
 tools/xxd.sh                        |  10 +++
 windows/resource.rc                 |   2 +-
 12 files changed, 318 insertions(+), 1 deletion(-)
 create mode 100644 assets/mkxp.manifest.in
 create mode 100644 assets/runtime.manifest.in
 create mode 100644 binding-mri/meson.build
 create mode 100644 binding-mruby/meson.build
 create mode 100644 binding-null/meson.build
 create mode 100644 cross/gentoo-i686-w64-mingw32.txt
 create mode 100644 cross/gentoo-x86_64-w64-mingw32.txt
 create mode 100644 meson.build
 create mode 100644 meson_options.txt
 create mode 100644 src/meson.build
 create mode 100755 tools/xxd.sh

diff --git a/assets/mkxp.manifest.in b/assets/mkxp.manifest.in
new file mode 100644
index 0000000..228210a
--- /dev/null
+++ b/assets/mkxp.manifest.in
@@ -0,0 +1,33 @@
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <assemblyIdentity type="win32"
+                    name="MKXP.Application"
+                    version="2.0.0.0"
+                    processorArchitecture="@ARCH@" />
+  <description>MKXP.Application</description>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type="win32"
+                        name="Microsoft.Windows.Common-Controls"
+                        version="6.0.0.0"
+                        language="*"
+                        processorArchitecture="*"
+                        publicKeyToken="6595b64144ccf1df" />
+    </dependentAssembly>
+  </dependency>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type="win32"
+                        name="runtime"
+                        version="1.0.0.0"
+                        language="*"
+                        processorArchitecture="@ARCH@" />
+    </dependentAssembly>
+  </dependency>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+</assembly>
diff --git a/assets/runtime.manifest.in b/assets/runtime.manifest.in
new file mode 100644
index 0000000..336847a
--- /dev/null
+++ b/assets/runtime.manifest.in
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+	<noInheritable></noInheritable>
+	<assemblyIdentity type="win32" name="runtime" version="1.0.0.0" processorArchitecture="@ARCH@" ></assemblyIdentity>
+	<!-- <file name="libstdc++-6.dll"></file> -->
+	<!-- <file name="libgcc_s_sjlj-1.dll"></file> -->
+	<file name="libboost_program_options.dll"></file>
+	<file name="libFLAC-8.dll"></file>
+	<file name="libfreetype-6.dll"></file>
+	<file name="libgcc_s_seh-1.dll"></file>
+	<file name="libjpeg-62.dll"></file>
+	<file name="libmodplug-1.dll"></file>
+	<file name="libogg-0.dll"></file>
+	<file name="libphysfs.dll"></file>
+	<file name="libpixman-1-0.dll"></file>
+	<file name="libpng16-16.dll"></file>
+	<file name="libSDL2-2-0-0.dll"></file>
+	<file name="libSDL_sound-1-0-1.dll"></file>
+	<file name="libsigc-2.0-0.dll"></file>
+	<file name="libspeex-1.dll"></file>
+	<file name="libstdc++-6.dll"></file>
+	<file name="libvorbis-0.dll"></file>
+	<file name="libvorbisfile-3.dll"></file>
+	<file name="libwebp-6.dll"></file>
+	<file name="OpenAL32.dll"></file>
+	<file name="ruby24.dll"></file>
+	<file name="SDL2_image.dll"></file>
+	<file name="SDL2_ttf.dll"></file>
+	<file name="zlib1.dll"></file>
+</assembly>
diff --git a/binding-mri/meson.build b/binding-mri/meson.build
new file mode 100644
index 0000000..5b6ef72
--- /dev/null
+++ b/binding-mri/meson.build
@@ -0,0 +1,27 @@
+binding_src = [
+	'audio-binding.cpp',
+	'binding-mri.cpp',
+	'binding-util.cpp',
+	'bitmap-binding.cpp',
+	'etc-binding.cpp',
+	'filesystem-binding.cpp',
+	'font-binding.cpp',
+	'graphics-binding.cpp',
+	'input-binding.cpp',
+	'module_rpg.cpp',
+	'plane-binding.cpp',
+	'sprite-binding.cpp',
+	'table-binding.cpp',
+	'tilemap-binding.cpp',
+	'tilemapvx-binding.cpp',
+	'viewport-binding.cpp',
+	'window-binding.cpp',
+	'windowvx-binding.cpp'
+]
+ruby = dependency('-'.join(['ruby', get_option('MRIVERSION')]))
+binding = build_target('binding',
+	binding_src,
+	dependencies : [ ruby, sdl2, sigcxx ],
+	include_directories : incdirs,
+	target_type : 'static_library')
+
diff --git a/binding-mruby/meson.build b/binding-mruby/meson.build
new file mode 100644
index 0000000..167fd7e
--- /dev/null
+++ b/binding-mruby/meson.build
@@ -0,0 +1,28 @@
+binding_src = [
+	'audio-binding.cpp',
+	'binding-mruby.cpp',
+	'binding-util.cpp',
+	'bitmap-binding.cpp',
+	'etc-binding.cpp',
+	'font-binding.cpp',
+	'graphics-binding.cpp',
+	'input-binding.cpp',
+	'module_rpg.c',
+	'mrb-ext/file.cpp',
+	'mrb-ext/kernel.cpp',
+	'mrb-ext/marshal.cpp',
+	'mrb-ext/rwmem.cpp',
+	'mrb-ext/time.cpp',
+	'plane-binding.cpp',
+	'sprite-binding.cpp',
+	'table-binding.cpp',
+	'tilemap-binding.cpp',
+	'viewport-binding.cpp',
+	'window-binding.cpp',
+]
+
+binding = static_library('binding',
+	binding_src,
+	include_directories : incdirs)
+
+error('mruby support is not yet implemented in meson')
diff --git a/binding-null/meson.build b/binding-null/meson.build
new file mode 100644
index 0000000..2c8c2c7
--- /dev/null
+++ b/binding-null/meson.build
@@ -0,0 +1,5 @@
+binding = static_library('binding',
+	'binding-null.cpp',
+	dependencies : [ sdl2, sigcxx ],
+	include_directories : incdirs)
+
diff --git a/cross/gentoo-i686-w64-mingw32.txt b/cross/gentoo-i686-w64-mingw32.txt
new file mode 100644
index 0000000..426c1cd
--- /dev/null
+++ b/cross/gentoo-i686-w64-mingw32.txt
@@ -0,0 +1,16 @@
+[binaries]
+c = '/usr/bin/i686-w64-mingw32-gcc'
+cpp = '/usr/bin/i686-w64-mingw32-g++'
+ar = '/usr/bin/i686-w64-mingw32-ar'
+strip = '/usr/bin/i686-w64-mingw32-strip'
+pkgconfig = '/usr/bin/i686-w64-mingw32-pkg-config'
+windres = '/usr/bin/i686-w64-mingw32-windres'
+
+[host_machine]
+system = 'windows'
+cpu_family = 'i686'
+cpu = 'x86'
+endian = 'little'
+
+[properties]
+root = '/usr/i686-w64-mingw32'
diff --git a/cross/gentoo-x86_64-w64-mingw32.txt b/cross/gentoo-x86_64-w64-mingw32.txt
new file mode 100644
index 0000000..8dd61fa
--- /dev/null
+++ b/cross/gentoo-x86_64-w64-mingw32.txt
@@ -0,0 +1,16 @@
+[binaries]
+c = '/usr/bin/x86_64-w64-mingw32-gcc'
+cpp = '/usr/bin/x86_64-w64-mingw32-g++'
+ar = '/usr/bin/x86_64-w64-mingw32-ar'
+strip = '/usr/bin/x86_64-w64-mingw32-strip'
+pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
+windres = '/usr/bin/x86_64-w64-mingw32-windres'
+
+[host_machine]
+system = 'windows'
+cpu_family = 'x86_64'
+cpu = 'amd64'
+endian = 'little'
+
+[properties]
+root = '/usr/x86_64-w64-mingw32'
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..cccf621
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,102 @@
+project('mkxp',
+	'c', 'cpp',
+	default_options : [ 'c_std=c11', 'cpp_std=c++14'])
+incdirs = include_directories(['assets', 'src'])
+
+# xxd embedding 
+xxd_sh = find_program('tools/xxd.sh')
+xxd_exe = find_program('xxd')
+sed_exe = find_program('sed')
+
+#bin2h_exe = executable('bin2h', 'tools/bin2h.c', native : true)
+xxd_gen = generator(xxd_sh,
+	output : '@PLAINNAME@.xxd',
+	arguments : [ xxd_exe.path(), sed_exe.path(), '@INPUT@', '@OUTPUT@']
+)
+
+embedded = xxd_gen.process(
+	[
+		'assets/icon.png',
+		'assets/liberation.ttf',
+		'shader/bitmapBlit.frag',
+		'shader/blur.frag',
+		'shader/blurH.vert',
+		'shader/blurV.vert',
+		'shader/common.h',
+		'shader/flashMap.frag',
+		'shader/flatColor.frag',
+		'shader/gray.frag',
+		'shader/hue.frag',
+		'shader/minimal.vert',
+		'shader/plane.frag',
+		'shader/simple.frag',
+		'shader/simple.vert',
+		'shader/simpleAlpha.frag',
+		'shader/simpleAlphaUni.frag',
+		'shader/simpleColor.frag',
+		'shader/simpleColor.vert',
+		'shader/simpleMatrix.vert',
+		'shader/sprite.frag',
+		'shader/sprite.vert',
+		'shader/tilemap.vert',
+		'shader/tilemapvx.vert',
+		'shader/trans.frag',
+		'shader/transSimple.frag'
+	]
+)
+
+boost = dependency('boost', modules : ['program_options'])
+openal = dependency('openal')
+physfs = dependency('physfs', version : '>=2.1')
+pixman = dependency('pixman-1')
+sdl2 = dependency('sdl2')
+sdl2_image = dependency('SDL2_image')
+sdl2_ttf = dependency('SDL2_ttf')
+sdl_sound = dependency('SDL_sound')
+sigcxx = dependency('sigc++-2.0')
+vorbisfile = dependency('vorbisfile')
+zlib = dependency('zlib')
+
+fluidsynth = []
+if get_option('SHARED_FLUID')
+	fluidsynth = dependency('fluidsynth')
+	add_global_arguments('-DSHARED_FLUID', language : 'cpp')
+endif
+
+if get_option('RGSS2')
+	add_global_arguments('-DRGSS2', language : 'cpp')
+endif
+
+res = []
+manifest = []
+platdeps = []
+if host_machine.system() == 'windows'
+conf_data = configuration_data()
+conf_data.set('ARCH', host_machine.cpu())
+manifest = configure_file(
+	input : 'assets/mkxp.manifest.in',
+	output : 'mkxp.manifest',
+	configuration : conf_data
+)
+configure_file(
+	input : 'assets/runtime.manifest.in',
+	output : 'runtime.manifest',
+	configuration : conf_data
+)
+win = import('windows')
+res = win.compile_resources([ 'assets/resource.rc' ],
+	include_directories : incdirs)
+endif
+
+subdir('-'.join(['binding', get_option('BINDING').to_lower()]))
+
+subdir('src')
+
+executable(
+	'mkxp',
+	sources : [ embedded, main_src, res ],
+	link_with : binding,
+	dependencies : [boost, fluidsynth, openal, physfs, pixman, sdl2,
+			sdl2_image, sdl2_ttf, sdl_sound, sigcxx, vorbisfile, zlib ],
+	include_directories : [ incdirs ]
+)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..7771015
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,5 @@
+option('SHARED_FLUID', type : 'boolean', value : false, description : 'Dynamically link with fluidsynth at build time')
+option('WORKDIR_CURRENT', type : 'boolean', value : false, description : 'Keep current directory on startup')
+option('BINDING', type : 'combo', choices : ['MRI', 'MRUBY', 'NULL'], value : 'MRI', description : 'The Binding Type (MRI, MRUBY, NULL)')
+option('MRIVERSION', type : 'string', value : '2.1', description : 'Version of MRI to link with')
+option('RGSS2', type : 'boolean', value : false)
diff --git a/src/meson.build b/src/meson.build
new file mode 100644
index 0000000..bac5848
--- /dev/null
+++ b/src/meson.build
@@ -0,0 +1,45 @@
+main_src = files(
+	'alstream.cpp',
+	'audio.cpp',
+	'audiostream.cpp',
+	'autotiles.cpp',
+	'autotilesvx.cpp',
+	'bitmap.cpp',
+	'bundledfont.cpp',
+	'config.cpp',
+	'etc.cpp',
+	'eventthread.cpp',
+	'filesystem.cpp',
+	'fluid-fun.cpp',
+	'font.cpp',
+	'gl-debug.cpp',
+	'gl-fun.cpp',
+	'gl-meta.cpp',
+	'glstate.cpp',
+	'graphics.cpp',
+	'input.cpp',
+	'keybindings.cpp',
+	'main.cpp',
+	'midisource.cpp',
+	'plane.cpp',
+	'rgssad.cpp',
+	'scene.cpp',
+	'sdlsoundsource.cpp',
+	'settingsmenu.cpp',
+	'shader.cpp',
+	'sharedstate.cpp',
+	'soundemitter.cpp',
+	'sprite.cpp',
+	'table.cpp',
+	'texpool.cpp',
+	'tileatlas.cpp',
+	'tileatlasvx.cpp',
+	'tilemap.cpp',
+	'tilemapvx.cpp',
+	'tilequad.cpp',
+	'vertex.cpp',
+	'viewport.cpp',
+	'vorbissource.cpp',
+	'window.cpp',
+	'windowvx.cpp'
+)
diff --git a/tools/xxd.sh b/tools/xxd.sh
new file mode 100755
index 0000000..758851f
--- /dev/null
+++ b/tools/xxd.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# meson resolves paths such as processing assets/icon.png's command line
+# ends up being `xxd -i ../assets/icon.png icon.png.xxd`, resulting in a
+# prefix of `___` on all variable names. We postprocess xxd with sed for
+# now in order to have proper variable names.
+# ./xxd.sh /path/to/xxd /path/to/sed infile outfile
+
+$1 -i $3 $3.tmp
+$2 's:___::g' $3.tmp > $4
+rm $3.tmp
diff --git a/windows/resource.rc b/windows/resource.rc
index 293e38d..cf86965 100644
--- a/windows/resource.rc
+++ b/windows/resource.rc
@@ -1,4 +1,4 @@
 #include <windows.h>
 #include "resource.h"
-
+1 RT_MANIFEST mkxp.manifest
 IDI_APPICON ICON "icon.ico"