Difference between revisions of "Compiling for Windows with scons"

From The Powder Toy
Jump to: navigation, search
(windows scons compiling guide, from mniip)
 
(Add outdated notice)
 
(48 intermediate revisions by 7 users not shown)
Line 1: Line 1:
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.
+
{{Languages|Compiling for Windows with scons}}
  
If you get any problems, ask for help in the Development assistance section on [http://powdertoy.co.uk/Discussions/Categories/Topics.html?Category=5 The Powder Toy forums].
+
'''ATTENTION: This guide is outdated as of 2021. Please use this guide for building any recent version of the game: [[Building TPT with Meson]]'''
 +
 
 +
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 [https://powdertoy.co.uk/Discussions/Categories/Topics.html?Category=5 The Powder Toy forums].
  
 
== Downloads ==
 
== Downloads ==
Start by downloading msys at: http://msysgit.github.io/
+
Start by downloading Git for Windows at: https://git-for-windows.github.io/
<br>Install with the default settings.
+
<br>If you want to install it for all users you need to run the installer as administrator (or else it will assume you want to install it for just yourself). If you use windows 10 you may want to select to use the windows-like console instead of the one they provide. Besides that, it is recommended to use the defaults in the rest of the installer.
 +
 
 +
[[File:Mingw-gui.png|thumb|]]
 +
Next, download MinGW, the compiler: http://sourceforge.net/projects/mingw/files/latest/download?source=files
 +
<br>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.
 +
[[File:Mingw-quit.png|thumb|Press quit after it hits 100%]]
 +
<br>The installer is a little bit confusing, when it gets to 100% you are supposed to press "Quit".
  
Next, download mingw, the compiler: http://sourceforge.net/projects/mingw/files/latest/download?source=files
+
Now, download python at: https://www.python.org/ftp/python/3.6.4/python-3.6.4.exe
<br>When it'll ask you what folder to install, make sure it's "C:\MinGW"
+
<br>It is recommended you download the 32 bit version and not the 64 bit, since if not the SCons install may not work.
<br>When it'll ask for additional components to install, select "C compiler" and "C++ compiler". Do not select "MSYS", you already have that.
+
When installing make sure the installation directory is "C:\Python36\". Everything else is default.
  
Now, download python at: http://python.org/download/
+
If you have multiple cores and want to use them to compile faster, you will also need to download the [https://github.com/mhammond/pywin32/releases/download/b222/pywin32-222.win32-py3.6.exe pywin32 extensions] (not required).
<br>Do *NOT* download version 3.x, it isn't compatible. Download 2.x instead (2.7.5 at the moment of writing.) It is also 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
+
Finally, get SCons, the build system, here: https://sourceforge.net/projects/scons/files/scons/3.0.0/scons-3.0.0-setup.exe/download
 
<br>Hopefully it will find your python installation automatically. There pretty much aren't any settings to adjust.
 
<br>Hopefully it will find your python installation automatically. There pretty much aren't any settings to adjust.
  
 
== Add variables to Path ==
 
== Add variables to Path ==
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.  
+
[[File:Windows-path.png|left|thumb|]]
<br>At the end you should add a semicolon and the mingw binaries directory, python bin directory, and scons script 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.
+
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. Before windows 10, it is located in System and Security -> System, and then hit "Advanced System settings" on the left and click "Environment variables" at the bottom. In Windows 10, right click the start button and click System -> Advanced -> Environment variables. At the bottom of the window there is a list, find "Path" there, select it, click Edit.
 +
<br>In Windows 7 and 8, 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 <code>;C:\MinGW\bin;C:\Python36;C:\Python36\Scripts</code>. If for some reason one of these is already in the path, don't add it again. You will need to restart git bash for changes to take effect. In Windows 10, you can just hit "New" and add each entry on a separate line.
  
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` without the quotes and press enter, it should say something like "cc.exe: fatal error: no input files, compilation terminated." That is alright, means that it sees 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.
+
[[File:Windows-path-test.png|thumb|]]
<br>Now type `python -h` (no quotes), 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.
+
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 <code>cc</code> and press enter, it should say something like "cc.exe: fatal error: no input files, compilation terminated." That is alright, it means that it finds the compiler and everything works correctly. If instead you get "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.
<br>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 python's path setup.
+
<br>Now type <code>python -h</code>, 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 worked correctly, it will print a large amount of help text and exit.
 +
<br>Lastly, to check if SCons is in path, type <code>scons.py</code>, 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 ==
 
== Getting Needed Libraries ==
Now we need to get a few libraries to compile TPT successfully.
+
[[File:Mingw-get.png|thumb|]]
 +
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). (If that fails open command prompt and type in the command there)
  
Let's start with easy ones, bz2 and zlib. In the git bash window still open, type this without quotes:
+
<code>mingw-get install gcc g++ mingw32-libbz2 bzip2 mingw32-libz zlib mingw32-pthreads-w32</code>
<br>`mingw-get install mingw32-libbz2 bzip2 mingw32-libz zlib `
 
  
The other libraries are SDL, lua, regex and fftw. They can't be downloaded so easily, so you have to download them manually here:
+
Now we need to get a few libraries to compile TPT successfully. The others you need are SDL, Lua, and fftw. They can't be downloaded so easily, so you have to download them manually here:
<br>https://dl.dropboxusercontent.com/u/43784416/PowderToy/MingwLibraries.zip
+
<br><!--[https://drive.google.com/uc?id=0B1XWtCTn2YPAZ3dqSU5CbjE4OXM&export=download MingwLibraries.zip]-->[https://starcatcher.us/TPT/MingwLibraries.zip MingwLibraries.zip]
 
<br>Copy both of the folders into your C:\MinGW
 
<br>Copy both of the folders into your C:\MinGW
 +
<br>You'll also need libsdl2, you can get that [https://www.libsdl.org/download-2.0.php Here] Under Development Libraries download <code>SDL2-devel-2.0.8-mingw.tar.gz</code>
  
 
== Getting the Source ==
 
== 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?).
+
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).
<br>Use `cd` to switch to some folder, i'll create a folder named "TPT" on my desktop and use it. (You may cd into any other folder you want to store the code, if you don't want it on your desktop. The location doesn't matter). Do these commands without the quotes
+
Create a new folder where the source will be. Open it, right click and select "Git Bash here". A bash prompt will open.
<br>`cd Desktop`
+
<br>The following command will obtain the source and all historically important information about it.
<br>`mkdir TPT`
+
<br><code><nowiki>git clone http://github.com/The-Powder-Toy/The-Powder-Toy.git .</nowiki></code>
<br>`cd TPT`
+
<br>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.
<br>The following command will actually obtain the source and all historically important information about it.
+
<br>After the command has finished, you'll find out that the folder contains a lot of stuff, like, umm, TPT source.
<br>`git clone http://github.com/FacialTurd/The-Powder-Toy.git .`
 
<br>The download size is ~23 megabytes, so, if you have a slow internet, go eat something meanwhile.
 
<br>After the command has finished, you'll find out that the folder (TPT on desktop in my case) contains a lot of stuff, like, umm, TPT source.
 
  
 
== Compiling ==
 
== Compiling ==
Now to compile, run `scons.py --win --release`. It should check for libraries, then should start compiling (if anything fails, check config.log in the folder). Depending on your computer it will take from a few, to a few dozen minutes.
+
Now to compile, run <code>scons.py</code>. 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.
 
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.
<br>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.
+
<br>P.S. If you have a multicore processor, and installed the pywin32 extensions earlier, use <code>scons.py -j#</code>, 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.
  
 +
<br>[[Scons_command_line_flags|List of all sconscript flags you can use]]
  
 +
-- written by mniip, edited by jacob1
 +
-- revision 2 with screenshots, by mniip
  
-- written by mniip, edited by jacob1
+
[[Category: Development]]
 +
[[Category: Compiling]]

Latest revision as of 08:59, 3 April 2021

Language: English  • 中文

ATTENTION: This guide is outdated as of 2021. Please use this guide for building any recent version of the game: Building TPT with Meson

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

Start by downloading Git for Windows at: https://git-for-windows.github.io/
If you want to install it for all users you need to run the installer as administrator (or else it will assume you want to install it for just yourself). If you use windows 10 you may want to select to use the windows-like console instead of the one they provide. Besides that, it is recommended to 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".

Now, download python at: https://www.python.org/ftp/python/3.6.4/python-3.6.4.exe
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 directory is "C:\Python36\". Everything else is default.

If you have multiple cores and want to use them to compile faster, you will also need to download the pywin32 extensions (not required).

Finally, get SCons, the build system, here: https://sourceforge.net/projects/scons/files/scons/3.0.0/scons-3.0.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. Before windows 10, it is located in System and Security -> System, and then hit "Advanced System settings" on the left and click "Environment variables" at the bottom. In Windows 10, right click the start button and click System -> Advanced -> Environment variables. At the bottom of the window there is a list, find "Path" there, select it, click Edit.
In Windows 7 and 8, 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:\Python36;C:\Python36\Scripts. If for some reason one of these is already in the path, don't add it again. You will need to restart git bash for changes to take effect. In Windows 10, you can just hit "New" and add each entry on a separate line.

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, it means that it finds the compiler and everything works correctly. If instead you get "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 worked 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

Mingw-get.png

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). (If that fails open command prompt and type in the command there)

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

Now we need to get a few libraries to compile TPT successfully. The others you need are SDL, Lua, and fftw. They can't be downloaded so easily, so you have to download them manually here:
MingwLibraries.zip
Copy both of the folders into your C:\MinGW
You'll also need libsdl2, you can get that Here Under Development Libraries download SDL2-devel-2.0.8-mingw.tar.gz

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/The-Powder-Toy/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. 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, and installed the pywin32 extensions earlier, use scons.py -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.


List of all sconscript flags you can use

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