Commit bc2546a6 authored by Sam Ravnborg's avatar Sam Ravnborg

kbuild: fix building single targets with make O=.. single-target

This fixes single targets build so it now works relaiably in
following cases:
- build with mixed kernel source and output files (make single-target)
- build with separate output directory (make O=.. single-target)
- external module with mixed kernel source and output files
  (make M='pwd' single-target)
- external module with separate kernel source and output files
  (make O=.. M='pwd' single-target)
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent b46da056
...@@ -1275,40 +1275,43 @@ kernelversion: ...@@ -1275,40 +1275,43 @@ kernelversion:
# Single targets # Single targets
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# The directory part is taken from first prerequisite, so this # Single targets are compatible with:
# works even with external modules # - build whith mixed source and output
# - build with separate output dir 'make O=...'
# - external modules
#
# target-dir => where to store outputfile
# build-dir => directory in kernel source tree to use
ifeq ($(KBUILD_EXTMOD),)
build-dir = $(dir $@)
target-dir = $(dir $@)
else
zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@)))
build-dir = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash))
target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
endif
%.s: %.c prepare scripts FORCE %.s: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(dir $<) $(dir $<)$(notdir $@) $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.i: %.c prepare scripts FORCE %.i: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(dir $<) $(dir $<)$(notdir $@) $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.o: %.c prepare scripts FORCE %.o: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(dir $<) $(dir $<)$(notdir $@) $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.lst: %.c prepare scripts FORCE %.lst: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(dir $<) $(dir $<)$(notdir $@) $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.s: %.S prepare scripts FORCE %.s: %.S prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(dir $<) $(dir $<)$(notdir $@) $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.o: %.S prepare scripts FORCE %.o: %.S prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(dir $<) $(dir $<)$(notdir $@) $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
# For external modules we shall include any directory of the target, # Modules
# but usual case there is no directory part. / %/: prepare scripts FORCE
# make M=`pwd` module.o => $(dir $@)=./
# make M=`pwd` foo/module.o => $(dir $@)=foo/
# make M=`pwd` / => $(dir $@)=/
ifeq ($(KBUILD_EXTMOD),)
target-dir = $(@D)
else
zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@)))
target-dir = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash))
endif
/ %/: scripts prepare FORCE
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
$(build)=$(target-dir) $(build)=$(build-dir)
%.ko: scripts FORCE %.ko: prepare scripts FORCE
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
$(build)=$(target-dir) $(@:.ko=.o) $(build)=$(build-dir) $(@:.ko=.o)
$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
# FIXME Should go into a make.lib or something # FIXME Should go into a make.lib or something
......
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