Compiling MegaZeux: Difference between revisions

From MZXWiki
Jump to navigation Jump to search
m (→‎Linux cross compilation with Mingw-w64: Fix typo in tar options.)
 
(59 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Instructions]]
[[Category:Instructions]] [[Category:MegaZeux]]
Compiling any MegaZeux 2.8x source requires a POSIX compatible shell (bash, dash) to be installed.  Download the source .tar.bz2 or .tar.xz and extract it to a new folder.
Compiling any MegaZeux 2.80 or later source requires a POSIX compatible shell (bash, dash) to be installed.  Download the source .tar.bz2 or .tar.xz and extract it to a new folder.


==Building==
==General Commands==
  ./config.sh
  ./config.sh
This will give you help about how to configure MegaZeux.
This will give you help about how to configure MegaZeux.


  ./config.sh --platform unix
  ./config.sh --platform unix
To configure the sources. On OS X, the platform is "darwin", and on win32 the platform is "win32".
To configure the sources. On OS X, the platform is "darwin", and on Windows the platform is either "win64" or "win32".


  make
  make
Line 13: Line 13:


  make install
  make install
This will install MegaZeux to the system. Do not use for the "unix-devel" platform, which is intended to run straight out of the source directory.
This will install MegaZeux to the system. This should not be used with the "unix-devel" platform or any other option intended to run straight out of the source directory.


Please see debian/README for more information.
Please see debian/README for more information.


==Windows==
For developing and testing MegaZeux with Windows, the generally supported POSIX platform is [https://www.msys2.org/ '''MSYS2''']. Other available options include MINGW32/msys, Cygwin, MSVC, etc., but are typically more complicated to set up than MSYS2. Download and install '''MSYS2''' before continuing. MSYS2 no longer works on 32-bit Windows and recommends the UCRT64 environment, so that will be used here.
It is no longer recommended to produce release builds with MSYS2, as they have increased the default architecture of MINGW32 to '''pentium4''' and the default architecture of MINGW64 to '''nocona'''. MegaZeux still targets '''i686''' and '''x86-64''' respectively. While most dependencies can be rebuilt, MSYS2 may or may not embed system library stubs that require the newer architectures into the binary (untested). Linux Mingw-w64 cross compilers are now recommended for release builds instead.


===Windows with MSYS2===
===Windows with MSYS2===
Download and install msys2 (these instructions are for msys2-x86_64-20161025.exe specifically)
Run '''ucrt64.exe''' in the ''msys2'' directory. You will be in the "{MSYS DIRECTORY}\home\{your username}\" directory.  (This will display in the mingw64 shell as either "~" or "/home/{your username}")
 
Run mingw64.exe in the msys2 directory. You will be in {MSYS DIRECTORY}\home\{USERNAME}\
First, run this command. MSYS2 will need to restart when it is finished.
   
 
Run the following commands.
  yes Y | pacman -Syu
   
 
After restarting MSYS2, run the following commands.
 
  yes Y | pacman -Su
  yes Y | pacman -S git
  yes Y | pacman -S git
  yes Y | pacman -S make
  yes Y | pacman -S make
  yes Y | pacman -S mingw-w64-x86_64-zlib
  yes Y | pacman -S mingw-w64-ucrt-x86_64-gcc
  yes Y | pacman -S mingw-w64-x86_64-gcc
yes Y | pacman -S mingw-w64-ucrt-x86_64-gdb
  yes Y | pacman -S mingw-w64-x86_64-libpng
yes Y | pacman -S mingw-w64-ucrt-x86_64-pkgconf
  yes Y | pacman -S mingw-w64-x86_64-libogg
  yes Y | pacman -S mingw-w64-ucrt-x86_64-zlib
  yes Y | pacman -S mingw-w64-x86_64-libvorbis
  yes Y | pacman -S mingw-w64-ucrt-x86_64-libpng
  yes Y | pacman -S mingw-w64-x86_64-SDL2
  yes Y | pacman -S mingw-w64-ucrt-x86_64-libogg
  yes Y | pacman -S mingw-w64-ucrt-x86_64-libvorbis
  yes Y | pacman -S mingw-w64-ucrt-x86_64-SDL2
  git clone https://github.com/AliceLR/megazeux.git
  git clone https://github.com/AliceLR/megazeux.git
  cd megazeux
  cd megazeux
  ./config.sh --platform win32 --enable-libsdl2
  ./config.sh --platform win64
  make
  make


===Windows with Git Bash and MinGW===
MegaZeux should be built and ready to run! If you are not running MegaZeux from '''ucrt64.exe''', add the folder containing your dependencies (generally ''C:\msys64\ucrt64\bin'') to your Windows PATH variable. Otherwise, MegaZeux will not be able to start from Explorer.
 
The following optional tools packages may be of use. They are not required or are part of the packaging process for some architectures.
 
yes Y | pacman -S autoconf
yes Y | pacman -S automake
yes Y | pacman -S libtool
yes Y | pacman -S nano
yes Y | pacman -S p7zip
yes Y | pacman -S mingw-w64-ucrt-x86_64-clang
yes Y | pacman -S mingw-w64-ucrt-x86_64-cmake
yes Y | pacman -S mingw-w64-ucrt-x86_64-diffutils
yes Y | pacman -S mingw-w64-ucrt-x86_64-imagemagick
yes Y | pacman -S mingw-w64-ucrt-x86_64-ntldd
 
The following optional library packages may be useful for testing with alternate configurations. These packages may not be available for all targets (especially MINGW32/i686).
 
# SDL 3 (--enable-sdl3)
yes Y | pacman -S mingw-w64-ucrt-x86_64-sdl3
# SDL 1.2.15 (--enable-sdl1)
yes Y | pacman -S mingw-w64-ucrt-x86_64-SDL
# ANGLE (--enable-gles)
yes Y | pacman -S mingw-w64-ucrt-x86_64-angleproject
 
====Troubleshooting====
- ''"The program can't start because ___.dll is missing."''
 
If you are running MegaZeux from Explorer, add the folder containing your dependencies (generally ''C:\msys64\ucrt64\bin'') to your Windows PATH variable.
 
- ''"The procedure entry point inflateReset2 could not be located in the dynamic link library zlib1.dll." (and similar errors)''
 
This can happen because the Windows PATH variable contains a directory older copy of ''zlib1.dll'' (or the DLL in question).  You can use '''where zlib1.dll''' in Command Prompt to view the different PATH locations that contain the DLL, as well as the order in which Windows will try to load it.
 
===Linux cross compilation with Mingw-w64===
The Windows port of MegaZeux can be compiled on Linux using the same Mingw-w64 toolchains used by MSYS2. It can also be run like any other program in Linux if you have Wine and binfmt-misc installed. MegaZeux uses self-built dependency bundles (rather than dependencies offered by whatever distro you are using) for consistency.
 
Install toolchains (Fedora; other distros will vary):
sudo dnf install mingw{32,64}-{gcc,gcc-c++,binutils}
 
Download a MinGW dependency bundle from [https://github.com/AliceLR/megazeux-dependencies/releases/ here] into the MegaZeux <code>scripts/deps</code> directory and extract it. The bundle contains both '''i686''' and '''x86_64''' dependencies, which will be located at <code>scripts/deps/mingw/x86</code> and <code>scripts/deps/mingw/x64</code>, respectively.
(cd scripts/deps && wget https://github.com/AliceLR/megazeux-dependencies/releases/download/v2.93c-r1/megazeux-dependencies-2.93c-r1-mingw.tar.xz)
(cd scripts/deps && tar -xJf megazeux-dependencies-2.93c-r1-mingw.tar.xz)
 
Configure:
# x86_64
./config.sh --platform mingw64 --prefix scripts/deps/mingw/x64 --enable-release --enable-lto
# i686
./config.sh --platform mingw32 --prefix scripts/deps/mingw/x86 --enable-release --enable-lto
 
Build:
make -j8 debuglink
 
Build and run regression tests (requires Wine and binfmt-misc):
make -j8 test
 
Generate manifest (requires sha256sum and xargs with the -P option) and archive (requires Info-ZIP or 7-Zip):
make archive
 
==Ubuntu/Debian==
 
sudo apt install build-essential
Download compilers to build MegaZeux. MegaZeux will also build with clang.
 
supo apt install libpng-dev libogg-dev libvorbis-dev libsdl2-dev
Download the dependencies required to build MegaZeux. To build with SDL 1.2, install the package ''libsdl1.2-dev''.
 
To install the latest master, use:
sudo apt install git
git clone https://github.com/AliceLR/megazeux.git [dest dir]
Alternatively, download and extract the [https://vault.digitalmzx.net/download.php?latest=src latest .tar.xz or .tar.bz2 source archive] to the desired location.
 
See the "general commands" section above for more information.
 
===Packaging===
 
sudo apt install devscripts debhelper
Download the packaging tools.
 
From the MegaZeux source directory:
debuild -us -uc
 
==Fedora==
 
sudo dnf install gcc gcc-c++ make binutils
Download compilers to build MegaZeux. MegaZeux will also build with clang/clang++.
 
supo dnf install zlib-devel libpng-devel libogg-devel libvorbis-devel SDL2-devel
Download the dependencies required to build MegaZeux. To build with SDL 1.2, install the package ''sdl12-compat-devel'' (''SDL-devel'' for older Fedora releases).
 
To install the latest master, use:
sudo dnf install git
git clone https://github.com/AliceLR/megazeux.git [dest dir]
Alternatively, download and extract the [https://vault.digitalmzx.net/download.php?latest=src latest .tar.xz or .tar.bz2 source archive] to the desired location.
 
See the "general commands" section above for more information.
 
===Packaging===
 
The rpm-build package is required:


These instructions are intended to help you build and install all of MZX's dependencies from scratch to bin/mingw32/ in your home folder. The format of MZXPREFIX (c: instead of /c, forward slashes) is mandatory. The required dependencies for MZX are [https://www.zlib.net zlib], [http://www.libpng.org/pub/png/libpng.html libpng], [https://www.xiph.org/downloads/ libogg and libvorbis], and one of [https://www.libsdl.org/download-1.2.php SDL 1.2] or [https://www.libsdl.org/download-2.0.php SDL 2.0] (as of GIT/version 2.85, requires the --enable-libsdl2 config.sh flag).
sudo dnf install rpm-build


This requires Git installed to C:\Git, and MinGW installed to C:\MinGW. MinGW's bin folder must be on your path. Do not install Git or MinGW to Program Files or any other path with a space in it.
If you're building from a cloned Git repository, checkout the appropriate MegaZeux version tag. For example:


Do not install Git to Program Files.
git checkout v2.93


Do not install Git to Program Files.
To build the rpm:


Do not install Git to Program Files.
make distclean
rpm-build -bb --build-in-place megazeux.spec


Do this first:
==Mac OS X==
===With MacPorts (testing only)===
You will need to install XCode and MacPorts before continuing. This method is suitable only for testing builds, and should not be used to produce releases.


echo "export MZXPREFIX=c:/users/\$(whoami)/bin/mingw32" >> ~/.bashrc
Compile/install dependencies. At least one SDL package is required, but there are several different options.
  echo "export PATH=\"\$PATH:$MZXPREFIX/bin\"" >> ~/.bashrc
  sudo port install zlib libpng libogg libvorbis
  echo "export SDL_STDIO_REDIRECT=no" >> ~/.bashrc
  . ~/.bashrc
# Newer versions of macOS can use SDL3; configure MegaZeux with --enable-sdl3
  mkdir ~/bin
sudo port install SDL3
  mkdir $MZXPREFIX
  mkdir $MZXPREFIX/bin
# Most versions of macOS support SDL2.
  sudo port install libsdl2
# Snow Leopard users may need this build of SDL2 instead.
  sudo port install libsdl2-snowleopard
   
  # Even older versions of macOS may need SDL 1.2; configure MegaZeux with --enable-sdl1
  sudo port install libsdl


Compiling zlib: one of these two methods may work.
Navigate to the MegaZeux source directory and configure MegaZeux. Add any relevant SDL option here. For debug builds, omit --enable-release and --enable-lto.


  make -f win32/Makefile.gcc
  ./config.sh --platform darwin-devel --prefix /opt/local --enable-release --enable-lto
make -f win32/Makefile.gcc install INCLUDE_PATH=$MZXPREFIX/include/ LIBRARY_PATH=$MZXPREFIX/lib/ BINARY_PATH=$MZXPREFIX/bin/


./configure --static --64
Build MegaZeux as usual:
cp Makefile Makefile.old
  make -j8
cp win32/Makefile.gcc Makefile
  make
make install INCLUDE_PATH=$MZXPREFIX/include/ LIBRARY_PATH=$MZXPREFIX/lib/ BINARY_PATH=$MZXPREFIX/bin/


Compiling libpng16: libpng folder should be in the same folder as the zlib folder, they should be called "libpng" and "zlib", and zlib should already be built. For versions other than libpng16, replace the '16'.
===Multiarchitecture .app===
''THIS SECTION IS A WORK IN PROGRESS.'' Please refer to the documentation in arch/darwin/ and docs/platform_matrix.html for more details.


cp scripts/pnglibconf.h.prebuilt pnglibconf.h
====Environment Setup====
cp scripts/makefile.gcc makefile
This is heavily dependent on the architectures being targeted. For compilation on a Mac, typically select the highest Xcode being targeted as a base and install the lower versions using [https://github.com/devernay/xcodelegacy XcodeLegacy]. Linux cross compilation isn't tested currently.
make static
cp scripts/makefile.msys makefile
make libpng-config
mkdir $MZXPREFIX/include/libpng16/
cp libpng-config $MZXPREFIX/bin/
cp libpng.a $MZXPREFIX/lib/libpng16.a
cp png.h pngconf.h pnglibconf.h $MZXPREFIX/include/libpng16/


Compiling libogg and libvorbis: these instructions should work for both.
{|class="wikitable"
! Architecture
! MegaZeux PREFIX
! SDK version
! OS minimum version
! Xcode toolchain
! Cross toolchain
! Last working SDL
! Notes
|-
| arm64
| PREFIX_ARM64
| 11.0
| 11.0
| Xcode 12.2 or higher
| [https://github.com/tpoechtrager/osxcross osxcross]
| Latest
|
|-
| arm64e
| PREFIX_ARM64E
| 11.0
| 11.0
| Xcode 12.2 or higher
| [https://github.com/tpoechtrager/osxcross osxcross]
| Latest
| Builds containing this architecture seem to be killed immediately by the kernel when run on ARM64; avoid for now.
|-
| i686
| PREFIX_I686
| 10.13
| 10.6
| Xcode 9.4.1
| [https://github.com/tpoechtrager/osxcross osxcross]
| 2.0.22
| Mac OS X Snow Leopard is targeted to support Core Duo Macs.
|-
| x86_64
| PREFIX_AMD64
| 10.13
| 10.6
| Xcode 9.4.1
| [https://github.com/tpoechtrager/osxcross osxcross]
| 2.0.22 (10.6) or latest (10.9+)
|
|-
| x86_64h
| PREFIX_AMD64H
| 10.13
| 10.9
| Xcode 9.4.1
| [https://github.com/tpoechtrager/osxcross osxcross]
| Latest
| OS X Mavericks is the minimum version for this architecture. Versions prior to Yosemite may have no clue how to handle software with both x86_64 and x86_64h executables; probably avoid unless targeting 10.10+.
|-
| ppc
| PREFIX_PPC
| 10.4
| 10.4
| Xcode 3.2.6
| [https://github.com/tpoechtrager/osxcross/blob/ppc-test/README.PPC-GCC-5.5.0-SDK-10.5.md osxcross (ppc-test)]
| 2.0.3 (panther_SDL2) or 1.2.15
| Mac OS X Tiger is targeted to support G3 Macs. SDL2 has Core Audio issues, 1.2.15 recommended.
|-
| ppc64
| PREFIX_PPC64
| 10.5
| 10.5
| Xcode 3.2.6
| [https://github.com/tpoechtrager/osxcross/blob/ppc-test/README.PPC-GCC-5.5.0-SDK-10.5.md osxcross (ppc-test)]
| 2.0.3 (panther_SDL2) or 1.2.15
| Mac OS X Leopard is targeted as Objective-C is broken for PowerPC64 in the Tiger SDK. SDL2 has Core Audio issues, 1.2.15 recommended.
|}


./configure --prefix=$MZXPREFIX --disable-shared
WARNING: if targeting PowerPC64 via XcodeLegacy, you need to revert a fix that XcodeLegacy applies to libgcc_s.10.5.dylib OR apply [https://github.com/devernay/xcodelegacy/pull/74 this patch to XcodeLegacy] before building your SDK bundles.
make
make install


Compiling SDL 1.2 and SDL 2.0: these instructions should work for both.
cp /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libgcc_s.10.5.dylib /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libgcc_s.10.5.dylib.vectorfix
cp /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libgcc_s.10.5.dylib.bak /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libgcc_s.10.5.dylib


./configure --build=mingw32 --prefix=$MZXPREFIX
WARNING: when installing the Xcode 3 compilers via XcodeLegacy, it will replace the current Xcode's ld with a wrapper which either selects the original ld or redirects all PowerPC usage ''and'' Intel <=10.6 usage to the Xcode 3 ld. This breaks linking anything targeting Intel 10.6 with newer SDKs, so the ld script needs to be modified to redirect <=10.5 instead to fix this. It can be found at
make
make install INSTALL=/c/Git/usr/bin/install.exe


Compiling MZX:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld


./config.sh --platform win64 --prefix $MZXPREFIX [other options, i.e. --enable-libsdl2]
====Other required tools====
make


If MZX fails to compile libmodplug due to a previous declaration of Sleep(), edit contrib/libmodplug/src/libmodplug/stdafx.h and comment out line 42:
[https://github.com/auriamg/macdylibbundler dylibbundler], which can be installed using MacPorts:


  //#define sleep(_ms)      Sleep(_ms)
  sudo port install dylibbundler


===Ubuntu/Debian===
WARNING: dylibbundler relies on otool and therefore llvm-objdump. LLVM currently lacks support for reading the LC_UNIXTHREAD load commands of PowerPC64 Mach-O executables, so bundling will fail. Workarounds:


sudo apt-get install gcc g++
1) Currently, MegaZeux's bundle script (arch/darwin/bundle.sh) will add an otool wrapper to PATH (arch/darwin/bin/otool) which instead invokes '''xcrun otool-classic'''. This only works for Xcode versions which contain otool-classic.
We need compilers!


supo apt-get install libsdl1.2-dev libogg-dev libvorbis-dev libpng-dev
2) Disabling those lines of bundle.sh and instead selecting a pre-LLVM Xcode to build for PowerPC64 should also work.
Download our dependencies.


The above instructions should work now.
====Dependencies====
Fetch a macOS dependencies bundle from [https://github.com/AliceLR/megazeux-dependencies the MegaZeux dependencies GitHub repository] and extract it to scripts/deps/ in your local MegaZeux Git repository.


Alternatively, if you are feeling very brave, you may attempt to compile the dependencies yourself using the Makefile in scripts/deps/. This requires the same environment as described above for compiling MegaZeux, plus '''cmake''' and '''wget''' (available from MacPorts or Homebrew).


===Mac OS X===
====Compilation====
Unlike most other architectures, the prefix is provided PER ARCHITECTURE to a Makefile meta target.


You will need to install XCode and optionally MacPorts before continuing.
./config.sh --platform darwin-dist --enable-release --enable-lto


NOTE: Using MacPorts is not acceptable for official releases!  Use it for personal builds only.
To compile for a given architecture, provide to Make one or more of the PREFIX variables defined in the table above:


Determine the name of your compiler before continuing; typing 'i686-' or 'powerpc-' and pressing tab twice should be sufficient. Example output:
  make PREFIX_I686=scripts/deps/macos/i686 PREFIX_AMD64=scripts/deps/macos/x86_64
i686-apple-darwin10-g++-4.2.1 i686-apple-darwin10-gcc-4.2.1


Compile/install dependencies.  If you're using MacPorts:
For each architecture, Make will invoke:
sudo port install libsdl libogg libvorbis libpng


Navigate to the extracted source directory. If you're building MZX 2.84 and under, please download [https://github.com/AliceLR/megazeux/blob/master/arch/darwin/Makefile.in this updated Makefile.in] and put it in arch/darwin/, otherwise MegaZeux will fail to compile.
  make ARCH=[arch] PREFIX=[prefix] package
make ARCH=[arch] PREFIX=[prefix] clean


Run ./config.sh.  Consider the following flags:
The "package" target is similar to "all", except afterward, dylibbundler is used to generate a dependency bundle in "bundles/", and then all binaries are moved to [binary].[arch].
--platform darwin  ---------- Mandatory.
--disable-x11      ---------- Also mandatory.
--disable-utils    ---------- This disables compilation of utilities such as downver and checkres. This is optional.
--enable-release    ---------- Removes debug symbols.  This will make the package smaller if you intend on installing MZX in app form.
--prefix /opt/local ---------- Mandatory if you're using MacPorts; omit otherwise.


Make options:
Finally, Make will perform
ARCH={ your architecture: i686, amd64, ppc, or ppc64 }
CROSS_COMPILE_{ X86 or PPC }_CC={ name of your gcc compiler}
CROSS_COMPILE_{ X86 or PPC }_CXX={ name of your g++ compiler}


Run make:
  make lipo
  make ARCH=i686 CROSS_COMPILE_X86_CC=i686-apple-darwin10-gcc-4.2.1 CROSS_COMPILE_X86_CXX=i686-apple-darwin10-g++-4.2.1


Hopefully nothing will go wrong! :)
to merge all of the currently existing [binary].[arch] files into a new multiarchitecture file [binary].


==Packaging==
====Packaging====
===Mac OS X===
Make sure there is not a "MegaZeux" volume mounted before continuing.
Make sure there is not a "MegaZeux" volume mounted before continuing.


  rm -r build/
  rm -r build/
make lipo
  make archive
  make archive
A .dmg will appear in build/arch/darwin/.  Please refer to the documentation in arch/darwin/ for more details.
You can test the .app files generated in build/darwin-dist/ to make sure they run. A .dmg will appear in build/dist/darwin-dist/ containing the generated .app files, documentation, and multiarchitecture utilities.
 
==HTML5 (Emscripten)==
NOTE: emsdk may not function properly in MSYS2. Using Linux or similar is strongly recommended.
 
Download and install emsdk.
git clone https://github.com/emscripten-core/emsdk /opt/emsdk
cd /opt/emsdk
./emsdk install latest
./emsdk activate latest
. ./emsdk_env.sh
 
Configure and build MZX:
./config.sh --platform emscripten --enable-release
make -j8
make archive
 
Note that compiling MZX will make emsdk automatically install all required dependencies.
 
==BlocksDS/Wonderful (Nintendo DS)==
Follow the instructions [https://blocksds.skylyrac.net/docs/setup/options/ here] to install Wonderful and BlocksDS.
 
Install the following packages:
wc-pacman -S toolchain-gcc-arm-none-eabi-zlib
 
Configure and build:
arch/nds-blocksds/CONFIG.NDS
make -j8
make archive
 
==devkitARM, devkitA64, and devkitPPC ==
Follow the instructions [https://devkitpro.org/wiki/Getting_Started here] to install the devkitPro toolchains.
 
Note that if you're using MSYS2 (or a Linux distribution with pacman already installed), you can simply add the devkitPro repository to your pacman.conf and install devkitpro-keyring:
 
[dkp-libs]
Server = http://downloads.devkitpro.org/packages
[dkp-windows]
Server = http://downloads.devkitpro.org/packages/windows
 
===Nintendo DS===
Install the following packages:
pacman --needed --noconfirm -S devkitARM libnds libfat-nds maxmod-nds nds-zlib ndstool dstools
 
Configure and build:
arch/nds/CONFIG.NDS
make -j8
make archive
 
===Nintendo 3DS===
Install the following packages:
pacman --needed --noconfirm -S devkitARM libctru citro3d picasso 3dstools general-tools
pacman --needed --noconfirm -S 3ds-zlib 3ds-libpng 3ds-libogg 3ds-libvorbisidec
 
Configure and build:
arch/3ds/CONFIG.3DS
make -j8
make archive
 
===Nintendo Wii===
Install the following packages:
pacman --needed --noconfirm -S devkitPPC libogc libfat-ogc gamecube-tools
pacman --needed --noconfirm -S ppc-zlib ppc-libpng ppc-libogg ppc-libvorbisidec
 
Configure and build:
arch/wii/CONFIG.WII
make -j8
make archive
 
===Nintendo Wii U===
 
Install the following packages:
pacman --needed --noconfirm -S devkitPPC wut wut-tools
pacman --needed --noconfirm -S ppc-zlib ppc-libpng ppc-libogg ppc-libvorbis wiiu-sdl2
 
Configure and build:
arch/wiiu/CONFIG.WIIU
make -j8
make archive
 
===Nintendo Switch===
Install the following packages:
pacman --needed --noconfirm -S devkitA64 libnx switch-tools
pacman --needed --noconfirm -S switch-glad switch-glm switch-mesa switch-libdrm_nouveau
pacman --needed --noconfirm -S switch-zlib switch-libpng switch-libogg switch-libvorbis switch-sdl2
 
Configure and build:
arch/switch/CONFIG.SWITCH
make -j8
make archive
 
==DJGPP==
 
Get a pre-built copy of DJGPP for your operating system from [https://github.com/andrewwutw/build-djgpp here]. Create an environment variable DJGPP pointing to the location you extracted DJGPP and add the toolchain to your PATH variable:
export DJGPP=/opt/djgpp
export PATH="$PATH:$DJGPP/bin"
or
export DJGPP_PREFIX=/c/djgpp
export PATH="$PATH:$DJGPP/bin"
 
Build [https://zlib.net zlib]:
CHOST=i586-pc-msdosdjgpp ./configure --prefix=$DJGPP
make -j8
make install
 
Build [http://www.libpng.org/pub/png/libpng.html libpng]:
CFLAGS="-I$DJGPP/include" \
CPPFLAGS="-I$DJGPP/include" \
LDFLAGS="-L$DJGPP/lib -lz" \
./configure --prefix=$DJGPP --host=i586-pc-msdosdjgpp --disable-shared --enable-static
make -j8
make install
 
Build tremor (lowmem):
git clone https://gitlab.xiph.org/xiph/tremor
git checkout lowmem
./autogen.sh --prefix=$DJGPP --host=i586-pc-msdosdjgpp --disable-shared --enable-static
make -j8
make install
 
Build [https://xiph.org/downloads/ libogg and libvorbis]:
./configure --prefix=$DJGPP --host=i586-pc-msdosdjgpp --disable-shared --enable-static
make -j8
make install
 
Configure and build MegaZeux (libpng disabled and using tremor by default):
arch/djgpp/CONFIG.DJGPP
make -j8
  make archive
 
==VitaSDK==
Follow the instructions [https://vitasdk.org here] to set up the Vita toolchain. It is strongly recommended you substitute all instances of <code>/usr/local/vitasdk</code> in their instructions for <code>/opt/vitasdk</code>. /opt is the location that is intended for monolithic software, and placing VitaSDK here will group it with every other toolchain used by the MegaZeux console ports. install_all.sh should install every dependency that MegaZeux needs.
 
Configure and build MegaZeux:
arch/psvita/CONFIG.PSVITA
make -j8
make archive

Latest revision as of 03:26, 1 April 2025

Compiling any MegaZeux 2.80 or later source requires a POSIX compatible shell (bash, dash) to be installed. Download the source .tar.bz2 or .tar.xz and extract it to a new folder.

General Commands

./config.sh

This will give you help about how to configure MegaZeux.

./config.sh --platform unix

To configure the sources. On OS X, the platform is "darwin", and on Windows the platform is either "win64" or "win32".

make

This will build MegaZeux from sources. If it fails, you probably don't have one of SDL, libvorbis, libogg, libpng, zlib or the corresponding dev packages installed.

make install

This will install MegaZeux to the system. This should not be used with the "unix-devel" platform or any other option intended to run straight out of the source directory.

Please see debian/README for more information.


Windows

For developing and testing MegaZeux with Windows, the generally supported POSIX platform is MSYS2. Other available options include MINGW32/msys, Cygwin, MSVC, etc., but are typically more complicated to set up than MSYS2. Download and install MSYS2 before continuing. MSYS2 no longer works on 32-bit Windows and recommends the UCRT64 environment, so that will be used here.

It is no longer recommended to produce release builds with MSYS2, as they have increased the default architecture of MINGW32 to pentium4 and the default architecture of MINGW64 to nocona. MegaZeux still targets i686 and x86-64 respectively. While most dependencies can be rebuilt, MSYS2 may or may not embed system library stubs that require the newer architectures into the binary (untested). Linux Mingw-w64 cross compilers are now recommended for release builds instead.

Windows with MSYS2

Run ucrt64.exe in the msys2 directory. You will be in the "{MSYS DIRECTORY}\home\{your username}\" directory. (This will display in the mingw64 shell as either "~" or "/home/{your username}")

First, run this command. MSYS2 will need to restart when it is finished.

yes Y | pacman -Syu

After restarting MSYS2, run the following commands.

yes Y | pacman -Su
yes Y | pacman -S git
yes Y | pacman -S make
yes Y | pacman -S mingw-w64-ucrt-x86_64-gcc
yes Y | pacman -S mingw-w64-ucrt-x86_64-gdb
yes Y | pacman -S mingw-w64-ucrt-x86_64-pkgconf
yes Y | pacman -S mingw-w64-ucrt-x86_64-zlib
yes Y | pacman -S mingw-w64-ucrt-x86_64-libpng
yes Y | pacman -S mingw-w64-ucrt-x86_64-libogg
yes Y | pacman -S mingw-w64-ucrt-x86_64-libvorbis
yes Y | pacman -S mingw-w64-ucrt-x86_64-SDL2
git clone https://github.com/AliceLR/megazeux.git
cd megazeux
./config.sh --platform win64
make

MegaZeux should be built and ready to run! If you are not running MegaZeux from ucrt64.exe, add the folder containing your dependencies (generally C:\msys64\ucrt64\bin) to your Windows PATH variable. Otherwise, MegaZeux will not be able to start from Explorer.

The following optional tools packages may be of use. They are not required or are part of the packaging process for some architectures.

yes Y | pacman -S autoconf
yes Y | pacman -S automake
yes Y | pacman -S libtool
yes Y | pacman -S nano
yes Y | pacman -S p7zip
yes Y | pacman -S mingw-w64-ucrt-x86_64-clang
yes Y | pacman -S mingw-w64-ucrt-x86_64-cmake
yes Y | pacman -S mingw-w64-ucrt-x86_64-diffutils
yes Y | pacman -S mingw-w64-ucrt-x86_64-imagemagick
yes Y | pacman -S mingw-w64-ucrt-x86_64-ntldd

The following optional library packages may be useful for testing with alternate configurations. These packages may not be available for all targets (especially MINGW32/i686).

# SDL 3 (--enable-sdl3)
yes Y | pacman -S mingw-w64-ucrt-x86_64-sdl3
# SDL 1.2.15 (--enable-sdl1)
yes Y | pacman -S mingw-w64-ucrt-x86_64-SDL
# ANGLE (--enable-gles)
yes Y | pacman -S mingw-w64-ucrt-x86_64-angleproject

Troubleshooting

- "The program can't start because ___.dll is missing."

If you are running MegaZeux from Explorer, add the folder containing your dependencies (generally C:\msys64\ucrt64\bin) to your Windows PATH variable.

- "The procedure entry point inflateReset2 could not be located in the dynamic link library zlib1.dll." (and similar errors)

This can happen because the Windows PATH variable contains a directory older copy of zlib1.dll (or the DLL in question). You can use where zlib1.dll in Command Prompt to view the different PATH locations that contain the DLL, as well as the order in which Windows will try to load it.

Linux cross compilation with Mingw-w64

The Windows port of MegaZeux can be compiled on Linux using the same Mingw-w64 toolchains used by MSYS2. It can also be run like any other program in Linux if you have Wine and binfmt-misc installed. MegaZeux uses self-built dependency bundles (rather than dependencies offered by whatever distro you are using) for consistency.

Install toolchains (Fedora; other distros will vary):

sudo dnf install mingw{32,64}-{gcc,gcc-c++,binutils}

Download a MinGW dependency bundle from here into the MegaZeux scripts/deps directory and extract it. The bundle contains both i686 and x86_64 dependencies, which will be located at scripts/deps/mingw/x86 and scripts/deps/mingw/x64, respectively.

(cd scripts/deps && wget https://github.com/AliceLR/megazeux-dependencies/releases/download/v2.93c-r1/megazeux-dependencies-2.93c-r1-mingw.tar.xz)
(cd scripts/deps && tar -xJf megazeux-dependencies-2.93c-r1-mingw.tar.xz)

Configure:

# x86_64
./config.sh --platform mingw64 --prefix scripts/deps/mingw/x64 --enable-release --enable-lto
# i686
./config.sh --platform mingw32 --prefix scripts/deps/mingw/x86 --enable-release --enable-lto

Build:

make -j8 debuglink

Build and run regression tests (requires Wine and binfmt-misc):

make -j8 test

Generate manifest (requires sha256sum and xargs with the -P option) and archive (requires Info-ZIP or 7-Zip):

make archive

Ubuntu/Debian

sudo apt install build-essential

Download compilers to build MegaZeux. MegaZeux will also build with clang.

supo apt install libpng-dev libogg-dev libvorbis-dev libsdl2-dev 

Download the dependencies required to build MegaZeux. To build with SDL 1.2, install the package libsdl1.2-dev.

To install the latest master, use:

sudo apt install git
git clone https://github.com/AliceLR/megazeux.git [dest dir]

Alternatively, download and extract the latest .tar.xz or .tar.bz2 source archive to the desired location.

See the "general commands" section above for more information.

Packaging

sudo apt install devscripts debhelper

Download the packaging tools.

From the MegaZeux source directory:

debuild -us -uc

Fedora

sudo dnf install gcc gcc-c++ make binutils

Download compilers to build MegaZeux. MegaZeux will also build with clang/clang++.

supo dnf install zlib-devel libpng-devel libogg-devel libvorbis-devel SDL2-devel

Download the dependencies required to build MegaZeux. To build with SDL 1.2, install the package sdl12-compat-devel (SDL-devel for older Fedora releases).

To install the latest master, use:

sudo dnf install git
git clone https://github.com/AliceLR/megazeux.git [dest dir]

Alternatively, download and extract the latest .tar.xz or .tar.bz2 source archive to the desired location.

See the "general commands" section above for more information.

Packaging

The rpm-build package is required:

sudo dnf install rpm-build

If you're building from a cloned Git repository, checkout the appropriate MegaZeux version tag. For example:

git checkout v2.93

To build the rpm:

make distclean
rpm-build -bb --build-in-place megazeux.spec

Mac OS X

With MacPorts (testing only)

You will need to install XCode and MacPorts before continuing. This method is suitable only for testing builds, and should not be used to produce releases.

Compile/install dependencies. At least one SDL package is required, but there are several different options.

sudo port install zlib libpng libogg libvorbis

# Newer versions of macOS can use SDL3; configure MegaZeux with --enable-sdl3
sudo port install SDL3

# Most versions of macOS support SDL2.
sudo port install libsdl2

# Snow Leopard users may need this build of SDL2 instead.
sudo port install libsdl2-snowleopard

# Even older versions of macOS may need SDL 1.2; configure MegaZeux with --enable-sdl1
sudo port install libsdl

Navigate to the MegaZeux source directory and configure MegaZeux. Add any relevant SDL option here. For debug builds, omit --enable-release and --enable-lto.

./config.sh --platform darwin-devel --prefix /opt/local --enable-release --enable-lto

Build MegaZeux as usual:

make -j8

Multiarchitecture .app

THIS SECTION IS A WORK IN PROGRESS. Please refer to the documentation in arch/darwin/ and docs/platform_matrix.html for more details.

Environment Setup

This is heavily dependent on the architectures being targeted. For compilation on a Mac, typically select the highest Xcode being targeted as a base and install the lower versions using XcodeLegacy. Linux cross compilation isn't tested currently.

Architecture MegaZeux PREFIX SDK version OS minimum version Xcode toolchain Cross toolchain Last working SDL Notes
arm64 PREFIX_ARM64 11.0 11.0 Xcode 12.2 or higher osxcross Latest
arm64e PREFIX_ARM64E 11.0 11.0 Xcode 12.2 or higher osxcross Latest Builds containing this architecture seem to be killed immediately by the kernel when run on ARM64; avoid for now.
i686 PREFIX_I686 10.13 10.6 Xcode 9.4.1 osxcross 2.0.22 Mac OS X Snow Leopard is targeted to support Core Duo Macs.
x86_64 PREFIX_AMD64 10.13 10.6 Xcode 9.4.1 osxcross 2.0.22 (10.6) or latest (10.9+)
x86_64h PREFIX_AMD64H 10.13 10.9 Xcode 9.4.1 osxcross Latest OS X Mavericks is the minimum version for this architecture. Versions prior to Yosemite may have no clue how to handle software with both x86_64 and x86_64h executables; probably avoid unless targeting 10.10+.
ppc PREFIX_PPC 10.4 10.4 Xcode 3.2.6 osxcross (ppc-test) 2.0.3 (panther_SDL2) or 1.2.15 Mac OS X Tiger is targeted to support G3 Macs. SDL2 has Core Audio issues, 1.2.15 recommended.
ppc64 PREFIX_PPC64 10.5 10.5 Xcode 3.2.6 osxcross (ppc-test) 2.0.3 (panther_SDL2) or 1.2.15 Mac OS X Leopard is targeted as Objective-C is broken for PowerPC64 in the Tiger SDK. SDL2 has Core Audio issues, 1.2.15 recommended.

WARNING: if targeting PowerPC64 via XcodeLegacy, you need to revert a fix that XcodeLegacy applies to libgcc_s.10.5.dylib OR apply this patch to XcodeLegacy before building your SDK bundles.

cp /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libgcc_s.10.5.dylib /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libgcc_s.10.5.dylib.vectorfix
cp /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libgcc_s.10.5.dylib.bak /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libgcc_s.10.5.dylib

WARNING: when installing the Xcode 3 compilers via XcodeLegacy, it will replace the current Xcode's ld with a wrapper which either selects the original ld or redirects all PowerPC usage and Intel <=10.6 usage to the Xcode 3 ld. This breaks linking anything targeting Intel 10.6 with newer SDKs, so the ld script needs to be modified to redirect <=10.5 instead to fix this. It can be found at

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld

Other required tools

dylibbundler, which can be installed using MacPorts:

sudo port install dylibbundler

WARNING: dylibbundler relies on otool and therefore llvm-objdump. LLVM currently lacks support for reading the LC_UNIXTHREAD load commands of PowerPC64 Mach-O executables, so bundling will fail. Workarounds:

1) Currently, MegaZeux's bundle script (arch/darwin/bundle.sh) will add an otool wrapper to PATH (arch/darwin/bin/otool) which instead invokes xcrun otool-classic. This only works for Xcode versions which contain otool-classic.

2) Disabling those lines of bundle.sh and instead selecting a pre-LLVM Xcode to build for PowerPC64 should also work.

Dependencies

Fetch a macOS dependencies bundle from the MegaZeux dependencies GitHub repository and extract it to scripts/deps/ in your local MegaZeux Git repository.

Alternatively, if you are feeling very brave, you may attempt to compile the dependencies yourself using the Makefile in scripts/deps/. This requires the same environment as described above for compiling MegaZeux, plus cmake and wget (available from MacPorts or Homebrew).

Compilation

Unlike most other architectures, the prefix is provided PER ARCHITECTURE to a Makefile meta target.

./config.sh --platform darwin-dist --enable-release --enable-lto

To compile for a given architecture, provide to Make one or more of the PREFIX variables defined in the table above:

make PREFIX_I686=scripts/deps/macos/i686 PREFIX_AMD64=scripts/deps/macos/x86_64

For each architecture, Make will invoke:

make ARCH=[arch] PREFIX=[prefix] package
make ARCH=[arch] PREFIX=[prefix] clean

The "package" target is similar to "all", except afterward, dylibbundler is used to generate a dependency bundle in "bundles/", and then all binaries are moved to [binary].[arch].

Finally, Make will perform

make lipo

to merge all of the currently existing [binary].[arch] files into a new multiarchitecture file [binary].

Packaging

Make sure there is not a "MegaZeux" volume mounted before continuing.

rm -r build/
make archive

You can test the .app files generated in build/darwin-dist/ to make sure they run. A .dmg will appear in build/dist/darwin-dist/ containing the generated .app files, documentation, and multiarchitecture utilities.

HTML5 (Emscripten)

NOTE: emsdk may not function properly in MSYS2. Using Linux or similar is strongly recommended.

Download and install emsdk.

git clone https://github.com/emscripten-core/emsdk /opt/emsdk
cd /opt/emsdk
./emsdk install latest
./emsdk activate latest
. ./emsdk_env.sh

Configure and build MZX:

./config.sh --platform emscripten --enable-release
make -j8
make archive

Note that compiling MZX will make emsdk automatically install all required dependencies.

BlocksDS/Wonderful (Nintendo DS)

Follow the instructions here to install Wonderful and BlocksDS.

Install the following packages:

wc-pacman -S toolchain-gcc-arm-none-eabi-zlib

Configure and build:

arch/nds-blocksds/CONFIG.NDS
make -j8
make archive

devkitARM, devkitA64, and devkitPPC

Follow the instructions here to install the devkitPro toolchains.

Note that if you're using MSYS2 (or a Linux distribution with pacman already installed), you can simply add the devkitPro repository to your pacman.conf and install devkitpro-keyring:

[dkp-libs]
Server = http://downloads.devkitpro.org/packages

[dkp-windows]
Server = http://downloads.devkitpro.org/packages/windows

Nintendo DS

Install the following packages:

pacman --needed --noconfirm -S devkitARM libnds libfat-nds maxmod-nds nds-zlib ndstool dstools

Configure and build:

arch/nds/CONFIG.NDS
make -j8
make archive

Nintendo 3DS

Install the following packages:

pacman --needed --noconfirm -S devkitARM libctru citro3d picasso 3dstools general-tools
pacman --needed --noconfirm -S 3ds-zlib 3ds-libpng 3ds-libogg 3ds-libvorbisidec

Configure and build:

arch/3ds/CONFIG.3DS
make -j8
make archive

Nintendo Wii

Install the following packages:

pacman --needed --noconfirm -S devkitPPC libogc libfat-ogc gamecube-tools
pacman --needed --noconfirm -S ppc-zlib ppc-libpng ppc-libogg ppc-libvorbisidec

Configure and build:

arch/wii/CONFIG.WII
make -j8
make archive

Nintendo Wii U

Install the following packages:

pacman --needed --noconfirm -S devkitPPC wut wut-tools
pacman --needed --noconfirm -S ppc-zlib ppc-libpng ppc-libogg ppc-libvorbis wiiu-sdl2

Configure and build:

arch/wiiu/CONFIG.WIIU
make -j8
make archive

Nintendo Switch

Install the following packages:

pacman --needed --noconfirm -S devkitA64 libnx switch-tools
pacman --needed --noconfirm -S switch-glad switch-glm switch-mesa switch-libdrm_nouveau
pacman --needed --noconfirm -S switch-zlib switch-libpng switch-libogg switch-libvorbis switch-sdl2

Configure and build:

arch/switch/CONFIG.SWITCH
make -j8
make archive

DJGPP

Get a pre-built copy of DJGPP for your operating system from here. Create an environment variable DJGPP pointing to the location you extracted DJGPP and add the toolchain to your PATH variable:

export DJGPP=/opt/djgpp
export PATH="$PATH:$DJGPP/bin"

or

export DJGPP_PREFIX=/c/djgpp
export PATH="$PATH:$DJGPP/bin"

Build zlib:

CHOST=i586-pc-msdosdjgpp ./configure --prefix=$DJGPP
make -j8
make install

Build libpng:

CFLAGS="-I$DJGPP/include" \
CPPFLAGS="-I$DJGPP/include" \
LDFLAGS="-L$DJGPP/lib -lz" \
./configure --prefix=$DJGPP --host=i586-pc-msdosdjgpp --disable-shared --enable-static
make -j8
make install

Build tremor (lowmem):

git clone https://gitlab.xiph.org/xiph/tremor
git checkout lowmem
./autogen.sh --prefix=$DJGPP --host=i586-pc-msdosdjgpp --disable-shared --enable-static
make -j8
make install

Build libogg and libvorbis:

./configure --prefix=$DJGPP --host=i586-pc-msdosdjgpp --disable-shared --enable-static
make -j8
make install

Configure and build MegaZeux (libpng disabled and using tremor by default):

arch/djgpp/CONFIG.DJGPP
make -j8
make archive

VitaSDK

Follow the instructions here to set up the Vita toolchain. It is strongly recommended you substitute all instances of /usr/local/vitasdk in their instructions for /opt/vitasdk. /opt is the location that is intended for monolithic software, and placing VitaSDK here will group it with every other toolchain used by the MegaZeux console ports. install_all.sh should install every dependency that MegaZeux needs.

Configure and build MegaZeux:

arch/psvita/CONFIG.PSVITA
make -j8
make archive