代码之家  ›  专栏  ›  技术社区  ›  Jay Conrod

生成文件图灵是否完整?

  •  44
  • Jay Conrod  · 技术社区  · 15 年前

    最近在工作中,我一直在做一些从makefile到另一个构建系统的转换。我在一些地方见过一些使用函数映射、过滤器和foreach构造的Make代码。这让我很惊讶,因为我认为构建脚本应该尽可能声明性。

    无论如何,这让我想到:Makefile语言(比如说最新的GNU make)图灵完整吗?

    2 回复  |  直到 15 年前
        1
  •  48
  •   deinst    13 年前

    this

    plagiarized 斐波那契例子

    这应该足以建立一个更普遍的基础(我必须回去工作,否则我会玩得更多)。

    dec = $(patsubst .%,%,$1)
    
    not = $(if $1,,.)
    
    lteq = $(if $1,$(if $(findstring $1,$2),.,),.)
    gteq = $(if $2,$(if $(findstring $2,$1),.,),.)
    eq = $(and $(call lteq,$1,$2),$(call gteq,$1,$2))
    lt = $(and $(call lteq,$1,$2),$(call not,$(call gteq,$1,$2)))
    
    add = $1$2
    sub = $(if $(call not,$2),$1,$(call sub,$(call dec,$1),$(call dec,$2)))
    mul = $(if $(call not,$2),$2,$(call add,$1,$(call mul,$1,$(call dec,$2))))
    fibo = $(if $(call lt,$1,..),$1,$(call add,$(call fibo,$(call dec,$1)),$(call fibo,$(call sub,$1,..))))
    fact = $(if $(call lt,$1,..),.,$(call mul,$1,$(call fact,$(call dec,$1))))
    
    numeral = $(words $(subst .,. ,$1))
    
    go = $(or $(info $(call numeral,$(call mul,$1,$1)) $(call numeral,$(call fibo,$1)) $(call numeral,$(call fact,$1)) ),$(call go,.$1))
    
    _ := $(call go,)
    

    打印出正方形,斐波那契数和阶乘。数字大小似乎有16位的限制。真倒霉。

        2
  •  9
  •   reinierpost    14 年前

    GNU make主动阻止一些机制来创建递归:

    1) Recursively expanded variables

    Actually make detects the infinite loop and reports an error.
    

    (顺便说一句,我不认为允许他们在实践中有什么用处。)

    2) Rule chaining

    也不能是递归的:

    No single implicit rule can appear more than once in a chain. (...)
    This constraint has the added benefit of preventing any infinite loop
    in the search for an implicit rule chain.
    

    (在调试makefile的过程中,我浪费了很多时间,此外还有其他一些使makefile难以维护的事情。)

    我最近写的一个项目 a patch to GNU make 3.82 -米 discussion