Skip to content
Zwetan Kjukov edited this page Dec 9, 2015 · 8 revisions

Mac OS X Setup

Everything you have to install and setup to be able to compile Redtamarin under Mac OS X.

The Basic

We are installing a Mac OS X 10.10 Yosemite,
but it should also work with a Mac OS X 10.11 El Capitan (not tested).

Once the system is installed, update
"Apple" menu (top-left) then "Software Update...".

The "optional", install whatever you need as a developer like Google Chrome, Flash Debug version, Adobe AIR, your preferred code editor, etc.

The Development Stack

From that point, we install what we consider the "essential", and yes it will certainly be biased toward specific tools but it's what we're going with because we know it works, if you don't install those for whatever reasons we will not be able to help or support you.

Basic

Install Google Chrome
For Mac OS X 10.6 or later

Install Sublime Text 2
OS X (OS X 10.6 or later is required)

Install Xcode 7.1.1 (or latest version)
you need an Apple developer account (free, you just need the Apple ID)
then go to the Apple developer downloads
sign in with this account and download the following

note:
If you are already using another Xcode (like 6.4 or earlier), you can install different Xcodes in parallel, just rename your current /Applications/Xcode.app to /Applications/Xcode 6.4.app.

Command-line

Everything is in place you already have a Terminal and a Bash Shell.

But we are missing a package manager for OS X, and there are more than one to chose from, the more popular are: Fink, MacPorts and Homebrew.

If you never installed such package manager follow our lead (it will be all fine I promise) but if you're already using one of those above there is a high probability that our choice will not please you.

We decided to go with MacPorts and support only compilation problems related to MacPorts.

That said, even if you curse us because you prefer Fink or Homebrew or anything else, you can keep using them but if you run into problems you will have to support yourself.

Why do we chose MacPorts?

  • biggest selection of packages / ports
  • in general very up to date
  • nice variant system
    that let us customise stuff
  • easy to use as apt-get
    (even if fink feel more debian)
  • the big selection of GCC compilers
  • leave the /usr/local alone

Don't try to install and mix different package managers on one system

  • if you have no package manager just install macports
  • if you already have another package manager
    try to install the same tools
    (eg. tree, wget, etc.)

Follow MacPorts install instructions
and install MacPorts for OS X 10.10 Yosemite.

If you're not familiar at all with MacPorts,
read Using MacPorts Quick Start.

To open the Terminal, run "/Applications/Utilities/Terminal.app".

You should get a prompt looking like this

machine:~ username$

First let's update our package definitions
$ sudo port selfupdate
and upgrade outdated packages
$ sudo port upgrade outdated

Now let's install some tools
$ sudo port install bash_completion
$ sudo port install wget
$ sudo port install tree
$ sudo port install subversion
$ sudo port install git-core +credential_osxkeychain +svn
$ sudo port install mercurial

If you need to search for a particular package
$ port search --name --line --regex '^gcc\d*$'
(regex could be whatever you need: '^gcc\d*$', '^gcc.*$', '.*gcc.*$', etc.)
you'll get some results

gcc5	5.2.0	lang	The GNU compiler collection
gcc6	6-20151129	lang	The GNU compiler collection, prerelease BETA
gcc43	4.3.6	lang	The GNU compiler collection
gcc44	4.4.7	lang	The GNU compiler collection
gcc45	4.5.4	lang	The GNU compiler collection
gcc46	4.6.4	lang	The GNU compiler collection
gcc47	4.7.4	lang	The GNU compiler collection
gcc48	4.8.5	lang	The GNU compiler collection
gcc49	4.9.3	lang	The GNU compiler collection
gcc410	5-20140817	lang	this port is only a stub and has been made obsolete by gcc5

note:
You don't need to install make with macports as it was already installed by the Command Line Utilities.

Configuring your environment

  • Open a Terminal
  • go to your home directory
    $ cd ~ or $ CD $HOME
  • check if you have a .profile
    $ ls -la
    • if not, create a .profile
      $ touch .profile
  • edit it
    $ nano .profile

To obtain something like that

export EDITOR=nano
export CLICOLOR=1
export TERM=xterm-color
export LSCOLORS=DxFxcxdxBxegedbxHxHcHd
export LS_COLORS="di=01;33;40:ln=01;95;40:so=32;40:pi=33;40:ex=01;91;40:bd=34;46:cd=34;43:su=31;40:sg=01;97;40:tw=01;97;42:ow=01;97;43:"

export PORT_HOME=/opt/local

export PATH=$PORT_HOME/bin:$PORT_HOME/sbin:$PATH

alias ls="ls --color=auto"
alias tree="tree -C"

if [ -f /opt/local/etc/bash_completion ]; then
  . /opt/local/etc/bash_completion
fi

Because you have installed macports you should see something like that in your .profile

##
# Your previous /Users/zwetan/.profile file was backed up as /Users/zwetan/.profile.macports-saved_2015-12-07_at_04:53:58
##

# MacPorts Installer addition on 2015-12-07_at_04:53:58: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.

To apply the changes
$ source .profile

If you don't have tree installed
$ port install tree

Now try to do a ls -la or a tree -L 1 /usr and you should have some nice colors in your terminal.

This is mainly about editing your .profile to add environment variables, if you want a custom color scheme use the LSCOLORS configurator, also look at Configuring LS_COLORS and Colorizing the Terminal.

If you can not or struggle to apply such configuration you should stop here, not trying to discourage you but what's coming next is much much more complex and so maybe you should get familiar with the Bash Shell and the Terminal first (you can find tons of tutorial online).

About Terminal, Shell and dotfiles

If you use ssh to connect to a remote machine,
it will read your .profile because you "login".

Normally, opening the Terminal.app should nto read the .profile because you are already logged in, but Apple default is to open the terminal as a login shell (If I remember well).

That's good for us as we define all our config etc. in the .profile
so in this case it is already done for us.

Let's check anyway

  • go to "Terminal / Preferences ..."
  • in the "General" tab check that
    "Shells open with (*) Default login shell"
    is indeed selected
  • and in the "Profiles" tab, under "Advanced"
    be sure that "Declare terminal as:" is set to
    xterm-256color

Java

We need Java to run Ant and compile with the Flex SDK.

Java SDK

First check if you have java (it could be there if you upgraded from earlier version of OS X) $ java -version
if you don't have it it will say
No Java runtime present, requesting install.
if you click on "More Info" it will redirect you to the Oracle website.

Download a recent Java SDK (minimum Java 1.6)
http://java.sun.com/javase/downloads/index.jsp
http://www.oracle.com/technetwork/java/javase/downloads/index.html

For example download Java SE 8u65 / 8u66 SDK
be sure to download the Mac OS X x64 version
Java SE Development Kit 8u66
once you clicked "Accept License Agreement",
click the link and it will download jdk-8u66-macosx-x64.dmg.

Install jdk-8u66-macosx-x64.dmg.

To be able to use Java from the command-line we need to configure our environment

  • Open a Terminal
  • go to your home directory
    $ cd ~ or $ CD $HOME
  • check if you have a .profile
    $ ls -la
    • if not, create a .profile
      $ touch .profile
  • edit it
    $ nano .profile
export JAVA_HOME=`/usr/libexec/java_home`

export PATH="$JAVA_HOME/bin:$PATH"

note:
/usr/libexec/java_home is that magic think that will find out the installation path of java
you can try for yourself: $ /usr/libexec/java_home
also each time you update java it will automatically find the new one

Apply the changes
$ source .profile

Test Java
$ java -version

You should obtain something like

java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

your .profile should look like the following (without comments)

export EDITOR=nano
export CLICOLOR=1
export TERM=xterm-color
export LSCOLORS=DxFxcxdxBxegedbxHxHcHd
export LS_COLORS="di=01;33;40:ln=01;95;40:so=32;40:pi=33;40:ex=01;91;40:bd=34;46:cd=34;43:su=31;40:sg=01;97;40:tw=01;97;42:ow=01;97;43:"

export PORT_HOME=/opt/local
export JAVA_HOME=`/usr/libexec/java_home`

export PATH=$PORT_HOME/bin:$PORT_HOME/sbin:$JAVA_HOME/bin:$PATH

alias ls="ls --color=auto"
alias tree="tree -C"

if [ -f /opt/local/etc/bash_completion ]; then
  . /opt/local/etc/bash_completion
fi
Ant

Let's find ant
$ port search apache-ant

output

apache-ant @1.9.6 (devel, java)
    Java opensource build system

install it
$ sudo port install apache-ant

now let's find where it is installed
$ which ant
output /opt/local/bin/ant
$ ls -la /opt/local/bin/ant
output /opt/local/bin/ant -> ../share/java/apache-ant/bin/ant
$ ls -1 /opt/local/share/java/apache-ant/
output

CONTRIBUTORS
bin
contributors.xml
etc
fetch.xml
get-m2.xml
lib
patch.xml

Now you need to edit your .profile
$ nano ~/.profile

add the following

export ANT_HOME=/opt/local/share/java/apache-ant/

Apply the changes
$ source ~/.profile

Check it
$ ant -version

and now you should obtain

Apache Ant(TM) version 1.9.6 compiled on June 29 2015

you can check your different HOME env vars like that
$ printenv | grep HOME
result

ANT_HOME=/opt/local/share/java/apache-ant/
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
HOME=/Users/zwetan
PORT_HOME=/opt/local
Flex SDK

We want to install all SDK in the /sdk folder
and we want all Flex SDK to be in the /sdk/flex folder

  • open the Terminal
  • go to the root
    $ cd /
  • create the directories path
    $ sudo mkdir -p /sdk/flex
  • make the directory and subdirectories accessible by anyone
    $ sudo chmod -R 777 sdk/

Download the Adobe Flex SDK
For example: Adobe Flex 4.6 SDK

  • go into our flex sdk folders
    $ cd /sdk/flex
  • download the Adobe Flex 4.6 SDK
    $ wget http://download.macromedia.com/pub/flex/sdk/flex_sdk_4.6.zip
  • unzip it into the folder "4_6"
    $ unzip flex_sdk_4.6.zip -d 4_6
  • do not delete "flex_sdk_4.6.zip"
    we can reuse it in the future
  • go into the "4_6" folder
    $ cd 4_6/
  • test it
    $ bin/mxmlc

If you obtain

Error: This Java instance does not support a 32-bit JVM.
Please install the desired version.

if you open the bin/mxmlc bash script, the problem is here

        if [ "$isOSX" != "" -a "$HOSTTYPE" = "x86_64" -a "$check64" != "" ]; then
                D32='-d32'
        fi

there are many way to fix it

  • comment out those 3 lines
  • replace the last line of the script
    removing $D32
  • modify the script to test the java version
  • downgrade the java version
  • upgrade the Flex SDK version

The simpler way in our opinion is just to comment out those 3 lines

        #if [ "$isOSX" != "" -a "$HOSTTYPE" = "x86_64" -a "$check64" != "" ]; then
        #        D32='-d32'
        #fi

but do it for all of mxmlc, asdoc and compc

Test again
$ bin/mxmlc

You should get

Loading configuration file /sdk/flex/4_6/frameworks/flex-config.xml
Adobe Flex Compiler (mxmlc)
Version 4.6.0 build 23201
Copyright (c) 2004-2011 Adobe Systems, Inc. All rights reserved.

Error: a target file must be specified

Use 'mxmlc -help' for information about using the command line.

Download the Apache Flex SDK
For example: Apache Flex SDK 4.14.1 (download from OVH)
List of mirrors: mirrors Apache Flex SDK 4.14.1

  • go into our flex sdk folders
    $ cd /sdk/flex
  • download the Apache Flex SDK 4.14.1
    $ wget http://apache.mirrors.ovh.net/ftp.apache.org/dist/flex/4.14.1/binaries/apache-flex-sdk-4.14.1-bin.tar.gz
  • untar it
    $ tar -xvjf apache-flex-sdk-4.14.1-bin.tar.gz
  • rename the folder to "4_14_1"
    $ mv apache-flex-sdk-4.14.1-bin 4_14_1
  • do not delete "apache-flex-sdk-4.14.1-bin.tar.gz"
    we can reuse it in the future
  • go into the "4_14_1" folder
    $ cd 4_14_1/
  • complete the installation with the Ant-based installer
    $ ant -f installer.xml -Dair.sdk.version=3.0 when asked questions answer "y" to all
  • install the playerglobal.swc
    $ mkdir -p frameworks/libs/player/11.1/
    $ wget http://download.macromedia.com/get/flashplayer/updaters/11/playerglobal11_1.swc -O frameworks/libs/player/11.1/playerglobal.swc
  • now create some environment properties
    $ touch env.properties
    $ nano env.properties
    add
    env.PLAYERGLOBAL_HOME=/sdk/flex/4_14_1/frameworks/libs/player
  • make the binary files executable
    $ chmod +x bin/*
  • test it
    $ bin/mxmlc

You should get

Loading configuration file /sdk/flex/4_14_1/frameworks/flex-config.xml
Apache Flex Compiler (mxmlc)
Version 4.14.1 build 20150325
Copyright 2015 The Apache Software Foundation.

Error: a target file must be specified

Use 'mxmlc -help' for information about using the command line.

GCC

Find your GCC version
$ gcc --version

You should obtain something like

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

That's not gcc, that's clang and this is a problem.

For the little history, the simpler way to obtain gcc and make was simply to install Xcode, but with time Apple started to phase out gcc for the profit of clang and this is quite problematic to us as we would have to rewrite some part of the Redtamarin source code that we don;t really want to rewrite just to fit Apple agenda.

To know more read MacPorts - Using the Right Compiler.

So you can see there are a lot of different versions of GCC, the one we want is apple-gcc-4.2 Apple GCC 4.2 MacPorts (apple-gcc42).

Let's install Apple GCC 4.2
$ sudo port install apple-gcc42

Now let's configure it to be our default GCC on the command line

$ sudo rm /usr/local/bin/gcc
$ sudo rm /usr/local/bin/g++
$ sudo ln -s /opt/local/bin/gcc-apple-4.2 /usr/local/bin/gcc
$ sudo ln -s /opt/local/bin/g++-apple-4.2 /usr/local/bin/g++

note: we don't use gcc_select on purpose

Let's open a new Terminal.app and test it
$ gcc --version

you should obtain

i686-apple-darwin14-gcc-apple-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) (MacPorts apple-gcc42 5666.3_15)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

With this setting you should be able to use Xcode 7 with its own compiler (clang) and use this gcc v4.2 on the command line to build Redtamarin.

Now we also need "Mac OS X SDK", you cna find them following this path
$ ls -la /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
as you can see with Xcode 7.1.1 we have only "MacOSX10.11.sdk"
and that is also a problem.

For example, if you compile from Mac OX 10.10 with the "MacOSX10.11.sdk"
it will work, but the binary generated could fail on anything earlier than Mac OS X 10.11,
not the case here but still as a good habit we should ALWAYS compile
with the minimum version of the Mac OS X SDK we want to support.

For now we want to support as a minimum: mac OS X 10.9 Maverick,
so the complied executable can run on OS X 10.9, 10.10 and 10.11.

So we need to install those 2 missing SDK, to do that we need
to download Xcode 6.4 (2.4 GB).

  • you don't need to install it
  • open Xcode_6.4.dmg
  • select Xcode.app
  • right click "Show package Contents"
  • then navigate to ../Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
  • copy both MacOSX10.9.sdk and MacOSX10.10.sdk
  • now open your current "Applications" folder
    eg. /Applications/
  • select Xcode.app
  • right click "Show package Contents"
  • then navigate to ../Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
  • paste both both MacOSX10.9.sdk and MacOSX10.10.sdk
    next to MacOSX10.11.sdk

With that we can now compile for either OS X 10.9, 10.10 or 10.11
by default we compile Redtamarin for OS X 10.9
(we use the compiler flag --mac-sdk=109).

Building Tools

Optional, but for case when we need a smaller exe
let's install a packer: UPX - the Ultimate Packer for eXecutables
$ sudo port install upx

Use file to check the exe
for example in /bin-release/macintosh/64/debugger/
$ file redshell_dd
result:
redshell_dd: Mach-O 64-bit executable x86_64

for example in /bin-release/macintosh/32/debugger/
$ file redshell_dd
result:
redshell_dd: Mach-O executable i386

Use otool to check for dynamic libraries
for example in /bin-release/linux/64/debugger/
$ otool -L redshell_dd
result:

redshell_dd:
	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 62.0.0)
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

note:
upx can change those results, as when you pack an exe
you create a stub which by nature is considered "statically linked"

SDK

TODO

Redtamarin

We want to work from a folder named "work"

  • open the Terminal
  • go to the root
    $ cd /
  • create the directory "work"
    $ sudo mkdir work
  • make the directory and subdirectories accessible by anyone
    $ sudo chmod -R 777 work/

Follow the directions in Compiling Redtamarin.

Misc.

Hardware

This is not related to the Hardware Setup based on the Gigabyte GB-BXBT-2807.

Because you can install Mac OS X only on Apple hardware then you need some apple hardware.

Any mac would do as long as you can install Mac OS X 10.10, be careful some older mac hardware can not install anything, see Which Macs can run OS X Yosemite?.

Apple’s list of Macs that will support Yosemite:

  • iMac (Mid-2007 or later)
  • MacBook (13-inch Aluminum, Late 2008), (13-inch, Early 2009 or later)
  • MacBook Pro (13-inch, Mid-2009 or later), (15-inch, Mid/Late 2007 or later), (17-inch, Late 2007 or later)
  • MacBook Air (Late 2008 or later)
  • Mac Mini (Early 2009 or later)
  • Mac Pro (Early 2008 or later)
  • Xserve (Early 2009)

Here we use a Mac Mini (Late 2012) with an Intel i7 (quad core) and 16GB of RAM, but lower options (2GB of RAM) or older macs should work too (not tested).

Clone this wiki locally