diff --git a/kernel/gcov/Kconfig b/kernel/gcov/Kconfig index 04f4ebdc3cf5..c95d93189ecc 100644 --- a/kernel/gcov/Kconfig +++ b/kernel/gcov/Kconfig @@ -37,6 +37,10 @@ config GCOV_KERNEL config ARCH_HAS_GCOV_PROFILE_ALL def_bool n +config GCOV_PROFILE_DIRS + string "Directories to enable gcov profiling" + depends on GCOV_KERNEL + config GCOV_PROFILE_ALL bool "Profile entire Kernel" depends on !COMPILE_TEST diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 1a965fe68e01..5d80f784b922 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -147,8 +147,12 @@ _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds) # (in this order) # ifeq ($(CONFIG_GCOV_KERNEL),y) +ifneq ($(filter $(obj),$(CONFIG_GCOV_PROFILE_DIRS)),) +export GCOV_PROFILE_SUBDIR := y +endif + _c_flags += $(if $(patsubst n%,, \ - $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ + $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(GCOV_PROFILE_SUBDIR)$(CONFIG_GCOV_PROFILE_ALL)), \ $(CFLAGS_GCOV)) endif