PDA

View Full Version : Linux Kernel Makefiles



Kennedy
08-10-2009, 12:01 PM
I want to distribute my make environment into several sub-dirs. These are modules to the kernel, but all the sub-dirs will be out-of-stream builds. I was attempting to mimic the way the Linux kernel build works, but something is seriously missing from these files. The main directory make file looks something like this:
ifeq ($(KERNELRELEASE), )
KERNELDIR ?= ../../../kernel/linux-2.6.24.5/linux-2.6.24.5
ARCH ?= arm
CROSS_COMPILE ?= arm-unknown-linux-gnueabi-
PWD := $(shell pwd)

modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

else

EXTRA_CFLAGS += -I$(PWD)/include
obj-y += common/
obj-y += convert/
obj-y += drivers/

endif

One of the sub-dir Makefiles looks like this:
obj-y += safe_inc.o
obj-y += callback.o safe_inc.o
So, what am I doing wrong? Any ideas?

Kennedy
08-10-2009, 12:34 PM
Doh!!! I think I found it. I may need more work, but here is the bottom line:

All the obj-y stuff, should be replaced with obj-m (Modules, man, Modules!!!!).

I'll post more if I find more corrections.

Kennedy
08-27-2009, 01:25 PM
ifeq ($(KERNELRELEASE), )
KERNELDIR ?= <path to kernel>
ARCH ?= <if you are using a different arch>
CROSS_COMPILE ?= <your cross compiler>
PWD := $(shell pwd)

modules:
@$(MAKE) MYPWD=$(PWD) -C $(KERNELDIR) M=$(PWD) modules

clean:
@rm -r *.o */*.o *.ko *.mod.c .*cmd */.*cmd .tmp_versions Module.symvers

else
EXTRA_CFLAGS := -I$(MYPWD)/include

obj-m += mydriver.o
mydriver-y := drivers/mydriver.o
mydriver-y += common/some.o

obj-m += mydriver2.o
mydriver2-y := drivers/mydriver2.o
mydriver2-y += common/callback.o
mydriver2-y += convert/mydriver2.o
mydriver2-y += common/mymemory.o
mydriver2-y += common/some.o

#etc. . .

endif