Are turing makefiles ready?

Recently, at work, I was doing a transfer from Makefiles to an alternative build system. I saw in some places the rather hairy Make code using function maps, filters, and foreach constructs. This surprised me, because I believe that build scripts should be as declarative as possible.

In any case, this made me think: is there a Makefile language (let's say the last GNU makes it concrete)? Turing completed?

+39
turing-complete makefile
Aug 13 '10 at 21:58
source share
2 answers

Yes, see this . Once you have the lambda, it all goes down.

Here is a plagiarized example of fibonacci

This should be enough to create the basis for more community (I need to get back to work, or I will play more.)

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,) 

It displays squares, fibonacci numbers and factorials. There appears to be a 16-bit number size limit. Bummer.

+40
Aug 13 2018-10-10T00:
source share

Now for the negative answer: GNU is actively blocking some mechanisms for creating recursion:

1) Recursively extended variables

are not recursive in the sense of a "recursive function": they cannot be defined in terms of themselves:

 Actually make detects the infinite loop and reports an error. 

(I don’t see how they could be used in practice, by the way.)

2) Chain of rules

cannot be recursive:

 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. 

(I lost a lot of time doing this by debugging my Make files - in addition to everything else, which makes working with make files difficult.)

PS For a recent project, I wrote a patch for GNU make 3.82 that removes this restriction using the new -M option (see discussion ). This works great for me.

+6
Aug 17 '10 at 8:44
source share



All Articles