Automatically Generating a makefile from Xcode
I'm starting work on a new project, which will ultimately be built and used in a linux environment. However, in the mean time I'd like to be able to develop and test it on my laptop with Xcode. Thanks to the excellent PBTOMAKE it's easy to generate a makefile fromm your Xcode project that can be used on systems where Xcode itself isn't available. However, who wants to have to remember to generate the makefile manually? What drudgery! Instead, you can have Xcode do it for you. In a 'Run Script' phase of your favorite Xcode target, just put in:
PBTOMAKE=`which pbtomake`
if [ -n "$PBTOMAKE" ]
then
if [ -f ./makefile ]
then
mv makefile makefile.bak
fi
echo "generating makefile"
$PBTOMAKE -i "$PROJECT_FILE_PATH" -obj "./$BUILD_DIR/objects" -cc "g++"
if [ -f ./makefile ]
then
echo "Succeeded"
else
echo "Failed"
if [ -f ./makefile.bak ]
then
echo "Restoring previous makefile"
mv makefile.bak makefile
fi
fi
else
echo "Can't find pbtomake; not generating makefile"
fi
This script should be smart enough to check whether pbtomake is actually available and keep a clean copy of any existing makefile just in case something goes horribly wrong. Note that it will tell the makefile to put all intermediate objects in ./$BUILD_DIR/objects/; you'll have to make sure that this directory exists in order for the generated makefile to work.