AGK for Pascal
ContentsIndexHome
PreviousUpNext
4. Getting Started for OS X
Requirements
  • OS X 10.6 (Snow Leopard) or later.
  • Xcode 4.2 or later (available in Apple's App Store).
  • Free Pascal 2.5.1 or later.
  • Lazarus 0.9.30 or later.

 

You can download Lazarus with Free Pascal for OS X here: 

http://sourceforge.net/projects/lazarus/files/ 

Select the "Lazarus Mac OS X i386" folder and select the latest version. You will see three .dmg files here (lazarus*, fpcsrc* and fpc*). Download all 3. 

Alternatively, you can download the latest development snapshots here: 

http://freepascal.dfmk.hu/test/lazarus/ 

but be aware that those are untested and may contain bugs. 

 

Installation
  • Install Xcode 4.2 or later. Note that Xcode 4.3 changed the way that Xcode is installed. In particular, there is no /Developer directory anymore and the command line tools are not installed by default anymore. Both of these are needed by Free Pascal. So these additional steps are needed if you use Xcode 4.3 or later:
    • Create an alias (symbolic link) /Developer to the /Developer folder inside the Xcode bundle. To do this, open a terminal window and enter this command:

      sudo ln -s /Applications/Xcode.app/Contents/Developer /

      (Note the space before the last slash).

    • You must have read and write access in the Developer folder. An easy way to give everyone read and write access is with this command:

      sudo chmod 777 /Applications/Xcode.app/Contents/Developer

    • Open Xcode and go to the "Xcode | Preferences..." menu option. Go to the "Downloads" tab and install the Command Line Tools.
  • Install AGK for Pascal in the directory /Developer/AgkPas. You may install it in a different directory, but the Lazarus template assumes it is installed in this directory.
  • Open the downloaded fpc*.dmg file. It contains two packages (fpc*.pkg and fpc-xcode*.pkg). Install both packages.
  • Open the fpcsrc*.dmg file and install the package it contains.
  • Open the lazarus*.dmg file and install the package it contains.

 

Creating an AGK project

The easiest way to start a Lazarus AGK application is to use a template. The template can be found in the /Developer/AgkPas/Templates/OSX_Lazarus directory. 

 

  1. Copy the files in the /Developer/AgkPas/Templates/OSX_Lazarus directory to your application directory.
  2. Start Lazarus. You can find it in the directory /Developer/lazarus
  3. Open the copied project.
  4. Choose "Project | Save Project As..." and save the project under a new name. You can now delete the copied AgkTemplate_macos.lpi, AgkTemplate_macos.lpr and AgkTemplate_macos.res files.
  5. Build and run the application.

 

You should now see a small 480x320 pixel window showing the text "Hello AGK for Pascal!". You can now modify the unit uMain and change the application settings and add your game code. 

Note: if you get a compiler error like "Can't open include file "AGK.inc" the you probably have not installed AGK for Pascal in the /Developer/AgkPas directory. In that case you will need to modify the search paths. Go to "Project | Options... | Compiler Options | Paths" and update all the paths containing /Developer/AgkPas to match your installation. 

 

Note about application resources

OS X applications expect that its resources (like images, sounds etc.) are packaged into the application bundle, inside the /Contents/Resources folder. The Lazarus template project takes care of copying the resources for you by executing the osx_post_build.sh script after each compile and build. This script contains the commands needed to copy resources to the application bundle. It contains lines like this: 

 

cp agk.png $1.app/Contents/Resources

 

This example copies the agk.png file from the source directory to the Resources folder in the bundle. 

When you add resources to your project, you must update the shell script and add the appropriate lines to copy your resources. 

 

Examples

If you want to check out some examples, then look at the Examples directory. It contains a large number of sample applications, categorized in various subdirectories. Each subdirectory contains further subdirectories for each sample application. In those subdirectories you will find 3 Lazarus projects. Open the one with the "_macos" suffix (the other ones are for building Windows and Android applications).

Copyright (c) 2012. All rights reserved.