• Makefile


    Makefile语法

    <target> : <prerequisites> 
    [tab]  <commands> 
    
    - target : 即自定义的想要执行的命令
    - prerequisites: 前置条件,即执行 target 命令之前执行的命令
    - commands : 具体的执行的命令
    - .PHONY 伪指令,内置的关键字
    - 不带参数,默认执行第一个 target
    - @ 表示禁止回声,即终端不会打印真实的执行命令
    - # 表示注释
    - ${val} 表示变量,和 shell 脚本中的变量的声明和使用一致
    - 允许使用 通配符
    

    1.在命令的前面加上@,就可以关闭回声。

    // 现在再执行make test,就不会有任何输出。
    
    test:
        @# 这是测试
    

    2.伪目标

    // 声明clean是"伪目标"之后,make就不会去检查是否存在一个叫做clean的文件,而是每次运行都执行对应的命令。
    
    .PHONY: clean
    clean:
            rm *.o temp
    

    3.内置变量

    $(CC) 指向当前使用的编译器,$(MAKE) 指向当前使用的Make工具.
    $@指代当前目标,就是Make命令当前构建的那个目标。 $< 指代第一个前置条件。
    
    1. go makefile 示例

    make default : 编译
    make fmt: 格式化
    make vet: 静态检查
    make test: 运行测试
    make install: 下载依赖库
    make clean: 移除编译的二进制文件

    BINARY="example"
    VERSION=1.0.0
    BUILD=`date +%FT%T%z`
    
    PACKAGES=`go list ./... | grep -v /vendor/`
    VETPACKAGES=`go list ./... | grep -v /vendor/ | grep -v /examples/`
    GOFILES=`find . -name "*.go" -type f -not -path "./vendor/*"`
    
    default:
    	@go build -o ${BINARY} -tags=jsoniter
    
    list:
    	@echo ${PACKAGES}
    	@echo ${VETPACKAGES}
    	@echo ${GOFILES}
    
    fmt:
    	@gofmt -s -w ${GOFILES}
    
    fmt-check:
    	@diff=$$(gofmt -s -d $(GOFILES)); 
    	if [ -n "$$diff" ]; then 
    		echo "Please run 'make fmt' and commit the result:"; 
    		echo "$${diff}"; 
    		exit 1; 
    	fi;
    
    install:
    	@govendor sync -v
    
    test:
    	@go test -cpu=1,2,4 -v -tags integration ./...
    
    vet:
    	@go vet $(VETPACKAGES)
    
    docker:
        @docker build -t wuxiaoxiaoshen/example:latest .
    
    clean:
    	@if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
    
    .PHONY: default fmt fmt-check install test vet docker clean
    

    相关链接

    http://c.biancheng.net/view/7113.html

  • 相关阅读:
    SQL 数据库中将某表中的一列数据拆分作为查询条件
    SQL数据库导入数据时提示未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序。 (System.Data)
    SQL常用内置函数
    SQL常用语句
    关于网页中鼠标双击文字选中设置
    SQL数据库查询列的类型及长度
    ASP. NET MVC项目 使用iTextSharp将网页代码生成PDF文件
    eslint-config-airbnb vs prettier vs standard
    windows批处理(bat脚本)
    python日志库loguru
  • 原文地址:https://www.cnblogs.com/tomtellyou/p/12895394.html
Copyright © 2020-2023  润新知