cannam@154: # =========================================================================== cannam@154: # Modified from https://www.gnu.org/software/autoconf-archive/ax_add_fortify_source.html cannam@154: # =========================================================================== cannam@154: # cannam@154: # SYNOPSIS cannam@154: # cannam@154: # AX_ADD_FORTIFY_SOURCE cannam@154: # cannam@154: # DESCRIPTION cannam@154: # cannam@154: # Check whether -D_FORTIFY_SOURCE=2 can be added to CFLAGS without macro cannam@154: # redefinition warnings. Some distributions (such as Gentoo Linux) enable cannam@154: # _FORTIFY_SOURCE globally in their compilers, leading to unnecessary cannam@154: # warnings in the form of cannam@154: # cannam@154: # :0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] cannam@154: # : note: this is the location of the previous definition cannam@154: # cannam@154: # which is a problem if -Werror is enabled. This macro checks whether cannam@154: # _FORTIFY_SOURCE is already defined, and if not, adds -D_FORTIFY_SOURCE=2 cannam@154: # to CFLAGS. cannam@154: # cannam@154: # LICENSE cannam@154: # cannam@154: # Copyright (c) 2017 David Seifert cannam@154: # cannam@154: # Copying and distribution of this file, with or without modification, are cannam@154: # permitted in any medium without royalty provided the copyright notice cannam@154: # and this notice are preserved. This file is offered as-is, without any cannam@154: # warranty. cannam@154: cannam@154: #serial 1 cannam@154: cannam@154: AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[ cannam@154: AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 to CFLAGS]) cannam@154: AC_LINK_IFELSE([ cannam@154: AC_LANG_SOURCE( cannam@154: [[ cannam@154: int main() { cannam@154: #ifndef _FORTIFY_SOURCE cannam@154: return 0; cannam@154: #else cannam@154: this_is_an_error; cannam@154: #endif cannam@154: } cannam@154: ]] cannam@154: )], [ cannam@154: AC_MSG_RESULT([yes]) cannam@154: CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2" cannam@154: ], [ cannam@154: AC_MSG_RESULT([no]) cannam@154: ]) cannam@154: ])