Compiling for Windows with scons

From The Powder Toy
Revision as of 18:07, 12 February 2014 by mniip (talk | contribs) (a few typos, formatting errors, etc)
Jump to: navigation, search

This guide is for compiling tpt from git with scons, the official build system of tpt. You will need to install git, mingw, python, and scons in order to follow this guide. Setting everything up and then compiling tpt could take from 30 minutes to an hour depending on your internet connection and cpu speed.

Note: This guide does not include info on how to set up an ide and edit the code. You will have to get an ide yourself if you want to code easily. You may want to look at Code::Blocks or Eclipse, both good ide's, or just use what you prefer, even a simple Notepad would work. You can configure them to automatically run the correct build command when done. If you want to use visual studio, follow that guide instead.

If you get any problems, ask for help in the Development assistance section on The Powder Toy forums.

Downloads

Options shown in green are recommended.

Start by downloading msys at: http://msysgit.github.io/
See the context menu settings on the image to the left. Use the defaults in the rest of the installer.

Mingw-gui.png

Next, download mingw, the compiler: http://sourceforge.net/projects/mingw/files/latest/download?source=files
When it'll ask you what folder to install, make sure it's "C:\MinGW". Uncheck "install support for the graphical user interface". At the moment of writing it is totally silly and unusable.

Press quit after it hits 100%


The installer is a little bit confusing, when it gets to 100% you are supposed to press "Quit".

Mingw-get.png

Now, to complete mingw installation, locate Git Bash in the start menu and open it. Copy the following into the terminal (right click the window's title and select Edit -> Paste).

mingw-get install gcc g++ mingw32-libbz2 bzip2 mingw32-libz zlib mingw32-pthreads-w32

Now, download python at: http://www.python.org/ftp/python/2.7.6/python-2.7.6.msi
It is recommended you download the 32 bit version and not the 64 bit, since if not the scons install may not work. When installing make sure the installation dir is "C:\Python27\". Everything else is default.

Finally, get scons, the build system, here: http://sourceforge.net/projects/scons/files/scons/2.3.0/scons-2.3.0-setup.exe/download
Hopefully it will find your python installation automatically. There pretty much aren't any settings to adjust.

Add variables to Path

Windows-path.png

You need to add the mingw and python tools you just installed to your %path% in order to compile. Open Control panel, and go into System -> Advanced -> Environment variables. In windows 7 may be located in System and Security -> System, and then hit "Advanced System settings" on the left and click "Environment variables" at the bottom. At the bottom of here there is a list, find "Path" there, select it, click Edit. It will give you a [rather small] window for editing.
This variable is a semicolon-separated list, at the end you should add mingw binaries directory, python directory and python scripts directory. That is, at the end you should add ;C:\Mingw\bin;C:\Python27;C:\Python27\Scripts\. If for some reason one of these is already in the path, don't add it again.

Windows-path-test.png

To test if this worked, you can use git bash (if you already have this open, close it and restart it). Open your start menu, find "Git bash" somewhere there, probably in the git folder. Run it, it will display a shell. Type cc and press enter, it should say something like "cc.exe: fatal error: no input files, compilation terminated." That is alright, means that it finds the compiler and everything works correctly. If it instead says "cc: command not found", then you did something wrong and it wasn't properly added to path. Check it again and make sure you typed it exactly.
Now type python -h, if you see "python: command not found", it can't find python, you probably didn't add it to path correctly, so check again. If it did work correctly it will print a large amount of help text and exit.
Lastly, to check if scons is in path, type scons.py, it should say "scons: *** No SConstruct file found", that's alright, since we don't even have the source at this point. If it says "scons.py: command not found", it means you've probably done something wrong in path setup.

Getting Needed Libraries

Now we need to get a few libraries to compile TPT successfully.

We have already installed zlib and bzip2 while installing mingw, the others you need are SDL, lua, and fftw. They can't be downloaded so easily, so you have to download them manually here:
https://dl.dropboxusercontent.com/u/43784416/PowderToy/MingwLibraries.zip
Copy both of the folders into your C:\MinGW

Getting the Source

Now we're actually going to get TPT's source. We're going to behave like a pro, and use git (we have git bash after all). Create a new folder where the source will be. Open it, right click and select "Git Bash here". A bash prompt will open.
The following command will obtain the source and all historically important information about it.
git clone http://github.com/FacialTurd/The-Powder-Toy.git .
The period at the end means the source will download into the current directory. If you omit it, a new directory will be made inside current one.
After the command has finished, you'll find out that the folder contains a lot of stuff, like, umm, TPT source.

Compiling

Now to compile, run scons.py --win. It should check for libraries, then should start compiling (if anything fails, check config.log in the folder and post to pastebin.com if you need help figuring out what it means). Depending on your computer it will take from a few, to a few dozen minutes. If your compilation succeeds, the exe will be placed in the build/ folder, so go run it and hope it works. If it does, you can now start modding tpt.
P.S. If you have a multicore processor, use scons.py --win -j#, replacing # with the number of cores you have, ex. -j4 for 4 cores. This will make it compile with all the cores, making it go much faster, since it can be slow especially the first time.

P.P.S. You can append a few more options after --win. For instance --release makes a release version (that is, non-beta), --debugging adds a few debug features, --64bit (if you install MinGW-W64 from here [1], it produces a 64-bit executable.)
List of all sconscript flags you can use

P.P.P.S. the compiler produces unstripped output, which is great for debugging, but not for distribution. You might get a few dozen megabytes of powder.exe, when it should only be about 4. To fix that, use the strip command, which will cut all unnecessary information from binary. For instance, strip build/Powder.exe

-- written by mniip, edited by jacob1 -- revision 2 with screenshots, by mniip