Disclaimer

The content of this blog is my personal opinion only. Although I am an employee - currently of Nvidia, in the past of other companies such as Iagination Technologies, MIPS, Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Wednesday, October 24, 2012

GMake order dependent inconsistency

I dislike how GMake is inconsistent about ordering:

You can define rules out-of-order

top-rule: sub-rule1 sub-rule2
      @echo top-rule
sub-rule1:
      @echo sub-rule1

sub-rule2:
      @echo sub-rule2

but if you want to do something like collecting the sunb rules in a variable this breaks

top-rule: $(SUBRULES)
      @echo top-rule
SUBRULES+= sub-rule1
sub-rule1:
      @echo sub-rule1

SUBRULES+= sub-rule1
sub-rule2:
      @echo sub-rule2

because the variable is expanded when encountered

It must be fixed by rearranging

SUBRULES+= sub-rule1
sub-rule1:
      @echo sub-rule1

SUBRULES+= sub-rule1
sub-rule2:
      @echo sub-rule2
top-rule: $(SUBRULES)
      @echo top-rule

Darn! But I like being able write things out of order, top-down.

In general, I like languages that have relaxed order dependencies.  Like some RTL languages (notably Intel iHDL).  Even C++ has relaxed ordering in some places.

But the inconsistencies such as above are painful and confusing.

--

Single assignment is the easiest way to do non-order dependent.

But accumulation - += - is very much required.

Q: is the accumulation done order dependent, or not?

What is needed is accumulating += - probably order dependent.
And then expanding.

With an error if expanding results in changes to variables already being expanded.  ??

Or relaxation.

No comments: