On Jan 7, 2006, at 2:46 PM, Daniel Jalkut wrote: On Jan 7, 2006, at 4:34 PM, Chris Espinosa wrote: So in Preprocessor Definitions just set HOSTNAME=$HOSTNAME and be done with it.
On my machine it looks like I have $HOST. But in any case I don't have any luck trying to set a build setting with the expanded value. I've tried:
$HOSTNAME is a bash built-in variable. It's set by the bash shell, but it's not exported to the environment. Thus commands started by bash don't see $HOSTNAME. Shell scripts would see it, because shell scripts run in the context of (another) bash shell.
$HOST is set by the c-shell, and since you have $HOST, it tells me that your shell is the c-shell. In this case, $HOST *is* an actual environment variable and it is available to commands started by the c-shell. The make command would see it, if xcode used your c-shell to start make, but it doesn't do this.
HOSTNAME=$HOST HOSTNAME=$(HOST) HOSTNAME=${HOST}
(This is on the Preprocessor Macros build setting)
None of these will work inside xcode because xcode wasn't started from your c-shell, it was started from the environment created when you were logged in. This is a default shell environment (not a c-shell environment) plus whatever environment settings are in your ~/.MacOS/ environment.plist file.
Is there a particular build setting where I can "promote" shell variables into Xcode variables? Or is there a different format I'm supposed to use to expand them in a build setting's definition?
You could hardcode a HOSTNAME into your ~/.MacOS/environment.plist file, and it would be in the environment of xcode and should be available then as a $(HOSTNAME) build setting, however hardcoding the hostname into the environment is not such a great idea.
I have 4 possible solutions, not in any particular order:
1) You could set the HOSTNAME inside the Makefile where it's needed, using make features to execute a shell script:
HOSTNAME := $(shell /bin/hostname) $(CC) -DHOSTNAME=$(HOSTNAME) ...
2) you could create a shell script to run the make and have xcode execute this shell script as the build command in your target settings, instead of /usr/bin/make
#!/bin/sh export HOSTNAME=`hostname` exec /usr/bin/make -DHOSTNAME=${HOSTNAME} "$@"
3) use the shell as your target settings Build Command, like this: Build Tool: /bin/sh Arguments: -c 'exec /usr/bin/make HOSTNAME=`hostname` $$@' xx $(ACTION)
4) use perl as your target settings Build Command, like this: Build Tool: /usr/bin/perl Arguments: -MSys::Hostname -e '$$ENV{"HOSTNAME"}=hostname(); exec "/usr/bin/make",@ARGV;' $(ACTION)
I prefer #3 for ease of use, no changes to your make system, and no external files . If the situation needs more power, then the perl solution is an option.
|