Commit 09bd7c75 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'kbuild-v4.15' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:
 "One of the most remarkable improvements in this cycle is, Kbuild is
  now able to cache the result of shell commands. Some variables are
  expensive to compute, for example, $(call cc-option,...) invokes the
  compiler. It is not efficient to redo this computation every time,
  even when we are not actually building anything. Kbuild creates a
  hidden file ".cache.mk" that contains invoked shell commands and their
  results. The speed-up should be noticeable.

  Summary:

   - Fix arch build issues (hexagon, sh)

   - Clean up various Makefiles and scripts

   - Fix wrong usage of {CFLAGS,LDFLAGS}_MODULE in arch Makefiles

   - Cache variables that are expensive to compute

   - Improve cc-ldopton and ld-option for Clang

   - Optimize output directory creation"

* tag 'kbuild-v4.15' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (30 commits)
  kbuild: move coccicheck help from scripts/Makefile.help to top Makefile
  sh: decompressor: add shipped files to .gitignore
  frv: .gitignore: ignore vmlinux.lds
  selinux: remove unnecessary assignment to subdir-
  kbuild: specify FORCE in Makefile.headersinst as .PHONY target
  kbuild: remove redundant mkdir from ./Kbuild
  kbuild: optimize object directory creation for incremental build
  kbuild: create object directories simpler and faster
  kbuild: filter-out PHONY targets from "targets"
  kbuild: remove redundant $(wildcard ...) for cmd_files calculation
  kbuild: create directory for make cache only when necessary
  sh: select KBUILD_DEFCONFIG depending on ARCH
  kbuild: fix linker feature test macros when cross compiling with Clang
  kbuild: shrink .cache.mk when it exceeds 1000 lines
  kbuild: do not call cc-option before KBUILD_CFLAGS initialization
  kbuild: Cache a few more calls to the compiler
  kbuild: Add a cache for generated variables
  kbuild: add forward declaration of default target to Makefile.asm-generic
  kbuild: remove KBUILD_SUBDIR_ASFLAGS and KBUILD_SUBDIR_CCFLAGS
  hexagon/kbuild: replace CFLAGS_MODULE with KBUILD_CFLAGS_MODULE
  ...
parents fa7f5780 7f855fc8
...@@ -18,7 +18,6 @@ targets := kernel/bounds.s ...@@ -18,7 +18,6 @@ targets := kernel/bounds.s
# We use internal kbuild rules to avoid the "is up to date" message from make # We use internal kbuild rules to avoid the "is up to date" message from make
kernel/bounds.s: kernel/bounds.c FORCE kernel/bounds.s: kernel/bounds.c FORCE
$(Q)mkdir -p $(dir $@)
$(call if_changed_dep,cc_s_c) $(call if_changed_dep,cc_s_c)
$(obj)/$(bounds-file): kernel/bounds.s FORCE $(obj)/$(bounds-file): kernel/bounds.s FORCE
...@@ -54,7 +53,6 @@ targets += arch/$(SRCARCH)/kernel/asm-offsets.s ...@@ -54,7 +53,6 @@ targets += arch/$(SRCARCH)/kernel/asm-offsets.s
# We use internal kbuild rules to avoid the "is up to date" message from make # We use internal kbuild rules to avoid the "is up to date" message from make
arch/$(SRCARCH)/kernel/asm-offsets.s: arch/$(SRCARCH)/kernel/asm-offsets.c \ arch/$(SRCARCH)/kernel/asm-offsets.s: arch/$(SRCARCH)/kernel/asm-offsets.c \
$(obj)/$(timeconst-file) $(obj)/$(bounds-file) FORCE $(obj)/$(timeconst-file) $(obj)/$(bounds-file) FORCE
$(Q)mkdir -p $(dir $@)
$(call if_changed_dep,cc_s_c) $(call if_changed_dep,cc_s_c)
$(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE $(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
......
This diff is collapsed.
...@@ -16,11 +16,11 @@ LDFLAGS := ...@@ -16,11 +16,11 @@ LDFLAGS :=
LDFLAGS_vmlinux :=-p --no-undefined -X --pic-veneer LDFLAGS_vmlinux :=-p --no-undefined -X --pic-veneer
ifeq ($(CONFIG_CPU_ENDIAN_BE8),y) ifeq ($(CONFIG_CPU_ENDIAN_BE8),y)
LDFLAGS_vmlinux += --be8 LDFLAGS_vmlinux += --be8
LDFLAGS_MODULE += --be8 KBUILD_LDFLAGS_MODULE += --be8
endif endif
ifeq ($(CONFIG_ARM_MODULE_PLTS),y) ifeq ($(CONFIG_ARM_MODULE_PLTS),y)
LDFLAGS_MODULE += -T $(srctree)/arch/arm/kernel/module.lds KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/arm/kernel/module.lds
endif endif
GZFLAGS :=-9 GZFLAGS :=-9
...@@ -122,7 +122,7 @@ CFLAGS_ISA :=-mthumb $(AFLAGS_AUTOIT) $(AFLAGS_NOWARN) ...@@ -122,7 +122,7 @@ CFLAGS_ISA :=-mthumb $(AFLAGS_AUTOIT) $(AFLAGS_NOWARN)
AFLAGS_ISA :=$(CFLAGS_ISA) -Wa$(comma)-mthumb AFLAGS_ISA :=$(CFLAGS_ISA) -Wa$(comma)-mthumb
# Work around buggy relocation from gas if requested: # Work around buggy relocation from gas if requested:
ifeq ($(CONFIG_THUMB2_AVOID_R_ARM_THM_JUMP11),y) ifeq ($(CONFIG_THUMB2_AVOID_R_ARM_THM_JUMP11),y)
CFLAGS_MODULE +=-fno-optimize-sibling-calls KBUILD_CFLAGS_MODULE +=-fno-optimize-sibling-calls
endif endif
else else
CFLAGS_ISA :=$(call cc-option,-marm,) CFLAGS_ISA :=$(call cc-option,-marm,)
......
...@@ -12,7 +12,7 @@ cflags-y += -mno-dsbt -msdata=none -D__linux__ ...@@ -12,7 +12,7 @@ cflags-y += -mno-dsbt -msdata=none -D__linux__
cflags-$(CONFIG_C6X_BIG_KERNEL) += -mlong-calls cflags-$(CONFIG_C6X_BIG_KERNEL) += -mlong-calls
CFLAGS_MODULE += -mlong-calls -mno-dsbt -msdata=none KBUILD_CFLAGS_MODULE += -mlong-calls -mno-dsbt -msdata=none
CHECKFLAGS += CHECKFLAGS +=
......
...@@ -12,9 +12,9 @@ KBUILD_CFLAGS += -fno-short-enums ...@@ -12,9 +12,9 @@ KBUILD_CFLAGS += -fno-short-enums
# Modules must use either long-calls, or use pic/plt. # Modules must use either long-calls, or use pic/plt.
# Use long-calls for now, it's easier. And faster. # Use long-calls for now, it's easier. And faster.
# CFLAGS_MODULE += -fPIC # KBUILD_CFLAGS_MODULE += -fPIC
# LDFLAGS_MODULE += -shared # KBUILD_LDFLAGS_MODULE += -shared
CFLAGS_MODULE += -mlong-calls KBUILD_CFLAGS_MODULE += -mlong-calls
cflags-y += $(call cc-option,-mv${CONFIG_HEXAGON_ARCH_VERSION}) cflags-y += $(call cc-option,-mv${CONFIG_HEXAGON_ARCH_VERSION})
aflags-y += $(call cc-option,-mv${CONFIG_HEXAGON_ARCH_VERSION}) aflags-y += $(call cc-option,-mv${CONFIG_HEXAGON_ARCH_VERSION})
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
* 02110-1301, USA. * 02110-1301, USA.
*/ */
#include <generated/compile.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/sched/task_stack.h> #include <linux/sched/task_stack.h>
...@@ -180,7 +178,7 @@ static const struct user_regset hexagon_regsets[] = { ...@@ -180,7 +178,7 @@ static const struct user_regset hexagon_regsets[] = {
}; };
static const struct user_regset_view hexagon_user_view = { static const struct user_regset_view hexagon_user_view = {
.name = UTS_MACHINE, .name = "hexagon",
.e_machine = ELF_ARCH, .e_machine = ELF_ARCH,
.ei_osabi = ELF_OSABI, .ei_osabi = ELF_OSABI,
.regsets = hexagon_regsets, .regsets = hexagon_regsets,
......
...@@ -15,6 +15,12 @@ ifneq ($(SUBARCH),$(ARCH)) ...@@ -15,6 +15,12 @@ ifneq ($(SUBARCH),$(ARCH))
endif endif
endif endif
ifeq ($(ARCH),sh)
KBUILD_DEFCONFIG := shx3_defconfig
else
KBUILD_DEFCONFIG := cayman_defconfig
endif
isa-y := any isa-y := any
isa-$(CONFIG_SH_DSP) := sh isa-$(CONFIG_SH_DSP) := sh
isa-$(CONFIG_CPU_SH2) := sh2 isa-$(CONFIG_CPU_SH2) := sh2
...@@ -105,14 +111,12 @@ ifdef CONFIG_SUPERH32 ...@@ -105,14 +111,12 @@ ifdef CONFIG_SUPERH32
UTS_MACHINE := sh UTS_MACHINE := sh
BITS := 32 BITS := 32
LDFLAGS_vmlinux += -e _stext LDFLAGS_vmlinux += -e _stext
KBUILD_DEFCONFIG := shx3_defconfig
else else
UTS_MACHINE := sh64 UTS_MACHINE := sh64
BITS := 64 BITS := 64
LDFLAGS_vmlinux += --defsym phys_stext=_stext-$(CONFIG_PAGE_OFFSET) \ LDFLAGS_vmlinux += --defsym phys_stext=_stext-$(CONFIG_PAGE_OFFSET) \
--defsym phys_stext_shmedia=phys_stext+1 \ --defsym phys_stext_shmedia=phys_stext+1 \
-e phys_stext_shmedia -e phys_stext_shmedia
KBUILD_DEFCONFIG := cayman_defconfig
endif endif
ifdef CONFIG_CPU_LITTLE_ENDIAN ifdef CONFIG_CPU_LITTLE_ENDIAN
......
ashiftrt.S
ashldi3.c
ashlsi3.S
ashrsi3.S
lshrsi3.S
vmlinux.bin.* vmlinux.bin.*
...@@ -130,10 +130,6 @@ $(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE ...@@ -130,10 +130,6 @@ $(obj)/vdsox32.so.dbg: $(src)/vdsox32.lds $(vobjx32s) FORCE
CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds) CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1 VDSO_LDFLAGS_vdso32.lds = -m32 -Wl,-m,elf_i386 -Wl,-soname=linux-gate.so.1
# This makes sure the $(obj) subdirectory exists even though vdso32/
# is not a kbuild sub-make subdirectory.
override obj-dirs = $(dir $(obj)) $(obj)/vdso32/
targets += vdso32/vdso32.lds targets += vdso32/vdso32.lds
targets += vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o targets += vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o
targets += vdso32/vclock_gettime.o targets += vdso32/vclock_gettime.o
......
...@@ -8,6 +8,8 @@ squote := ' ...@@ -8,6 +8,8 @@ squote := '
empty := empty :=
space := $(empty) $(empty) space := $(empty) $(empty)
space_escape := _-_SPACE_-_ space_escape := _-_SPACE_-_
right_paren := )
left_paren := (
### ###
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
...@@ -80,6 +82,71 @@ cc-cross-prefix = \ ...@@ -80,6 +82,71 @@ cc-cross-prefix = \
echo $(c); \ echo $(c); \
fi))) fi)))
# Tools for caching Makefile variables that are "expensive" to compute.
#
# Here we want to help deal with variables that take a long time to compute
# by making it easy to store these variables in a cache.
#
# The canonical example here is testing for compiler flags. On a simple system
# each call to the compiler takes 10 ms, but on a system with a compiler that's
# called through various wrappers it can take upwards of 100 ms. If we have
# 100 calls to the compiler this can take 1 second (on a simple system) or 10
# seconds (on a complicated system).
#
# The "cache" will be in Makefile syntax and can be directly included.
# Any time we try to reference a variable that's not in the cache we'll
# calculate it and store it in the cache for next time.
# Include values from last time
make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk
$(make-cache): ;
-include $(make-cache)
cached-data := $(filter __cached_%, $(.VARIABLES))
# If cache exceeds 1000 lines, shrink it down to 500.
ifneq ($(word 1000,$(cached-data)),)
$(shell tail -n 500 $(make-cache) > $(make-cache).tmp; \
mv $(make-cache).tmp $(make-cache))
endif
create-cache-dir := $(if $(KBUILD_SRC),$(if $(cache-data),,1))
# Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios)
#
# Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_'
__sanitize-opt = $(subst $$,_,$(subst $(right_paren),_,$(subst $(left_paren),_,$(subst \,_,$(subst =,_,$(subst $(space),_,$(subst $(comma),_,$(subst :,_,$(1)))))))))
# Usage: $(call shell-cached,shell_command)
# Example: $(call shell-cached,md5sum /usr/bin/gcc)
#
# If we've already seen a call to this exact shell command (even in a
# previous invocation of make!) we'll return the value. If not, we'll
# compute it and store the result for future runs.
#
# This is a bit of voodoo, but basic explanation is that if the variable
# was undefined then we'll evaluate the shell command and store the result
# into the variable. We'll then store that value in the cache and finally
# output the value.
#
# NOTE: The $$(2) here isn't actually a parameter to __run-and-store. We
# happen to know that the caller will have their shell command in $(2) so the
# result of "call"ing this will produce a reference to that $(2). The reason
# for this strangeness is to avoid an extra level of eval (and escaping) of
# $(2).
define __run-and-store
ifeq ($(origin $(1)),undefined)
$$(eval $(1) := $$(shell $$(2)))
ifeq ($(create-cache-dir),1)
$$(shell mkdir -p $(dir $(make-cache)))
$$(eval create-cache-dir :=)
endif
$$(shell echo '$(1) := $$($(1))' >> $(make-cache))
endif
endef
__shell-cached = $(eval $(call __run-and-store,$(1)))$($(1))
shell-cached = $(call __shell-cached,__cached_$(call __sanitize-opt,$(1)),$(1))
# output directory for tests below # output directory for tests below
TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/)
...@@ -87,30 +154,36 @@ TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) ...@@ -87,30 +154,36 @@ TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/)
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
# Exit code chooses option. "$$TMP" serves as a temporary file and is # Exit code chooses option. "$$TMP" serves as a temporary file and is
# automatically cleaned up. # automatically cleaned up.
try-run = $(shell set -e; \ __try-run = set -e; \
TMP="$(TMPOUT).$$$$.tmp"; \ TMP="$(TMPOUT).$$$$.tmp"; \
TMPO="$(TMPOUT).$$$$.o"; \ TMPO="$(TMPOUT).$$$$.o"; \
if ($(1)) >/dev/null 2>&1; \ if ($(1)) >/dev/null 2>&1; \
then echo "$(2)"; \ then echo "$(2)"; \
else echo "$(3)"; \ else echo "$(3)"; \
fi; \ fi; \
rm -f "$$TMP" "$$TMPO") rm -f "$$TMP" "$$TMPO"
try-run = $(shell $(__try-run))
# try-run-cached
# This works like try-run, but the result is cached.
try-run-cached = $(call shell-cached,$(__try-run))
# as-option # as-option
# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
as-option = $(call try-run,\ as-option = $(call try-run-cached,\
$(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
# as-instr # as-instr
# Usage: cflags-y += $(call as-instr,instr,option1,option2) # Usage: cflags-y += $(call as-instr,instr,option1,option2)
as-instr = $(call try-run,\ as-instr = $(call try-run-cached,\
printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
# __cc-option # __cc-option
# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) # Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
__cc-option = $(call try-run,\ __cc-option = $(call try-run-cached,\
$(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
# Do not attempt to build with gcc plugins during cc-option tests. # Do not attempt to build with gcc plugins during cc-option tests.
...@@ -130,23 +203,23 @@ hostcc-option = $(call __cc-option, $(HOSTCC),\ ...@@ -130,23 +203,23 @@ hostcc-option = $(call __cc-option, $(HOSTCC),\
# cc-option-yn # cc-option-yn
# Usage: flag := $(call cc-option-yn,-march=winchip-c6) # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
cc-option-yn = $(call try-run,\ cc-option-yn = $(call try-run-cached,\
$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
# cc-disable-warning # cc-disable-warning
# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
cc-disable-warning = $(call try-run,\ cc-disable-warning = $(call try-run-cached,\
$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
# cc-name # cc-name
# Expands to either gcc or clang # Expands to either gcc or clang
cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) cc-name = $(call shell-cached,$(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
# cc-version # cc-version
cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) cc-version = $(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
# cc-fullversion # cc-fullversion
cc-fullversion = $(shell $(CONFIG_SHELL) \ cc-fullversion = $(call shell-cached,$(CONFIG_SHELL) \
$(srctree)/scripts/gcc-version.sh -p $(CC)) $(srctree)/scripts/gcc-version.sh -p $(CC))
# cc-ifversion # cc-ifversion
...@@ -159,22 +232,23 @@ cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo ...@@ -159,22 +232,23 @@ cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo
# cc-ldoption # cc-ldoption
# Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
cc-ldoption = $(call try-run,\ cc-ldoption = $(call try-run-cached,\
$(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
# ld-option # ld-option
# Usage: LDFLAGS += $(call ld-option, -X) # Usage: LDFLAGS += $(call ld-option, -X)
ld-option = $(call try-run,\ ld-option = $(call try-run-cached,\
$(CC) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \
$(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2))
# ar-option # ar-option
# Usage: KBUILD_ARFLAGS := $(call ar-option,D) # Usage: KBUILD_ARFLAGS := $(call ar-option,D)
# Important: no spaces around options # Important: no spaces around options
ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) ar-option = $(call try-run-cached, $(AR) rc$(1) "$$TMP",$(1),$(2))
# ld-version # ld-version
# Note this is mainly for HJ Lu's 3 number binutil versions # Note this is mainly for HJ Lu's 3 number binutil versions
ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) ld-version = $(call shell-cached,$(LD) --version | $(srctree)/scripts/ld-version.sh)
# ld-ifversion # ld-ifversion
# Usage: $(call ld-ifversion, -ge, 22252, y) # Usage: $(call ld-ifversion, -ge, 22252, y)
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
# and for each file listed in this file with generic-y creates # and for each file listed in this file with generic-y creates
# a small wrapper file in $(obj) (arch/$(SRCARCH)/include/generated/$(src)) # a small wrapper file in $(obj) (arch/$(SRCARCH)/include/generated/$(src))
PHONY := all
all:
kbuild-file := $(srctree)/arch/$(SRCARCH)/include/$(src)/Kbuild kbuild-file := $(srctree)/arch/$(SRCARCH)/include/$(src)/Kbuild
-include $(kbuild-file) -include $(kbuild-file)
......
...@@ -65,15 +65,6 @@ ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(h ...@@ -65,15 +65,6 @@ ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(h
include scripts/Makefile.host include scripts/Makefile.host
endif endif
ifneq ($(KBUILD_SRC),)
# Create output directory if not already present
_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
# Create directories for object files if directory does not exist
# Needed when obj-y := dir/file.o syntax is used
_dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
endif
ifndef obj ifndef obj
$(warning kbuild: Makefile.build is included improperly) $(warning kbuild: Makefile.build is included improperly)
endif endif
...@@ -563,7 +554,7 @@ $(multi-used-m): FORCE ...@@ -563,7 +554,7 @@ $(multi-used-m): FORCE
$(call multi_depend, $(multi-used-m), .o, -objs -y -m) $(call multi_depend, $(multi-used-m), .o, -objs -y -m)
targets += $(multi-used-y) $(multi-used-m) targets += $(multi-used-y) $(multi-used-m)
targets := $(filter-out $(PHONY), $(targets))
# Descending # Descending
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
...@@ -584,13 +575,23 @@ FORCE: ...@@ -584,13 +575,23 @@ FORCE:
# optimization, we don't need to read them if the target does not # optimization, we don't need to read them if the target does not
# exist, we will rebuild anyway in that case. # exist, we will rebuild anyway in that case.
targets := $(wildcard $(sort $(targets))) cmd_files := $(wildcard $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
ifneq ($(cmd_files),) ifneq ($(cmd_files),)
include $(cmd_files) include $(cmd_files)
endif endif
ifneq ($(KBUILD_SRC),)
# Create directories for object files if they do not exist
obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
# If cmd_files exist, their directories apparently exist. Skip mkdir.
exist-dirs := $(sort $(patsubst %/,%, $(dir $(cmd_files))))
obj-dirs := $(strip $(filter-out $(exist-dirs), $(obj-dirs)))
ifneq ($(obj-dirs),)
$(shell mkdir -p $(obj-dirs))
endif
endif
# Declare the contents of the .PHONY variable as phony. We keep that # Declare the contents of the .PHONY variable as phony. We keep that
# information in a variable se we can use it in if_changed and friends. # information in a variable se we can use it in if_changed and friends.
......
...@@ -27,11 +27,11 @@ subdirs := $(patsubst $(srcdir)/%/,%,\ ...@@ -27,11 +27,11 @@ subdirs := $(patsubst $(srcdir)/%/,%,\
# Recursion # Recursion
__headers: $(subdirs) __headers: $(subdirs)
.PHONY: $(subdirs) PHONY += $(subdirs)
$(subdirs): $(subdirs):
$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@ $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@
# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi. # Skip header install/check for include/uapi and arch/$(SRCARCH)/include/uapi.
# We have only sub-directories there. # We have only sub-directories there.
skip-inst := $(if $(filter %/uapi,$(obj)),1) skip-inst := $(if $(filter %/uapi,$(obj)),1)
...@@ -115,9 +115,8 @@ $(check-file): scripts/headers_check.pl $(output-files) FORCE ...@@ -115,9 +115,8 @@ $(check-file): scripts/headers_check.pl $(output-files) FORCE
endif endif
targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard \ cmd_files := $(wildcard \
$(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
ifneq ($(cmd_files),) ifneq ($(cmd_files),)
include $(cmd_files) include $(cmd_files)
...@@ -125,6 +124,7 @@ endif ...@@ -125,6 +124,7 @@ endif
endif # skip-inst endif # skip-inst
.PHONY: $(PHONY)
PHONY += FORCE PHONY += FORCE
FORCE: ; FORCE: ;
.PHONY: $(PHONY)
checker-help:
@echo ' coccicheck - Check with Coccinelle.'
...@@ -49,15 +49,6 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) ...@@ -49,15 +49,6 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs)))) host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs)))) host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
# output directory for programs/.o files
# hostprogs-y := tools/build may have been specified.
# Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
host-objdirs := $(dir $(__hostprogs) $(host-cobjs) $(host-cxxobjs))
host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs))))
__hostprogs := $(addprefix $(obj)/,$(__hostprogs))
host-csingle := $(addprefix $(obj)/,$(host-csingle)) host-csingle := $(addprefix $(obj)/,$(host-csingle))
host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
...@@ -67,9 +58,6 @@ host-cshlib := $(addprefix $(obj)/,$(host-cshlib)) ...@@ -67,9 +58,6 @@ host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib)) host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs)) host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs)) host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
obj-dirs += $(host-objdirs)
##### #####
# Handle options to gcc. Support building with separate output directory # Handle options to gcc. Support building with separate output directory
......
...@@ -5,24 +5,25 @@ ccflags-y += $(EXTRA_CFLAGS) ...@@ -5,24 +5,25 @@ ccflags-y += $(EXTRA_CFLAGS)
cppflags-y += $(EXTRA_CPPFLAGS) cppflags-y += $(EXTRA_CPPFLAGS)
ldflags-y += $(EXTRA_LDFLAGS) ldflags-y += $(EXTRA_LDFLAGS)
# # flags that take effect in current and sub directories
# flags that take effect in sub directories KBUILD_AFLAGS += $(subdir-asflags-y)
export KBUILD_SUBDIR_ASFLAGS := $(KBUILD_SUBDIR_ASFLAGS) $(subdir-asflags-y) KBUILD_CFLAGS += $(subdir-ccflags-y)
export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
# Figure out what we need to build from the various variables # Figure out what we need to build from the various variables
# =========================================================================== # ===========================================================================
# When an object is listed to be built compiled-in and modular, # When an object is listed to be built compiled-in and modular,
# only build the compiled-in version # only build the compiled-in version
obj-m := $(filter-out $(obj-y),$(obj-m)) obj-m := $(filter-out $(obj-y),$(obj-m))
# Libraries are always collected in one lib file. # Libraries are always collected in one lib file.
# Filter out objects already built-in # Filter out objects already built-in
lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
# Determine modorder.
# Unfortunately, we don't have information about ordering between -y
# and -m subdirs. Just put -y's first.
modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
# Handle objects in subdirs # Handle objects in subdirs
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
...@@ -30,12 +31,6 @@ lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) ...@@ -30,12 +31,6 @@ lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
# and add the directory to the list of dirs to descend into: $(subdir-y) # and add the directory to the list of dirs to descend into: $(subdir-y)
# o if we encounter foo/ in $(obj-m), remove it from $(obj-m) # o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
# and add the directory to the list of dirs to descend into: $(subdir-m) # and add the directory to the list of dirs to descend into: $(subdir-m)
# Determine modorder.
# Unfortunately, we don't have information about ordering between -y
# and -m subdirs. Just put -y's first.
modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
subdir-y += $(__subdir-y) subdir-y += $(__subdir-y)
__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
...@@ -44,10 +39,9 @@ obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) ...@@ -44,10 +39,9 @@ obj-y := $(patsubst %/, %/built-in.o, $(obj-y))
obj-m := $(filter-out %/, $(obj-m)) obj-m := $(filter-out %/, $(obj-m))
# Subdirectories we need to descend into # Subdirectories we need to descend into
subdir-ym := $(sort $(subdir-y) $(subdir-m)) subdir-ym := $(sort $(subdir-y) $(subdir-m))
# if $(foo-objs) exists, foo.o is a composite object # if $(foo-objs), $(foo-y), or $(foo-m) exists, foo.o is a composite object
multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m)))) multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m))))
multi-used := $(multi-used-y) $(multi-used-m) multi-used := $(multi-used-y) $(multi-used-m)
...@@ -57,15 +51,11 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) ...@@ -57,15 +51,11 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
# objects depend on those (obviously) # objects depend on those (obviously)
multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y)))
multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)))
multi-objs := $(multi-objs-y) $(multi-objs-m)
# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
# tell kbuild to descend # tell kbuild to descend
subdir-obj-y := $(filter %/built-in.o, $(obj-y)) subdir-obj-y := $(filter %/built-in.o, $(obj-y))
# $(obj-dirs) is a list of directories that contain object files
obj-dirs := $(dir $(multi-objs) $(obj-y))
# Replace multi-part objects by their individual parts, look at local dir only # Replace multi-part objects by their individual parts, look at local dir only
real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y)
real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
...@@ -93,11 +83,9 @@ multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) ...@@ -93,11 +83,9 @@ multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y))
multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
obj-dirs := $(addprefix $(obj)/,$(obj-dirs))
# These flags are needed for modversions and compiling, so we define them here # These flags are needed for modversions and compiling, so we define them here
# already # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
# $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will
# end up in (or would, if it gets compiled in) # end up in (or would, if it gets compiled in)
# Note: Files that end up in two or more modules are compiled without the # Note: Files that end up in two or more modules are compiled without the
# KBUILD_MODNAME definition. The reason is that any made-up name would # KBUILD_MODNAME definition. The reason is that any made-up name would
...@@ -107,10 +95,10 @@ basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) ...@@ -107,10 +95,10 @@ basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
modname_flags = $(if $(filter 1,$(words $(modname))),\ modname_flags = $(if $(filter 1,$(words $(modname))),\
-DKBUILD_MODNAME=$(call name-fix,$(modname))) -DKBUILD_MODNAME=$(call name-fix,$(modname)))
orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
$(ccflags-y) $(CFLAGS_$(basetarget).o) $(ccflags-y) $(CFLAGS_$(basetarget).o)
_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \ orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
$(asflags-y) $(AFLAGS_$(basetarget).o) $(asflags-y) $(AFLAGS_$(basetarget).o)
_a_flags = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags)) _a_flags = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags))
_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
......
...@@ -143,8 +143,7 @@ FORCE: ...@@ -143,8 +143,7 @@ FORCE:
# optimization, we don't need to read them if the target does not # optimization, we don't need to read them if the target does not
# exist, we will rebuild anyway in that case. # exist, we will rebuild anyway in that case.
targets := $(wildcard $(sort $(targets))) cmd_files := $(wildcard $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
ifneq ($(cmd_files),) ifneq ($(cmd_files),)
include $(cmd_files) include $(cmd_files)
......
...@@ -188,10 +188,8 @@ sortextable() ...@@ -188,10 +188,8 @@ sortextable()
# Delete output files in case of error # Delete output files in case of error
cleanup() cleanup()
{ {
rm -f .old_version
rm -f .tmp_System.map rm -f .tmp_System.map
rm -f .tmp_kallsyms* rm -f .tmp_kallsyms*
rm -f .tmp_version
rm -f .tmp_vmlinux* rm -f .tmp_vmlinux*
rm -f built-in.o rm -f built-in.o
rm -f System.map rm -f System.map
...@@ -239,12 +237,12 @@ esac ...@@ -239,12 +237,12 @@ esac
# Update version # Update version
info GEN .version info GEN .version
if [ ! -r .version ]; then if [ -r .version ]; then
rm -f .version; VERSION=$(expr 0$(cat .version) + 1)
echo 1 >.version; echo $VERSION > .version
else else
mv .version .old_version; rm -f .version
expr 0$(cat .old_version) + 1 >.version; echo 1 > .version
fi; fi;
# final build of init/ # final build of init/
...@@ -332,6 +330,3 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then ...@@ -332,6 +330,3 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then
exit 1 exit 1
fi fi
fi fi
# We made a new kernel - delete old version file
rm -f .old_version
...@@ -28,12 +28,7 @@ LC_ALL=C ...@@ -28,12 +28,7 @@ LC_ALL=C
export LC_ALL export LC_ALL
if [ -z "$KBUILD_BUILD_VERSION" ]; then if [ -z "$KBUILD_BUILD_VERSION" ]; then
if [ -r .version ]; then VERSION=$(cat .version 2>/dev/null || echo 1)
VERSION=`cat .version`
else
VERSION=0
echo 0 > .version
fi
else else
VERSION=$KBUILD_BUILD_VERSION VERSION=$KBUILD_BUILD_VERSION
fi fi
......
subdir-y := mdp genheaders subdir-y := mdp genheaders
subdir- += mdp genheaders
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment