Using Makefiles in Xcode 4

October 12th, 2011

Filed under: Xcode | 2 comments

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.

Tags:


2 thoughts on “Using Makefiles in Xcode 4

  1. kash56789 says:

    This is a very useful tutorial.

  2. Joe Austin says:

    I am working on building a curriculum for my people regarding a finite state machine. I have examples using C code, command line, vi, cc, makefiles, et al) and want to demonstrate using X-Code. I have four files in C (that compile to and executable) and a well formed Makefile. My best task is to put the four C files and the Makefile into a project so that they can use it with the xCode project system. I do not want to teach how to use vi, cc, makefiles et all. Simply put, I just want them to use the work and compile using xCode.

    Best regards,

    - Joe

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*