Difference between revisions of "Compiling for OS X"

From The Powder Toy
Jump to: navigation, search
(Page complete!)
(Standard meson notice)
 
(24 intermediate revisions by 8 users not shown)
Line 1: Line 1:
Note: This page is only for OS X (10.7, 10.8)
+
'''ATTENTION: This guide is outdated as of 2021. Please use this guide for building any recent version of the game: [[Building TPT with Meson]]'''
Note: If you are 10.6 or below, go to this page: [https://powdertoy.co.uk/Wiki/index.html?title=Compiling_for_Mac_OS_X 10.6]
 
  
 +
This guide is for compiling TPT on OS X. It should work on all OS X versions before Mavericks (OS X 10.9). It '''does not''' work on OS X 10.10 (Yosemite), 10.11 (El Capitan), or 10.12 (Sierra).
  
Download Xcode from the App Store [http://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12 link]
+
If there are problems, try posting your errors on the development help section of the forums, or coming onto [http://webchat.freenode.net/?channels=#powder irc].
  
Download SDL [http://www.libsdl.org/release/SDL-1.2.14.tar.gz link]
+
== Installing Xcode ==
  
Download xQuartz [http://xquartz.macosforge.org/downloads/SL/XQuartz-2.7.2.dmg link]
+
This step is optional, if you don't want to install Xcode (very large, 3 GB), then instead follow the section "Installing the command line tools". You'll probably want another IDE to edit the code with if you don't use Xcode.
  
 +
Download [http://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12 Xcode] from the App Store. If you are on OS X 10.7 you will have to register a developer account and download 4.6.3 [https://developer.apple.com/downloads/index.action here].
  
This should download to your downloads folder. Keep uncompressing until it becomes a folder.
+
Install and open Xcode. Go to Xcode -> Preferences and click on Downloads. Install "Command Line Tools"
  
Then, in terminal, type <code bash>cd </code> (<-- Make sure there is a space after) and then drag the SDL folder in.
+
== Installing the command-line tools ==
  
then type in (or copy / paste) <code bash>./configure && make</code>
+
If you don't want to install Xcode due to the size or other reasons, follow this section instead. If you already have Xcode and the command line tools, skip ahead.
  
 +
There are some smaller downloads for just the command line tools in the [https://developer.apple.com/downloads/index.action?name=Xcode Apple developer website]. You'll need an [https://developer.apple.com/register/ Apple ID with developer access] to get to it, though!
  
If that comes up with an error, go to this [https://developer.apple.com/downloads/index.action# page] and download 'Command Line Tools for OS X'.  
+
[http://i.imgur.com/NzuvEKT.png (Here's the kind of thing you have to download. Make sure the version matches your OSX version!)]
  
There are two versions. One is for lion 10.7 and the other is for mountain lion 10.8. If you don't know which you are using, go to the apple in the top left hand corner and press about my mac.
+
== Option #1: Homebrew ==
  
 +
Install [http://brew.sh Homebrew] - this will give you easy access to each of the libraries below. You can then install all the necessary tools and libraries with it:
 +
<code bash>brew install fftw scons sdl2 lua@5.1</code>
  
After that, install SDL by typing in <code bash>sudo make install</code>
+
== Option #2: Manual library installation ==
It will ask you for your password. Type it in and press enter.
 
  
 +
=== Compiling scons ===
  
 +
Download [http://prdownloads.sourceforge.net/scons/scons-2.3.0.zip scons] and unzip it. Go into the terminal, and type in <code bash>cd ~/Downloads/scons-2.3.0/</code>
 +
(you can use tab to complete a folder name so you don't have to type it all out). Next type <code bash>sudo python setup.py install</code>. The terminal will ask you for your password. Note that you can not see your password while you are typing it in. You now have scons installed. Keep the terminal open for later.
  
After that is done, time to install Lua.
+
=== Getting FFTW ===
  
 +
Download the [http://www.fftw.org/fftw-3.3.4.tar.gz fftw3 source]. Double click to extract it, then go back to the terminal and type <code bash>cd ../fftw-3.3.4/</code>. Once in the fftw folder, type <code bash>./configure && make </code>. Some different options may be needed to make it compile (I used a lot) but maybe this works.
  
Download this file: [http://www.lua.org/ftp/lua-5.1.4.tar.gz link]
+
== Getting Lua ==
  
Keep uncompressing until it becomes a folder
+
Download the [http://www.lua.org/ftp/lua-5.1.5.tar.gz lua source]. Double click to extract it, then go back to the terminal and type <code bash>cd ../lua-5.1.5/</code>. Once in the lua folder, type <code bash>make macosx</code> and then <code bash>sudo make install</code>. The lua library is now installed.
  
Now, type <code bash>cd </code> in terminal and drag your lua folder inside.
+
== Getting SDL ==
  
Run this: <code bash> ./configure && make</code>
+
Download the [https://www.libsdl.org/release/SDL-1.2.15.dmg SDL framework]. Open the freshly downloaded DMG file and drag SDL.Framework to the folder <code>/Library/Frameworks/</code>
  
Then run: <code bash>sudo make install</code>
+
== Getting TPT source code ==
  
Lua has been installed in the system, but TPT will not accept it yet.
+
Make a new folder in your Documents called "TPT" - this will become your project directory for all the TPT source code. We'll now download the entire commit history to that folder - this will let you add your own commits, creating your unique code project.
  
Open The Powder Toy's source folder and open "makefile" with TextEdit.
+
First, use <code bash>cd ~/Documents/TPT</code> to move to the project directory, then
 +
<code bash>git clone https://github.com/The-Powder-Toy/The-Powder-Toy.git .</code> to clone all the history. The dot at the end means that we won't make a new subdirectory inside the TPT project directory.
  
Find the line that says "powder-x", near this you will see a bit of text that says "-lua5.1", remove the 5.1 from this and save the file.
+
At the end of this we have a fully functional environment to build, as well as a local copy of the entire project. Great job! :D
  
 +
== Building ==
  
Done! Now, you are able to compile Source code into the applications!
+
This is the part you've been waiting for - type <code bash>scons</code> into the terminal and press enter. The script will check if your environment is alright (it is) and then it'll start compiling each of the source code files.
  
 +
For a list of all the options you can give to scons, see [[Scons_command_line_flags]].
  
To compile, type in <code bash>cd </code> and drag the source code into it.  
+
Additionally, compiler flags can be added with the CFLAGS and CXXFLAGS environment variables. For example, the <code bash>march</code> (microarchitecture) can be set specific to the host machine for minor performance improvements: <code bash>CFLAGS="-march=native" CXXFLAGS="-march=native" scons</code>.
  
Then type <code bash>make powder-x</code>
+
== Aftermath ==
  
 +
If it compiled without errors, you will find a file called <code>powder-x</code> or <code>powder64-x</code> in the build folder. Double click it and run it.
 +
Congrats, you have compiled the source code and have made a OS X application.
  
It will go though the process of compiling the source code, and it should say something along the lines of 'strip powder-x'
+
This was written by Candunc, rewritten by jmeyer2k, and fixed again by jacob1, and cleaned up by boxmein. Thanks to the editors on the Mac OS X compile page, and thanks to people at Mac Rumors and Ximon to help me find out various errors.
  
In your source folder, you will see a powder-x file. How do you run it, you ask?
+
I hope this helps future users become Mac Compilers and push TPT to Mac users!
 
 
Well, you will need to download a copy of powder toy, and right click (or control click) and click 'show contents'
 
 
 
Open the Contents folder, followed by the MacOS folder. Inside it is a powder-x file! Simply copy or move the powder-x from the source code folder and place it inside the .app
 
 
 
Congrats, you have compiled spare code and have made a OS X application.
 
  
This was written by Candunc, although parts were copied from the Mac OS X compile page. Thanks to the editors on the Mac OS X compile page, and thanks to people at Mac Rumors and Ximon to help me find out various errors.
+
[[Category:Compiling]]
 
 
I hope this helps future users become Mac Compilers and push TPT to Mac users!
 

Latest revision as of 05:48, 25 June 2021

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 on OS X. It should work on all OS X versions before Mavericks (OS X 10.9). It does not work on OS X 10.10 (Yosemite), 10.11 (El Capitan), or 10.12 (Sierra).

If there are problems, try posting your errors on the development help section of the forums, or coming onto irc.

Installing Xcode

This step is optional, if you don't want to install Xcode (very large, 3 GB), then instead follow the section "Installing the command line tools". You'll probably want another IDE to edit the code with if you don't use Xcode.

Download Xcode from the App Store. If you are on OS X 10.7 you will have to register a developer account and download 4.6.3 here.

Install and open Xcode. Go to Xcode -> Preferences and click on Downloads. Install "Command Line Tools"

Installing the command-line tools

If you don't want to install Xcode due to the size or other reasons, follow this section instead. If you already have Xcode and the command line tools, skip ahead.

There are some smaller downloads for just the command line tools in the Apple developer website. You'll need an Apple ID with developer access to get to it, though!

(Here's the kind of thing you have to download. Make sure the version matches your OSX version!)

Option #1: Homebrew

Install Homebrew - this will give you easy access to each of the libraries below. You can then install all the necessary tools and libraries with it: brew install fftw scons sdl2 lua@5.1

Option #2: Manual library installation

Compiling scons

Download scons and unzip it. Go into the terminal, and type in cd ~/Downloads/scons-2.3.0/ (you can use tab to complete a folder name so you don't have to type it all out). Next type sudo python setup.py install. The terminal will ask you for your password. Note that you can not see your password while you are typing it in. You now have scons installed. Keep the terminal open for later.

Getting FFTW

Download the fftw3 source. Double click to extract it, then go back to the terminal and type cd ../fftw-3.3.4/. Once in the fftw folder, type ./configure && make . Some different options may be needed to make it compile (I used a lot) but maybe this works.

Getting Lua

Download the lua source. Double click to extract it, then go back to the terminal and type cd ../lua-5.1.5/. Once in the lua folder, type make macosx and then sudo make install. The lua library is now installed.

Getting SDL

Download the SDL framework. Open the freshly downloaded DMG file and drag SDL.Framework to the folder /Library/Frameworks/

Getting TPT source code

Make a new folder in your Documents called "TPT" - this will become your project directory for all the TPT source code. We'll now download the entire commit history to that folder - this will let you add your own commits, creating your unique code project.

First, use cd ~/Documents/TPT to move to the project directory, then git clone https://github.com/The-Powder-Toy/The-Powder-Toy.git . to clone all the history. The dot at the end means that we won't make a new subdirectory inside the TPT project directory.

At the end of this we have a fully functional environment to build, as well as a local copy of the entire project. Great job! :D

Building

This is the part you've been waiting for - type scons into the terminal and press enter. The script will check if your environment is alright (it is) and then it'll start compiling each of the source code files.

For a list of all the options you can give to scons, see Scons_command_line_flags.

Additionally, compiler flags can be added with the CFLAGS and CXXFLAGS environment variables. For example, the march (microarchitecture) can be set specific to the host machine for minor performance improvements: CFLAGS="-march=native" CXXFLAGS="-march=native" scons.

Aftermath

If it compiled without errors, you will find a file called powder-x or powder64-x in the build folder. Double click it and run it. Congrats, you have compiled the source code and have made a OS X application.

This was written by Candunc, rewritten by jmeyer2k, and fixed again by jacob1, and cleaned up by boxmein. Thanks to the editors on the Mac OS X compile page, and thanks to people at Mac Rumors and Ximon to help me find out various errors.

I hope this helps future users become Mac Compilers and push TPT to Mac users!