Irfy
Irfy

Reputation: 9587

How to define AUTOMAKE_OPTIONS conditionally?

In an autotools-based project, I currently have the following line in my Makefile.am:

AUTOMAKE_OPTIONS = serial-tests

I would like to make this option apply if and only if my automake version is 1.12 or greater. The reason is the need to support the serial test harness with both 1.11 and 1.13 automake. What is the best way to do this?


I have already tried this:

AM_VER = $(shell $(AUTOMAKE) --version | head -n1 | sed -e 's|[^0-9.]||g')
AM_VER_MAJOR = $(shell echo $(AM_VER) | cut -d. -f1)
AM_VER_MINOR = $(shell echo $(AM_VER) | cut -d. -f2)
AM_VER_PATCH = $(shell echo $(AM_VER) | cut -d. -f3)

$(info $(AM_VER_MAJOR) $(AM_VER_MINOR) $(AM_VER_PATCH))

supports_serial_tests_opt = $(shell if [ "$(AM_VER_MAJOR)" -gt 1 ] || { [ "$(AM_VER_MAJOR)" -eq 1 ] && [ "$(AM_VER_MINOR)" -ge 12 ]; }; then echo true; fi)

$(info $(supports_serial_tests_opt))

$(if $(supports_serial_tests_opt), $(eval AUTOMAKE_OPTIONS=serial-opts))

$(info $(AUTOMAKE_OPTIONS))

and it doesn't work, because AUTOMAKE_OPTIONS need to be set at automake execution time, and the function conditionals are executed at make time. Even if it worked, I would have found it ridiculously verbose and bloated; is there a better way? My gut tells me I should use my configure.ac to set a variable which I will then simply let expand in the Makefile.am, like this:

AUTOMAKE_OPTIONS = $(SERIAL_TESTS)

The philosophy behind autoconfiguration is to check for features -- can I somehow skip the version checking and check for the serial-tests option availability and use it if given?

Upvotes: 4

Views: 1876

Answers (1)

adl
adl

Reputation: 16044

Your attempt does not work because $(shell ...) is only interpreted by GNU Make, and Automake reads Makefile.am by itself and knows nothing about GNU Make's features.

Instead of trying to use the AUTOMAKE_OPTIONS variables, you should try to use the AM_INIT_AUTOMAKE arguments. Because configure.ac is always read using M4, you can use shell expansions there. Besides, the options you set there will apply to the entire project and do not need to be repeated in each Makefile.am.

For instance:

...
AM_INIT_AUTOMAKE(m4_esyscmd([case `automake --version | head -n 1` in 
                             *1.11*);; 
                             *) echo serial-tests;; 
                             esac]))
...

If you need to debug that script, use autoconf -t AM_INIT_AUTOMAKE to trace the arguments that are being passed to AM_INIT_AUTOMAKE.

(That said, I have to agree with William's comment. Requiring 1.12 seems a better move to me.)

Upvotes: 3

Related Questions