All of lore.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH 03/24] kbuild: support building of per-directory mod.a
Date: Fri, 15 Jun 2018 17:11:30 +1000	[thread overview]
Message-ID: <152904669016.10587.15454151232253137450.stgit@noble> (raw)
In-Reply-To: <152904663333.10587.10934053155404014785.stgit@noble>

This patch allows a "mod.a" to be built in any
directory.  A previous patch allows that mod.a
to be included in any module or another mod.a.

This is achieved via a new pair of macros: modobj-y and modobj-m.

Anything in modobj-y is added to obj-y and is otherwise
ignored.
Anything listed in modobj-m is built, almost as though "modobj.o" was
a requested target.  The objects are then combined
into mod.a.
These objects are always built with part-of-module=y.

This is sufficient to build a module from source in
multiple directories.  Each "other" directory lists
something like
 modobj-$(CONFIG_FOO) += bar.o bar.o bat.o

and the main directory lists

 obj-$(CONFIG-FOO) = foo.o
 foo-y = other1/ ../friend/other2/ module.o

Signed-off-by: NeilBrown <neilb@suse.com>
---
 scripts/Makefile.build |   44 +++++++++++++++++++++++++++++++++-----------
 scripts/Makefile.lib   |   14 ++++++++++----
 2 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index d42091532021..703bc210f71f 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -15,6 +15,8 @@ obj-y :=
 obj-m :=
 lib-y :=
 lib-m :=
+modobj-y :=
+modobj-m :=
 always :=
 targets :=
 subdir-y :=
@@ -80,12 +82,16 @@ ifneq ($(strip $(real-obj-y) $(need-builtin)),)
 builtin-target := $(obj)/built-in.a
 endif
 
+ifneq ($(strip $(modobj-m)),)
+modobj-target := $(obj)/mod.a
+endif
+
 modorder-target := $(obj)/modules.order
 
 # We keep a list of all modules in $(MODVERDIR)
 
 __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
-	 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
+	 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target) $(modobj-target))  \
 	 $(subdir-ym) $(always)
 	@:
 
@@ -119,17 +125,19 @@ modkern_cflags =                                          \
 		$(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL))
 quiet_modtag := $(empty)   $(empty)
 
-$(real-obj-m)        : part-of-module := y
-$(real-obj-m:.o=.i)  : part-of-module := y
-$(real-obj-m:.o=.s)  : part-of-module := y
-$(real-obj-m:.o=.lst): part-of-module := y
+_mod_obj = $(real-obj-m) $(real-modobj-m)
+
+$(_mod_obj)        : part-of-module := y
+$(_mod_obj:.o=.i)  : part-of-module := y
+$(_mod_obj:.o=.s)  : part-of-module := y
+$(_mod_obj:.o=.lst): part-of-module := y
 
-$(real-obj-m)        : quiet_modtag := [M]
-$(real-obj-m:.o=.i)  : quiet_modtag := [M]
-$(real-obj-m:.o=.s)  : quiet_modtag := [M]
-$(real-obj-m:.o=.lst): quiet_modtag := [M]
+$(_mod_obj)        : quiet_modtag := [M]
+$(_mod_obj:.o=.i)  : quiet_modtag := [M]
+$(_mod_obj:.o=.s)  : quiet_modtag := [M]
+$(_mod_obj:.o=.lst): quiet_modtag := [M]
 
-$(obj-m)             : quiet_modtag := [M]
+$(obj-m)           : quiet_modtag := [M]
 
 quiet_cmd_cc_s_c = CC $(quiet_modtag)  $@
 cmd_cc_s_c       = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
@@ -413,7 +421,7 @@ $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
 	$(call if_changed_rule,as_o_S)
 
 targets += $(filter-out $(subdir-obj-y), $(real-obj-y))
-targets += $(filter-out $(subdir-obj-m), $(real-obj-m))
+targets += $(filter-out $(subdir-obj-m) $(real-modobj-m), $(real-obj-m))
 targets += $(lib-y) $(extra-y) $(MAKECMDGOALS) $(always)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
@@ -509,6 +517,20 @@ targets += $(obj)/lib-ksyms.o
 
 endif
 
+ifdef modobj-target
+
+quiet_cmd_ar_modobj = AR      $@
+      cmd_ar_modobj = rm -f $@; \
+                    $(AR) rcTP$(KBUILD_ARFLAGS) $@ $(filter $(real-modobj-m), $^)
+
+$(modobj-target): $(real-modobj-m) FORCE
+	$(call if_changed,ar_modobj)
+
+targets += $(modobj-target)
+
+endif # modobj-target
+
+
 #
 # Rule to link composite objects
 #
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index c8f643144cd6..90ee6e8c910f 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -16,12 +16,13 @@ KBUILD_CFLAGS += $(subdir-ccflags-y)
 # is exactly what happens for directories in obj-y. So move all
 # directories from obj-m to obj-y.  Then we will know that any directory
 # in real-obj-m is a component of some other object.
-obj-y := $(obj-y) $(filter %/, $(obj-m))
+obj-y := $(obj-y) $(filter %/, $(obj-m)) $(filter-out $(obj-y), $(modobj-y))
 obj-m := $(filter-out %/, $(obj-m))
 
 # When an object is listed to be built compiled-in and modular,
 # only build the compiled-in version
 obj-m := $(filter-out $(obj-y),$(obj-m))
+modobj-m := $(filter-out $(obj-y), $(modobj-m))
 
 # Libraries are always collected in one lib file.
 # Filter out objects already built-in
@@ -42,6 +43,7 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
 # including built-in.a from subdirectories
 real-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
 real-obj-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-modobj-m := $(foreach m, $(modobj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
 
 # Handle objects in subdirs
 # ---------------------------------------------------------------------------
@@ -53,8 +55,11 @@ __subdir-y	:= $(patsubst %/,%,$(filter %/, $(real-obj-y)))
 subdir-y	+= $(__subdir-y)
 __subdir-m	:= $(patsubst %/,%,$(filter %/, $(real-obj-m)))
 subdir-m	+= $(__subdir-m)
+__subdir-mo	:= $(patsubst %/,%,$(filter %/, $(real-modobj-m)))
+subdir-m	+= $(__subdir-mo)
 real-obj-y	:= $(patsubst %/, %/built-in.a, $(real-obj-y))
 real-obj-m	:= $(patsubst %/, %/mod.a, $(real-obj-m))
+real-modobj-m	:= $(patsubst %/, %/mod.a, $(real-modobj-m))
 
 # Subdirectories we need to descend into
 subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
@@ -62,9 +67,9 @@ subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
 # $(subdir-obj-y) is the list of objects in $(real-obj-y) which uses dir/ to
 # tell kbuild to descend
 subdir-obj-y := $(filter %/built-in.a, $(real-obj-y))
-# $(subdir-obj-m) is the list of objects in $(real-obj-m) which uses dir/ to
-# tell kbuild to descend
-subdir-obj-m := $(filter %/mod.a, $(real-obj-m))
+# $(subdir-obj-m) is the list of objects in $(real-obj-m) and
+# $(real-modobj-m) which use dir/ to tell kbuild to descend
+subdir-obj-m := $(filter %/mod.a, $(real-obj-m) $(real-modobj-m))
 
 # DTB
 # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
@@ -83,6 +88,7 @@ subdir-obj-y	:= $(addprefix $(obj)/,$(subdir-obj-y))
 subdir-obj-m	:= $(addprefix $(obj)/,$(subdir-obj-m))
 real-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
 real-obj-m	:= $(addprefix $(obj)/,$(real-obj-m))
+real-modobj-m	:= $(addprefix $(obj)/,$(real-modobj-m))
 single-used-m	:= $(addprefix $(obj)/,$(single-used-m))
 multi-used-m	:= $(addprefix $(obj)/,$(multi-used-m))
 subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))

  parent reply	other threads:[~2018-06-15  7:11 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-15  7:11 [lustre-devel] [PATCH 00/24] lustre - more cleanups including module reduction NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 18/24] lustre/lnet: move tracefile locking from linux-tracefile.c to tracefile.c NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 17/24] lustre: remove lustre_compat.h NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 21/24] lustre: move remainder of linux-tracefile.c to tracefile.c NeilBrown
2018-06-21  1:37   ` James Simmons
2018-06-22  3:19     ` NeilBrown
2018-06-24 20:29       ` James Simmons
2018-06-24 23:25         ` NeilBrown
2018-06-25 21:52           ` James Simmons
2018-06-15  7:11 ` NeilBrown [this message]
2018-06-15  7:11 ` [lustre-devel] [PATCH 16/24] lustre: remove redefinition of module_init() NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 06/24] lustre: build ldlm in the ldlm directory NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 05/24] kbuild: Add documentation for modobj-m NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 11/24] lustre: discard current_n*groups macros NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 04/24] kbuild: disable KBUILD_MODNAME when building for mod.a NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 24/24] lustre: discard TCD_MAX_TYPES NeilBrown
2018-06-21  1:38   ` James Simmons
2018-06-21  4:28     ` NeilBrown
2018-06-24 20:37       ` James Simmons
2018-06-24 23:26         ` NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 13/24] lustre: discard NO_QUOTA and QUOTA_OK NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 01/24] kbuild: detect directories in components of a module NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 22/24] lustre: fold cfs_tracefile_*_arch into their only callers NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 08/24] lustre: use truncate_inode_page in place of truncate_complete_page NeilBrown
2018-06-16  0:17   ` James Simmons
2018-06-16  0:52     ` NeilBrown
2018-06-16  0:59       ` Oleg Drokin
2018-06-18  2:03         ` NeilBrown
2018-06-25  0:02           ` [lustre-devel] [PATCH 1/3] lustre: use generic_error_remove_page() NeilBrown
2018-06-25  0:02             ` [lustre-devel] [PATCH 2/3] lustre: use delete_from_page_cache() for directory pages NeilBrown
2018-06-25  0:03               ` [lustre-devel] [PATCH 3/3] lustre: discard truncate_complete_page() NeilBrown
2018-06-26  0:19                 ` James Simmons
2018-06-25  0:38               ` [lustre-devel] [PATCH 2/3] lustre: use delete_from_page_cache() for directory pages Oleg Drokin
2018-06-26  0:18               ` James Simmons
2018-06-25  0:38             ` [lustre-devel] [PATCH 1/3] lustre: use generic_error_remove_page() Oleg Drokin
2018-06-25  1:57               ` NeilBrown
2018-06-26  0:26                 ` James Simmons
2018-06-26  0:14             ` James Simmons
2018-06-15  7:11 ` [lustre-devel] [PATCH 15/24] lustre: centralize TIMES_SET_FLAGS NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 07/24] lustre: merge libcfs module into lnet NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 09/24] lustre: don't use spare bits in iattr.ia_valid NeilBrown
2018-06-21  1:35   ` James Simmons
2018-06-21  4:19     ` NeilBrown
2018-06-22  2:23       ` NeilBrown
2018-06-24 20:33         ` James Simmons
2018-06-24 23:50           ` NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 20/24] lustre: move tcd locking across to tracefile.c NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 10/24] lustre: remove lustre_patchless_compat.h NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 19/24] lustre: open code cfs_trace_max_debug_mb() into cfs_trace_set_debug_mb() NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 02/24] kbuild: treat a directory listed in a composite object as foo/mod.a NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 14/24] lustre: discard ext2* bit operations NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 12/24] lustre: discard LTIME_S macro NeilBrown
2018-06-15  7:11 ` [lustre-devel] [PATCH 23/24] lustre: renamed CFS_TCD_TYPE_MAX to CFS_TCD_TYPE_CNT NeilBrown
2018-06-21  1:48 ` [lustre-devel] [PATCH 00/24] lustre - more cleanups including module reduction James Simmons
2018-06-21  2:29   ` Patrick Farrell
2018-06-21  2:57     ` James Simmons
2018-06-21  7:22       ` Andreas Dilger
2018-06-21 12:28         ` Patrick Farrell
2018-06-24 20:35           ` James Simmons
2018-06-24 23:40           ` NeilBrown
2018-06-26  1:13             ` James Simmons
2018-06-26 13:51               ` Patrick Farrell
2018-06-27  3:08                 ` NeilBrown
2018-06-27  4:00                   ` Cory Spitz
2018-06-28  1:26                     ` NeilBrown
2018-06-27 11:01                   ` Andreas Dilger
2018-06-27 12:06                     ` Patrick Farrell
2018-06-28  1:59                       ` NeilBrown
2018-06-28  2:35                         ` Patrick Farrell
2018-06-28 23:12                           ` Andreas Dilger
2018-07-05 23:47                             ` James Simmons
2018-07-06  0:01                               ` Doug Oucharek
2018-06-28 15:03                         ` Cory Spitz
2018-06-28 17:03                           ` Doug Oucharek
2018-07-04 17:54                             ` Alexey Lyashkov
2018-06-28  1:39                     ` NeilBrown
2018-06-21  3:00     ` NeilBrown
2018-06-21  3:42       ` Patrick Farrell
2018-06-24 20:39       ` James Simmons
2018-06-21  2:54   ` NeilBrown
2018-06-24 20:46     ` James Simmons
2018-06-24 23:58       ` NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=152904669016.10587.15454151232253137450.stgit@noble \
    --to=neilb@suse.com \
    --cc=lustre-devel@lists.lustre.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.