Skip to main content

Using Makefiles in Xcode 4

·3 mins

Sometimes I read questions from developers who want to use makefiles in Xcode. The short answer to their questions is to create an external build system project. The rest of this article provides a longer answer for those of you using Xcode 4.

Create an External Build System Project #

An external build system project uses something besides Xcode to build the project. By using an external build system project you can use another build tool, such as make, ant, CMake, and SCons to build the project. An external build system also lets you use languages Xcode does not directly support. Supply the path to the language’s compiler when creating the project.

Choose File > New > New Project to create a new project. The external build system project is in the Other section under Mac OS X.

External Build System Project Step 1

After selecting the external build system project, click the Next button to move on to the next step. In the next step you name the project and supply the path to the build tool. Xcode is initially configured to use make so you should not have to change the build tool if you’re using a makefile.

External Build System Project Step 2

If you’re running Xcode 4.2 or later you will see the Use Automatic Reference Counting checkbox. This checkbox applies only to Objective-C code. If you’re not using Objective-C, deselect the checkbox.

After naming the project, click the Next button. Choose a location to save the project, and click the Create button to finish creating the project.

Add Files to the Project #

Now that you’ve created an external build system project, you must add the makefile and source code files to the project. If you have existing files, choose File > Add Files to ProjectName to add the files to the project. Choose File > New > New File to add a blank file to your project. Xcode does not have a makefile file template. Add an empty file to the project to add a new makefile. The empty file template is in the Other section under Mac OS X.

Configuring the Build Tool #

If you need to configure the build tool, use the project editor. Choose the project file from the project navigator on the left side of the project window to open the project editor.

External Build Tool Configuration

Select the target from the target list. Click the Info button at the top of the editor, which you can see in the screenshot.

Build the Project #

Click the Run button or use the Product menu to build the project. Xcode builds the project using the makefile. If you chose a different build tool, Xcode uses the tool you specified to build the project.