Skip to content

Commit

Permalink
kbuild: error out if targets prefixed with '__' are directly run
Browse files Browse the repository at this point in the history
Some targets are internal-use only.

It is tedious to care about "what if __build_one_by_one is contained
in $(MAKECMDGOALS)?" etc.

Prefix internal targets with double underscores. Stop parsing Makefile
if they are directly run.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
  • Loading branch information
masahir0y committed May 25, 2020
1 parent 93fdddf commit 121c2a1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ NAME = Kleptomaniac Octopus
# Comments in this file are targeted only to the developer, do not
# expect to learn how to build the kernel reading this file.

$(if $(filter __%, $(MAKECMDGOALS)), \
$(error targets prefixed with '__' are only for internal use))

# That's our default target when none is given on the command line
PHONY := _all
_all:
PHONY := __all
__all:

# We are using a recursive build, so we need to do a little thinking
# to get the ordering right.
Expand Down Expand Up @@ -172,13 +175,13 @@ export sub_make_done := 1

ifeq ($(need-sub-make),1)

PHONY += $(MAKECMDGOALS) sub-make
PHONY += $(MAKECMDGOALS) __sub-make

$(filter-out _all sub-make $(this-makefile), $(MAKECMDGOALS)) _all: sub-make
$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
@:

# Invoke a second make in the output directory, passing relevant variables
sub-make:
__sub-make:
$(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS)

endif # need-sub-make
Expand Down Expand Up @@ -323,7 +326,7 @@ ifdef mixed-build

PHONY += $(MAKECMDGOALS) __build_one_by_one

$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
$(MAKECMDGOALS): __build_one_by_one
@:

__build_one_by_one:
Expand Down Expand Up @@ -598,12 +601,12 @@ else #!config-build
# targets and others. In general all targets except *config targets.

# If building an external module we do not care about the all: rule
# but instead _all depend on modules
# but instead __all depend on modules
PHONY += all
ifeq ($(KBUILD_EXTMOD),)
_all: all
__all: all
else
_all: modules
__all: modules
endif

# Decide whether to build built-in, modular, or both.
Expand All @@ -625,7 +628,7 @@ endif
# in addition to whatever we do anyway.
# Just "make" or "make all" shall build modules as well

ifneq ($(filter all _all modules nsdeps,$(MAKECMDGOALS)),)
ifneq ($(filter all modules nsdeps,$(MAKECMDGOALS)),)
KBUILD_MODULES := 1
endif

Expand Down

0 comments on commit 121c2a1

Please sign in to comment.