JamesThomasMoon
JamesThomasMoon

Reputation: 7124

mark Make target as not directly callable

How can I mark Make targets as "uncallable" or "do not call this target directly"?

For example,

common:
    touch $(VAR)  # VAR is expected to be set

foo: VAR = this
foo: common

bar: VAR = that
bar: common

I do not want users to do the following:

make common


Is there a Make idiom to mark common as uncallable?

Upvotes: 2

Views: 670

Answers (3)

itsmethemojo
itsmethemojo

Reputation: 36

you can use a specific pattern for "private targets" and check for this pattern

also targets starting with "_" seem to be not listed in auto completion

ifeq ($(findstring _,$(MAKECMDGOALS)),_)
$(error target $(MAKECMDGOALS) is private)
endif

.PHONY: public-target
public-target: _private-target
public-target:
    echo "public target"

.PHONY: _private-target
_private-target:
    echo "private target"

Upvotes: 1

MadScientist
MadScientist

Reputation: 100781

There is nothing akin to .PHONY that keeps a target from being built via the command line. You could do this though:

common:
        $(if $(VAR),,$(error You must run 'make foo' or 'make bar'))
        touch $(VAR)

Upvotes: 0

JamesThomasMoon
JamesThomasMoon

Reputation: 7124

The following would work

ifeq ($(MAKECMDGOALS),common)
$(error do not call common directly)
endif

However, writing the ifeq ($(MAKECMDGOALS), ...) is difficult for targets like

%-$(VERSION).tar:
     # create the final .tar file

Upvotes: 0

Related Questions