may, 2006

19
Copyright 2006 Aplix Corporation. All rights reserved. 1 May, 2006 Tokyo Jamboree #8 Cross-Development on Mac André Krützfeldt

Upload: dee

Post on 26-Jan-2016

40 views

Category:

Documents


2 download

DESCRIPTION

Cross-Development on Mac. May, 2006. Andr é Krützfeldt. Tokyo Jamboree #8. Macintosh and Xcode. OS X does come with Xcode bundled Newest version at: http://developer.apple.com/tools/xcode/index.html Includes all gnu compilers (4.0.1) and utilities Download is about 900MB - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 1

May, 2006

Tokyo Jamboree #8

Cross-Development on Mac

André Krützfeldt

Page 2: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 2

Macintosh and XcodeMacintosh and Xcode

OS X does come with Xcode bundled• Newest version at:• http://developer.apple.com/tools/xcode/index.html

• Includes all gnu compilers (4.0.1) and utilities

• Download is about 900MB• Good for Apple development

– you will need it

• For embedded systems, not applicable

Page 3: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 3

Complete your Mac toolsComplete your Mac tools

Make your development complete!• Use fink• http://fink.sourceforge.net/• It installs everything under /sw• After install use FinkCommander

QuickTime™ and aTIFF (LZW) decompressor

are needed to see this picture.

Page 4: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 4

Complete your Mac tools (2)Complete your Mac tools (2)

• Add the fink distribution to your path– Easy:

• more “test -r /sw/bin/init.sh && . /sw/bin/init.sh” >> .profile

• Close your terminal window and open it again.

• Now the path should look like:• $ echo $PATH

– /sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/local/bin: /usr/sbin:/usr/local/teTeX/bin/powerpc-apple-darwin-current:/usr/X11R6/bin

Page 5: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 5

Compile the CompilerCompile the Compiler

Next step is to select a Cross CompilerBest: Crosstoolhttp://www.kegel.com/crosstool/Current version 0.42Supports: gcc-2.95, gcc-3.2.x - gcc-4.0.xCheck the current build results:http://www.kegel.com/crosstool/crosstool-0.42/buildlogs/

If you intend to compile for Motorola devices, use:Crosstool for EZXhttp://lsb.blogdns.net/ezx-crosstoolCurrent version 0.5

Page 6: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 6

Compiler the Compiler (2)Compiler the Compiler (2)

Extract the downloaded files with:• gzip if the file ends with .gz• bzip2 if the file ends with .bz2(Both in fink)

Make sure you have ‘wget’ installed– the build process uses it– Check with: $ type wgetwget is /sw/bin/wget

You MUST be online to do the build!– It will get the sources to compile from websites

Page 7: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 7

Compiler source downloadCompiler source download

The scripts use wget to download the libraries and linux components defined in:

gcc-<version>-glib-<version>.dat

If you have a proxy setup, make sure that wget can work with it.

If you cannot get wget to work, just run the demo-XYZ.sh

It will try to access the sites, use <ctrl>-c to stop it and use a normal browser to download the needed files.

Place then into the download directory, usually$HOME/download

Start demo-XYZ.sh again

Page 8: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 8

Setup the target directorySetup the target directory

At the end you will have to install your cross compiler.

Best to setup the directory and rights now.

• sudo mkdir /opt/crosstool• sudo chown $USER /opt/crosstool

The following script will build the Motorola cross compiler and install the result into the same directory!

Page 9: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 9

How to compile the compilerHow to compile the compiler

build.sh from ezx-crosstool derived from demo-*.sh

#!/bin/shset -exCROSSTOOL_DIR=`pwd`TARBALLS_DIR=$CROSSTOOL_DIR/downloadsRESULT_TOP=$CROSSTOOL_DIR/gcc-arm-iwmmxtSRC_DIR=$CROSSTOOL_DIR/srcexport TARBALLS_DIR RESULT_TOP SRC_DIRGCC_LANGUAGES="c,c++"export GCC_LANGUAGES

# Really, you should do the mkdir before running this,# and chown /opt/crosstool to yourself so you don't need to run as root.mkdir -p $RESULT_TOP

# Build the toolchain. Takes a couple hours and a couple gigabytes.

eval `cat arm-ezx.dat gcc-3.3.6-glibc-2.3.2.dat` sh all.sh --notest

echo Done.

Page 10: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 10

What if there is an Error?What if there is an Error?

Mostly errors are not really errors.The Mac uses different versions of GNU Utilities.

Look at the error and see what produced it.

E.g. Error in an awk-script is not the script:– Use fink and install ‘gawk’– Run “./build.sh” again– Mostly the error is gone.

Unfortunately it does take hours and the “./build.sh” always starts from the beginning.

Page 11: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 11

Expected ErrorExpected Error

There is an expected error:• At the end it will complain about:

– PATH_MAX is undefined

• This is to be ignored.

ALSO (known):Apple make does have a bug/feature:• .m files are treated differently! (Objective-C)

• Get a make from gnu and compile it separately

• Copy it in /sw/bin do not copy it in /usr/bin!

Page 12: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 12

Distributed CompileDistributed Compile

Once you are done, you will have a cross compiler for your embedded device.

If you happen to have more than one Mac, you can distribute the cross compiler and compile in your network.

Tool to use is‘distcc’ which is part OS X Xcode.

(Very advanced, I have not tested it yet.)

Page 13: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 13

Cross-compile TrickCross-compile Trick

Some developers prefer to use a different shell for the cross compilation.

This assures that the builds do not interfere.

E.g. ‘tcsh’ uses‘.tcshrc’Set the PATH and other values to the target compiler.

And do not forget:./configure --host=arm-linuxThis tells configure that you are cross compiling

Page 14: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 14

Set the environmentSet the environment

The PATH must be set to the cross compiler:

PATH=/opt/crosstool/gcc-3.4.5-glibc-2.3.3/arm-linux/bin:…

Also set the environment variables:AR=arm-linux-arCC=arm-linux-gccCXX=arm-linux-g++LD=arm-linux-ldRANLIB=arm-linux-ranlibSTRIP=arm-linux-strip

Page 15: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 15

Tools for MacTools for Mac

iTerm as xterm substitute, it supports bookmarks:

http://iterm.sourceforge.net/

QuickTime™ and aTIFF (LZW) decompressor

are needed to see this picture.

Page 16: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 16

Tools for Mac (2)Tools for Mac (2)

Fugu to copy over sshhttp://rsug.itd.umich.edu/software/fugu/

QuickTime™ and aTIFF (LZW) decompressor

are needed to see this picture.

Page 17: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 17

Utilities for MacUtilities for Mac

Some devices use Ethernet over USB:Get the Mac driver at:http://www.dsitri.de/wiki.php?page=AJZaurusUSB

Originally for the Zaurus, but works with most USBLan or USBNet enabled devices.

If you want to enable a device this way, look at:

http://www.linux-usb.org/usbnet/

Page 18: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 18

DevicesDevices

A1200Rokr E2A780

Page 19: May,  2006

Copyright 2006 Aplix Corporation. All rights reserved. 19