从简单开始,编写一个Makefile(1)

来源:互联网 发布:ftp在运输层默认端口 编辑:程序博客网 时间:2024/05/21 10:08

Makefile的工作在于指挥make更高效的来编译程序

其中最重要是

  1. 目标 target
  2. 依赖 dependency
  3. 命令 command
    三者通过规则rule关联一起

Ex1:建立一个Makefile文件

Makefile
all:    echo "Hello World"

all = target;
echo "Hello World" = command

结果
image

目的
命令行必须是Tab键开头


Ex2:

all:    echo "Hello World"test:    echo "just test"

结果
image

目的
一个Makefile可以定义多个target 调用make时,得告诉他构建的target是什么,不然就会以第一个目标座位默认目标来运行 make得到target后,会找到对应规则来构建目标,一个规则中可以根据需要存在多条命令


Ex3:

all:    @echo "Hello World"test:    @echo "just test"

结果
image

目的
@可以让程序不再显示输出的命令


Ex4:

all: test    @echo "Hello World"test:    @echo "just test"

结果
image

目的
表示all依赖于test,所以test是all的先决条件prerequisite,即先构建test再构建all,大概的格式就是

targets:prerequisite
  command
  ...


Ex5:

all test:     @echo "Hello World"

结果
image

目的
如果make中不带任何目标,那么规则中的第一个目标将被视为默认目标


0 0
原创粉丝点击