Recently I've become more and more addicted to the Xcode environment. Prior to using Xcode I was strictly a vi (specifically elvis a vi clone) power user. Good old vi served well as a multi platform editing tool, however I am finding that I perform most of initial development on a Mac Desktop (when I first started programming I worked from a Linux desktop) and then copy the source to other platforms (Linux, FreeBSD, Solaris, and Windows) for testing and deployment. This usually means that 90% of my time is spent working from a Mac desktop.
Although vi is an invaluable tool, I prefer writing code in Xcode. This has led me to figure out how to write the code in Xcode and compile it using a GNU Autoconf/Automake/Libtool/Make environment. It turns out to be pretty simple. Xcode has the ability to configure an Xcode target to call an external script. The arguments passed to the script can be configured, but Xcode will pass the requested action (clean, install, etc) by default.
To configure Xcode 3.0 to create a target which calls make, follow these steps:
- Right click (or Command-Click) Targets
- Select Add->New Target
- In the new window that opens, select Other from the table on the left and select External Target from the items on the right.
- Click Next
- Type in all apps for the target name and click Finish
This should create a target which defaults to calling /usr/bin/make. If you do not need to call configure, you are now done.
If like me you use GNU Autoconf and GNU Automake to help port projects to different platforms, you need to create an additional target which will create the make file. Follow these steps to create a target which will create the Makefile by running configure:
- Right click (or Command-Click) Targets
- Select Add->New Target
- In the new window that opens, select Other from the table on the left and select External Target from the items on the right.
- Click Next
- Type in Makefile for the target name and click Finish
- Double click on the target Makefile to open the properties window
- In the Arguments box, add -f Makefile-xcode before the $(ACTIONS) variable.
- Drag the target Makefile to be under the target all apps. This should create a "second" Makefile object as a dependency for all apps
-
Create a file called the file Makefile-xcode in the root of your Xcode project directory and add the following contents:
# special make file used by Xcode to run configure
all: Makefile
Makefile: Makefile-xcode configure Makefile.in config.h.in
./configure
clean:
test -f Makefile && make distclean
#end of Makefile
The second target essentially tells make to use an alternative Makefile (Makefile-xcode) to generate the Makefile used by the rest of the project. Automake, and autoconf can also be run to generate configure, Makefile.in, config.h.in, etc, by using a longer Makefile-xcode. For example the following Makefile-xcode uses autoconf and automake:
#
# Makefile-xcode - automate Automake compiling from Xcode
#
# GNU build tools
ACLOCAL ?= /opt/local/bin/aclocal
AUTOCONF ?= /opt/local/bin/autoconf
AUTOHEADER ?= /opt/local/bin/autoheader
AUTOMAKE ?= /opt/local/bin/automake
# local targets for building environment
all: Makefile
aclocal.m4: Makefile-xcode acinclude.m4 configure.ac
$(ACLOCAL)
touch aclocal.m4
config.h.in: Makefile-xcode aclocal.m4
$(AUTOHEADER)
touch config.h.in
configure: Makefile-xcode aclocal.m4 configure.ac
$(AUTOCONF)
touch configure
Makefile.in: Makefile-xcode Makefile.am configure
$(AUTOMAKE)
touch Makefile.in
Makefile: Makefile-xcode configure Makefile.in config.h.in
./configure --enable-dependency-tracking
clean:
test -f Makefile && make distclean
install:
# end of Makefile file
Well that's it for now. I hope this is helpful to the autoconf, automake, Xcode users out there.