当前位置: 技术问答>linux和unix
一个关于Makefile的问题
来源: 互联网 发布时间:2015-11-06
本文导语: 1 ifeq ($(KERNELRELEASE),) 2 3 KERNELDIR ?= /lib/modules/$(shell uname -r)/build 4 PWD := $(shell pwd) 5 6 else 7 obj-m := hello.o 8 endif 9 10 11 .PHONY: modules modules_install clean 12 13 modules: 14 $(MAKE) -C $(KERNELDIR)...
1 ifeq ($(KERNELRELEASE),)
2
3 KERNELDIR ?= /lib/modules/$(shell uname -r)/build
4 PWD := $(shell pwd)
5
6 else
7 obj-m := hello.o
8 endif
9
10
11 .PHONY: modules modules_install clean
12
13 modules:
14 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
15
16 modules_install:
17 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
18
19 clean:
20 rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
--------------------------------------------
以上是编译一个内核模块的Makefile,
据我实践发现第1行的条件是成立的,
但是我comment掉第7行后编译却不能生成所需文件。
第1行的条件成立,第7行的语句不是应该不起作用吗?
请高人做答。
2
3 KERNELDIR ?= /lib/modules/$(shell uname -r)/build
4 PWD := $(shell pwd)
5
6 else
7 obj-m := hello.o
8 endif
9
10
11 .PHONY: modules modules_install clean
12
13 modules:
14 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
15
16 modules_install:
17 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
18
19 clean:
20 rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
--------------------------------------------
以上是编译一个内核模块的Makefile,
据我实践发现第1行的条件是成立的,
但是我comment掉第7行后编译却不能生成所需文件。
第1行的条件成立,第7行的语句不是应该不起作用吗?
请高人做答。
|
呵呵,楼主想问题挺细.ldd3里P24作者这样说:
Once again, we are seeing the extended GNU make syntax in action. This makefile is
read twice on a typical build. When the makefile is invoked from the command line,
it notices that the KERNELRELEASE variable has not been set. It locates the kernel source
directory by taking advantage of the fact that the symbolic link build in the installed
modules directory points back at the kernel build tree. If you are not actually run-
ning the kernel that you are building for, you can supply a KERNELDIR= option on the
command line, set the KERNELDIR environment variable, or rewrite the line that sets
KERNELDIR in the makefile. Once the kernel source tree has been found, the makefile
invokes the default: target, which runs a second make command (parameterized in
the makefile as $(MAKE)) to invoke the kernel build system as described previously.
On the second reading, the makefile sets obj-m, and the kernel makefiles take care of
actually building the module.
Once again, we are seeing the extended GNU make syntax in action. This makefile is
read twice on a typical build. When the makefile is invoked from the command line,
it notices that the KERNELRELEASE variable has not been set. It locates the kernel source
directory by taking advantage of the fact that the symbolic link build in the installed
modules directory points back at the kernel build tree. If you are not actually run-
ning the kernel that you are building for, you can supply a KERNELDIR= option on the
command line, set the KERNELDIR environment variable, or rewrite the line that sets
KERNELDIR in the makefile. Once the kernel source tree has been found, the makefile
invokes the default: target, which runs a second make command (parameterized in
the makefile as $(MAKE)) to invoke the kernel build system as described previously.
On the second reading, the makefile sets obj-m, and the kernel makefiles take care of
actually building the module.
|
ifeq、else和endif。ifeq的意思表示条件语句的开始,并指定一个条件表达式,表达式包含两个参数,以逗号分隔,表达式以圆括号括起。else表示条件表达式为假的情况。endif表示一个条件语句的结束,任何一个条件表达式都应该以endif结束。我不是太能理解你的参数意义。