Linux Make

语法格式:

目标:条件

(Tab键)命令

说明:

  • 目标可以是任意一个字符串称或文件名;
  • 条件可以是任意一个字符串称或文件名;
  • 执行Make脚本时,Make解释器会检查目标和条件中包含的文件的时间戳是否相同,当不同时才执行命令;

示例:

#Filename Makefile
#this file is used for show how to use makefile
$(info start working)
hello:hello.c
	echo "nothing"

hello.bin:hello.c
	@echo "now make hello.bin"
	gcc hello.c -o hello.bin

.PHONY:he
he:hello.c
	@echo "now make file"
	gcc hello.c -o hello.bin

#function
define showFirstName
	@echo $(1)
endef

define showWithoutParameters
	echo "OSS"
endef

.PHONY:name
name:
	#call function with parameters
	$(call showFirstName, AnhuiOSS, OSS)
	#call function without parameters
	$(showWithoutParameters)

 说明:

  • #符号是注释符;
  • $是函数调用符号;
  • 目标定义行前不能加空格,命令行前必须有Tab键;
  • .PHONY关键字声明的目标总是执行其指定的命令;
  • 命令行前的@符号的作用是不显示被执行的命令;

hello.c代码示例:

#include <stdio.h>    
int main(int argc, char** argv){
	printf("hello world!\n");
}

 运行方式:

make -f Makefile hello

 说明:-f用于指定被执行脚本的名称

宏(函数):Make脚本中有两种函数,分别是内置函数和用户定义函数,其中用户定义函数又分为有参和无参两类。

调用方式:

  1. 内置函数:(fname, param...);
  2. 带参用户定义函数:(call fname, param...);
  3. 无参用户定义函数:(fname);

定义方式:

define fname

#函数体

endef

猜你喜欢

转载自wangleyiang.iteye.com/blog/1765426