How to change behavior according to other macro defined later?

39 Views Asked by At

Suppose I have a file tools.m4 with macro definitions:

define([YEAR_2_DIGITS], substr(YEAR, [2], [2]))

I want to use in another file query.sql:

changequote(`[', `]')
include(./tools.m4)

define([YEAR], [2017])

YEAR_2_DIGITS

But obviously it will return:

$ m4 query.sql


AR


instead of 17.

Is there a workaround to make that construct work?

1

There are 1 best solutions below

0
pietrodito On BEST ANSWER

I finally did it. One has to quote the body of the first definition:

define([YEAR_2_DIGITS], [substr(YEAR, [2], [2])])