0

This is the Makefile that I'm using for cross-buildig a kernel module.

export CROSS_COMPILE:=aarch64-none-linux-gnu-
export ARCH:=arm64
obj-m += chr_drv_ex1.o
export KDIR:=linux-source-5.4.0
#EXTRA_CFLAGS=-I../../qemu-5.1.0/hw/misc
#ccflags-y=-I../../qemu-5.1.0/hw/misc

all: test_chr_drv map_hugetlb test_ioctl_drv
    make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KDIR) M=$(PWD) modules

clean:
    make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KDIR) M=$(PWD) clean
    rm -f test_chr_drv map_hugetlb test_ioctl_drv

%: %.c
    $(CROSS_COMPILE)gcc $^ -o $@

Now in my chr_drv_ex1.c file, I want to include a header file placed in ../../qemu-5.1.0/hw/misc directory. What is the correct method to add this path? I saw this and tried setting EXTRA_CFLAGS and ccflags-y but none of them works(those are commented out above). Of course if I use #include "../../qemu-5.1.0/hw/misc/axpu_regs.h" in the chr_drv_ex1.c source I can compile it. But I want to use #include <axpu_regs.h>.

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • My gosh, for achieving what you want to is enough to have line 3 and possible line with `cflags-y`. – 0andriy Jul 21 '21 at 06:18
  • 1
    Does this answer your question? [Linux kernel module Makefile can't include relative paths](https://stackoverflow.com/questions/62196308/linux-kernel-module-makefile-cant-include-relative-paths) – Tsyvarev Jul 21 '21 at 09:22

1 Answers1

0

I changed the ccflags-y from

ccflags-y := -I../../qemu-5.1.0/hw/misc

to

ccflags-y := -I../../../qemu-5.1.0/hw/misc

So the include path should be specified as seen from the kernel make directory (where the Makefile for linux kernel is located. in this case linux-source-5.4.0 directory which is one step below from where I am now).

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • Learn about `$(src)` and `$(srctree)` (name of second one I don’t remember by heart, use `git grep ...` to find examples. – 0andriy Jul 21 '21 at 06:21