1

For an iPad application I need to transform some CoffeeScript files into JavaScript files before bundling them with the application.

I tried to add a Makefile to my XCode project with the following code:

MANUAL_ROOT=IOS12BSH/manual
SCRIPTS_ROOT=$(MANUAL_ROOT)/scripts

COFFEE_SOURCES=$(SCRIPTS_ROOT)/*.coffee $(SCRIPTS_ROOT)/guides/*.coffee
JAVASCRIPT_TARGETS=$(COFFEE_SOURCES:.coffee=.js)

all: build

build: coffeescript

clean: clean_coffeescript

coffeescript: $(JAVASCRIPT_TARGETS)

clean_coffeescript:
    rm -f $(JAVASCRIPT_TARGETS)

$(JAVASCRIPT_TARGETS): $(COFFEE_SOURCES)
    coffee -c $(COFFEE_SOURCES)

Running this Makefile from the shell works without problems. However, after I added the Makefile as a target in XCode, I ran into problems.

The following error was produced by the Makefile:

coffee -c IOS12BSH/manual/scripts/*.coffee IOS12BSH/manual/scripts/guides/*.coffee
/bin/sh: coffee: command not found
make: *** [IOS12BSH/manual/scripts/*.js] Error 127
Command /Applications/Xcode.app/Contents/Developer/usr/bin/make failed with exit code 2

That is strange, as the coffee command is installed on my machine (it is installed under /opt/local/bin/coffee and /opt/local/bin is added to my $PATH in ~/.profile).

So I added an echo $(PATH) to my Makefile and it seems that the $PATH is different, when the Makefile is executed by XCode. XCode does not seem to read the settings from ~/.profile and therefore /opt/local/bin is not in $PATH.

What is the reason for this and how can I fix this, so that the coffee command is found?

Simon
  • 1,521
  • 2
  • 13
  • 20
  • Why not modify your "`$PATH`" within your makefile to add "`/opt/local/bin`"? How are you running your makefile within Xcode? Is it in a "run script" build phase? – Michael Dautermann Jun 17 '12 at 14:25
  • 1
    I can't change it in the Makefile because the Makefile is in a shared repository. Other developers might have installed their `coffee` command somewhere else. – Simon Jun 17 '12 at 14:53
  • I've got no experience with `Makefile`'s but can you not `source ~/.profile` ? – Paul.s Jun 17 '12 at 15:22

3 Answers3

2

Well, it seems that programs started via the Dock or Spotlight do not execute .profile and therefore $PATH is not set correctly.

So one way would be to set the $PATH in ~/.MacOSX/environments.plist. That works then apparently, but you will need a restart before it works.

Another way is to start XCode always from the command line with open projectfile.

Simon
  • 1,521
  • 2
  • 13
  • 20
  • that should be `~/.MacOSX/environment.plist` not plural `environments.plist`. :) – NHDaly Aug 22 '13 at 05:59
  • Is there any clever way here to set this path to be sourced from the ~/.profile? – NHDaly Aug 22 '13 at 06:00
  • 1
    Hmm, I just checked and I actually already have `/opt/local/bin` in that plist file.. (OS 10.8; XCode 4.6.3). But it still doesn't seem to be able to find the file. After actually printing out the path in the Makefile like the OP suggested, I found that this path is actually very different from the path in `~/.MacOSX/environment.plist` and it doesn't include `/opt/local/bin`. – NHDaly Aug 22 '13 at 06:05
0

This answer explains the problem in detail: https://stackoverflow.com/a/14285335/751061

What ended up working best for me is just to launch Xcode from the command line. I wrote a simple bash script that looks like:

source ~/.bash_profile  # This is the trick that gets us our environment variables.
open -a "Xcode"

And then I call it from an Applescript Application just to give it a bundle I could put on the dock:

do shell script "~/xcode_launcher"

Sourcing your profile is necessary in the bash script, because running a script from Applescript doesn't ever source from a profile, so you still wouldn't have your default environment variables.

Community
  • 1
  • 1
NHDaly
  • 7,390
  • 4
  • 40
  • 45
0

SAme thing with ant command. It works on terminal, not if Xcode have to do it. Only way to got it work: sudo open project.xcodeproj in terminal.

kurtanamo
  • 1,808
  • 22
  • 27