开发者

Kernel Module Make file problem

开发者 https://www.devze.com 2023-01-14 17:42 出处:网络
This is the first time I am trying to build kernal module. Following is make file. On running make command. I get the error

This is the first time I am trying to build kernal module. Following is make file. On running make command. I get the error

/bin/sh: Syntax error: "(" unexpected

make: *** [all] Error 2

obj-m =mod.o
obj-m +=depmod.o

obj-m +=mod1.o
obj-m +=mod2.o
obj-m +=mod3.o


KDIR=/lib/modules/$(shell uname -r)/build

all:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) mo开发者_开发知识库dules
clean: 
        rm -rf $(wildcard *.o *.ko *.mod.* .c* .t* test Module.symvers *.order *.markers)


The kernel release (given by uname -r) can have parentheses in it, and in this case I'll bet it does. This means that a) it doesn't do well as part of a path, and b) the shell doesn't like receiving it in the middle of a Make command. I suggest you translate the parentheses into, say, underscores:

KDIR=/lib/modules/$(shell uname -r | sed s/[\(\)]/_/g)/build

(uname -r can also give you forward slashes, which you can deal with the same way if you have to.)


You should properly quote the arguments, i.e.

${MAKE} -C "${KDIR}" M="${PWD}" modules

Also, for clean: you should similarly use

${MAKE} -C "${KDIR}" M="${PWD}" clean

instead of trying to match all the files generated by Kbuild yourself with some wildcards (that's just not future-proof).

0

精彩评论

暂无评论...
验证码 换一张
取 消