Skip to content

Instantly share code, notes, and snippets.

@ChimeraCoder
Created September 29, 2012 18:57
Show Gist options
  • Save ChimeraCoder/3804898 to your computer and use it in GitHub Desktop.
Save ChimeraCoder/3804898 to your computer and use it in GitHub Desktop.
Test for environment variable
#Taken from
#http://stackoverflow.com/questions/4728810/makefile-variable-as-prerequisite
#Remember that each make target is run within a separate sub-shell, which defaults to sh (not bash)
#so bash-specific default environment variables like $HOSTNAME will *not* be accessible *unless*
# they are exported *before* `make' is run; ie, `export HOSTNAME=$HOSTNAME'
change-hostname: assertenvar-USER assertenvar-TESTVAR assertenvar-HOSTNAME assertenvar-TEF
assertenvar-%:
@if [ -z ${${*}} ] ; then \
echo "Environment variable $* not set"; \
exit 1; \
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment