Setup Xcode for using external compiler

jelipito picture jelipito · Mar 27, 2013 · Viewed 10.8k times · Source

I am trying to use Xcode as an editor for microcontroller code. I want to use the Build, Run buttons. How can i use those to trigger a script that compiles the program ? I already have a script that works on the command line. I need to pass some parameters, like filename and maybe a couple of options. I am using SDCC which is an 8501 compiler. Is it possible to create a custom target or something in Xcode so it calls the script and passes the filename or parameters? Any examples on how to do this? Of course i can't use GCC for this.

Answer

cody picture cody · Mar 27, 2013

Well, you need to create "External Build System" project:

  • File -> New -> Project -> OS X -> External Build System -> Next
  • Set "/bin/bash" to the "Build Tool" field
  • Set other information and create project
  • Choose your target and on "Info" tab set arguments (your script name and arguments to be passed to the script) and work directory (if needed). You also can change build tool here.

If you want to set a separate script as a run command than:

  • at the bottom click on your current scheme and choose "Edit Scheme..."
  • Choose "Run" in left panel
  • "Info" tab: select "Executable" -> "Other..." -> navigate to /bin directory (Command + Shift + G) -> choose "bash". Set "Debugger" to "None"
  • "Arguments" tab: set arguments (your script and arguments to be passed).
  • "Options" tab: set working directory.

I usually use just one script for all (set as run script). In this case just leave arguments on target's "Info" tab empty.

Edit: for make as a build tool no need to pass any arguments, just set Directory appropriately and make will find Makefile there.