• This repository has been archived on 28/Nov/2019
  • Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    C
  • Created about 13 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A cross compiler toolchain targeting macOS/iOS/etc.

Based on original documentation by OpenTTD team.

With these files you may build odcctools and GCC 4.2.1 targetting Darwin/macOS.

This has been tested in the following environments:

  • x86_64-pc-linux-gnu with GCC 4.5.3

The following targets have been tested:

  • i686-apple-darwin11
  • x86_64-apple-darwin11
  • arm-apple-darwin (requires iOS SDK)

These might work:

  • ppc-apple-darwin11
  • ppc64-apple-darwin11

Decide your target, and export:

export TARGET=i686-apple-darwin11

11 denotes Lion, 10 for Snow Leopard, and 9 for Leopard. These are mostly superficial. All code will run on 10.5 and greater.

Decide your prefix directory and set it to a variable.

export PREFIX=/usr/$TARGET
mkdir $PREFIX
cd $PREFIX

In ~/.bashrc or similar you may want:

export DARWIN_PREFIX=<prefix you chose>

Prepare your prefix

If you don't have a Mac, skip this and read Prepare your prefix (no Mac). Even if you have a Mac, the no-Mac method is cleaner than using scp but not as easy.

You will need a copy of an SDK directory to begin. You can choose any version past 10.4u really but I suppose only if you need new things in Lion would copy Lion's SDK (and that requires Lion itself of course). I expect that you are doing most development on the Mac anyway so therefore your compiler settings in Xcode will decide support level.

mkdir $PREFIX/SDKs
cd $PREFIX/SDKs

If you have Snow Leopard:

export SDK=MacOSX10.6.sdk
scp -r myname@mymac:/Developer/SDKs/$SDK .

If you have Lion (and want latest headers):

export SDK=MacOSX10.7.sdk
scp -r myname@mymac:/Developer/SDKs/$SDK .

Prepare your prefix (no Mac)

If you are copying from Mac with scp, skip to 'Continue with scp'.

Download the DMG from Apple for Xcode, any version. You need to have the following:

Use mount and umount as root or with sudo (probably easier with sudo). Example here is with Xcode 4.2. Replace /mnt/tmp with your own mount point.

cd where-my-xcode-dmg-lives
java -jar path/to/dmgextractor.jar xcode_4.2_and_ios_5_sdk_for_snow_leopard.dmg my.iso (click OK on any prompts)
# if on Gentoo, you can use `dmgextractor xcode_4.2_and_ios_5_sdk_for_snow_leopard.dmg` my.iso
7z x my.iso
mount -t hfsplus disk\ image.hfs /mnt/tmp
xar -f /mnt/tmp/Packages/MacOSX10.6.pkg Payload
cpio -i < Payload
umount /mnt/tmp

You will now have an SDKs directory, but it needs fixing.

cd SDKs/MacOSX10.6.sdk
rm Library/Frameworks
ln -s System/Library/Frameworks Library
mv Developer/usr/llvm-gcc-4.2 usr
rm -r Developer/usr
ln -s usr Developer

Copy the prefix:

cd ../..
cp -r SDKs $PREFIX

cd $PREFIX

Note that we are going to put stuff in this .sdk directory. Anything we build from here will be placed inside. So we are going to create symlinks to its directories in $PREFIX.

ln -s SDKs/$SDK/Developer
ln -s SDKs/$SDK/Library
ln -s SDKs/$SDK/System
ln -s SDKs/$SDK/usr

If you used the no-Mac method, skip to Building cctools'.

Continue with scp

Delete any of YOUR frameworks (these are all from 3rd parties, not Apple). None of these are necessary.

rm -R Library/Frameworks

Create a symlink to the Apple Frameworks directory.

cd Library
ln -s ../System/Library/Frameworks
cd ..

Later on, you can copy the 3rd party frameworks from your Mac to $PREFIX/Library/Frameworks:

scp -r /Developer/SDKs/MacOSX10.6.sdk/Library/Frameworks/* $PREFIX/Library/Frameworks

usr is of great importantance to us in the next steps. It's where cctools and GCC will go. So yes, this usr directory (and possibly Library) will eventually be 'dirty' and non-equivalent to the one in macOS (and in the next steps we will overwrite files in the directory).

Never copy the SDK directory back to macOS for any reason.

Building cctools

You really should only apply the patch if you are not on macOS/Darwin, because I have not tested any of this on OS X/Darwin yet.

wget http://opensource.apple.com/tarballs/cctools/cctools-806.tar.gz
tar xvf cctools-806.tar.gz
patch -p0 < patches/cctools-806-nondarwin.patch
cd cctools-806
chmod +x configure
CFLAGS="-m32" LDFLAGS="-m32" ./configure --prefix=$PREFIX/usr --target=$TARGET --with-sysroot=$PREFIX
make
make install
cd ..

Note -m32. Everything will be 32-bit. Building for 64-bit is not supported (but using 32-bit to build 64-bit binaries is). Do not try optimisation flags. ranlib is especially sensitive.

Ignore ALL warnings. There will be many (or you can use -w for a CFLAG).

Building ld64

To build GCC we cannot use what's known as 'classic' ld. We have to use ld64 (even though we are not going to build it in 64-bit mode). For the moment, use odcctools-9.2 from the iphone-dev project (the version in this repository is patched for GCC 4.5):

cd odcctools-9.2-ld
CFLAGS="-m32" LDFLAGS="-m32" ./configure \
    --prefix=$PREFIX/usr \
    --target=$TARGET \
    --with-sysroot=$PREFIX \
    --enable-ld64
make
cd ld64
make install
cd ../..

Do not try optimisation flags here either.

Set $PATH to have your new tools. You may want to add this to your ~/.bashrc or similar.

export PATH="$PATH:/usr/$TARGET/usr/bin"

Building GCC

Now you can proceed to build GCC, but it must be patched first. Patches are located in patches.

wget http://opensource.apple.com/tarballs/gcc/gcc-5666.3.tar.gz
tar xvf gcc-5666.3.tar.gz
cd gcc-5666.3
patch -p1 < ../patches/gcc-5666.3-cflags.patch

Apply if you are annoyed by the default directory structure:

patch -p1 < ../patches/gcc-5666.3-tooldir.patch

After patching, I recommend building outside of the source of GCC.

cd ..
mkdir gcc-build
cd gcc-build

CFLAGS="-m32" CXXFLAGS="$CFLAGS" LDFLAGS="-m32" \
    ../gcc-5666.3/configure --prefix=$PREFIX/usr \
    --disable-checking \
    --enable-languages=c,objc,c++,obj-c++ \
    --with-as=$PREFIX/usr/bin/$TARGET-as \
    --with-ld=$PREFIX/usr/bin/$TARGET-ld64 \
    --target=$TARGET \
    --with-sysroot=$PREFIX \
    --enable-static \
    --enable-shared \
    --enable-nls \
    --disable-multilib \
    --disable-werror \
    --enable-libgomp \
    --with-gxx-include-dir=$PREFIX/usr/include/c++/4.2.1 \
    --with-ranlib=$PREFIX/usr/bin/$TARGET-ranlib \
    --with-lipo=$PREFIX/usr/bin/$TARGET-lipo

Optimisations do work here (most of the time). You can try to configure with:

CFLAGS="-m32 -O2 -msse2"

No, there is no Java (GCJ) or Fortran.

Make and install like normal.

make
make install

Sometimes you may get an issue about ranlib not working or lipo, which is why --with-ranlib and --with-lipo are appended to ./configure. However, you may have to run make again or not use a -j flag. I would recommend not using the -j flag anyway just to ease debugging of any issues. Seriously, try doing make over and over until it does work.

If ranlib has a buffer overflow during build, it is probably because you enabled optimisation flags.

Hack to fix include path

export LAST=$PWD
cd $PREFIX/usr/local
ln -s ../lib/gcc/$TARGET/4.2.1/include
cd $LAST

Test GCC

From the cloned source:

$TARGET-gcc -o msg msg.m \
    -fconstant-string-class=NSConstantString \
    -lobjc -framework Foundation

Test C++:

$TARGET-g++ -o msgcpp msg.cpp -I$PREFIX/usr/include/c++/4.2.1

I know, that's a weird -I flag. For now, just use an alias for $TARGET-g++ with it. You can safely alias $TARGET-gcc as well with -fconstant-string-class=NSConstantString even if you are compiling C.

file msg

Output:

msg: Mach-O executable i386

Copying to Mac and executing with ssh:

scp msg myname@mymac:
ssh myname@mymac ./msg
scp msgcpp myname@mymac:
ssh myname@mymac ./msgcpp

Output:

2011-09-03 03:51:52.887 msg[31266:1007] Are you John smith?
2011-09-03 03:51:52.889 msg[31266:1007] My message
This was compiled on a non-Mac!

Optional: Building LLVM-GCC

Because LLVM is the future right?

First, force the use of ld64 everywhere (yes you can keep this as permanent):

export LAST=$PWD
cd $PREFIX/usr/bin
mv $TARGET-ld $TARGET-ld.classic
ln -s $TARGET-ld64 $TARGET-ld
cd $LAST

You need to build Apple's LLVM first.

wget http://opensource.apple.com/tarballs/llvmgcc42/llvmgcc42-2335.15.tar.gz
tar xvf llvmgcc42-2335.15.tar.gz
mkdir llvm-obj
cd llvm-obj
CFLAGS="-m32" CXXFLAGS="$CFLAGS" LDFLAGS="-m32" \
    ../llvmgcc42-2335.15/llvmCore/configure \
    --prefix=$PREFIX/usr \
    --enable-optimized \
    --disable-assertions \
    --target=$TARGET
make
make install # optional
cd ..

This is somewhat intensive (lots of C++) so if you don't have a powerful PC do not use -j flag with make.

Next, proceed to build GCC itself, but you need to patch one thing (at least needed GCC 4.5):

cd llvmgcc42-2335.15
patch -p0 < ../patches/llvmgcc42-2335.15-redundant.patch
patch -p0 < ../patches/llvmgcc42-2335.15-mempcpy.patch
cd ..

Build outside the directory.

mkdir llvmgcc-build
cd llvmgcc-build
CFLAGS="-m32" CXXFLAGS="$CFLAGS" LDFLAGS="-m32" \
    ../llvmgcc42-2335.15/configure \
    --target=$TARGET \
    --with-sysroot=$PREFIX \
    --prefix=$PREFIX/usr \
    --enable-languages=objc,c++,obj-c++ \
    --disable-bootstrap \
    --enable--checking \
    --enable-llvm=$PWD/../llvm-obj \
    --enable-shared \
    --enable-static \
    --enable-libgomp \
    --disable-werror \
    --disable-multilib \
    --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ \
    --with-gxx-include-dir=$PREFIX/usr/include/c++/4.2.1 \
    --program-prefix=$TARGET-llvm- \
    --with-slibdir=$PREFIX/usr/lib \
    --with-ld=$PREFIX/usr/bin/$TARGET-ld64 \
    --with-tune=generic \
    --with-as=$PREFIX/usr/bin/$TARGET-as \
    --with-ranlib=$PREFIX/usr/bin/$TARGET-ranlib \
    --with-lipo=$PREFIX/usr/bin/$TARGET-lipo
make
make install

Test:

export LAST=$PWD
cd $PREFIX/usr/bin
ln -s $TARGET-as as
cd $LAST
cd ..
PATH="$PREFIX/usr/bin" $TARGET-llvm-gcc -o msg msg.m \
    -fconstant-string-class=NSConstantString \
    -lobjc -framework Foundation
PATH="$PREFIX/usr/bin" $TARGET-llvm-g++ -o msgcpp msg.cpp \
    -I$PREFIX/usr/include/c++/4.2.1

I know, yet again C++ paths fail to work.

Ignore all warnings.

Distcc

Distcc for Gentoo (not for Objective-C or C++ yet due to default argument issues): Follow these instructions:

What works for me

  • CFLAGS="-O2 -msse2 -pipe -m32" for building llvm-GCC and regular GCC
  • make -j3 works for everything for me

iPhone

This is with a default install of Xcode 4.1.1 from the Mac App Store. You can also try the non-Mac method to get the equivalent file.

Follow the above instructions but rather than 10.7 or 10.6 SDK, copy the iOS 4.3 SDK:

scp -r myname@mymac:/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk .
export TARGET="arm-apple-darwin"
export PREFIX="/usr/$TARGET"

Build cctools and ld64. Do not build GCC. Instead build LLVM as described above.

cctools for Gentoo the easy way (as root, example amd64 architecture):

export OVERLAY="/usr/tatsh-overlay" # or where you want it
git clone git://github.com/tatsh/tatsh-overlay.git $OVERLAY
echo "$PORTDIR_OVERLAY=\"\$PORTDIR_OVERLAY $OVERLAY\"" >> /etc/make.conf
eix-update # optional, only if you have eix installed
echo 'cross-arm-apple-darwin/cctools ~amd64' >> /etc/portage/package.keywords
emerge cross-arm-apple-darwin/cctools

The difference comes in building LLVM GCC. Use LLVM-GCC from Apple's site, apply the patches as described, but build with the following arguments to ./configure (note lack of -m32):

../llvmgcc42-2335.15/configure \
    --target=$TARGET \
    --with-sysroot=$PREFIX \
    --prefix=$PREFIX/usr \
    --enable-languages=objc,c++,obj-c++ \
    --disable-bootstrap \
    --enable--checking \
    --enable-llvm=$PWD/../llvm-obj \
    --enable-shared \
    --enable-static \
    --enable-libgomp \
    --disable-werror \
    --disable-multilib \
    --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ \
    --with-gxx-include-dir=$PREFIX/usr/include/c++/4.2.1 \
    --program-prefix=$TARGET-llvm- \
    --with-slibdir=$PREFIX/usr/lib \
    --with-ld=$PREFIX/usr/bin/$TARGET-ld64 \
    --with-as=$PREFIX/usr/bin/$TARGET-as \
    --with-ranlib=$PREFIX/usr/bin/$TARGET-ranlib \
    --with-lipo=$PREFIX/usr/bin/$TARGET-lipo \
    --enable-sjlj-exceptions
make
make install

This will fix g++:

cd $PREFIX/usr/lib
ln -s libgcc_s.1.dylib libgcc_s.10.4.dylib

This will make it a little more sane:

cd $PREFIX/usr/bin
ln -s arm-apple-darwin-gcc-4.2.1 arm-apple-darwin-gcc
ln -s arm-apple-darwin-g++-4.2.1 arm-apple-darwin-g++

You will have a working compiler targetting iOS. You need a jailbroken phone before any code will run.

Try:

ssh root@My_iPhone uname -a
arm-apple-darwin-g++ -o msg.arm msg.cpp \
    -I$PREFIX/usr/include/c++/4.2.1 \
    -I$PREFIX/usr/include/c++/4.2.1/armv6-apple-darwin10
scp msg.arm root@My_iPhone:
ssh root@My_iPhone ./msg.arm

Output:

Darwin My_iPhone 11.0.0 Darwin Kernel Version 11.0.0: Wed Mar 30 18:51:10 PDT 2011; root:xnu-1735.46~10/RELEASE_ARM_S5L8930X iPhone3,1 arm N90AP Darwin
This was compiled on a non-Mac!

Note that you need both of those include path arguments. Yes, it's an ongoing issue.

Also note that the minimum version to run any code is iOS 3.0 by default. To get 2.0 support for example, use -miphoneos-version-min=2.0 in your line:

arm-apple-darwin-g++ -o msg.o -c msg.cpp \
    -I$PREFIX/usr/include/c++/4.2.1 \
    -I$PREFIX/usr/include/c++/4.2.1/armv6-apple-darwin10 \
    -miphoneos-version-min=2.0

Also note that these are not univeral binaries, even if you use -force_cpusubtype_ALL. These are armv6.

Generate fat binary

Compile both architectures:

export TARGET=x86_64-apple-darwin11
$TARGET-g++ -o msg.x86_64 -I$PREFIX/usr/include/c++/4.2.1
export TARGET=arm-apple-darwin
$TARGET-g++ -o msg.arm \
    -I$PREFIX/usr/include/c++/4.2.1 \
    -I$PREFIX/usr/include/c++/4.2.1/armv6-apple-darwin10

Now use lipo from any of the architectures you have built:

$TARGET-lipo x86_64-apple-darwin11-lipo -create -arch arm msg.arm -arch x86_64 msg.x86_64 -output msg

Testing on iPhone:

scp msg root@My_iPhone:
ssh root@My_iPhone ./msg

Output:

This was compiled on a non-Mac!

Get info from a mac:

scp msg myname@mymac
ssh myname@mymac lipo -detailed_info msg

Output:

Fat header in: msg
fat_magic 0xcafebabe
nfat_arch 2
architecture arm
    cputype CPU_TYPE_ARM
    cpusubtype CPU_SUBTYPE_ARM_ALL
    offset 4096
    size 13052
    align 2^12 (4096)
architecture x86_64
    cputype CPU_TYPE_X86_64
    cpusubtype CPU_SUBTYPE_X86_64_ALL
    offset 20480
    size 9288
    align 2^12 (4096)

To-do list

  • Fix paths when invoked (sysroot issue, maybe --with-gxx-include-dir will fix):
    • Double search paths for C++: $PREFIX/x86_64-apple-darwin11:$PREFIX/x86_64-apple-darwin11/$PREFIX/x86_64-apple-darwin11/include/c++/4.2.1/x86_64-apple-darwin11
  • ld warnings about arch maybe
  • distcc for Objective-C and C++
  • distcc with MacPorts
  • Get latest cctools to build on Linux (DONE except for cbtlibs, efitools, gprof; these are probably unnecessary)
  • Clang
  • HOWTO generate .app directory, plist, Resources, etc (nib files and CoreData impossible without Mac?)

More Repositories

1

youtube-unofficial

Access parts of your account unavailable through normal YouTube API access.
Python
40
star
2

tatsh-overlay

Personal Gentoo Portage overlay.
Shell
29
star
3

jxa-lib

Library to simplify use of JXA with ES6 and TypeScript.
TypeScript
23
star
4

dbeaver-creds

Decrypt DBeaverData/credentials-config.json
Shell
14
star
5

kate-wakatime

Kate plugin to interface with WakaTime
C++
12
star
6

ffmpeg-progress

Get progress information from ffmpeg.
Python
10
star
7

open-in-mpv

Extension to open any link or page in mpv via the context menu.
Python
10
star
8

bincookie

A header-only library to parse Apple's binarycookies format.
C
9
star
9

imessage-remote

A simple script for remote control of Messages.app using AppleScript.
8
star
10

misc-scripts

Scripts that are randomly made by me. Caution: these come and go.
Python
7
star
11

tapmania

Working fork of TapMania for iOS 9.3 and above.
Objective-C++
6
star
12

libipa

Small library to read metadata from iOS application archives (IPA files).
Python
6
star
13

macprefs

Backup and convert your macOS preferences to an executable shell script.
Python
5
star
14

gwmt-dl

Download search queries and top pages from Google Webmaster Tools.
Python
5
star
15

sHistory

Back/forward/hashchange library with no external dependencies. ~2 KiB when compressed with gzip.
JavaScript
4
star
16

php-peg-markdown

peg-markdown as a PHP extension
C
4
star
17

re3-installer

Install GTA III files from ISO or directories for use with re3.
C
4
star
18

sutra

Set of libraries based on ideas from Flourish unframework.
PHP
4
star
19

sendspace-cli

Upload to Sendspace with your credentials from the command line.
Python
3
star
20

clem2itunes

Crazy way to synchronise a remote (Linux-based) Clementine top-rated library with iTunes using Python, JXA and SSH.
Python
3
star
21

StepMania-Utilities

Basic utilities to manage simfiles.
C
3
star
22

mkisofs-md5

Automatically exported from code.google.com/p/mkisofs-md5
C
2
star
23

qsettings2json

Convert QSettings-generated files to JSON. Compatible with quasselcore.conf and many others.
C++
2
star
24

patreon-archiver

Python
2
star
25

xirvik-tools

Python
2
star
26

tnfoview

NFO viewer using the Qt toolkit.
C++
2
star
27

camera-always-hdr

Makes the Camera application always enable HDR on load.
Logos
2
star
28

youtube-no-trending

Removes Trending tab from iOS YouTube app
Logos
2
star
29

flac-tools

A set of commands and various library functions to manage FLAC files.
Python
2
star
30

bpmdetect

BPMDetect updated for Qt 5
C++
2
star
31

jailbreakstatus

Simple check for jailbreak for latest version of iOS.
Python
2
star
32

pngdefry

A fork of Jongware's pngdefry (for converting iOS PNGs to normal ones)
C
2
star
33

tccx

Objective-C
1
star
34

minchoc

Minimal Chocolatey-compatible NuGet server in a Django app
Python
1
star
35

gentoo-livecheck

Check if a package has been updated upstream.
Python
1
star
36

ratelimit-types

Type stub package for ratelimit.
Python
1
star
37

hello-world-efi

Hello World for EFI.
C
1
star
38

constantine

Missing PHP constants.
PHP
1
star
39

no-radio-tab

Removes Radio tab from Music app on iPad. Also makes Songs the default tab.
Logos
1
star
40

scenechange

Because the original author is not putting this here
C
1
star
41

facetime-clear-badge

Utility to clear the FaceTime.app badge.
TypeScript
1
star
42

jpnkanji

Japanese/English web dictionary application
PHP
1
star
43

chrome-utils

1
star
44

nodejs-overlay

Portage overlay for node (mostly npm stuff)
1
star
45

corkami

Automatically exported from code.google.com/p/corkami
Assembly
1
star
46

ansible-portage-chrome

Installs Chromium or Google Chrome.
1
star
47

vscode-pkgcheck

Run pkgcheck from within VSCode.
TypeScript
1
star
48

tgr-decomp

C
1
star
49

debut

Debut is an MP3 tagger using the Qt toolkit.
Python
1
star
50

recaptcha5

A PHP 5 version of the reCAPTCHA PHP library.
PHP
1
star
51

cross-pc-mingw32-openssl

OpenSSL patches for building in a Mingw32 environment.
Shell
1
star
52

cssq

Filter HTML with a CSS query
Python
1
star
53

battery-percent-when-charging

Displays the battery percent status bar item only when the device is charging.
Logos
1
star
54

snel

An unofficial client to Google Lens.
Python
1
star
55

closure-compiler-externs

Unofficial externs for Closure Compiler.
JavaScript
1
star
56

mpris-tweeter

Listens to programs exposing mpris D-Bus interface (Amarok, Clementine, etc) and tweets #nowplaying messages on Twitter
Python
1
star
57

upkeep

Commands to make keeping a Gentoo system updated an easier task.
Python
1
star
58

citfix

For Citrix Receiver.
Logos
1
star
59

cssmin

CssMin mirror
PHP
1
star
60

flourish-js

Flourish library, ported to JavaScript for web browsers.
JavaScript
1
star
61

coding-standards

My coding standards across several languages and platforms.
1
star
62

fakesignal

Always show 5 bar signal, even when the device is deactivated off the cellular network. Do not install if you care about actually knowing your reception.
Logos
1
star
63

tynder

Old code for Tinder prior to 1.4 to auto-like everyone
Objective-C
1
star
64

dvdxchap

dvdxchap from ogmtools.
C
1
star
65

dev-scripts

1
star
66

ecomposer

Generates ebuilds for Composer packages
PHP
1
star
67

gcrud

Clean up extraneous files from your Gentoo machine.
C
1
star