Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-01

First version of FPC for iPhone SDK 2.x available

18 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jonas Maebe

Hello,

I'm happy to announce that the first version of FPC for the iPhone SDK 2.x is available. It includes an Xcode template to build the demo application that I mentioned in my message last week.

Note that unlike other FPC releases, this installer will install the FPC sources (of FPC 2.3.1, svn revision 12530 of today) and a script, and will then launch this script in order to compile FPC (after you tell it where you installed the iPhone SDK, so it can generate a Pascal version of some required C headers). This modus operandi is necessary to comply with the iPhone SDK agreement's stipulation that no derived works of the SDK may be distributed.

Requirements:
* Intel Mac (because the iPhone SDK requires an Intel Mac)
* iPhone SDK 2.x installed (only tested with 2.2 though)
* FPC 2.2.2 or a later FPC 2.2.x release installed

Some features:
* Simulator support (it turned out to be trivial to add)
* the Xcode template transparently supports (requires, actually) integrating Pascal and Objective-C source files into a single application
* Pascal translation of the OpenGL ES 1.1 C-header from the SDK (this one I can distribute, because it's licensed under an SGI open source license), available in the gles11 unit

Please read the entire ReadMe.rtf on the installer disk image before asking for help. It contains quite a bit of information on things to watch out for (especially when using the Simulator), and how to change the included template when adding extra Pascal source files.

The installer disk image is available here (17MB -- there are also advantages to only distributing the source):
ftp://ftp.freepascal.org/fpc/snapshot/v23/arm-macosx/fpc-2.3.1v1.arm-iphone.dmg

If you encounter problems with the script that is launched when the installer finishes the installation, please always provide the entire contents of the Terminal window in which the script was executed when asking for help.

Enjoy,

Jonas

Reply by email

dmitry boyarintsev
to Jonas Maebe

Jonas,

I've tried to use the disk image without checking my iPhone SDK version first. It has turned out that my SDK is out of date. So I'm downloading it right now.
Anyway, it would be nice, if there would be 're-launch script' button at the last step of installation, just in case if anything goes wrong. Or if script is available itself right after installation.

Also, then script asked me about location of iPhoneSDK it a bit confused me, but i guess default location is /Developer directory. It would be nice to add a hint about it on the script text.

Great job! Thanks
Dmitry

Reply by email

Jonas Maebe
to dmitry boyarintsev
dmitry boyarintsev wrote
I've tried to use the disk image without checking my iPhone SDK version first. It has turned out that my SDK is out of date. So I'm downloading it right now.

Which version did you have?

Anyway, it would be nice, if there would be 're-launch script' button at the last step of installation, just in case if anything goes wrong. Or if script is available itself right after installation.

The installer opens a Finder window with the script selected when it reaches the last screen. And both the first and final window of the installation display the full path to the script. I really don't know in how many more ways I should make it clear where the script is located.

Also, then script asked me about location of iPhoneSDK it a bit confused me, but i guess default location is /Developer directory. It would be nice to add a hint about it on the script text.

The problem is that the SDK can be installed anywhere. In my case, it's in /iphone2.1 (my regular Xcode is installed in /Developer). I have found no way to automatically detect where the iPhone SDK is installed. Suggesting that it's in /Developer may confuse as many people as it could help.

Jonas

Reply by email

dmitry boyarintsev
to Jonas Maebe
Which version did you have?

It's quite old:
iPhone SDK named Aspen 1.2, XCode version 3.1 (beta) with iPhone OS 2.0 support.
Platform SDK dir is named Aspen.platform (/Developer/Platforms/Aspen.platform).

The installer opens a Finder window with the script selected when it reaches the last screen. And both the first and final window of the installation display the full path to the script. I really don't know in how many more ways I should make it clear where the script is located.

Sorry, did not noticed the name, to much excited about fpc library.

Reply by email

Jonas Maebe
to Jonas Maebe: I'm happy to announce that the first version of FPC for the iPhone SDK 2.x is available.…
Jonas Maebe wrote
I'm happy to announce that the first version of FPC for the iPhone SDK 2.x is available. It includes an Xcode template to build the demo application that I mentioned in my message last week.

Also, to make it clear: FPC cannot work around the requirement of having an Apple-issued certificate to run self-written programs on an iPhone/iPod Touch. So you have to sign up to Apple's iPhone Developer program ($99/year) to run FPC-compiled programs on the real hardware (just like for regular Xcode-compiled programs).

Without such a certificate, you can only run programs on the simulator (possibly unless you have a jailbroken iPhone/iPod Touch, but in that case you are on your own; I will not involve myself with jailbreaks, to avoid any potential legal troubles with the status of this FPC port).

Jonas

Reply by email

Jonas Maebe
to Vincent Snijders
Vincent Snijders wrote 8 lines
Jonas Maebe schreef: > Hello, > I'm happy to announce that the first version of FPC for the iPhone > SDK 2.x is available. It includes an Xcode template to build the > demo application that I mentioned in my message last week. I guess this is worth a mention on http://www.freepascal.org/ and http://www.freepascal.org/news.var .

I want to wait a week or so to see what the main problems are (e.g., I'll let the installation script mention where it's located whenever it aborts), and then package a new version and announce that one on the website.

Jonas

Reply by email

dmitry boyarintsev
to Jonas Maebe

Jonas

1) While building the template, i've met only one problem: 'gles11' unit used by fpclogo.pas could not be found. I've added a path to "opengles" package checked to /etc/fpc.cfg and project compiled and run with no problems. Really nice!
tested for Simulator 2.0

#/etc/fpc.cfg sample. I've iPhone SDK installed to /Developer ...
-Fu/Developer/FreePascalCompiler/iPhoneSnapshot-2.3.1-r12531/Source/packages/opengles/*

I wonder if obj-c 2.0 run-time is available at iPhone/iPod devices, so it's possible to compile with out ObjC of cause using Lazarus instead of XCode can save a LOT of time :)

2) Also a note. While switching between Simulator target versions (i.e. 2.0 -> 2.1), the project refuses to build:
----
Building target "iPhoneFPC" of project "iPhoneFPC" with configuration "Release" — (1 error)
cd /Users/igorkokarev/gdb-768/src/gdb/macosx/iPhoneFPC /bin/sh -c
/bin/sh: -c: option requires an argument
/bin/sh: -c: option requires an argument
/bin/sh: -c: option requires an argument
Build failed (1 error)
----

The problem is solved by Cleaning the project before rebuilding it.

Reply by email

Jonas Maebe
to dmitry boyarintsev
dmitry boyarintsev wrote
1) While building the template, i've met only one problem: 'gles11' unit used by fpclogo.pas could not be found. I've added a path to "opengles" package checked to /etc/fpc.cfg and project compiled and run with no problems. Really nice!

I don't understand, you should not need any such path. /etc/fpc.cfg always contains:

-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/*

$fpcversion is 2.3.1 and $fpctarget is either i386-darwin (simulator) or arm-darwin (real hardware). The gles11 unit is installed by the post-install script into /usr/local/lib/fpc/2.3.1/units/i386-darwin/ opengles (resp. arm-darwin).

Do you perhaps have an .fpc.cfg in your home directory that contains other unit search paths? Maybe I should modify the Xcode compilation scripts to ignore any configuration files, and hardcode the paths (via an option, so you can still change the path to point elsewhere, if you want). That would prevent such problems.

Show quoted text 6 lines
tested for Simulator 2.0 #/etc/fpc.cfg sample. I've iPhone SDK installed to /Developer ... -Fu/Developer/FreePascalCompiler/iPhoneSnapshot-2.3.1-r12531/Source/ packages/opengles/*

Those are the sources. You should not have to add this at all.

I wonder if obj-c 2.0 run-time is available at iPhone/iPod devices, so it's possible to compile with out ObjC is perfectly possible to compile programs without using Objective-C

code (the testsuite programs, which are plain command line programs, work fine on the iPhone/iPod Touch -- of course, their output only appears on the console log and not on the screen, because they don't have a GUI).

However, it is against the iPhone SDK agreement to distribute derivative works, and this is includes Pascal translations of framework headers. So it would be quite a challenge (if possible at all) to create and distribute the sources of a complete Pascal program with a GUI that does not violate the iPhone SDK agreement terms at this time. See the ReadMe.rtf file for more information.

And of cause using Lazarus instead of XCode can save a LOT of time :)

Afaik that is impossible at this time, because I know of no way other than Xcode to copy an application to the iPhone/iPod Touch and to execute it. It should be possible to modify Lazarus to work with the Simulator, if you wish to figure that out. Personally, I have however no intention to work on that.

Show quoted text 12 lines
2) Also a note. While switching between Simulator target versions (i.e. 2.0 -> 2.1), the project refuses to build: ---- Building target "iPhoneFPC" of project "iPhoneFPC" with configuration "Release" — (1 error) cd /Users/igorkokarev/gdb-768/src/gdb/macosx/iPhoneFPC /bin/sh -c /bin/sh: -c: option requires an argument /bin/sh: -c: option requires an argument /bin/sh: -c: option requires an argument Build failed (1 error) ----

I cannot reproduce this. Please provide the full build transcript. You can obtain it by clicking on the third icon at the bottom of the pane with the output above (the one that looks like some text lines, next to the yellow warning triangle).

This error means that Xcode cannot find the assembler code for a compiled Pascal unit. I'll add a proper error message in the next version.

Jonas

Reply by email

dmitry boyarintsev
to Jonas Maebe
Show quoted text 5 lines
Do you perhaps have an .fpc.cfg in your home directory that contains other unit search paths? Maybe I should modify the Xcode compilation scripts to ignore any configuration files, and hardcode the paths (via an option, so you can still change the path to point elsewhere, if you want). That would prevent such problems.

I'm using fpc trunk, so sometimes i have to rebuild compiler, rtl and packages. Since building to /usr/* required root rights, i don't use the path. I keep fpc sources and units at home directory. And so not mess up with numerous fpc.cfg, i've modified /etc/fpc.cfg to search for units at the home dir.

Show quoted text 5 lines
However, it is against the iPhone SDK agreement to distribute derivative works, and this is includes Pascal translations of framework headers. So it would be quite a challenge (if possible at all) to create and distribute the sources of a complete Pascal program with a GUI that does not violate the iPhone SDK agreement terms at this time.

isn't it the same trick you've already done with the current implementation? The only thing necessary is converter from ObjC headers to Pascal headers. There's objcparser (objc 1.0 supported) already available for Cocoa.

Show quoted text 7 lines
I cannot reproduce this. Please provide the full build transcript. You can obtain it by clicking on the third icon at the bottom of the pane with the output above (the one that looks like some text lines, next to the yellow warning triangle). This error means that Xcode cannot find the assembler code for a compiled Pascal unit. I'll add a proper error message in the next version.

transcript is attached to the mail, hope it helps.

Reply by email

Jonas Maebe
to dmitry boyarintsev
dmitry boyarintsev wrote 5 lines
I'm using fpc trunk, so sometimes i have to rebuild compiler, rtl and packages. Since building to /usr/* required root rights, i don't use the path. I keep fpc sources and units at home directory. And so not mess up with numerous fpc.cfg, i've modified /etc/fpc.cfg to search for units at the home dir.

Ok, so the solution is indeed to ignore any (.)fpc.cfg files.

Show quoted text 13 lines
> However, it is against the iPhone SDK agreement to distribute > derivative > works, and this is includes Pascal translations of framework > headers. So it > would be quite a challenge (if possible at all) to create and > distribute the > sources of a complete Pascal program with a GUI that does not > violate the > iPhone SDK agreement terms at this time. isn't it the same trick you've already done with the current implementation? The only thing necessary is converter from ObjC headers to Pascal headers. There's objcparser (objc 1.0 supported) already available for Cocoa.

It depends. If it is fully automatic without any need for manual intervention afterwards, it could indeed work. I don't know whether the iPhone SDK supports both Objective-C 1.0 and 2.0, or only 2.0 though.

Show quoted text 14 lines
> I cannot reproduce this. Please provide the full build transcript. > You can > obtain it by clicking on the third icon at the bottom of the pane > with the > output above (the one that looks like some text lines, next to the > yellow > warning triangle). > > This error means that Xcode cannot find the assembler code for a > compiled > Pascal unit. I'll add a proper error message in the next version. transcript is attached to the mail, hope it helps. <transcript.zip>

I managed to reproduce it also in the mean time. It only happens for me if I wait a while between building for different SDK's (when I rebuild immediately for another SDK, it works fine). I'm working on a fix.

Thanks for the feedback,

Jonas

Reply by email

dmitry boyarintsev
to Jonas Maebe
It depends. If it is fully automatic without any need for manual intervention afterwards, it could indeed work. I don't know whether the iPhone SDK supports both Objective-C 1.0 and 2.0, or only 2.0 though.

i've been studying iPhone UIKit headers before and they're 2.0 only. After my exams end i will update then objcparser to support 2.0. Since headers are not to be updated too often by Apple, i guess it's possible to make the process fully automatic.

Reply by email

dmitry boyarintsev
to Jonas Maebe: I don't understand, you should not need any such path. /etc/fpc.cfg always contains:…
It is perfectly possible to compile programs without using Objective-C code (the testsuite programs, which are plain command line programs, work fine on the iPhone/iPod Touch -- of course, their output only appears on the console log and not on the screen, because they don't have a GUI).

What's the correct way to build testsuite programs using fpc and XCode? are they Simulator runnable too?

Reply by email

Jonas Maebe
to dmitry boyarintsev
dmitry boyarintsev wrote 9 lines
> It is perfectly possible to compile programs without using > Objective-C code > (the testsuite programs, which are plain command line programs, > work fine on > the iPhone/iPod Touch -- of course, their output only appears on > the console > log and not on the screen, because they don't have a GUI). What's the correct way to build testsuite programs using fpc and XCode? are they Simulator runnable too?

It does not make sense much to run them in the Simulator, because the Simulator allows full access to the real Mac OS X, so you have no idea whether you are testing Mac OS X/iPhone-specific code or regular Mac OS X/i386 code. It's probably safer (and definitely much easier) to run them under plain Mac OS X/i386 in that case.).

That said, I've usually just compiled test programs on the command line (for ARM), and then copied them over the built binary in an Xcode project. If you then "run" the program in Xcode, it will code sign and run the binary that you copied over rather than the original program :) (just make sure that the binary in Xcode has been compiled recently so there are no changes that trigger Xcode to relink it).

You can find the binary's location by opening the "products" folder in the project overview, right-clicking on the .app file and selecting "Reveal in Finder". The binary's location is then in program.app/ Contents/MacOS. Just overwrite whatever file is there with the program you compiled.

To compile on the command line (replace "iphone2.1" with the directory in which you installed the SDK):
ppcarm -FD/iphone2.1/Platforms/iPhoneOS.platform/Developer/usr/bin -XR/ iphone2.1/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk tt2

To compile for the simulator, replace "ppcarm" with "/usr/local/lib/ fpc/2.3.1/ppc386", and the -XR parameter with the path to a simulator SDK. And in case you created an alternate fpc.cfg that uses a different unit search path than /usr/local/lib/fpc/2.3.1/units/*, also add -Fu/usr/local/lib/fpc/2.3.1/units/*

You can also directly compile from Xcode, if you want: just create a new project based on the template, remove all files except for the *Prefix.pch, Info.plist, Framewoeks and Products from the project, and then add the test program file (Project->Add to Project...). Finally, double click on the project icon at the top left in the file list, go to the Build tab, and change the FPC_MAIN_FILE setting to the name of the test program you added (for all configurations). Then you can build it.

To see the console output of the test programs, press cmd-shift-r (or select Run->Console)

Jonas

Reply by email

dmitry boyarintsev
to Jonas Maebe

Thanks for very informative explanation, i will try it! BTW: this thread already contains a lot of usefull information about iPhone/iPod and XCode FPC development, Should I add it to Freepascal (Lazarus?) Wiki?

Reply by email

Jonas Maebe
to dmitry boyarintsev
dmitry boyarintsev wrote
Thanks for very informative explanation, i will try it! BTW: this thread already contains a lot of usefull information about iPhone/iPod and XCode FPC development, Should I add it to Freepascal (Lazarus?) Wiki?

Sure, feel free to do so! (wiki.freeascal.org is exactly the same site as wiki.lazarus.freepascal.org, so it doesn't matter where you add it)

Jonas

Reply by email