autoconf gives you a config.h
, which provides string macros such as PACKAGE
, PACKAGE_NAME
, PACKAGE_STRING
, PACKAGE_VERSION
, and VERSION
.
(When I use the Argp argument parser, I simply use
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <argp.h>
const char *argp_program_version = PACKAGE_STRING;
const char *argp_program_bug_address = PACKAGE_BUGREPORT;
/* et cetera */
int main(int argc, char **argv) {
error_t argp_result = argp_parse(&argp, argc, argv, 0, 0, NULL);
if (argp_result) return argp_result;
/* et cetera */
}
and then --help
, --version
, etc. just automatically work.)
You could also add
AC_CANONICAL_HOST
AC_DEFINE_UNQUOTED([CHOST], ["$host"], [Canonical host])
AC_CANONICAL_BUILD
AC_DEFINE_UNQUOTED([CBUILD], ["$build"], [Canonical build])
AC_CANONICAL_TARGET
AC_DEFINE_UNQUOTED([CTARGET], ["$target"], [Canonical target])
to your configure.ac
, if you want to have those string macros in your config.h
too. These are typically strings of the form $arch-$vendor-$kernel-$libc
, where
CHOST
is the platform that will run the software after it is built,
CBUILD
is the platform that is currently building the software, and
CTARGET
is the platform the software will act on.
(These are all the same unless you are cross-compiling or building a cross-compile toolchain.)