mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kbuild: add Makefile snippet to list compiled files
@ 2011-12-07  6:25 Christian Dietrich
  2011-12-18 22:20 ` Michal Marek
  2011-12-26 15:49 ` Cong Wang
  0 siblings, 2 replies; 3+ messages in thread
From: Christian Dietrich @ 2011-12-07  6:25 UTC (permalink / raw)
  To: Michal Marek, linux-kbuild, linux-kernel; +Cc: vamos-dev

To list the compilation units compiled by the current configuration the
scripts/Makefile.list can be executed. It supports:

- printing of all compilation units
- all directories considered for compilation units
- test if a given file is compiled by the configuration
- use a different auto.conf

Signed-off-by: Christian Dietrich <christian.dietrich@informatik.uni-erlangen.de>
---
 Hi,

 the following patch is a result of our research work at VAMOS[1],
 where we try to examine the perconditions under which a file is
 compiled into the linux kernel.

 While working on this, we needed a way to get all compilation units,
 which are compiled with the current configuration. And since this
 might be useful for others, I think it would be great to have this
 possibility in the mainline kernel.

 chris

 [1] http://vamos.informatik.uni-erlangen.de

 scripts/Makefile.list           |   48 ++++++++++++++++++++++
 scripts/Makefile.list_recursion |   83 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 0 deletions(-)
 create mode 100644 scripts/Makefile.list
 create mode 100644 scripts/Makefile.list_recursion

diff --git a/scripts/Makefile.list b/scripts/Makefile.list
new file mode 100644
index 0000000..725500b
--- /dev/null
+++ b/scripts/Makefile.list
@@ -0,0 +1,48 @@
+# -*- mode: makefile -*-#
+#===============================================
+# Listing files compiled by current configuration
+#
+# For retrieving a list of files compiled into the kernel with the current
+# configuration use (in a kernel source tree)
+# - make -f scripts/Makefile.list
+#   options:
+#     print_files - print all compiles files (default: "y")
+#     print_dirs  - print all directories considered for compilation (default: "")
+#
+# If you want to check if a file is compiled by the current configuration
+# - make -f scripts/Makefile.list compiled=kernel/sched.c
+#
+# You can also override, which auto.conf should be loaded, when the source
+# tree is traversed
+# - make -f scripts/Makefile.list auto_conf=another/path/to/auto.conf
+
+list:
+
+# We include the main Makefile to get a list of all considered
+# directories.
+include $(if $(KBUILD_SRC),$(srctree)/)Makefile
+
+list-dirs      := $(addprefix _list_, . $(vmlinux-alldirs))
+
+# Default value for print_files
+print_files ?= y
+
+PHONY += $(list-dirs) list
+$(list-dirs):
+ifeq ($(compiled),)
+	$(Q)$(MAKE) $(list) \
+		auto_conf=$(auto_conf) \
+		print_dirs=$(print_dirs) \
+		print_files=$(print_files) \
+		obj=$(patsubst _list_%,%,$@)
+else
+	$(Q)$(MAKE) $(list) \
+		auto_conf=$(auto_conf) \
+		compiled=$(patsubst %.c,%.o,$(compiled)) \
+		obj=$(patsubst _list_%,%,$@)
+endif
+
+list: $(list-dirs)
+
+list := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.list_recursion
+
diff --git a/scripts/Makefile.list_recursion b/scripts/Makefile.list_recursion
new file mode 100644
index 0000000..e448a06
--- /dev/null
+++ b/scripts/Makefile.list_recursion
@@ -0,0 +1,83 @@
+# This is the recursive part of scripts/Makefile.list
+# Have a look there if you are interested in modes of operation
+#==============================================================
+src := $(obj)
+
+PHONY := __list __find
+
+ifeq ($(compiled),)
+__list:
+else
+__find:
+endif
+
+# Read auto.conf if it exists, otherwise ignore
+ifeq ($(auto_conf),)
+-include include/config/auto.conf
+else
+include $(auto_conf)
+endif
+
+# The filename Kbuild has precedence over Makefile
+kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
+include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
+
+# Figure out what we need to build from the various variables
+# ==========================================================================
+
+__subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
+subdir-y	+= $(__subdir-y)
+__subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
+subdir-m	+= $(__subdir-m)
+__subdir-n	:= $(patsubst %/,%,$(filter %/, $(obj-n)))
+subdir-n	+= $(__subdir-n)
+__subdir-	:= $(patsubst %/,%,$(filter %/, $(obj-)))
+subdir-		+= $(__subdir-)
+
+# Subdirectories we need to descend into
+subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
+subdir-ymn      := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
+
+include scripts/Makefile.lib
+
+__list: $(subdir-ym)
+ifneq ($(print_dirs),)
+	@echo $(obj)/
+endif
+ifneq ($(print_files),)
+ifneq ($(strip $(real-objs-y)),)
+	@for a in $(real-objs-y); do \
+		echo $$a y; \
+	done
+endif
+ifneq ($(strip $(real-objs-m)),)
+	@for a in $(real-objs-m); do \
+		echo $$a m; \
+	done
+endif
+endif
+	@:
+
+__find: $(foreach dir,$(subdir-ym),$(if $(filter $(dir)%,$(compiled)), $(dir)))
+ifneq ($(filter $(compiled),$(real-objs-y)),)
+	@echo $(compiled) y
+endif
+ifneq ($(filter $(compiled),$(real-objs-m)),)
+	@echo $(compiled) m
+endif
+	@:
+
+
+list := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.list_recursion
+
+PHONY += $(subdir-ym)
+$(subdir-ym):
+ifeq ($(compiled),)
+	$(Q)$(MAKE) $(list) obj=$(patsubst _list_%,%,$@)
+else
+	$(Q)$(MAKE) $(list) compiled=$(compiled) obj=$(patsubst _list_%,%,$@)
+endif
+
+# 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.
+.PHONY: $(PHONY)
-- 
1.7.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kbuild: add Makefile snippet to list compiled files
  2011-12-07  6:25 [PATCH] kbuild: add Makefile snippet to list compiled files Christian Dietrich
@ 2011-12-18 22:20 ` Michal Marek
  2011-12-26 15:49 ` Cong Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Marek @ 2011-12-18 22:20 UTC (permalink / raw)
  To: Christian Dietrich; +Cc: linux-kbuild, linux-kernel, vamos-dev

On Wed, Dec 07, 2011 at 07:25:37AM +0100, Christian Dietrich wrote:
> To list the compilation units compiled by the current configuration the
> scripts/Makefile.list can be executed. It supports:
> 
> - printing of all compilation units
> - all directories considered for compilation units
> - test if a given file is compiled by the configuration
> - use a different auto.conf
> 
> Signed-off-by: Christian Dietrich <christian.dietrich@informatik.uni-erlangen.de>
> ---
>  Hi,
> 
>  the following patch is a result of our research work at VAMOS[1],
>  where we try to examine the perconditions under which a file is
>  compiled into the linux kernel.
> 
>  While working on this, we needed a way to get all compilation units,
>  which are compiled with the current configuration. And since this
>  might be useful for others, I think it would be great to have this
>  possibility in the mainline kernel.

I agree it would be useful, I have just a couple of comments.

- The user interface should either be a target of the main makefile or
  a script. The make -f call seems a bit clumsy to me.
- You should perhaps start with less features. E.g. overriding the
  location of auto.conf is hardly needed, also the compiled= option adds
  some code, while the goal could be achieved by simply grepping the full
  output.
- The deficiency of the approach is that it misses directories that are
  only visited by an explicit make call in another makefile. An example
  is the arch/x86/boot directory on x86. This should be at least
  documented.
- The output can contain duplicates, if a object file is listed twice in
  a Makefile (e.g. arch/x86/kernel/apic/ipi.o with x86_64 defconfig)
- lib-y is not considered.
- In general, it would be good to do a comparison between the output of
  your Makefile and find -name '*.o' after a build and either fix or
  document the differences.


> +# Read auto.conf if it exists, otherwise ignore
> +ifeq ($(auto_conf),)
> +-include include/config/auto.conf
> +else
> +include $(auto_conf)
> +endif

auto.conf missing should be considered fatal.


> +# The filename Kbuild has precedence over Makefile
> +kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
> +include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
> +
> +# Figure out what we need to build from the various variables
> +# ==========================================================================
> +
> +__subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
> +subdir-y	+= $(__subdir-y)
> +__subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
> +subdir-m	+= $(__subdir-m)
> +__subdir-n	:= $(patsubst %/,%,$(filter %/, $(obj-n)))
> +subdir-n	+= $(__subdir-n)
> +__subdir-	:= $(patsubst %/,%,$(filter %/, $(obj-)))
> +subdir-		+= $(__subdir-)
> +
> +# Subdirectories we need to descend into
> +subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
> +subdir-ymn      := $(sort $(subdir-ym) $(subdir-n) $(subdir-))

You are assiging variables that are immediatelly reassigned by
Makefile.lib (if there is a special reason that I'm missing, please
explain in a comment).

Michal

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kbuild: add Makefile snippet to list compiled files
  2011-12-07  6:25 [PATCH] kbuild: add Makefile snippet to list compiled files Christian Dietrich
  2011-12-18 22:20 ` Michal Marek
@ 2011-12-26 15:49 ` Cong Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Cong Wang @ 2011-12-26 15:49 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-kbuild

On Wed, 07 Dec 2011 at 06:25 GMT, Christian Dietrich <christian.dietrich@informatik.uni-erlangen.de> wrote:
> To list the compilation units compiled by the current configuration the
> scripts/Makefile.list can be executed. It supports:
>
> - printing of all compilation units
> - all directories considered for compilation units
> - test if a given file is compiled by the configuration
> - use a different auto.conf
>

It would be nice if it can list the files complied for some
object or module. Sometimes, people wants to know which files
are compiled for some module.

Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-12-26 15:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-07  6:25 [PATCH] kbuild: add Makefile snippet to list compiled files Christian Dietrich
2011-12-18 22:20 ` Michal Marek
2011-12-26 15:49 ` Cong Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®