How to include .m4 files in Autoconf?
Asked Answered
M

5

26

I have downloaded a macro from Autoconf Archive, and I want to use it. What do I have to put in my configure.ac file to make use this macro?

Metaphrast answered 14/3, 2011 at 12:54 Comment(0)
C
40

You may want to add AC_CONFIG_MACRO_DIR to configure.ac to the directory where the macro is:

AC_CONFIG_MACRO_DIR([path/to/macros])

You'll need to invoke the macro somewhere in this file also.

and in Makefile.am you'll probably need to set up ACLOCAL_AMFLAGS (if you are using automake):

ACLOCAL_AMFLAGS         = -I path/to/macros

Then invoke autoreconf -fvi and you should be set.

Chanterelle answered 14/3, 2011 at 17:21 Comment(0)
G
12

I had this exact same question, and it was harder to find an answer than I thought. It looked like AC_CONFIG_MACRO_DIR was what I wanted, but if you are not using libtoolize, it appears that AC_CONFIG_MACRO_DIR is useless at present.

If you're using automake, I think the answer above is right.

I'm not using automake, so the only way I've found is to use the m4_include macro to suck in each .m4 file individually. I found this approach here:

http://www.flameeyes.eu/autotools-mythbuster/autoconf/macros.html

Hope this helps. (Considering how long autoconf has been around, it boggles my mind somewhat that there's no built-in way to just specify a directory in the .ac file. Seems like it would be an awefully common use case. Oh, well.)

Ginetteginevra answered 17/11, 2011 at 22:17 Comment(4)
"if you are not using libtoolize, it appears that AC_CONFIG_MACRO_DIR is useless at present." Why? I haven't found any documentation that suggests any association between MACRO_DIR and libtoolize.Fayola
@Fayola It's been a while, so I don't remember for sure, but I think it was by experiment that I discovered this.Ginetteginevra
Running libtoolize will create symlinks in the directory specified by AC_CONFIG_MACRO_DIR, provided you DON'T use m4_include for certain things because libtoolize fails to follow such includes (see my Q/A here: unix.stackexchange.com/questions/340633/…Cootch
Using a AC_CONFIG_MACRO_DIRS([. macro]) directive plus autoreconf made the system create a aclocal.m4 which automatically writes all the necessary imports.Christensen
B
7

As an alternative to Idav1s' solution (which is absolutely correct), you can install the macro in a location where aclocal will find it (use aclocal --print to see where aclocal is looking for .m4 files). Each approach has pros and cons. If you install the .m4 files in $(aclocal --print), you can use the macro in all of your projects without doing anything else. The primary drawback is that each developer who works on the project will have to install the macro on their box, and that requires each developer to have a reasonable understanding of the autotools.

Badinage answered 20/3, 2011 at 0:3 Comment(2)
Sorry, I have never used autoconf. How do you "you can install the macro" there?Tiv
Just copy the .m4 file that defines the macro into one of the directories that aclocal knows about. You can get the list of directories with aclocal --printBadinage
F
4

I have this issue as well, and just fixed it. My environment is: CentOS 6.4, M4 1.4.17 , autoconf 2.69, libtool 2.4, automake 1.14

Here are the steps I used.

add m4 as AC_CONFIG_MACRO_DIR to your configure.ac
rm aclocal.m4  if it exists
mkdir m4       if it does not exist
# copy some dummy files into the folder 
# or some versions of autoconf  won't work   
autoreconf -i --install    
Formulism answered 6/11, 2013 at 11:0 Comment(0)
A
3

Isn't it enough to just save the m4 macro in certain directory and run autoreconf with the -I option:

autoreconf -i -I/path/to/your/m4/file

Or did I misunderstand you and do you want to integrate it permanently, without the person running autoreconf to worry about downloading the m4 file?

Aurita answered 27/10, 2014 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.