Difference between revisions of "CrossCompilingOsX"

From Inkscape Wiki
Jump to navigation Jump to search
(Created page with "This is being worked on, please maintain your patience. I have successfully done this before but I don't remember what I did, so I will have to recreate a lot of stuff.")
 
(build dyld)
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is being worked on, please maintain your patience. I have successfully done this before but I don't remember what I did, so I will have to recreate a lot of stuff.
This is being worked on, please maintain your patience. I have successfully done this before but I don't remember what I did, so I will have to recreate a lot of stuff.
You need:
* a mind so deadset on cross-compiling you won't stop to think
* the Xcode .dmg for your target OS X version
* root access to your build system
* a good processor and a lot of RAM
The following should be done on the ''host'' system first. Download the Xcode DMG, and use dmg2img to convert it to an IMG. Mount the IMG, and put the .pkg files into the chroot somewhere. I'm using /mnt/apple.
= Making the chroot =
I used Ubuntu 14.04 "Trusty Tahr" for doing the initial chroot. The process was as follows:
apt-get install dchroot debootstrap
Then edit /etc/schroot/schroot.conf with your favourite text editor, and add this at the end:
[trusty]
description=Ubuntu Trusty
location=/var/chroot
priority=3
users='''your_username'''
groups=sbuild
root-groups=root
Install a base system:
sudo debootstrap --variant=buildd --arch '''amd64''' trusty /var/chroot/ '''mirror.url.com/ubuntu/'''
where '''mirror.url.com/ubuntu/''' can be any of [https://launchpad.net/ubuntu/+archivemirrors these mirrors].
Now copy your resolv.conf for internet access (required):
sudo cp /etc/resolv.conf /var/chroot/etc/resolv.conf
Bind your procfs into the chroot for gnustep:
sudo mount -o bind /proc /var/chroot/proc
Finally, chroot into your target:
sudo chroot /var/chroot
You should now have a working chroot, free for you to destroy as you see fit.
(from https://help.ubuntu.com/community/BasicChroot)
To avoid pointless warnings about missing locales, do this:
apt-get install language-pack-en
Install some packages to start off with:
apt-get install sudo nano vim bzr subversion groff man-db
Edit your /etc/apt/sources.list to include the universe source and update:
deb mirror.url.com/ubuntu/ trusty main
deb-src mirror.url.com/ubuntu/ trusty main
deb mirror.url.com/ubuntu/ trusty universe
deb-src mirror.url.com/ubuntu/ trusty universe
Now install gnustep:
apt-get install gnustep gnustep-devel
This may take a while.
= Building clang =
'''NOTE:''' There is a [http://llvm.org/bugs/show_bug.cgi?id=19945 bug] with building cross-compilers for OS X.
cd /usr/src
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ..; mkdir build; cd build
../configure --prefix=/usr/clang_3_4 --enable-optimized --enable-targets='''x86_64,x86''' \
    --disable-compiler-version-checks --host=x86_64-unknown-linux-gnu --build=x86_64-unknown-linux-gnu \
    --target='''x86_64-apple-darwin11.4.2'''
make -j4
make install
== Getting Headers ==
To tease the headers out of the Xcode so that we can compile anything, we need to install the xar archiver, which is not packaged in Trusty.
wget https://xar.googlecode.com/files/xar-1.5.2.tar.gz
tar -xvf xar-1.5.2.tar.gz
apt-get install libxml2-dev libssl-dev libbz2-dev
cd xar-1.5.2; ./configure
make; make install
Now go to the location of your PKG files. Each one needs to be extracted, and then the payload needs to be extracted too.
cd /mnt/apple
mkdir DeveloperToolsCLI
cd DeveloperToolsCLI
xar -xvf ../DeveloperToolsCLI.pkg
Extract the payload (gzip doesn't really like unnamed files)
mv ./Payload ./Payload.gz
gunzip ./Payload.gz
The resulting file is a compressed CPIO archive. Extract that too:
mkdir Contents; cd Contents
cpio -idv < ../Payload
Okay, finally. Now we can figure out what's going where.
./System and ./Library are fine. We can just copy those over:
cp -R ./System /System
cp -R ./Library /Library
But ./usr is tricky — we might end up overwriting some sort of important file if we try just blatantly overwriting our /usr.
So, what do we do?
Scan the include paths for clang, and see what we can get away with, of course.
Next step: APSL headers for OSX, from Xcode, and then add libc++ compile instructions
= Installing dyld =
dyld is the Mach-O loader for OS X, and will allow you to run many command line tools for OS X. We need to install the GNUStep sources as well as the binaries here, be careful!
apt-get install git cmake clang nasm libxml2-dev libgnutls-dev libicu-dev libcairo-dev libjpeg-dev libpng-dev \
libtiff-dev libbsd-dev libudev-dev liblcms-dev libkqueue-dev libssl-dev libbz2-dev uuid-dev libncurses-dev \
libxrandr-dev libavcodec-dev libavformat-dev autoconf automake autopoint
== Building gnustep-make ==
cd /usr/src
svn co http://svn.gna.org/svn/gnustep/tools/make/trunk/ gnustep-make
cd gnustep-make
CC=clang CXX=clang++ ./configure
make install
== Building gnustep-libobjc2 ==
svn co http://svn.gna.org/svn/gnustep/libs/libobjc2/trunk/ gnustep-libobjc2
cd gnustep-libobjc2
OBJCFLAGS=-fblocks CC=clang CXX=clang++ cmake .
rm GNUmakefile
make; make install
== Building gnustep-base ==
svn co http://svn.gna.org/svn/gnustep/libs/base/trunk/ gnustep-base
cd gnustep-base
OBJCFLAGS=-fblocks CC=clang CXX=clang++ ./configure
make; make install
== Building gnustep-gui ==
svn co http://svn.gna.org/svn/gnustep/libs/gui/trunk/ gnustep-gui
cd gnustep-gui
OBJCFLAGS=-fblocks CC=clang CXX=clang++ ./configure
make; make install
== Building libdispatch ==
git clone git://github.com/nickhutchinson/libdispatch.git libdispatch
cd libdispatch
./configure
make; make install
== Building gnustep-corebase ==
svn co http://svn.gna.org/svn/gnustep/libs/corebase/trunk/ gnustep-corebase
cd gnustep-corebase
'''NOTE: there seems to be a bug in the configure script.'''
To work around this bug, comment out these lines in configure.ac:
# AC_CHECK_LIB(dispatch, dispatch_get_main_queue_eventfd_np)
  # AS_IF([test "$ac_cv_lib_dispatch_dispatch_get_main_queue_eventfd_np" = "no"],
  # [AC_MSG_ERROR([Compatible libdispatch not found for GCD support! Use --disable-gcd to disable GCD support or install GCD.])])])
Then run:
autoconf configure.ac > configure
OBJCFLAGS=-fblocks CC=clang CXX=clang++ ./configure
make; make install
== Building darling ==
Finally!
git clone https://github.com/LubosD/darling.git
cd darling
CC=clang CXX=clang++ cmake .
There appears to be another bug here, in /usr/local/include/CoreFoundation/CFRunLoop.h:207.
To fix it, just deactivate the code block like this:
#if 0 && OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
DEFINE_BLOCK_TYPE_NO_ARGS(PerformBlockType, void);
CF_EXPORT void
CFRunLoopPerformBlock (CFRunLoopRef rl, CFTypeRef mode, PerformBlockType block);
#endif
Then continue:
make; make install
More coming...

Latest revision as of 20:49, 5 June 2014

This is being worked on, please maintain your patience. I have successfully done this before but I don't remember what I did, so I will have to recreate a lot of stuff.

You need:

  • a mind so deadset on cross-compiling you won't stop to think
  • the Xcode .dmg for your target OS X version
  • root access to your build system
  • a good processor and a lot of RAM

The following should be done on the host system first. Download the Xcode DMG, and use dmg2img to convert it to an IMG. Mount the IMG, and put the .pkg files into the chroot somewhere. I'm using /mnt/apple.


Making the chroot

I used Ubuntu 14.04 "Trusty Tahr" for doing the initial chroot. The process was as follows:

apt-get install dchroot debootstrap

Then edit /etc/schroot/schroot.conf with your favourite text editor, and add this at the end:

[trusty]
description=Ubuntu Trusty
location=/var/chroot
priority=3
users=your_username
groups=sbuild
root-groups=root

Install a base system:

sudo debootstrap --variant=buildd --arch amd64 trusty /var/chroot/ mirror.url.com/ubuntu/

where mirror.url.com/ubuntu/ can be any of these mirrors.

Now copy your resolv.conf for internet access (required):

sudo cp /etc/resolv.conf /var/chroot/etc/resolv.conf

Bind your procfs into the chroot for gnustep:

sudo mount -o bind /proc /var/chroot/proc

Finally, chroot into your target:

sudo chroot /var/chroot

You should now have a working chroot, free for you to destroy as you see fit. (from https://help.ubuntu.com/community/BasicChroot)

To avoid pointless warnings about missing locales, do this:

apt-get install language-pack-en

Install some packages to start off with:

apt-get install sudo nano vim bzr subversion groff man-db

Edit your /etc/apt/sources.list to include the universe source and update:

deb mirror.url.com/ubuntu/ trusty main
deb-src mirror.url.com/ubuntu/ trusty main

deb mirror.url.com/ubuntu/ trusty universe
deb-src mirror.url.com/ubuntu/ trusty universe

Now install gnustep:

apt-get install gnustep gnustep-devel

This may take a while.


Building clang

NOTE: There is a bug with building cross-compilers for OS X.

cd /usr/src
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ..; mkdir build; cd build
../configure --prefix=/usr/clang_3_4 --enable-optimized --enable-targets=x86_64,x86 \
   --disable-compiler-version-checks --host=x86_64-unknown-linux-gnu --build=x86_64-unknown-linux-gnu \
   --target=x86_64-apple-darwin11.4.2
make -j4
make install

Getting Headers

To tease the headers out of the Xcode so that we can compile anything, we need to install the xar archiver, which is not packaged in Trusty.

wget https://xar.googlecode.com/files/xar-1.5.2.tar.gz
tar -xvf xar-1.5.2.tar.gz
apt-get install libxml2-dev libssl-dev libbz2-dev
cd xar-1.5.2; ./configure
make; make install

Now go to the location of your PKG files. Each one needs to be extracted, and then the payload needs to be extracted too.

cd /mnt/apple
mkdir DeveloperToolsCLI
cd DeveloperToolsCLI
xar -xvf ../DeveloperToolsCLI.pkg

Extract the payload (gzip doesn't really like unnamed files)

mv ./Payload ./Payload.gz
gunzip ./Payload.gz

The resulting file is a compressed CPIO archive. Extract that too:

mkdir Contents; cd Contents
cpio -idv < ../Payload

Okay, finally. Now we can figure out what's going where.

./System and ./Library are fine. We can just copy those over:

cp -R ./System /System
cp -R ./Library /Library

But ./usr is tricky — we might end up overwriting some sort of important file if we try just blatantly overwriting our /usr. So, what do we do? Scan the include paths for clang, and see what we can get away with, of course.


Next step: APSL headers for OSX, from Xcode, and then add libc++ compile instructions


Installing dyld

dyld is the Mach-O loader for OS X, and will allow you to run many command line tools for OS X. We need to install the GNUStep sources as well as the binaries here, be careful!

apt-get install git cmake clang nasm libxml2-dev libgnutls-dev libicu-dev libcairo-dev libjpeg-dev libpng-dev \
libtiff-dev libbsd-dev libudev-dev liblcms-dev libkqueue-dev libssl-dev libbz2-dev uuid-dev libncurses-dev \
libxrandr-dev libavcodec-dev libavformat-dev autoconf automake autopoint

Building gnustep-make

cd /usr/src
svn co http://svn.gna.org/svn/gnustep/tools/make/trunk/ gnustep-make
cd gnustep-make
CC=clang CXX=clang++ ./configure
make install

Building gnustep-libobjc2

svn co http://svn.gna.org/svn/gnustep/libs/libobjc2/trunk/ gnustep-libobjc2
cd gnustep-libobjc2
OBJCFLAGS=-fblocks CC=clang CXX=clang++ cmake .
rm GNUmakefile
make; make install

Building gnustep-base

svn co http://svn.gna.org/svn/gnustep/libs/base/trunk/ gnustep-base
cd gnustep-base
OBJCFLAGS=-fblocks CC=clang CXX=clang++ ./configure
make; make install

Building gnustep-gui

svn co http://svn.gna.org/svn/gnustep/libs/gui/trunk/ gnustep-gui
cd gnustep-gui
OBJCFLAGS=-fblocks CC=clang CXX=clang++ ./configure
make; make install

Building libdispatch

git clone git://github.com/nickhutchinson/libdispatch.git libdispatch
cd libdispatch
./configure
make; make install

Building gnustep-corebase

svn co http://svn.gna.org/svn/gnustep/libs/corebase/trunk/ gnustep-corebase
cd gnustep-corebase

NOTE: there seems to be a bug in the configure script. To work around this bug, comment out these lines in configure.ac:

# AC_CHECK_LIB(dispatch, dispatch_get_main_queue_eventfd_np)
 # AS_IF([test "$ac_cv_lib_dispatch_dispatch_get_main_queue_eventfd_np" = "no"],
  # [AC_MSG_ERROR([Compatible libdispatch not found for GCD support! Use --disable-gcd to disable GCD support or install GCD.])])])

Then run:

autoconf configure.ac > configure
OBJCFLAGS=-fblocks CC=clang CXX=clang++ ./configure
make; make install

Building darling

Finally!

git clone https://github.com/LubosD/darling.git
cd darling
CC=clang CXX=clang++ cmake .

There appears to be another bug here, in /usr/local/include/CoreFoundation/CFRunLoop.h:207. To fix it, just deactivate the code block like this:

#if 0 && OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
DEFINE_BLOCK_TYPE_NO_ARGS(PerformBlockType, void);
CF_EXPORT void
CFRunLoopPerformBlock (CFRunLoopRef rl, CFTypeRef mode, PerformBlockType block);
#endif

Then continue:

make; make install

More coming...