How to determine AUTOMAKE_OPTIONS conditionally?

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

 AUTOMAKE_OPTIONS = serial-tests 

I would like this option to apply if and only if my version of automake is 1.12 or more. The reason is that it is necessary to maintain a consistent test harness using both the 1.11 and 1.13 machines. What is the best way to do this?


I 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 this will not work, because AUTOMAKE_OPTIONS must be set to automake runtime, and conditional conditional conditions are met at make time. Even if it worked, I would find it ridiculously verbose and bloated; Is there a better way? My gut tells me that I have to use my configure.ac to set a variable, which I will then just expand in Makefile.am , for example:

 AUTOMAKE_OPTIONS = $(SERIAL_TESTS) 

The philosophy of autoconfiguration is to test functions - can I somehow skip version checking and check for serial test options and use them if specified?

+4
source share
1 answer

Your attempt does not work, because $(shell ...) interpreted only by GNU Make, and Automake reads Makefile.am by itself and does not know anything about GNU Make functions.

Instead of trying to use AUTOMAKE_OPTIONS variables, you should try to use the arguments AM_INIT_AUTOMAKE . Since configure.ac always readable using M4, you can use shell extensions there. In addition, the parameters you set there will apply to the entire project and should not be repeated in every 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 this script, use autoconf -t AM_INIT_AUTOMAKE to track the arguments passed to AM_INIT_AUTOMAKE .

(However, I must agree with William's comment. Requirement 1.12 seems to me better for me.)

+3
source

All Articles