Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

omarshariffdont

macrumors newbie
Original poster
Mar 18, 2010
2
0
Hey everybody!

Having a little problem getting my head around the build rule system in Xcode. Heres a quick overview:

I've written an ANSI C program, a simple HTTP server. Some of the page this web server returns I am currently embedding into the program using the command line tool xxd to generate a header file containing the web page as a char array. Currently, I have to run the command:

xxd -i error.htm webpage_error.h

if I make a change to the html file before building in Xcode. If I forget, I have to rebuild all over again.

I came across some articles online pointing out how easy it was to create a build rule that would execute a bash script when you build. Could some one give me a quick walk through the steps involved in making sure the command line I manually run above runs in the source files folder and includes the newly created header file in the build? I've had a couple of stabs but no luck yet.

(bonus points if the instructions can be applied to any html file, e.g.:
xxd -i (*).htm webpage_$1.h)

Cheers and thanks in advance!

P.S. I'm aware of the sillyness in this: a web server with embedded pages in the source, but there are valid reasons :)
 

Detrius

macrumors 68000
Sep 10, 2008
1,623
19
Apex, NC
You are asking how to do two things that seem slightly different in concept but have remarkably different approaches in practice.

First things first: you know the file you want to work with. Add a custom script build phase to your target. Two very important details are that you need to specify the input files and the output files. Using environment variables should be very helpful. I wanted to run flex on a file, but I didn't like the default arguments Xcode passes, so I created my own script.

$(SRCROOT) is in your project settings. It's the root folder of your project, configured to be relative to your xcode project. $(DERIVED_FILE_DIR) is in your Build directory. You don't *have* to used this to specify the location of output. You can put it anywhere. Just make sure that you specify input files and output files at the bottom of the window. If you don't, dependencies won't work, so it won't rerun the script when files change. Also, if you're using these environment variables, it's important to note that the method used to reference them varies. See the attached screenshot.


The generic approach is something I have not done. It's configured under the "Rules" tab of the Target settings.
 

Attachments

  • Screen shot 2010-03-20 at 11.34.24 PM.png
    Screen shot 2010-03-20 at 11.34.24 PM.png
    58.7 KB · Views: 657
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.