• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Pass a C option based on command-line output?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pass a C option based on command-line output?


  • Subject: Re: Pass a C option based on command-line output?
  • From: Brian Onn <email@hidden>
  • Date: Sun, 8 Jan 2006 06:47:59 -0800


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. 


Thanks!

Daniel

Brian Onn
email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Pass a C option based on command-line output?
      • From: Daniel Jalkut <email@hidden>
References: 
 >Pass a C option based on command-line output? (From: Daniel Jalkut <email@hidden>)
 >Re: Pass a C option based on command-line output? (From: Chris Espinosa <email@hidden>)
 >Re: Pass a C option based on command-line output? (From: Daniel Jalkut <email@hidden>)

  • Prev by Date: Re: Pass a C option based on command-line output?
  • Next by Date: Re: Pass a C option based on command-line output?
  • Previous by thread: Re: Pass a C option based on command-line output?
  • Next by thread: Re: Pass a C option based on command-line output?
  • Index(es):
    • Date
    • Thread