Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect preprocessor macro in another library with Autoconf

I have an installed library we'll call it "custom_lib" which I am linking against.

I want to check if that library was installed with a specific option.

The options.h header file in that library has a list of pre-processor macros like so:

#undef THIS
#define THIS

#undef THAT
#define THAT

#undef WE_WANT_THIS_ONE
#define WE_WANT_THIS_ONE

In another project I have in my configure.ac file this test:

 OPTION_FOUND="no"
 AC_CHECK_HEADERS(custom_lib/options.h)                                             
 AC_MSG_CHECKING([is libary configured with --enable-we_want_this_one])

 #AC_EGREP_HEADER([ string to match ],                                            
 #                [ header file ],                                               
 #                [ action if found ],                                           
 #                [ action if not found ])

 AC_EGREP_HEADER([[WE_WANT_THIS_ONE]],                                                      
                 [custom_lib/options.h],                                          
                 [OPTION_FOUND="yes"],                                    
                 [OPTION_FOUND="no"])                                     

 if test "$OPTION_FOUND" = "yes"                                            
 then                                                                            
     # If we have WE_WANT_THIS_ONE check to see which compiler is being used                
     if test "$GCC" = "yes"                                                      
     then                                                                        
         if test "$CC" != "icc"                                                  
         then                                                                    
             #if compiler is not icc then add these flags                        
             CFLAGS="$CFLAGS -maes -msse4"                                       
         fi                                                                      
     fi                                                                          
     AC_MSG_RESULT([yes])                                                        
else                                                                            
     AC_MSG_RESULT([no])                                                         
fi

I then autreconf and run ./configure which always returns this message:

checking custom_lib/options.h usability... yes                                     
checking custom_lib/options.h presence... yes                                      
checking for custom_lib/options.h... yes
checking is library configured with --enable-we_want_this_one... no

Am I doing something wrong. What needs altered in the test I have in configure.ac so that autoconf can detect the pre-processor macro in options.h?

like image 712
Kaleb Avatar asked Sep 22 '15 23:09

Kaleb


1 Answers

AC_EGREP_HEADER macro doesn't perform grep on the text of the tested header but the on the output of the preprocessor running on that file.

From autoconf manual:

— Macro: AC_EGREP_HEADER (pattern, header-file, action-if-found, [action-if-not-found])

If the output of running the preprocessor on the system header file header-file matches the extended regular expression pattern, execute shell commands action-if-found, otherwise execute action-if-not-found.

You could use AC_COMPILE_IFELSE macro instead. For example (not tested):

AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include "custom_lib/options.h"
#ifndef WE_WANT_THIS_ONE
# error macro not defined
#endif
]])], [OPTION_FOUND="yes"], [OPTION_FOUND="no"])
like image 172
baf Avatar answered Sep 30 '22 15:09

baf