Back

Cross-Compiling with BlitzMax

One of the great features of BlitzMax, is its ability to compile the same source-code on multiple platforms. However, to accomplish this, you need to compile your application on the intended platform.

This document demonstrates a technique which allows you to compile Windows modules and applications from an OS X or Linux platform.

How it Works

On Windows, BlitzMax uses the MinGW utilities to compile its modules and applications. This "toolchain" is also available on Linux and Mac, and can be used to create Windows compatible binaries just as if you had compiled them on a Windows system.

One thing that is required for this to work are a couple of the original files from a Windows BlitzMax installation. These are bcc.exe and fasm.exe. bcc compiles BlitzMax source into assembler, which is then compiled into binary data by fasm. Since each version of bcc is designed to produce code for a specific platform, we unfortunately need to use the bcc for Windows to create the correct code. Wine is used to run these.

We have created a special version of BMK (the BlitzMax "make" utility) which can handle all this for you. All you need to do is install the utilities and point it in the right direction.

Compiling on Linux

Requirements

  • A recent Ubuntu, or equivalent
  • A copy of bcc.exe and fasm.exe (from a Windows BlitzMax distribution)
  • Wine - for running Windows binaries.
  • MinGW32 3.4.5 Linux binaries : available here - mingw32_3.4.5_linux.tar.bz2 (30 meg)
  • BMK (NG) Linux Binary : available here - bmk_ng_bin_linux.tar.bz2 (150kb)

Installation

Copy the Windows bcc.exe and fasm.exe into the BlitzMax/bin folder. These are required because there is currently not a Linux-native bcc which generates Win32 assembler.

Install Wine via your favourite package manager.

Unzip the MinGW32 archive somewhere. It will extract a mingw32 folder with everything pre-compiled and ready to use. Note the path to this folder (you will need it later).

Unzip the BMK archive. In here, you will find 2 folders. The files in "bin" should be copied into the BlitzMax/bin
folder. The files in "lib" should be copied into the BlitzMax/lib folder.
(IMPORTANT : Back up your original copy of bmk before you do anything. Just in case. Without a working bmk, you cannot compile anything!).

Edit the config.bmk file that you copied into BlitzMax/bin. This file contains paths which point to various files and folders necessary to perform a Windows build.
The most important of these is the path_to_mingw. It specifies where your copy of the MinGW32 folder is located. Change the PATH/TO text to the relative location of where you unzipped the folder previously. For
example, if you unzipped it into /home/sam, you would replave PATH/TO with home/sam, so that the path would begin, /home/sam/mingw32/...
Check that the lib paths and filenames are correct (for ar, ld, gcc and g++) - if you are using the download listed above, this should already be correct.

Also check that the path to the wine executable is also correct.

Compiling on OS X

Requirements

Installation

Copy the Windows bcc.exe and fasm.exe into the BlitzMax/bin folder. These are required because there is currently not a MacOS-native bcc which generates Win32 assembler.

Install Darwine, via the disk image. When the disk image opens, simply drag the Darwine app into your Applications folder (or elsewhere if you prefer). If you install it in a location other than /Applications you will need to change the BMK config file (see below).

Install the MinGW32 distribution, via the disk image above. This is a package installer, so it will install MinGW32 in a standard location. Once installed, you will have a folder with everything pre-compiled and ready to use.

Unzip the BMK archive. In here, you will find 2 folders. The files in "bin" should be copied into the BlitzMax/bin folder. The files in "lib" should be copied into the BlitzMax/lib folder.
(IMPORTANT : Back up your original copy of bmk before you do anything. Just in case. Without a working bmk, you cannot compile anything!).

If you installed Darwine in a location other than /Applications, you will now need to edit the config.bmk file that you copied into BlitzMax/bin.
This file contains PATHs which point to various files and folders necessary to perform a Windows build.
You will need to amend the path_to_wine variable, to refer to the location where you installed Darwine. (Simply replace /Applications with the new location)

Testing

Now that everything is installed, you can now try a test build using the following command from the BlitzMax/bin folder :

./bmk makemods -l win32 brl.blitz

If everything is set up correctly, this should build the BRL.Blitz module for the Windows target.
Once that works, simple run the following command to do a full build of all the modules, for the Windows target :

./bmk makemods -l win32

If you want to test build an application it is probably easier to do this from the IDE (assuming you have an IDE
already set up to use the new compiler options). Otherwise you need to know all the correct command-line options to pass to bmk.

Troubleshooting

General

Double-check the paths are correctly configured in the config.bmk file.

Linux

If Wine appears to take forever to run a command, then you might find that disabling hardware 3D acceleration in Wine will fix this issue. To do so, you can run winecfg, and disable it from the dialog.

The binaries have been built with gcc 4.3.3, which may cause problems on earlier systems. So, we may need to do specific builds for older GCCs. If you see errors which look like stdc errors or such like, this is more than likely the case.

OS X

Darwine relies on X11 for some of its GUI functionality. You may also need to update your installation of X11 if you get errors running wine. A copy of this can be found at http://xquartz.macosforge.org.

MaxIDE

A new version of the MaxIDE is available which supports all the new functionality of BMK (NG) is available here

Alternatively, you can download the source which from here - maxide_src.zip (160kb). (You will need MaxGUI to compile this)

The New BMK Options

There are two new command-line options for this version of BMK.

-l win32

This option targets Windows binaries. On x86 Mac and Linux systems, using this option will enable the generation of both Win32 modules and applications.

To use this feature, see the various requirements for your platform above.

-i

This option enables Universal building on x86 Mac systems. Using this option will generate both PPC and x86 modules. When use with the makeapp option, it will create a Universal binary (note : you must have built modules using this option previously for this to work).

You will need a copy of bcc from a PPC BlitzMax distribution. Rename it to bcc_ppc, and copy it into your BlitzMax/bin folder.

Back