Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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?

share|improve this question
4  
It makes no sense to do this; just require automake 1.13. The only people who should be using automake on your project are the maintainers. –  William Pursell Apr 4 '13 at 20:22
1  
It's the (multiple) maintainers that need to be supported. –  Irfy Apr 4 '13 at 20:25
1  
If you have a maintainer that is not capable of installing and running the correct version of automake, perhaps you should reconsider that person's position on the project! –  William Pursell Apr 4 '13 at 20:27
1  
Another option is to update your test-suite(s) to use parallel-tests. The parallel-tests option is compatible with the three versions, and your build will benefit from the parallelism. –  adl Apr 12 '13 at 9:20

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
I can now confirm that this doesn't work with either 1.12 or 1.13: both do their default mode of testing (serial-tests and parallel-tests, respectively) regardless of the test setting (one of serial-tests, parallel-tests) passed to AM_INIT_AUTOMAKE. However, passing a bogus string there leads to an automake error. Any ideas? –  Irfy Apr 10 '13 at 18:34
    
Are you sure you don't have some Makefile statements that overwrites the serial-tests or parallel-tests settings somewhere? The automake test-suite contains test cases that make sure AM_INIT_AUTOMAKE([serial-tests]) works, so if you have a counterexample, you should file a bug. See git.savannah.gnu.org/cgit/automake.git/tree/t/serial-tests.sh –  adl Apr 11 '13 at 15:14
    
I've used the above code in the top-most configure.ac of a project with multiple independent subprojects, each of which have their own configure.ac. I'm afraid this doesn't propagate to them. Is there an easy way to fix this, short of putting the code in every configure.ac? (or writing an m4 script that encapsulates the shell code?) –  Irfy Apr 11 '13 at 23:15
1  
Such settings never propagates to subprojects. Why would they? In autotool-land a subproject is supposed to be buildable independently; so a "top" project could reuse resources provided from an inner project, but going the other direction should be avoided. You sure can factor this setting in a m4 file or in a script, but then the question is where you'll store this file. If you already have such a complex setup, I'd strongly suggest you don't make it more complex by trying to support different Automake versions. –  adl Apr 12 '13 at 9:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.