dde_linux/create_dummies: out-of-tree build dir

This patch enables the tool/dde_linux/create_dummies tool to operate on
a out-of-tree build directory. The Linux source tree is determined by
examining the build directory's Makefile.

Issue #4188
This commit is contained in:
Norman Feske 2021-06-03 18:14:15 +02:00 committed by Christian Helmuth
parent 29b7c5a202
commit bf7500ad7b

View File

@ -117,25 +117,34 @@ endif # COMMAND=generate
ifneq ($(realpath $(LINUX_KERNEL_DIR)),)
CROSS_DEV_PREFIX ?= /usr/local/genode/tool/current/bin/genode-$(TOOL_ARCH)-
NM = $(CROSS_DEV_PREFIX)nm --print-file-name --defined-only
C_FILE_DEF := $(shell $(NM) `find $(LINUX_KERNEL_DIR) -name "*.o" | grep -v vmlinux.o` | grep -i " t " | sed 's/o:[0-f]* [tT] /c:/')
symbol_to_c_file = $(firstword $(subst :, ,$(filter %:$(1),$(C_FILE_DEF))))
# determine kernel source dir if an out-of-tree build directory is specified
LINUX_SRC_DIR := $(LINUX_KERNEL_DIR)
ifneq ($(shell grep "Automatically generated by" $(LINUX_KERNEL_DIR)/Makefile),)
LINUX_SRC_DIR := $(shell sed -n "/^include/s/.* \(.*\)\/Makefile/\\1/p" $(LINUX_KERNEL_DIR)/Makefile)
endif
CROSS_DEV_PREFIX ?= /usr/local/genode/tool/current/bin/genode-$(TOOL_ARCH)-
# gather list of <path.c>:<symbol> pairs, strip first path element (build dir)
NM = $(CROSS_DEV_PREFIX)nm --print-file-name --defined-only
C_FILE_DEF := $(shell cd $(LINUX_KERNEL_DIR); $(NM) `find -name "*.o" -printf "%P\n" | grep -v vmlinux.o` | grep -i " t " | sed -e 's/o:[0-f]* [tT] /c:/')
# query C_FILE_DEF database for a given symbol
symbol_to_c_file = $(addprefix $(LINUX_SRC_DIR)/, $(firstword $(subst :, ,$(filter %:$(1),$(C_FILE_DEF)))))
#
# Ctags database
#
HEADER_DECL := $(shell cd $(LINUX_KERNEL_DIR)/include; ctags -R -x --kinds-c=p --_xformat="%N:%F" .)
GLOBAL_VAR := $(shell cd $(LINUX_KERNEL_DIR)/include; ctags -R -x --kinds-c=x --_xformat="%N:%F" .)
HEADER_DECL := $(shell cd $(LINUX_SRC_DIR)/include; ctags -R -x --kinds-c=p --_xformat="%N:%F" .)
GLOBAL_VAR := $(shell cd $(LINUX_SRC_DIR)/include; ctags -R -x --kinds-c=x --_xformat="%N:%F" .)
func_to_h_file = $(lastword $(subst :, ,$(filter $(1):%,$(HEADER_DECL))))
do_func_to_def = $(subst :, ,$(subst typename:,,$(subst $(1): ,,$(shell ctags -x --kinds-c=f --_xformat="%N: %t %N%S" $(2) | grep "^\<$(1)\>:"))))
check_func_to_def = $(if $(2),$(call do_func_to_def,$(1),$(2)),)
func_to_def = $(call check_func_to_def,$(1),$(call symbol_to_c_file,$(1)))
var_to_h_file = $(lastword $(subst :, ,$(filter $(1):%,$(GLOBAL_VAR))))
do_var_to_def = $(subst ];,] = {};,$(subst \/,/,$(subst extern ,,$(subst $$/,,$(subst $(1): /^,,$(shell ctags -x --kinds-c=x --_xformat="%N: %P" $(LINUX_KERNEL_DIR)/include/$(2) | grep "^\<$(1)\>:"))))))
do_var_to_def = $(subst ];,] = {};,$(subst \/,/,$(subst extern ,,$(subst $$/,,$(subst $(1): /^,,$(shell ctags -x --kinds-c=x --_xformat="%N: %P" $(LINUX_SRC_DIR)/include/$(2) | grep "^\<$(1)\>:"))))))
check_var_to_def = $(if $(2),$(call do_var_to_def,$(1),$(2)),)
var_to_def = $(call check_var_to_def,$(1),$(call var_to_h_file,$(1)))
@ -202,7 +211,7 @@ check_func = $(if $(2),$(call check_fdef,$(1),$(2),$(call func_to_def,$(1))),$(c
ifeq ($(realpath $(LINUX_KERNEL_DIR)),)
show_symbol = "$1"
else
show_symbol = "$1 $(foreach F,$(call symbol_to_c_file,$1),(found at $(F:.c=.o)))"
show_symbol = "$1 $(foreach F,$(call symbol_to_c_file,$1),(found at $(subst $(LINUX_SRC_DIR)/,,$(F:.c=.o))))"
endif
show: