Autoconf宏从头文件中读取定义并写入config.h



我正在从遗留构建环境转换为使用Autotools的构建环境。我有一个遗留头文件,其中包含大量配置值,并包括许多其他头文件。我正试图编写一个宏,可以从遗留配置头中挑选特定的定义值并将其写入config.h。我已经能够编写下面的宏来检查定义是否等于某个值并执行一些操作。我想添加一个步骤,自动将定义的值写入config.h

AC_DEFUN([ZENO_CHECK_CONFIG],
    [
        AC_CHECK_HEADERS([legacy_config.h])
        AS_IF([test "x$ac_cv_header_legacy_config_h" = "xyes"],
            [
            AC_MSG_CHECKING([for definition of $1])
            AC_EGREP_CPP([test_true],
                [
#include <legacy_config.h>
#if defined($1) && $1 == $2
test_true
#endif
                ],
                [AC_MSG_RESULT([enabled])
                $3],
                [AC_MSG_RESULT([disabled])
                $4]
            )
            ]
        )
    ]
)

直接使用AC_DEFINE或者ac_define_unquotes:

...
            [AC_MSG_RESULT([enabled])
             AC_DEFINE($1, $2)
            $3],
            [AC_MSG_RESULT([disabled])
             AC_DEFINE($1, something)
            $4]
...
dnl -------------------------------------------------------------------  
dnl check if libmqmsgque.la was build with libconfig
                                                                        
dnl # 1. add include directory
CPPFLAGS="-I$abs_builddir/../../.. $CPPFLAGS"
AC_MSG_CHECKING([for NHI1 'HAVE_LIBCONFIG' in 'msgque_config.h'])
dnl # 2. compile and run small program with failure on not found
AC_RUN_IFELSE([
  AC_LANG_PROGRAM([#include "msgque_config.h"], [                                                                               
    #ifdef HAVE_LIBCONFIG  
      return 0;  
    #else
      return 1;                                                                                                                 
    #endif  
  ])   
],[    
  AC_MSG_RESULT([found])
  AC_DEFINE(HAVE_LIBCONFIG,[1],[libmqmsgque was build with libconfig])  
],[
  AC_MSG_RESULT([not found])  
])   

最新更新