Skip to content

Commit

Permalink
Initial support for the mingw platform
Browse files Browse the repository at this point in the history
  • Loading branch information
dciabrin committed May 29, 2018
1 parent 443d522 commit c655a25
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 13 deletions.
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015 Damien Ciabrini
# Copyright (c) 2015-2018 Damien Ciabrini
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -143,7 +143,7 @@ build/nggcc:

build/ngnewlib: build
@ echo compiling newlib...; \
export PATH=$(LOCALDIR)/bin:$$PATH; \
export PATH="$(LOCALDIR)/bin:$$PATH"; \
mkdir -p build/ngnewlib; \
cd build/ngnewlib; \
../../toolchain/$(SRC_NEWLIB)/configure \
Expand All @@ -157,7 +157,7 @@ build/ngnewlib: build

build/nggdb: build
@ echo compiling gdb...; \
export PATH=$(LOCALDIR)/bin:$$PATH; \
export PATH="$(LOCALDIR)/bin:$$PATH"; \
mkdir -p build/nggdb; \
cd build/nggdb; \
../../toolchain/$(SRC_GDB)/configure \
Expand All @@ -169,7 +169,7 @@ build/nggdb: build

build/ngsdcc: build
@ echo compiling sdcc...; \
export PATH=$(LOCALDIR)/bin:$$PATH; \
export PATH="$(LOCALDIR)/bin:$$PATH"; \
mkdir -p build/ngsdcc; \
cd build/ngsdcc; \
../../toolchain/sdcc/configure \
Expand All @@ -193,15 +193,15 @@ build/ngsdcc: build
make $(HOSTOPTS); \
make install

GNGEO_BUILD_FLAGS=--prefix=$(LOCALDIR) CPPFLAGS="-I$(LOCALDIR)/include" CFLAGS="-I$(LOCALDIR)/include" LDFLAGS="-L$(LOCALDIR)/lib"

build/gngeo: build
@ echo compiling gngeo...; \
export PATH=$(LOCALDIR)/bin:$$PATH; \
export PATH="$(LOCALDIR)/bin:$$PATH"; \
mkdir -p build/gngeo; \
cd build/gngeo; \
../../toolchain/gngeo/configure \
--prefix=$(LOCALDIR) \
CPPFLAGS="-I$(LOCALDIR)/include" CFLAGS="-I$(LOCALDIR)/include" LDFLAGS="-L$(LOCALDIR)/lib"; \
make $(HOSTOPTS); \
../../toolchain/gngeo/configure $(GNGEO_BUILD_FLAGS) && \
make $(HOSTOPTS) && \
make install

# (find . -name Makefile | xargs sed -i.bk -e 's/-frerun-loop-opt//g' -e 's/-funroll-loops//g' -e 's/-malign-double//g');
Expand All @@ -213,13 +213,13 @@ build-tools:

shellinit:
@ echo Variables set with eval $$\(make shellinit\) >&2
@ echo export PATH=$(LOCALDIR)/bin:\$$PATH
@ echo export PATH="$(LOCALDIR)/bin:\$$PATH"
ifeq ($(shell uname), Darwin)
@ echo export DYLD_LIBRARY_PATH=$(LOCALDIR)/lib:\$$DYLD_LIBRARY_PATH
@ echo export DYLD_LIBRARY_PATH="$(LOCALDIR)/lib:\$$DYLD_LIBRARY_PATH"
else
@ echo export LD_LIBRARY_PATH=$(LOCALDIR)/lib:\$$LD_LIBRARY_PATH
@ echo export LD_LIBRARY_PATH="$(LOCALDIR)/lib:\$$LD_LIBRARY_PATH"
endif
@ echo export PYTHONPATH=$(LOCALDIR)/bin:\$$PYTHONPATH
@ echo export PYTHONPATH="$(LOCALDIR)/bin:\$$PYTHONPATH"

clean:
rm -rf build/ngbinutils build/nggcc build/ngnewlib
Expand Down
9 changes: 9 additions & 0 deletions Makefile.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ HOSTOPTS=
# Default input config for gngeo
GNGEO_CFG=$(HOME)/.gngeo/gngeorc
define GNGEO_DEFAULT_INPUT_SETTINGS =
scale 3
joystick true
p1control A=K97,B=K115,C=K113,D=K119,START=K49,COIN=K51,UP=K82,DOWN=K81,LEFT=K80,RIGHT=K79,A=J0B0,B=J0B1,C=J0B2,D=J0B3,START=J0B9,COIN=J0B8,UP=J0a3,DOWN=J0a3,LEFT=J0A0,RIGHT=J0A0
endef

# MinGW configuration bits
# Absolute path are required here
GNGEO_INSTALL_PATH=
SDL2_DLL=
# Variable below are autodetected
MINGW_GCC=
ZLIB1_DLL=
43 changes: 43 additions & 0 deletions Makefile.mingw
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2018 Damien Ciabrini
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# ngdevkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ngdevkit. If not, see <http://www.gnu.org/licenses/>.

include Makefile

ifeq ($(strip $(GNGEO_INSTALL_PATH)),)
$(error Missing GnGEO installation path (GNGEO_INSTALL_PATH). See README.mingw for more details)
else
GNGEO_CFG=$(GNGEO_INSTALL_PATH)/conf/gngeorc
endif

ifeq ($(strip $(SDL2_DLL)),)
$(error Missing path to SDL2.dll (SDL2_DLL). See README.mingw for more details)
endif

# default mingw compiler
ifeq ($(strip $(MINGW_GCC)),)
MINGW_GCC=$(shell uname -p)-w64-mingw32-gcc
endif

ifeq ($(strip $(ZLIB1_DLL)),)
ZLIB1_DLL=$(shell $(MINGW_GCC) -print-file-name=zlib1.dll)
endif

GNGEO_BUILD_FLAGS=--enable-mingw --host=x86_64-w64-mingw32 --prefix=$(GNGEO_INSTALL_PATH) CPPFLAGS="-I$(LOCALDIR)/include" CFLAGS="-I$(LOCALDIR)/include" LDFLAGS="-L$(LOCALDIR)/lib"

all: install-emulator-dll
install-emulator-dll: build-emulator
cp $(SDL2_DLL) $(GNGEO_INSTALL_PATH) && \
cp $(ZLIB1_DLL) $(GNGEO_INSTALL_PATH)
123 changes: 123 additions & 0 deletions README-mingw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Compiling ngdevkit on the Windows platform

Compiling the devkit for Windows 10 is supported via [WSL][wsl]:

* The devkit generates Linux binaries that can be used from your
Linux environment or called like a regular Windows command via
WSL's [interoperability wrapper][interop].

* The GnGeo emulator is a native Windows GUI application. You
can call it from both Linux and Windows and don't need a
X server to run it.

* The source-level debugging extension is not available yet.

You need to run a couple of manual steps before being able to compile
the devkit. This documentation explains how to compile ngdevkit with
Ubuntu on Windows.

## Pre-requisite

### Make sure you have an available WSL environment

Follow the
[WSL install documentation](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
to enable the WSL subsystem on your Windows host.

Then go on the Windows store and choose a Linux distribution to
install on your Windows 10 host. This documentation uses Ubuntu 16.04,
but any other `apt`-based distribution should work the same.

## Building the devkit

### Configure the package repositories

Edit `/etc/apt/sources.list` to make the source packages from `main`
and `universe` repositories are available to apt. They are used to
resolve the packages that need to be installed to build gcc and
sdcc. Those two lines should be uncommented in
`/etc/apt/sources.list`:

deb-src http://archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu/ xenial universe

### Install the dependencies

Install the packages required to build the devkit's compilers and
tools:

sudo apt-get update
sudo apt-get install gcc curl unzip
GCC_VERSION_PKG=$(apt-cache depends gcc | awk '/Depends.*gcc/ {print $2}')
sudo apt-get build-dep $GCC_VERSION_PKG
sudo apt-get build-dep sdcc
sudo apt-get install libsdl2-dev
sudo apt-get install imagemagick
sudo apt-get install python-pygame
sudo apt-get install automake
sudo apt-get install autoconf-archive

Then install the mingw cross-compiler to build a native GnGeo binary,
and install GnGeo's DLL dependencies:

sudo apt-get install mingw-w64
sudo apt-get install libz-mingw-w64-dev

### Download SDL2 runtime and development files

You need to download the SDL2 development files (header, library,
pkgconfig) and the redistributable SDL2 runtime binary
(`SDL2.dll`) from the [SDL2 website](https://www.libsdl.org/download-2.0.php).
For example:

cd $HOME
curl -LO https://www.libsdl.org/release/SDL2-devel-2.0.8-mingw.tar.gz
curl -LO https://www.libsdl.org/release/SDL2-2.0.8-win32-x64.zip

Extract the SDL dll somewhere and remember the location of that file
for later:

cd $HOME
unzip SDL2-2.0.8-win32-x64.zip
# this yields a file $HOME/SDL2.dll

Extract the development files and install the mingw-specifc files
into system's default location:

tar xf SDL2-devel-2.0.8-mingw.tar.gz
sudo cp -af SDL2-2.0.8/i686-w64-mingw32 SDL2-2.0.8/x86_64-w64-mingw32 /usr/local

Note: even if Ubuntu's mingw package installs in `/usr`, SDL2 expects
mingw to be located in `/usr/local`; so extract into that destination
path, and let GnGeo autodetect it automatically during compilation.


### Building the toolchain

Unlike other platforms, a native Windows 10 GnGeo requires all
its files to be located under a common directory. You need to
configure that GnGeo installation directory directly in file
`Makefile.config`. For example:

GNGEO_INSTALL_PATH=/mnt/c/Users/ngdevkit/Desktop/gngeo

Note: it's a good idea to choose a directory under `/mnt/c` if you
want to run GnGeo easily from the Windows explorer.

You also need to update `Makefile.config` to specify the location of
file `SDL2.dll` that you extracted previously. This file will be
copied to the GnGeo installation directory automatically when building
the devkit. For example:

SDL2_DLL=/home/ngdevkit/SDL2.dll

Once this is done, you can build the devkit by using the dedicated
mingw makefile:

make -f Makefile.mingw

And voilà! You can now use the devkit and the emulator as described
in [the main README](README.md) file.

[wsl]: https://docs.microsoft.com/en-us/windows/wsl/install-win10
[interop]: https://docs.microsoft.com/en-us/windows/wsl/interop
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ If running OS X, you will need XCode and brew:
# "easy_install pip" if you don't have pip yet, then
pip install pygame

Compiling the devkit for Windows 10 is supported via [WSL][wsl],
detailed setup and build instructions are available in the
[the dedicated README](README-mingw.md).


### Building the toolchain

You may want to change `Makefile.config` to select a GNU mirror which
Expand Down Expand Up @@ -185,3 +190,4 @@ License along with this program. If not, see
[gngeo]: https://github.com/dciabrin/gngeo
[mame]: http://mamedev.org/
[sip]: https://support.apple.com/en-us/HT204899
[wsl]: https://docs.microsoft.com/en-us/windows/wsl/install-win10
14 changes: 14 additions & 0 deletions examples/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ common-clean:
rm -rf *.elf *.o *~ rom


# Emulator targets
#
ifeq ($(strip $(SDL2_DLL)),)
# regular case: pass the rompath to the emulator
$(call export_path,gngeo)
gngeo:
$(LOCALDIR)/bin/gngeo -b glsl --scale 3 --no-resize --shaderpath=$(LOCALDIR)/../toolchain/qcrt-glsl --shader qcrt-flat.glslp -i rom puzzledp
Expand All @@ -72,4 +76,14 @@ $(call export_path,gngeo-fullscreen)
gngeo-fullscreen:
$(LOCALDIR)/bin/gngeo -b glsl --fullscreen --scale 5 --no-resize --shaderpath=$(LOCALDIR)/../toolchain/qcrt-glsl --shader qcrt-flat.glslp -i rom puzzledp

else
# MinGW: copy ROMs to the gngeo dir
gngeo:
cp rom/puzzledp.zip rom/neogeo.zip $(GNGEO_INSTALL_PATH)/roms && (cd $(GNGEO_INSTALL_PATH) && ./gngeo.exe --scale 3 --no-resize puzzledp)

gngeo-fullscreen:
cp rom/puzzledp.zip rom/neogeo.zip $(GNGEO_INSTALL_PATH)/roms && (cd $(GNGEO_INSTALL_PATH) && ./gngeo.exe --fullscreen --scale 5 --no-resize puzzledp)

endif

.PHONY: cart nullbios common-clean gngeo gngeo-fullscreen

0 comments on commit c655a25

Please sign in to comment.