Skip to content

Commit

Permalink
Initial support for MSYS2 - native devkit for Windows
Browse files Browse the repository at this point in the history
Ref #47
  • Loading branch information
dciabrin committed Mar 25, 2021
1 parent 154920e commit f845e9c
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 13 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
- name: Install dependencies
run: |
sudo add-apt-repository -y ppa:dciabrin/ngdevkit
# bionic lacks python3-pygame, so install it from this ppa
sudo add-apt-repository -y ppa:thopiekar/pygame
sudo apt-get update -y
sudo apt-get install -y ngdevkit-toolchain python3 zip pkg-config
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/build-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
- name: Install dependencies
run: |
sudo add-apt-repository -y ppa:dciabrin/ngdevkit
# bionic lacks python3-pygame, so install it from this ppa
sudo add-apt-repository -y ppa:thopiekar/pygame
sudo apt-get update -y
sudo apt-get install -y ngdevkit-toolchain python3 zip pkg-config
Expand Down
7 changes: 6 additions & 1 deletion Makefile.config.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019 Damien Ciabrini
# Copyright (c) 2019-2021 Damien Ciabrini
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -44,11 +44,16 @@ INSTALL=@install@

# build flags
EMUDBG_BUILD_FLAGS=@EMUDBG_BUILD_FLAGS@
GNGEO_ACLOCAL_PATH=@GNGEO_ACLOCAL_PATH@
GNGEO_BUILD_FLAGS=@GNGEO_BUILD_FLAGS@
EXTRA_BUILD_CMD=@EXTRA_BUILD_CMD@
EXTRA_BUILD_CMD_TOOLCHAIN=@EXTRA_BUILD_CMD_TOOLCHAIN@
EXTRA_BUILD_FLAGS_TOOLCHAIN=@EXTRA_BUILD_FLAGS_TOOLCHAIN@

# MinGW configuration bits
GNGEO_INSTALL_PATH=@GNGEO_INSTALL_PATH@
ENABLE_MINGW=@ENABLE_MINGW@
ENABLE_MSYS2=@ENABLE_MSYS2@
ZLIB1_DLL=@ZLIB1_DLL@
SDL2_DLL=@SDL2_DLL@
GLEW_FLAGS=@GLEW_FLAGS@
Expand Down
15 changes: 11 additions & 4 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2019 Damien Ciabrini
# Copyright (c) 2015-2021 Damien Ciabrini
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -62,12 +62,12 @@ toolchain:
$(GIT) clone $(TOOLCHAIN_GIT) $@

build-toolchain: | download-toolchain build
$(MAKE) -Ctoolchain all BUILD=$(PWD)/build DESTDIR= prefix=$(prefix)
$(MAKE) -Ctoolchain all BUILD=$(PWD)/build DESTDIR= prefix=$(prefix) EXTRA_BUILD_CMD='$(EXTRA_BUILD_CMD_TOOLCHAIN)' EXTRA_BUILD_FLAGS='$(EXTRA_BUILD_FLAGS_TOOLCHAIN)'

install-toolchain: $(prefix)/bin

$(prefix)/bin: build/ngbinutils build/nggcc build/nggdb build/ngnewlib build/ngsdcc
$(MAKE) -Ctoolchain install BUILD=$(PWD)/build DESTDIR= prefix=$(prefix)
$(MAKE) -Ctoolchain install BUILD=$(PWD)/build DESTDIR= prefix=$(prefix) EXTRA_BUILD_CMD='$(EXTRA_BUILD_CMD_TOOLCHAIN)' EXTRA_BUILD_FLAGS='$(EXTRA_BUILD_FLAGS_TOOLCHAIN)'

distclean-toolchain:
rm -rf toolchain
Expand All @@ -77,11 +77,13 @@ distclean-toolchain:
# ------ ngdevkit ------

build-tools:
$(EXTRA_BUILD_CMD) && \
for i in nullsound nullbios runtime include tools; do \
$(MAKE) -C $$i; \
done

install-tools:
$(EXTRA_BUILD_CMD) && \
for i in nullsound nullbios runtime include tools; do \
$(MAKE) -C $$i install; \
done
Expand Down Expand Up @@ -132,6 +134,7 @@ build-emudbg: build/emudbg
build/emudbg: emudbg
@echo compiling emudbg...
CURPWD=$$(pwd) && \
$(EXTRA_BUILD_CMD) && \
mkdir -p build/emudbg && \
cd build/emudbg && \
$$CURPWD/emudbg/configure --prefix=$(prefix) \
Expand Down Expand Up @@ -169,7 +172,7 @@ endif

gngeo:
$(GIT) clone --branch ngdevkit $(GNGEO_GIT) $@ && \
cd gngeo && autoreconf -iv
cd gngeo && autoreconf -iv $(GNGEO_ACLOCAL_PATH)

build-gngeo: build/gngeo

Expand All @@ -178,6 +181,7 @@ build-emulator-config: $(GNGEO_CFG)
build/gngeo: gngeo
@echo compiling gngeo...
CURPWD=$$(pwd) && \
$(EXTRA_BUILD_CMD) && \
mkdir -p build/gngeo && \
cd build/gngeo && \
$$CURPWD/gngeo/configure --program-prefix=ngdevkit- $(GNGEO_BUILD_FLAGS) \
Expand Down Expand Up @@ -212,6 +216,9 @@ ifeq ($(EXTERNAL_GNGEO), no)
ifeq ($(ENABLE_MINGW), yes)
SHELL_BIN_PATH := $(SHELL_BIN_PATH):$(GNGEO_INSTALL_PATH)
endif
ifeq ($(ENABLE_MSYS2), yes)
SHELL_BIN_PATH := /mingw64/bin:$(SHELL_BIN_PATH)
endif
endif

shellinit:
Expand Down
108 changes: 108 additions & 0 deletions README-msys2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Using ngdevkit natively on the Windows platform

The ngdevkit toolchain can be compiled natively and used as any
other Windows executable by means of the [MSYS2][msys2] environment.

So far, no native binary package are available, but you can
follow the steps below to compile the entire toolchain from scratch
and test it by compiling a set of [example ROMs][examples].

## Prepare your environment for compilation

Ngdevkit currently requires two big dependencies: the [MSYS2][msys2]
environment to build the toolchain, and a [Python 3 release for
Windows][pywin] from https://www.python.org. The latter is needed
because that's currently the only way to install a pre-built
[PyGame][pygame], which is a dependency of ngdevkit.


### Install Python and PyGame

Download the [Python 3 binary release][pywin] according to your
Windows platform, run the installer, and remember where you installed
your Python environment. For the sake of the example, this document
assumes that the Python 3 interpreter is installed for user ngdevkit
in:

C:/Users/ngdevkit/AppData/Local/Programs/Python/Python39/python

Once the Python environment is installed, install a pre-built version
of PyGame with pip:

C:/Users/Matthieu/AppData/Local/Programs/Python/Python39/python -m pip install pygame

Your python environment is now ready to be used to compile ngdevkit


### Install MSYS2

To build ngdevkit, we rely on MSYS2 to provide the necessary C
development tools and generate native Windows executable.

Download the [MSYS2 installer][msys2] and install the MSYS2
environment locally. For the same of the example this document assumes
that you installed it in the default location:

C:\msys64

MSYS2 has two different runtimes:
- The msys2 runtime, which is a minimal POSIX-like environment
- The mingw runtime, which is the full Windows-native runtime

Ngdevkit is built for Windows, so it only uses the mingw runtime.
However, in order to compile it, you can use any runtime.

Important note: for the sake of the example all the commands in this
document are supposed to be run from a msys2 shell. Start this shell
by running "MSYS2 MSYS" from the Start menu. Alternatively, you can
start the shell from `cmd.exe` or from PowerShell with:

C:\msys64\usr\bin\bash.exe -l

Once you are in a msys2 shell, make sure your MSYS2 installation
is up-to-date with:

pacman -Syuu


## Compiling the devkit

In a MSYS2 shell, first install all the ngdevkit dependencies:

pacman -S git msys2-runtime-devel mingw-w64-x86_64-toolchain
pacman -S msys2-w32api-headers msys2-w32api-runtime windows-default-manifest
pacman -S autoconf autoconf-archive automake pkg-config make tar zip unzip
pacman -S mingw-w64-x86_64-zlib mingw-w64-x86_64-SDL2 mingw-w64-x86_64-glew mingw-w64-x86_64-nsis
pacman -S gmp-devel isl-devel mpc-devel mpfr-devel texinfo
pacman -S flex bison expat gettext ncurses-devel zlib-devel mingw-w64-x86_64-boost
# dependencies for the example ROMs
pacman -S rsync mingw-w64-x86_64-sox mingw-w64-x86_64-imagemagick

You're now ready to compile the entire devkit. You just have to pass
the location of the Python 3 distribution you downloaded earlier to
the configure script:

autoreconf -iv
./configure --prefix=$PWD/local --enable-msys2 --with-python=/c/Users/ngdevkit/AppData/Local/Programs/Python/Python39/python
make
make install

The most tedious part is over! You just need a couple of environment
variables in your path to use the devkit. Try it on the example ROMs
included in the repository:

# set the environment variable in the shell
eval $(make shellinit)
# build the example ROMs
cd examples
./configure --enable-msys2 --with-python=/c/Users/ngdevkit/AppData/Local/Programs/Python/Python39/python
make

Look at [the main README](README.md) file for more details on
how to run the examples and the debugger.


[msys2]: https://www.msys2.org
[examples]: https://github.com/dciabrin/ngdevkit-examples
[pywin]: https://www.python.org/downloads/windows
[pygame]: https://www.pygame.org
83 changes: 79 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
AC_INIT([ngdevkit], [0.2])
PKG_INSTALLDIR

AC_PATH_PROGS([python], [python3 python], [no])
if test x"$python" = x"no"; then
AC_MSG_ERROR([no python detected.])
AC_ARG_WITH([python],
AS_HELP_STRING([--with-python=path], [Absolute path to the python 3 binary]))

if test -n "$with_python"; then
python="$with_python"
AC_SUBST([python])
else
AC_PATH_PROGS([python], [python3 python], [no])
if test x"$python" = x"no"; then
AC_MSG_ERROR([no python detected.])
fi
fi
AC_MSG_CHECKING([whether detected python is at least python3])
AC_MSG_CHECKING([whether python is at least python3])
[pyver=`$python -c 'import sys; print(sys.version_info[0])'`]
if test $pyver -ge 3; then
AC_MSG_RESULT([yes])
Expand Down Expand Up @@ -47,6 +55,10 @@ AC_ARG_ENABLE([mingw],
AS_IF([test "x$enable_mingw" = xyes], [ENABLE_MINGW="yes"], [ENABLE_MINGW="no"]),
[ENABLE_MINGW="no"])
AC_SUBST([EXTERNAL_MINGW])
AC_ARG_ENABLE([msys2],
AS_HELP_STRING([--enable-msys2], [Build for MSYS2, with Win10-native gngeo]),
AS_IF([test "x$enable_msys2" = xyes], [ENABLE_MSYS2="yes"], [ENABLE_MSYS2="no"]),
[ENABLE_MSYS2="no"])

AC_ARG_WITH([sdl2],
AS_HELP_STRING([--with-sdl2=path], [Absolute path to file SDL2.dll]))
Expand Down Expand Up @@ -113,6 +125,10 @@ fi
AC_PATH_PROG([git], [git])
AC_PATH_PROG([zip], [zip])

EXTRA_BUILD_CMD_TOOLCHAIN=true
EXTRA_BUILD_FLAGS_TOOLCHAIN=
EXTRA_BUILD_CMD=true

if test x"$ENABLE_MINGW" = x"yes"; then
AC_PATH_PROG([mingwgcc], [`uname -m`-w64-mingw32-gcc], [no])
AS_IF([test x"$mingwgcc" = x"no"], [AC_MSG_ERROR([MinGW gcc not found in path.])])
Expand Down Expand Up @@ -157,16 +173,75 @@ if test x"$ENABLE_MINGW" = x"yes"; then

EMUDBG_BUILD_FLAGS="--host=x86_64-w64-mingw32 --build=\`\$\$CURPWD/emudbg/config.guess\`"
GNGEO_BUILD_FLAGS="--prefix=$GNGEO_INSTALL_PATH --enable-mingw --host=x86_64-w64-mingw32 --build=\`\$\$CURPWD/gngeo/config.guess\` $GLEW_FLAGS"

elif test x"$ENABLE_MSYS2" = x"yes"; then
# dnl technically, this is still relying on MinGW
ENABLE_MINGW=yes
arch=`uname -m | sed 's/.*_//'`
export PATH=/mingw${arch}/bin:$PATH
AC_PATH_PROG([mingwgcc], [`uname -m`-w64-mingw32-gcc], [no])
AS_IF([test x"$mingwgcc" = x"no"], [AC_MSG_ERROR([MinGW gcc not found in path.])])

AC_MSG_CHECKING([for zlib1.dll in MinGW distribution])
ZLIB1_DLL=/mingw${arch}/bin/zlib1.dll
if test -f "$ZLIB1_DLL"; then
AC_MSG_RESULT([$ZLIB1_DLL])
else
AC_MSG_ERROR([Could not find zlib1.dll on disk])
fi

AC_MSG_CHECKING([for SDL2])
if test -z "$with_sdl2"; then
with_sdl2=/mingw${arch}/bin/SDL2.dll
fi
if test x"$with_sdl2" != x"no" && test -f "$with_sdl2"; then
AC_MSG_RESULT([$with_sdl2])
SDL2_DLL=$with_sdl2
else
AC_MSG_ERROR(['$with_sdl2' is not a valid file on disk])
fi

AC_MSG_CHECKING([for GLEW])
if test -z "$with_glew"; then
with_glew=/mingw${arch}/bin/glew32.dll
fi
if test x"$with_glew" != x"no" && test -f "$with_glew"; then
AC_MSG_RESULT([$with_glew])
GLEW_DLL=$with_glew
else
AC_MSG_RESULT([no])
fi

if test x"$EXTERNAL_GNGEO" != x"yes"; then
AC_MSG_CHECKING([for GnGeo installation directory])
if test -z "$GNGEO_INSTALL_PATH"; then
GNGEO_INSTALL_PATH="$prefix/ngdevkit-gngeo"
fi
AC_MSG_RESULT([$GNGEO_INSTALL_PATH])
fi

EMUDBG_BUILD_FLAGS="--build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 CC=${mingwgcc}"
GNGEO_ACLOCAL_PATH="-I/mingw${arch}/share/aclocal"
GNGEO_BUILD_FLAGS="--prefix=$GNGEO_INSTALL_PATH --enable-mingw --enable-msys2 CC=${mingwgcc} $GLEW_FLAGS"
EXTRA_BUILD_CMD='export PATH=/mingw'${arch}'/bin:$$PATH'
EXTRA_BUILD_CMD_TOOLCHAIN='export MSYSTEM_CHOST=x86_64-w64-mingw32 && export MSYSTEM=MINGW64 && export PATH=/mingw64/bin:$$$$CURPWD/$$(@)/bin:$$$$PATH'
EXTRA_BUILD_FLAGS_TOOLCHAIN='--build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32'
else
GNGEO_BUILD_FLAGS="--prefix=$prefix"
fi

AC_SUBST([EXTRA_BUILD_CMD_TOOLCHAIN])
AC_SUBST([EXTRA_BUILD_FLAGS_TOOLCHAIN])
AC_SUBST([EXTRA_BUILD_CMD])

AC_SUBST([ENABLE_MINGW])
AC_SUBST([ENABLE_MSYS2])
AC_SUBST([ZLIB1_DLL])
AC_SUBST([SDL2_DLL])
AC_SUBST([GLEW_FLAGS])
AC_SUBST([GLEW_DLL])
AC_SUBST([EMUDBG_BUILD_FLAGS])
AC_SUBST([GNGEO_ACLOCAL_PATH])
AC_SUBST([GNGEO_BUILD_FLAGS])
AC_SUBST([GNGEO_INSTALL_PATH])
AC_SUBST([NGDK_GCC_SEARCH_PATH])
Expand Down

0 comments on commit f845e9c

Please sign in to comment.