Search code examples
shellautoconfm4

m4 - executing a shell command


I'm new to m4 and am trying to set up a macro which allows the user to specify the location of a library at configure-time ./configure --with-mylib=/path/to/lib.so.

In the m4 macro using AC_ARG_WITH, I'll check that the given file actually exists, and then store the path to said lib. MYLIB_PATH=esyscmd([dirname $withval]). This produces the error:

dirname: missing operand

The shell doesn't seem to know about $withval. How do I get it through to execute this command?

Thanks,

Andrew


Solution

  • That's because esyscmd is executed by m4 when generating your configure script, i.e. at "compile time". Use

    MYLIB_PATH=`dirname $with_mylib`
    

    instead.

    Note that $withval "is actually just the value of the shell variable named with_package, with any non-alphanumeric characters in package changed into _", so all occurrences of / will be removed and it will likely not be a valid path.