Using GNU Make 4.2.1
I'm writing a Makefile, and I want to use a conditional statement to have make check whether it is on a specific remote server or not. I'd like to do this using the unix HOSTNAME
environment variable. I also want it to run regardless of subdomain, so I use the make wildcard
function.
ifeq ($(wildcard *.remote.server.com),$(HOSTNAME))
echo "ON REMOTE SERVER"
else
echo "NOT ON REMOTE SERVER"
endif
This looks like it would work, but on my local machine the HOSTNAME
environment variable is not set and the ifeq
test evaluates to true and prints ON REMOTE SERVER
.
This doesn't make sense to me; *.remote.server.com
is being compared to an empty string and should evaluate false and print NOT ON REMOTE SERVER
.
Am I missing something about either unix environment variables, wildcard
, or make conditionals, or all three?
Edit: Problem resolved. Learned that this is not the spot to use the wildcard
function. Instead, used something similar to the following line
ifeq "$(shell hostname | sed -e 's/.*.remote.server.com/remote.server.com/')" "remote.server.com"
Based on this response: How to use bash regex inside Makefile Target