I have a core kernel module that other kernel modules interact with. I structured such modules (conceptually):
main module/ | \drivers/ | |\driver1 |\driver2 \driver3
Since these are kernel modules, I need to compile them as follows:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
However, since the Makefile from the drivers can be called from previous directories, I need to make $(shell pwd) before calling another make (linux make). So, the Makefile now looks like this:
CURRENT_DIR := $(shell pwd) .PHONY: all all: $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURRENT_DIR) modules
So far, this is great, and it works great. The problem is this: I have a file that drivers need to include, so I have to specify the path to include. I tried it first
EXTRA_CFLAGS += -I../..
and immediately realized why it does not work (the relative path will be in / lib / module / ... not in the current directory). So I changed it to:
MAIN_MODULE_HOME := $(CURRENT_DIR)/../.. EXTRA_CFLAGS += -I$(MAIN_MODULE_HOME)
Oddly enough, this does not work! If i write
EXTRA_CFLAGS += -Ipath/I/get/from/pwd/../..
manually, it compiles! Can someone explain what I'm doing wrong? Before calling make, I echo ed $(CURRENT_DIR) and $(MAIN_MODULE_HOME) , and the variables make sense.
I know that EXTRA_CFLAGS not immediately evaluated, but since CURRENT_DIR and MAIN_MODULE_HOME declared with := , I donβt understand how things got messed up.
(If anyone can articulate a better title for the question, do it!)