Skip to content
Makefile 70 KiB
Newer Older
single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
		$(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
$(single-ko): single_modules
$(single-no-ko): $(build-dir)
# Remove MODORDER when done because it is not the real one.
PHONY += single_modules
single_modules: $(single-no-ko) modules_prepare
	$(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$(m:%.ko=%.o);) } > $(MODORDER)
	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
ifneq ($(KBUILD_MODPOST_NOFINAL),1)
	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
	$(Q)rm -f $(MODORDER)
single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
KBUILD_MODULES := 1

# Preset locale variables to speed up the build process. Limit locale
# tweaks to this spot to avoid wrong language settings when running
# make menuconfig etc.
# Error messages still appears in the original language
PHONY += $(build-dir)
$(build-dir): prepare
	$(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
clean-dirs := $(addprefix _clean_, $(clean-dirs))
PHONY += $(clean-dirs) clean
$(clean-dirs):
	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)

clean: $(clean-dirs)
	$(call cmd,rmfiles)
	@find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
Miguel Ojeda's avatar
Miguel Ojeda committed
		\( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
		-o -name '*.ko.*' \
		-o -name '*.dtb' -o -name '*.dtbo' \
		-o -name '*.dtb.S' -o -name '*.dtbo.S' \
		-o -name '*.dt.yaml' \
		-o -name '*.dwo' -o -name '*.lst' \
		-o -name '*.su' -o -name '*.mod' \
		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
		-o -name '*.lex.c' -o -name '*.tab.[ch]' \
		-o -name '*.asn1.[ch]' \
		-o -name '*.symtypes' -o -name 'modules.order' \
Emese Revfy's avatar
Emese Revfy committed
		-o -name '*.c.[012]*.*' \
		-o -name '*.gcno' \
		-o -name '*.*.symversions' \) -type f -print \
		-o -name '.tmp_*' -print \
		| xargs rm -rf
Linus Torvalds's avatar
Linus Torvalds committed
# Generate tags for editors
# ---------------------------------------------------------------------------
      cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@
Linus Torvalds's avatar
Linus Torvalds committed

tags TAGS cscope gtags: FORCE
Linus Torvalds's avatar
Linus Torvalds committed
	$(call cmd,tags)

# Script to generate missing namespace dependencies
# ---------------------------------------------------------------------------

PHONY += nsdeps
nsdeps: export KBUILD_NSDEPS=1
	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps
# Clang Tooling
# ---------------------------------------------------------------------------

quiet_cmd_gen_compile_commands = GEN     $@
      cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))

$(extmod_prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
	$(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \
	$(if $(CONFIG_MODULES), $(MODORDER)) FORCE
	$(call if_changed,gen_compile_commands)

targets += $(extmod_prefix)compile_commands.json
PHONY += clang-tidy clang-analyzer

ifdef CONFIG_CC_IS_CLANG
quiet_cmd_clang_tools = CHECK   $<
      cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<

clang-tidy clang-analyzer: $(extmod_prefix)compile_commands.json
	$(call cmd,clang_tools)
else
clang-tidy clang-analyzer:
	@echo "$@ requires CC=clang" >&2
	@false
endif

Linus Torvalds's avatar
Linus Torvalds committed
# Scripts to check various things for consistency
# ---------------------------------------------------------------------------

PHONY += includecheck versioncheck coccicheck export_report
Linus Torvalds's avatar
Linus Torvalds committed
includecheck:
	find $(srctree)/* $(RCS_FIND_IGNORE) \
Linus Torvalds's avatar
Linus Torvalds committed
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
Linus Torvalds's avatar
Linus Torvalds committed

versioncheck:
	find $(srctree)/* $(RCS_FIND_IGNORE) \
Linus Torvalds's avatar
Linus Torvalds committed
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
Linus Torvalds's avatar
Linus Torvalds committed

	$(Q)$(BASH) $(srctree)/scripts/$@
export_report:
	$(PERL) $(srctree)/scripts/export_report.pl

PHONY += checkstack kernelrelease kernelversion image_name
# UML needs a little special treatment here.  It wants to use the host
# toolchain, so needs $(SUBARCH) passed to checkstack.pl.  Everyone
# else wants $(ARCH), including people doing cross-builds, which means
# that $(SUBARCH) doesn't work here.
ifeq ($(ARCH), um)
CHECKSTACK_ARCH := $(SUBARCH)
else
CHECKSTACK_ARCH := $(ARCH)
endif
Linus Torvalds's avatar
Linus Torvalds committed
checkstack:
	$(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
	$(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH)
Linus Torvalds's avatar
Linus Torvalds committed

	@echo $(KERNELVERSION)
Linus Torvalds's avatar
Linus Torvalds committed

image_name:
	@echo $(KBUILD_IMAGE)

Linus Torvalds's avatar
Linus Torvalds committed
quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))
      cmd_rmfiles = rm -rf $(rm-files)
Linus Torvalds's avatar
Linus Torvalds committed

# read saved command lines for existing targets
existing-targets := $(wildcard $(sort $(targets)))
Linus Torvalds's avatar
Linus Torvalds committed

-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
Linus Torvalds's avatar
Linus Torvalds committed

endif # config-build
endif # mixed-build
endif # need-sub-make
Linus Torvalds's avatar
Linus Torvalds committed

Linus Torvalds's avatar
Linus Torvalds committed
FORCE:
# Declare the contents of the PHONY variable as phony.  We keep that
# information in a variable so we can use it in if_changed and friends.