Setting up a Windows compile environment

This guide describes the steps that are needed to be able to compile NML NewGRFs on a Windows system using the make system as used by the #openttdcoop DevZone. This guide is made using a clean install of Windows 7, some names might be different on your system if you use a different version.

Installing programs

The following programs will be installed on your computer during this guide:
*Python (version 2.7.x)
*MinGW and MSYS

You are free to chose where you install the programs, as long as the path does not contain whitespaces, as the programs will be added to the PATH variable.

Installing NML

NML can be downloaded from the #openttdcoop bundles-sever . You can choose between Releases and Push. Releases are marked as stable and also contain older versions if needed, while Push contains the latest changes. For this guide it does not matter which one you use, the steps are the same for all versions.

Download the file named nml-<version>, where <version> is the version number of NML you are downloading. The other files are not relevant.

Copy the entire contents of the zip-file to the folder where you want to install NML.

Installing TortoiseHg

TortoiseHg is revision control client that is used to pull the code and changes from the #openttdcoop-server and push your own changes back. The download button can be found at the TortoiseHg-website .

During the installation, you can change the installation directory, all other settings are fine. If the Browse… button is greyed out, make sure you have selected TortoiseHg in the feature tree.

Installing Python 2.7.x

If you use a recent (r100 or newer) makefile from the make-nml project , you also need, which needs Python 2.7 to work. The link to the latest 2.7 release can be found on the Python-website .

During installation you can let the installer add python.exe already to the PATH variable, which is fine.

Installing MinGW and MSYS

To use make and other commands on Windows, you need MinGW and MSYS. Download MinGW-get-setup.exe to install the MinGW Installation Manager. During installation, you can disable the graphical user interface, as you will only use the command line. You can also change the installation directory to something else, following the advise to avoid white spaces in the path.

After selecting continue the program will download some things and start the MinGW Installation Manager. Mark the mingw32-base and msys-base packages for installation and select Installation > Apply Changes to start the installation of the selected packages. The packages will be installed in the same location as the Installation Manager.

Adding all programs to the PATH variable

You have now installed all programs you need, but running them from the command line will most likely result in a “‘Program’ is not recognized as an internal or external command, operable program or batch file.” message. Therefore you need to add the folders containing the programs to the Path-variable.

The paths you need to add are the installation directories for NML. For MinGW you need the \bin subdirectory and for MSYS the \msys\1.0\bin subdirectory of the MinGW installation directory. TortoiseHg and Python can be added upon installation, if not, you simply use the installation directory for those programs.

If you placed everything directly in folders on the C:\ drive, you would need to add
to the path variable, but if you used different paths, you would need to use those paths.

To edit the Path-variable, use the following steps:
*Right click on Computer and select properties
*In the window that opens, choose System Properties
*On the Advanced tab, select Environment Variables
*The Path variable is under System variables

*Select the Path-variable and choose Edit...
*Add the paths, separated by a ;. It is easiest to copy the paths from a notepad window directly to the end of the Path-variable, this reduces the chances of mistakes.
*Press OK until all windows are closed

To check if everything works, open the command line (cmd.exe) and issue the following commands:
nmlc --version
gcc --version

If all commands work properly, the programs are installed correctly. If one of the commands failed, check if the program is installed, run the command from the installation folder for that program (use the cd [path] command to change folders while on the command line) and check if you changed the Path-variable correctly.

Compiling your NewGRF

If all is working up to now, you can change the directory using the cd command to the folder containing your code. You can then use the “make” command to start the compiling of your NewGRF.

If you do not want to use cd to the right directory every time, you can also use shift+right click and open a command window from the context menu or write a small .bat-file that issues the make command.

Common errors

Command not found in bash

If you get errors that certain commands are not found in bash, it might be that the path in bash is not set correctly. It tries to copy the Windows Path-variable, but sometimes it fails copying the whole path (whitespaces for example). You can check this by starting the command line and issue the following commands two commands:
echo $PATH

It should list all the paths you added earlier to your Windows Path-variable, although the style will be different (paths start with /c/ instead of C:/ and different paths are separated by a : instead of a ;). If the list does not contain all the paths you added earlier, that might be the cause of the problem.

To fix that, you need to modify/create a file called .bashrc in C:\MinGW\msys\1.0\home\<username>\. Windows does not allow creation of files starting with a . using Windows Explorer, but you can do that from the command line. Open the command line from the context menu in C:\MinGW\msys\1.0\home\<username>\ (or use cd to go to that folder) and use the following command to create the file:

If you installed all programs directly in on the C:\ drive, you need to add the following text to .bashrc:
If you installed the programs in a different location, you need to add those locations.

Save the file and try compiling your NewGRF again.

Compilation stops with make: *** [docs/readme.txt] Error 2

If the make stops with the following error message:
[DOC] docs/readme.txt
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `[ -z "unix2dos" ] || unix2dos unix2dos 6.0.5 (2014-04-17) MSY
S version. Without Unicode UTF-16 support. With native language support. LOCALED
IR: /usr/share/locale -q docs/readme.txt'
make: *** [docs/readme.txt] Error 2

You can solve this by creating/modifying a file named Makefile.local in your repository and add the following text:

If you created makefile.local you also need to tell your Makefile that you want to include it by adding the following line somewhere near the top of the file (directly above/below -include Makefile.config if it is present)
-include Makefile.local

NML_Index.png (92.2 KB) Transportman, 2014-08-03 14:11

MinGW_Installation_Manager.png (22.1 KB) Transportman, 2014-08-03 14:11

NML_Copy.png (80.7 KB) Transportman, 2014-08-03 14:36

Python_Install.png (95.5 KB) Transportman, 2014-08-03 14:36

Path-1.png (112 KB) Transportman, 2014-08-03 14:55

Path-2.png (12.6 KB) Transportman, 2014-08-03 14:57

MinGW_Installation_Manager.png (66.7 KB) Transportman, 2014-08-03 15:27