1

I'd like to use the shell assignment operator (i.e., !=) in a makefile that is going to be executed on FreeBSD, macOS, and Linux. Here's an example:

a!= seq 3

.PHONY: all
all: $a

.PHONY: $a
$a:
    @echo $@

Here's the expected output:

$ touch 1 2 3
$ make all
1
2
3

Unfortunately, the shell assignment operator is not supported by the GNU Make shipped with macOS Monterey 12.6.1 and the output of the example is empty. It works in more recent versions of GNU Make though (e.g., 4.4), which are likely to be encountered in recent Linux distributions.

What should I do if I want this makefile to work with any version of GNU make and bmake?

1 Answer 1

1

The solution is to use the $(shell ...) construct in addition to the shell assignment operator like this:

a= $(shell seq 3)
a!= seq 3

.PHONY: all
all: $a

.PHONY: $a
$a:
    @echo $@

The GNU Make 3.81 seems to skip the shell assignment so it uses the output of the first assignment. bmake, however, does not really care about the first assignment because the second assignment overrides it anyway.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .