Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Some binaries save the command line used to configure them inside the binary (I don't remember any that do, otherwise I'd check the source). Is there a way to obtain the command line used as a macro in configure.ac?

For example, if I compile my code with

./configure --foo bar CXX=g++

I would like to save --foo bar CXX=g++ to a macro in config.h so it can be output by the binary using a flag

./myprogram -V
Version 1.0, compiled using: "./configure --foo bar CXX=g++"
share|improve this question
up vote 3 down vote accepted

configure is essentially a shell script bootstrapped from M4 macros, so you can use $* to grab all the arguments to ./configure. As per the autoconf manual you should do this right after AC_INIT, e.g.:

AC_INIT([My Program], 1.0, ...)
AC_DEFINE_UNQUOTED([CONFIG_FLAGS],["$config_flags"],[Flags passed to configure])

This will #define CONFIG_FLAGS in config.h.

share|improve this answer
Thanks, exactly what I was looking for! – zje Apr 7 '12 at 5:47

Your Answer


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.