GNU Make Doc Index
文章说明
本教程使用环境
- GNU Make: 4.1
- system: ubuntu 18.04.4 LTS
~# make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
~# uname -a
Linux mylinux 4.15.0-58-generic #64-Ubuntu SMP Tue Aug 6 11:12:41 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic
make
make 是项目管理工具,主要解决 目标 与 依赖 之间的关系,能够根据用户自定义的规则增量式更新 目标。和 git 一样属于通用工具,make 不局限于代码程序,也包括文档文件管理。
makefile
make 从 makefile 文件中读取具体规则1,解析规则来执行 命令。makefile 包含多条规则,每条格则都具有如下格式:
target : prerequisites
[tab]recipe
-
target:
目标,该条规则要生成的目标,一个makefile可以有多个目标(最终目标和中间目标),但每项规则仅能有以一个目标 -
prerequisites:
依赖,生成目标所需要的所有文件列表 -
recipe:
命令,由依赖生成目标的具体命令。默认以tab启示表示该行为命令行2
a simple example
通过以以一个简单的例子感受一下,由 a.txt, b.txt 生成 add.txt
Makefile
add.txt: a.txt b.txt
cat a.txt b.txt > add.txt
clean: add.txt
rm add.txt
a.txt
I am A
b.txt
I am B
执行 make -f Makefile,会生成 add.txt
I am A
I am B
make clean 会删除 add.txt
make 简介就到此为止了
全文参考官方英文文档,进一步拓展
官方文档很重要,一定要去读,即使有现成的翻译版
本文详细介绍GNUMake4.1在Ubuntu18.04.4LTS环境下的使用方法,涵盖make作为项目管理工具的基本概念,以及通过具体实例展示如何创建和使用makefile文件来管理目标和依赖。
2253

被折叠的 条评论
为什么被折叠?



