Commit 156f72cf authored by Kai Germaschewski's avatar Kai Germaschewski

kbuild: Assorted cleanups

    
o Provide $(obj),$(objtree) and friends in the top-level Makefile as well
  for consistency (Sam Ravnborg)
o Make $(call cmd,whatever) consistent with $(call if_changed,whatever),
  i.e. both will execute $(cmd_whatever)
o Add $(echo_target), which will print the current target in a suitable
  way for the quiet output format (i.e. target name relative to the
  top-level directory)
o Fix the dependencies for host compiled programs to work for files in
  subdirectories (missed converting them when introducing $(depfile))
o Add commands which will be useful when generating boot images.
parent cec54cde
...@@ -144,6 +144,13 @@ export CPPFLAGS EXPORT_FLAGS NOSTDINC_FLAGS ...@@ -144,6 +144,13 @@ export CPPFLAGS EXPORT_FLAGS NOSTDINC_FLAGS
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
src := .
obj := .
srctree := $(TOPDIR)
objtree := $(TOPDIR)
export srctree objtree
SUBDIRS := init kernel mm fs ipc lib drivers sound net SUBDIRS := init kernel mm fs ipc lib drivers sound net
noconfig_targets := xconfig menuconfig config oldconfig randconfig \ noconfig_targets := xconfig menuconfig config oldconfig randconfig \
...@@ -255,7 +262,7 @@ define rule_link_vmlinux ...@@ -255,7 +262,7 @@ define rule_link_vmlinux
. scripts/mkversion > .tmpversion . scripts/mkversion > .tmpversion
mv -f .tmpversion .version mv -f .tmpversion .version
+$(MAKE) -C init +$(MAKE) -C init
$(call cmd,cmd_link_vmlinux) $(call cmd,link_vmlinux)
$(cmd_link_vmlinux) $(cmd_link_vmlinux)
echo 'cmd_$@ := $(cmd_link_vmlinux)' > $(@D)/.$(@F).cmd echo 'cmd_$@ := $(cmd_link_vmlinux)' > $(@D)/.$(@F).cmd
$(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map $(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
...@@ -716,9 +723,9 @@ if_changed_rule = $(if $(strip $? \ ...@@ -716,9 +723,9 @@ if_changed_rule = $(if $(strip $? \
$(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\ $(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\
@$(rule_$(1))) @$(rule_$(1)))
# If quiet is set, only print short version of rule # If quiet is set, only print short version of command
cmd = @$(if $($(quiet)$(1)),echo ' $($(quiet)$(1))' &&) $($(1)) cmd = @$(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
define update-if-changed define update-if-changed
if [ -r $@ ] && cmp -s $@ $@.tmp; then \ if [ -r $@ ] && cmp -s $@ $@.tmp; then \
......
...@@ -34,7 +34,7 @@ endif ...@@ -34,7 +34,7 @@ endif
# $(srctree)/include/linux/module.h : Some file relative to the source # $(srctree)/include/linux/module.h : Some file relative to the source
# dir root # dir root
# #
# Those can only be used in the section after # $(obj) and $(src) can only be used in the section after
# include $(TOPDIR)/Rules.make, i.e for generated files and the like. # include $(TOPDIR)/Rules.make, i.e for generated files and the like.
# Intentionally. # Intentionally.
# #
...@@ -43,8 +43,10 @@ endif ...@@ -43,8 +43,10 @@ endif
obj := . obj := .
src := . src := .
objtree := $(TOPDIR)
srctree := $(TOPDIR) # For use in the quiet output
echo_target = $(RELDIR)/$@
# Figure out what we need to build from the various variables # Figure out what we need to build from the various variables
# =========================================================================== # ===========================================================================
...@@ -269,25 +271,25 @@ c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \ ...@@ -269,25 +271,25 @@ c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
-DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) \ -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) \
$(export_flags) $(export_flags)
quiet_cmd_cc_s_c = CC $(RELDIR)/$@ quiet_cmd_cc_s_c = CC $(echo_target)
cmd_cc_s_c = $(CC) $(c_flags) -S -o $@ $< cmd_cc_s_c = $(CC) $(c_flags) -S -o $@ $<
%.s: %.c FORCE %.s: %.c FORCE
$(call if_changed_dep,cc_s_c) $(call if_changed_dep,cc_s_c)
quiet_cmd_cc_i_c = CPP $(RELDIR)/$@ quiet_cmd_cc_i_c = CPP $(echo_target)
cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $< cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
%.i: %.c FORCE %.i: %.c FORCE
$(call if_changed_dep,cc_i_c) $(call if_changed_dep,cc_i_c)
quiet_cmd_cc_o_c = CC $(RELDIR)/$@ quiet_cmd_cc_o_c = CC $(echo_target)
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
%.o: %.c FORCE %.o: %.c FORCE
$(call if_changed_dep,cc_o_c) $(call if_changed_dep,cc_o_c)
quiet_cmd_cc_lst_c = ' Generating $(RELDIR)/$@' quiet_cmd_cc_lst_c = ' Generating $(echo_target)'
cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && $(TOPDIR)/scripts/makelst $*.o $(TOPDIR)/System.map $(OBJDUMP) > $@ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && $(TOPDIR)/scripts/makelst $*.o $(TOPDIR)/System.map $(OBJDUMP) > $@
%.lst: %.c FORCE %.lst: %.c FORCE
...@@ -304,13 +306,13 @@ $(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE) ...@@ -304,13 +306,13 @@ $(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(NOSTDINC_FLAGS) \ a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(NOSTDINC_FLAGS) \
$(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o) $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
quiet_cmd_as_s_S = CPP $(RELDIR)/$@ quiet_cmd_as_s_S = CPP $(echo_target)
cmd_as_s_S = $(CPP) $(a_flags) -o $@ $< cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
%.s: %.S FORCE %.s: %.S FORCE
$(call if_changed_dep,as_s_S) $(call if_changed_dep,as_s_S)
quiet_cmd_as_o_S = AS $(RELDIR)/$@ quiet_cmd_as_o_S = AS $(echo_target)
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
%.o: %.S FORCE %.o: %.S FORCE
...@@ -328,7 +330,7 @@ $(sort $(subdir-obj-y)): sub_dirs ; ...@@ -328,7 +330,7 @@ $(sort $(subdir-obj-y)): sub_dirs ;
# Rule to compile a set of .o files into one .o file # Rule to compile a set of .o files into one .o file
# #
ifdef O_TARGET ifdef O_TARGET
quiet_cmd_link_o_target = LD $(RELDIR)/$@ quiet_cmd_link_o_target = LD $(echo_target)
# If the list of objects to link is empty, just create an empty O_TARGET # If the list of objects to link is empty, just create an empty O_TARGET
cmd_link_o_target = $(if $(strip $(obj-y)),\ cmd_link_o_target = $(if $(strip $(obj-y)),\
$(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^),\ $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^),\
...@@ -344,7 +346,7 @@ endif # O_TARGET ...@@ -344,7 +346,7 @@ endif # O_TARGET
# Rule to compile a set of .o files into one .a file # Rule to compile a set of .o files into one .a file
# #
ifdef L_TARGET ifdef L_TARGET
quiet_cmd_link_l_target = AR $(RELDIR)/$@ quiet_cmd_link_l_target = AR $(echo_target)
cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y) cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
$(L_TARGET): $(obj-y) FORCE $(L_TARGET): $(obj-y) FORCE
...@@ -357,7 +359,7 @@ endif ...@@ -357,7 +359,7 @@ endif
# Rule to link composite objects # Rule to link composite objects
# #
quiet_cmd_link_multi = LD $(RELDIR)/$@ quiet_cmd_link_multi = LD $(echo_target)
cmd_link_multi = $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $($(basename $@)-objs),$^) cmd_link_multi = $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $($(basename $@)-objs),$^)
# We would rather have a list of rules like # We would rather have a list of rules like
...@@ -379,22 +381,22 @@ host-progs-single := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m))) ...@@ -379,22 +381,22 @@ host-progs-single := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m)))
host-progs-multi := $(foreach m,$(host-progs),$(if $($(m)-objs),$(m))) host-progs-multi := $(foreach m,$(host-progs),$(if $($(m)-objs),$(m)))
host-progs-multi-objs := $(foreach m,$(host-progs-multi),$($(m)-objs)) host-progs-multi-objs := $(foreach m,$(host-progs-multi),$($(m)-objs))
quiet_cmd_host_cc__c = HOSTCC $(RELDIR)/$@ quiet_cmd_host_cc__c = HOSTCC $(echo_target)
cmd_host_cc__c = $(HOSTCC) -Wp,-MD,.$(subst /,_,$@).d \ cmd_host_cc__c = $(HOSTCC) -Wp,-MD,$(depfile) \
$(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
$(HOST_LOADLIBES) -o $@ $< $(HOST_LOADLIBES) -o $@ $<
$(host-progs-single): %: %.c FORCE $(host-progs-single): %: %.c FORCE
$(call if_changed_dep,host_cc__c) $(call if_changed_dep,host_cc__c)
quiet_cmd_host_cc_o_c = HOSTCC $(RELDIR)/$@ quiet_cmd_host_cc_o_c = HOSTCC $(echo_target)
cmd_host_cc_o_c = $(HOSTCC) -Wp,-MD,.$(subst /,_,$@).d \ cmd_host_cc_o_c = $(HOSTCC) -Wp,-MD,$(depfile) \
$(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $< $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $<
$(host-progs-multi-objs): %.o: %.c FORCE $(host-progs-multi-objs): %.o: %.c FORCE
$(call if_changed_dep,host_cc_o_c) $(call if_changed_dep,host_cc_o_c)
quiet_cmd_host_cc__o = HOSTLD $(RELDIR)/$@ quiet_cmd_host_cc__o = HOSTLD $(echo_target)
cmd_host_cc__o = $(HOSTCC) $(HOSTLDFLAGS) -o $@ $($@-objs) \ cmd_host_cc__o = $(HOSTCC) $(HOSTLDFLAGS) -o $@ $($@-objs) \
$(HOST_LOADLIBES) $(HOST_LOADLIBES)
...@@ -410,9 +412,39 @@ endif # ! fastdep ...@@ -410,9 +412,39 @@ endif # ! fastdep
# =========================================================================== # ===========================================================================
%:: %_shipped %:: %_shipped
@echo ' CP $(RELDIR)/$@' @echo ' CP $(echo_target)'
@cp $< $@ @cp $< $@
# Commands useful for building a boot image
# ===========================================================================
#
# Use as following:
#
# target: source(s) FORCE
# $(if_changed,ld/objcopy)
#
# and add target to EXTRA_TARGETS so that we know we have to
# read in the saved command line
# Linking
# ---------------------------------------------------------------------------
quiet_cmd_ld = LD $(echo_target)
cmd_ld = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_$@) \
$(filter-out FORCE,$^) -o $@
# Objcopy
# ---------------------------------------------------------------------------
quiet_cmd_objcopy = OBJCPY $(echo_target)
cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $< $@
# Gzip
# ---------------------------------------------------------------------------
quiet_cmd_gzip = GZIP $(echo_target)
cmd_gzip = gzip -f -9 < $< > $@
# =========================================================================== # ===========================================================================
# Generic stuff # Generic stuff
# =========================================================================== # ===========================================================================
...@@ -520,4 +552,4 @@ if_changed_rule = $(if $(strip $? \ ...@@ -520,4 +552,4 @@ if_changed_rule = $(if $(strip $? \
# If quiet is set, only print short version of command # If quiet is set, only print short version of command
cmd = @$(if $($(quiet)$(1)),echo ' $($(quiet)$(1))' &&) $($(1)) cmd = @$(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
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