0
votes

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

1

1 Answers

1
votes

You could just print the values of these things to see what they are. Something like $(info wildcard='$(wildcard *.remote.server.com)' hostname='$(HOSTNAME)')? The reason for this behavior depends entirely on your local system, which we do not have access to.

However, I don't see why you say that *.remote.server.com is being compared to an empty string. You've written $(wildcard *.remote.server.com) and presumably you don't have a file that matched the glob *.remote.server.com, which means the wildcard function expands to the empty string.

I think you might be confused about what the wildcard function does: what did you expect it to do? It has nothing whatever to do with hostnames.