0

I'm writing kernel modules to do unit test for a project. Due to I need to include source files inside the project, I expect to use absolute path to those files. Which would make my Makefile like this

foo-objs := dir1/src1.o dir1/src2.o
foo-objs += dir2/src3.o src4.o
foo-objs := $(addprefix $(PROJECT_ROOT),$(foo-objs))
...
all:
$(MAKE) -C /lib/modules/"$(shell uname -r)"/build M=$(PWD)

$(PROJECT_ROOT) would be a environment variable recording absolute path of the project root.

By this way, I believe is much clearer and easier to maintain many unit tests.

But when I do make, kernel Makefile try to compile $(PWD)/$(PROJECT_ROOT)/src1.o, which of course does not exist. It seems to treat all object file as relative path.

As a result, I wonder that if there is a way to make kernel Makefile for modules to recognize absolute path, thanks a lot.

  • Be familiar with `readlink`, `realpath`, and predefined kernel variables for use in *Makefile*s, i.e. `$(srctree)`. – 0andriy Jul 21 '17 at 17:57

1 Answers1

0

I know no way to make kernel's Makefiles to recognize absolute paths.

In my projects I have converted absolute paths into relative ones. This conversion is simple with CMake, but I am unsure how to do this in plain Make. You may try to use shell for such purpose, see this question.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153