This post will show you how to create the simplest possible installer package with pkgbuild.
Making a simple installer is actually easy, but Apple only provides us with a man page and most tutorials dive too deep straight away.
That's not great. It's an intimidating tool. Let's start with the basics.
What does pkgbuild do?
pkgbuild packs your app's files into bare-bones .pkg packages. They are bare-bones because they don't have any of the fancy features like license or readme sections.
The bare-bones packages are actually called component packages, but don't let the "component" part fool you. It's fine to distribute your app as a component package. This is what you'll see if you open one:
A perfectly normal installer.
How to build a component package with pkgbuild
You can put your all of your app's files in a single component package. You just have to tell pkgbuild where everything goes.
Let's start with the basic scenario. An application bundle called MyApp.app that should be installed into /Applications.
The easiest way to tell pkgbuild where things should go is to make a fake root folder. That's just a folder that mimics the end result that your installer will create.
For example, if you want to end up with /Applications/MyApp.app, you prepare it inside some other folder like this: /tmp/MyAppRoot/Applications/MyApp.app. In this case, /tmp/MyAppRoot is the fake root folder. It doesn't matter how you name your fake root folder or where you put it.
Now you can call pkgbuild and point it to the fake root folder where you copied your app's files. The last parameter is the filename you want for the installer itself.
$ cd /tmp $ pkgbuild --root MyAppRoot MyInstaller.pkg
How to: Making OS X Installer Packages like a Pro - Xcode4 Developer ID Mountain Lion ready pkg
How to: Making OS X Installer Packages like a Pro – Xcode4 Developer ID Mountain Lion ready pkg
Making OS X Installer Packages like a Pro – Xcode4 Developer ID Mountain Lion ready pkg
Note: This is for OS X Installer packages only, packages for submission to the Mac App Store follow different rules.
Because of Mountain Lions Gatekeeper I finally had to take my PackageMakerbuild script behind the barn and shoot it. PackageMaker was already removed from Xcode and moved into “Auxiliary Tools…
PackageMaker - What do you need to know for migrating from XCode 3 to 4
Just a quick list for anybody who happen to come across same issues as me. If you have built an app and for some Godforsaken reason had to use PackageMaker following are things to watch out when moving your project to XCode 4 / Lion. (Yes you read correct, if you do not have to please please do not use PackageMaker, even Apple does not use it themselves)
XCode 4 output directory is now in Library
Not just that it builds your product in ~/Library it also creates a folder consisting of your productname-some_random_characters. Trouble with the folders in ~/Library is that these are not selectable in folder browser from PackageMaker (or elsewhere). It is also not guarenteed to work if you copy paste the complete path from Terminal. Copying the product does not copy everything needed and will fail the installer build as well.
There are two ways to change build location:
XCode > Preferences > Locations (Change the default to Relative for a subfolder in workspace or Change to custom for a custom location) - this change is global and recommended.
File > Project Settings > Build (similar changes as above) - this change is per project basis.
Double check location of resources and images
PackageMaker will not always give a helpful error if you have changed your core path of resources and product. Make sure you check path on everything including but not limited to Interface Editor - Background, app (as explained in first step), any other files and scripts.
Triple check location of scripts / jump into XML
If you have pre-install, post-install scripts then not all settings are changed (annoyingly) when you edit the path to your scripts in PackageMaker. Specially post-flight path in many cases. If you are still getting "Script not copied" error then you need to right click Project.pmdoc and click Show Package Contents and then double check paths in .xml files in any text editor. Re-open your PackageMaker file to try.
As always I will add anything if I remember, leave me a note if I saved you some time or if I forgot something.