第一章、Makefile 入门
1. 安装 Makefile
通常在 Mac OS 或 Linux 系统下使用 Makefile 是通过 make 命令来完成的。因此在你学习和使用 Makefile 前要确保你的电脑能够正常执行 make 命令。
需要注意的是 make 是基于终端的命令,在安装和使用时要通过命令行终端来进行。
Ubuntu Linux 下安装 Makefile
sudo apt install make
CentOS 下安装 Makefile
sudo yum install make
Mac OS 下安装 Makefile
安装 Xcode 命令行工具
xcode-select --install
验证 Makefile 是否成功安装
在 Mac OS 或 Linux 系统下打开终端,输入 make -v 命令查看 make 命令的版本信息,如果能够显示 make 的版本信息,则说明你已经安装了 make 命令。如果提示 make 命令没有找到,则说明你需要按上述方法安装 make 命令。
示例
Ubuntu Linux 成功安装的输出。
weimingze@mzstudio:~$ make -v
GNU Make 4.3
为 x86_64-pc-linux-gnu 编译
Copyright (C) 1988-2020 Free Software Foundation, Inc.
许可证:GPLv3+:GNU 通用公共许可证第 3 版或更新版本<http://gnu.org/licenses/gpl.html>。
本软件是自由软件:您可以自由修改和重新发布它。
在法律允许的范围内没有其他保证。
Mac OS 成功安装的输出。
weimz@mzstudio ~ % make -v
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
实验:
在你的电脑上安装 Makefile 的执行命令 make,然后验证是否安装成功。