2

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?

JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
  • Possible duplicate of [How can I make a target "private" in GNU make for internal use only? OR: how to best enforce target-specific variable-values?](http://stackoverflow.com/questions/26063839/how-can-i-make-a-target-private-in-gnu-make-for-internal-use-only-or-how-to) – Tsyvarev Feb 07 '16 at 18:55

3 Answers3

1

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"
0

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
JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
  • I was hoping for something more succinct. Something like the `.PHONY` label that can be applied to targets. For example, may something like `.INDIRECT` to mark the target as only indirectly callable (or not directly callable). – JamesThomasMoon Feb 03 '16 at 21:29
0

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)
MadScientist
  • 92,819
  • 9
  • 109
  • 136