24

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?

petersohn
  • 11,292
  • 13
  • 61
  • 98

5 Answers5

38

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.

ldav1s
  • 15,885
  • 2
  • 53
  • 56
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.)

Chris
  • 4,734
  • 2
  • 19
  • 26
  • "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. – underscore_d Oct 22 '16 at 23:23
  • @underscore_d It's been a while, so I don't remember for sure, but I think it was by experiment that I discovered this. – Chris Oct 24 '16 at 16:55
  • 1
    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: http://unix.stackexchange.com/questions/340633/implement-inclusion-of-another-file-into-a-stream-read-from-stdin – Carlo Wood Jan 28 '17 at 19:45
  • Using a `AC_CONFIG_MACRO_DIRS([. macro])` directive plus `autoreconf` made the system create a `aclocal.m4` which automatically writes all the necessary imports. – bukzor Nov 30 '19 at 00:09
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.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • Sorry, I have never used autoconf. How do you "you can install the macro" there? – Chad Mar 10 '21 at 20:41
  • 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 --print` – William Pursell Mar 10 '21 at 20:42
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    
Nigel B
  • 3,577
  • 3
  • 34
  • 52
DAG
  • 417
  • 4
  • 7
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?

ph0t0nix
  • 535
  • 14
  • 25