zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    TIMESTAMP类型字段在SQL Server和MySQL中的含义和使用
    Redis阻塞诊断基础
    MySQL分区表
    Redis 主从复制
    Redis安全以及备份还原
    Redis物理文件结构
    Redis的Errorlog或者启动日志(错误日志)的配置
    Redis 编译安装
    MySQL自增列锁模式 innodb_autoinc_lock_mode不同参数下性能测试
    SQL Server并发操作单个表时发生在page页面级的死锁
  • 原文地址:https://www.cnblogs.com/tomtellyou/p/12895394.html
Copyright © 2011-2022 走看看