Makefile
基本规则:
target:prerequisties ## 目标:前置条件
command ## 命令:使用tab键开头
Makefile
文件中可使用特殊的符号简化Makefile
文件的书写。
1、$@
:表示目标文件。
2、$^
:表示所有的依赖文件。
3、$<
:表示第一个依赖文件。
例:
## drivers/staging/greybus/tools/Makefile
## %表示任何非空字符串
%.o: %.c ../greybus_protocols.h ## %.o: %.c含义:所有的.o文件依赖于所有对应的.c文件,即一个.o对应一个同名的.c
@echo ' TARGET_CC $@'
$(Q)$(CC) $(CFLAGS) -c $< -o $@ ## 编译第一个依赖文件生成目标文件,即.o文件由相同文件名的.c文件编译生成。
loopback_%: loopback_%.o
@echo ' TARGET_LD $@'
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ ## 编译所有的依赖文件生成目标文件
4、@
在命令前,表示命令正常执行,但不显示该命令。
例:
## linux内核顶层Makefile
PHONY += help
help:
@echo 'Cleaning targets:'
@echo ' clean - Remove most generated files but keep the config and'
@echo ' enough build support to build external modules'
@echo ' mrproper - Remove all generated files + config + various backup files'
@echo ' distclean - mrproper + remove editor backup and patch files'
执行make help时,显示:
root@ubuntu:/home/run/code/rockchip/kernel# make help
Cleaning targets:
clean - Remove most generated files but keep the config and
enough build support to build external modules
mrproper - Remove all generated files + config + various backup files
distclean - mrproper + remove editor backup and patch files
网友评论