zoukankan      html  css  js  c++  java
  • Makefile

    语法规范

    <target> : <prerequisites>
    [tab]  <commands>

    target 是一个目标,一般是一个文件,指明要构建的对象

    也可以是一个操作的名字,这称为"伪目标"(phony target)。
    比如 make clean 要删除一些文件,如果在当前目录中正好有个文件叫作clean
    make clean 就不会执行了,就认为没有必要重新构建了。为了避免这种情况
    一般明确声明clean是"伪目标":

    .PHONY: clean
    clean:
            rm *.o temp

    如果Make命令运行时没有指定目标,默认会执行Makefile文件的第一个目标。

    比如Makefile 内容如下

    .PHONY: install
    install:
            bash test.sh

    执行 make 和 执行make install 都会去执行 install target

    下面的配置中,构建gotofile 的前置条件是 fromfile,如果当前目录中,fromfile存在,
    则 make gotofile 可以正常运行。如果fromfile 不存在则需要写一条规则,来生成fromfile
    如下:

    gotofile:fromfile
            cp fromfile gotofile
    fromfile:
            echo "11111" > fromfile

    如果一次需要构建多个文件,可以使用下面的写法
    gotofile 是个伪目标,只有3个前置文件,没有任何对应命令

    gotofile:file1 file2 file3
    file1:
            echo "11111" > file1
    file2:
            echo "22222" > file2
    file3:
            echo "22222" > file3

    执行 make gotofile 就会一次性生成 file1 file2 file3
    不需要要执行3次 make file1 ; make file2 ; make file3

    一些语法

    【1】 关闭回声
    file1:
    echo "11111" > file1

    上面的makefile 在构建时会打印出命令,然后去执行,叫作“echoing” 回声。
    [root@jinkang-centos7 make]# make
    echo "11111" > file1

    关闭回声
    file1:
    @echo "11111" > file1

    【2】 变量
    txt = "hello world"
    test:
    @echo $(txt)
    #输出 hello world

    调用Shell变量是 需要在$符号前,再加个$符号

    test:
    @echo $$SHELL
    @echo $$HOME

    #输出
    # /bin/bash
    # /root
    每行命令在一个单独的shell 中执行,因此两个相关联的命令要写在一起
    test:
    export name="kangkang";echo $$name

    或者在换行前用反斜杠转义。
    test:
    export name="kangkang";
    echo $$name

     【3】循环

    循环demo1

    list=one two three
    test:
    for i in $(list);do
    echo $$i;
    done

    循环demo2
    .PHONY: test
    test:
    for file in `find ./test/ -type f`;do
    echo test >> $$file;
    done

    4 【make 传参】

    install:
    mkdir -p $(DIR)/usr/bin/
    gcc helle.c -o $(DIR)/usr/bin/hello

    make 时传参  make install  DIR=xxx

  • 相关阅读:
    实现servlet的三种方式
    java中的运算符与表达式
    封装链接数据库的工具
    java 概述
    HTTP请求方式中get和post的区别
    asp.net获取当前网址url
    利用IP安全策略关闭危险端口
    IE6 css fixed
    存储过程中使用事务详解
    windows 2003内存性能分析工具
  • 原文地址:https://www.cnblogs.com/jkklearn/p/13301551.html
Copyright © 2011-2022 走看看