Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need an autoconf macro that detects if -m64 is a valid compiler option

Tags:

gcc

autoconf

I have code that I want to compile on all unix systems, but if -m64 i available and it works, I want the configure script to use it. How do I get autoconf to check to see if -m64 works and, if so, use it?

like image 497
vy32 Avatar asked Dec 18 '22 06:12

vy32


2 Answers

my_save_cflags="$CFLAGS"
CFLAGS=-m64
AC_MSG_CHECKING([whether CC supports -m64])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
    [AC_MSG_RESULT([yes])]
    [AM_CFLAGS=-m64],
    [AC_MSG_RESULT([no])]
)
CFLAGS="$my_save_cflags"
AC_SUBST([AM_CFLAGS])

Using AM_CFLAGS to add -m64 to the build assumes automake (or the use of AM_CFLAGS in your own non-automade makefiles.)

like image 118
William Pursell Avatar answered Apr 28 '23 02:04

William Pursell


dnl @synopsis CXX_FLAGS_CHECK [compiler flags]                                        
dnl @summary check whether compiler supports given C++ flags or not                   
AC_DEFUN([CXX_FLAG_CHECK],                                                            
[dnl                                                                                  
  AC_MSG_CHECKING([if $CXX supports $1])
  AC_LANG_PUSH([C++])
  ac_saved_cxxflags="$CXXFLAGS"                                                       
  CXXFLAGS="-Werror $1"                                                               
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],                                            
    [AC_MSG_RESULT([yes])],                                                           
    [AC_MSG_ERROR([no])]                                                              
  )                                                                                   
  CXXFLAGS="$ac_saved_cxxflags"                                                       
  AC_LANG_POP([C++])
])

And use

CXX_FLAGS_CHECK([-m64])
like image 28
Luba Tang Avatar answered Apr 28 '23 00:04

Luba Tang