makefile - HPECLab/tutorials GitHub Wiki

#Makefile tutorial ######Author: YangJian ######Email : [email protected]

##Makefile 组成 makefile包含如下几部分

  • 变量与函数定义
    myshell=bash
  • 注释
    # converting postscript to pdf
  • 包含
    -include Makefile.local
  • 规则
    main: main.o fun1.o fun2.o

显式规则

一般的显示规则如下所示 target : prerequisites commands 例如下例
hello: @echo hello world clean: @echo clean object files rm -rf *.o 运行结果如下 $ make hello hello world $ make clean clean object files rm -rf *.o $ make hello clean hello world clean object files rm -rf *.o $ make hello world

注1: commands 之前的@,阻止make 打印需要执行的命令,如echo前有@故不打印echo hello world而之打印出command执行的结果hello world
注2:如果make 后面不接target,则默认执行第一条target 注3: make 后面可以接多条target,make会依序执行这些target

依赖关系

隐式规则

自定义变量和函数

多个makefile合并

内嵌函数和内嵌变量