Difference between revisions of "iPhone/iPod development"

From Lazarus wiki
Jump to navigationJump to search
m (small reformatting and language changes)
Line 3: Line 3:
 
== Installation ==
 
== Installation ==
  
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.
+
Note that unlike other FPC releases, this installer will install the FPC sources (of FPC 2.3.1, svn revision 12531) 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. If the script aborts for some reason, you can find it at <tt>/Developer/FreePascalCompiler/iPhoneallScript/finish_fpc_iphone_install.command</tt> to relaunch it.
  
 
Requirements:
 
Requirements:
Line 11: Line 11:
  
 
Some features:
 
Some features:
* Simulator support (it turned out to be trivial to add)
+
* Simulator support
 
* the Xcode template transparently supports (requires, actually) integrating Pascal and Objective-C source files into a single application
 
* 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
 
* 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
Line 26: Line 26:
 
=== Developing applications for iPhone/iPod ===
 
=== Developing applications for iPhone/iPod ===
  
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).
+
FPC cannot work around requiring 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;
+
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).
  
Seek more about Apple's iPhone development program here: http://developer.apple.com/iphone/program/
+
Read more about Apple's iPhone development program here: http://developer.apple.com/iphone/program/
  
 
=== Pascal headers required for developing ===
 
=== Pascal headers required for developing ===
  
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 (provided at .dmg above) file for more information
+
It is against the iPhone SDK agreement to distribute derivative works of this SDK, 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 pure Pascal program with a GUI that does not violate the iPhone SDK agreement terms at this time. See the ReadMe.rtf (provided at .dmg above) file for more information
  
 
== Technical Development Limitations ==
 
== Technical Development Limitations ==
  
For now, it is impossible at this time, because now way known, other than XCode, to copy an application to the iPhone/iPod Touch and to execute it.  
+
At this time is not known whether and if so how it possible to copy an application to the iPhone/iPod Touch and to execute it without using Xcode. It's possible of course to write the application using any IDE available (Lazarus, Lightweight IDE, etc) and it should also be possible to make any of them work with the Simulator. However, any application has to be built by Xcode for it to be uploaded to the Device and to debug it.
It's possible to develop the application using any IDE available (Lazarus, Lightweight IDE, etc) as well as it should be possible to make any of it to work with the Simulator.
 
But still, any application should be build by XCode to upload the program to the Device.
 
  
 
=== iPhone Simulator is not iPhone ===
 
=== iPhone Simulator is not iPhone ===
  
It does not make sense much to run programs 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.).
+
It does not make much sense to run test programs 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. The Simulator is only really useful if you have a bug that takes a long time to reproduce and which occurs both in the Simulator and on real hardware.
  
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).
+
=== Compiling and running pure Pascal applications on an iPhone/iPod Touch ===
  
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.
+
While the full source code of such applications cannot be distributed due to licensing restrictions as outlined above, you can use your own private Pascal header translations (possible generated by an automated tool). It is also possible to run plain command line programs on an iPhone/iPod Touch (such as those in the FPC testsuite). The output from write/writeln will in this case appear in Xcode's console (cmd-shift-r, or select Run->Console)
  
To compile on the command line (replace "iphone2.1" with the directory in which you installed the SDK):
+
==== Using only Xcode ====
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/*
+
# Create a new project based on the template
 +
# Remove all files except for *Prefix.pch, Info.plist, Frameworks and Products from the project
 +
# Add your own Pascal sources (Project->Add to Project...)
 +
# Double-click on the project icon at the top left in the Xcode file list, go to the <tt>Build</tt> tab, and change the <tt>FPC_MAIN_FILE</tt> setting to the name of the test program you added (for all configurations).
 +
# Build the program
  
 +
==== Combining command-line compilation and Xcode ====
  
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.
+
If you compile a program on the command line (for Darwin/ARM) and copy it over the built binary in an Xcode project, then if "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 do this using a project based on the default template, without changing anything to the project.
  
To see the console output of the test programs, press cmd-shift-r (or select Run->Console)
+
You can find the Xcode binary's location by opening the <tt>Products</tt> folder in the project overview, right-clicking (ctrl-clicking) on the .app file and selecting "Reveal in Finder". The binary's location is then in program.app/Contents/MacOS (replace <tt>program.app</tt> with the actual name of the folder selected in the finder). Just overwrite whatever file is in this <tt>MacOS</tt> folder with the program you compiled (e.g. using the command line <tt>cp</tt> program).
 +
 
 +
To compile for Darwin/ARM on the command line (replace "iphone2.1" with the directory in which you installed the SDK):
 +
 
 +
<code>
 +
ppcarm -FD/iphone2.1/Platforms/iPhoneOS.platform/Developer/usr/bin -XR/iphone2.1/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk program.pas
 +
</code>
 +
 
 +
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 (e.g., <tt>-XR/iphone2.1/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk</tt>). ''(for advanced users)'' 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/*

Revision as of 23:17, 14 January 2009

The first version of FPC for the iPhone SDK 2.x is available.

Installation

Note that unlike other FPC releases, this installer will install the FPC sources (of FPC 2.3.1, svn revision 12531) 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. If the script aborts for some reason, you can find it at /Developer/FreePascalCompiler/iPhoneallScript/finish_fpc_iphone_install.command to relaunch it.

Requirements:

  • Intel Mac (because the iPhone SDK requires an Intel Mac)
  • iPhone SDK 2.x installed (only tested with 2.2 though) (note: SDK requires Leopard 10.5.5 or higher)
  • FPC 2.2.2 or a later FPC 2.2.x release installed

Some features:

  • Simulator support
  • 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.

Apple's Licencse limitations

Developing applications for iPhone/iPod

FPC cannot work around requiring 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).

Read more about Apple's iPhone development program here: http://developer.apple.com/iphone/program/

Pascal headers required for developing

It is against the iPhone SDK agreement to distribute derivative works of this SDK, 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 pure Pascal program with a GUI that does not violate the iPhone SDK agreement terms at this time. See the ReadMe.rtf (provided at .dmg above) file for more information

Technical Development Limitations

At this time is not known whether and if so how it possible to copy an application to the iPhone/iPod Touch and to execute it without using Xcode. It's possible of course to write the application using any IDE available (Lazarus, Lightweight IDE, etc) and it should also be possible to make any of them work with the Simulator. However, any application has to be built by Xcode for it to be uploaded to the Device and to debug it.

iPhone Simulator is not iPhone

It does not make much sense to run test programs 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. The Simulator is only really useful if you have a bug that takes a long time to reproduce and which occurs both in the Simulator and on real hardware.

Compiling and running pure Pascal applications on an iPhone/iPod Touch

While the full source code of such applications cannot be distributed due to licensing restrictions as outlined above, you can use your own private Pascal header translations (possible generated by an automated tool). It is also possible to run plain command line programs on an iPhone/iPod Touch (such as those in the FPC testsuite). The output from write/writeln will in this case appear in Xcode's console (cmd-shift-r, or select Run->Console)

Using only Xcode

  1. Create a new project based on the template
  2. Remove all files except for *Prefix.pch, Info.plist, Frameworks and Products from the project
  3. Add your own Pascal sources (Project->Add to Project...)
  4. Double-click on the project icon at the top left in the Xcode 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).
  5. Build the program

Combining command-line compilation and Xcode

If you compile a program on the command line (for Darwin/ARM) and copy it over the built binary in an Xcode project, then if "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 do this using a project based on the default template, without changing anything to the project.

You can find the Xcode binary's location by opening the Products folder in the project overview, right-clicking (ctrl-clicking) on the .app file and selecting "Reveal in Finder". The binary's location is then in program.app/Contents/MacOS (replace program.app with the actual name of the folder selected in the finder). Just overwrite whatever file is in this MacOS folder with the program you compiled (e.g. using the command line cp program).

To compile for Darwin/ARM 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 program.pas

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 (e.g., -XR/iphone2.1/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk). (for advanced users) 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/*