| 1 |
# =========================================================================== |
| 2 |
# https://www.gnu.org/software/autoconf-archive/ax_add_fortify_source.html |
| 3 |
# =========================================================================== |
| 4 |
# |
| 5 |
# SYNOPSIS |
| 6 |
# |
| 7 |
# AX_ADD_FORTIFY_SOURCE |
| 8 |
# |
| 9 |
# DESCRIPTION |
| 10 |
# |
| 11 |
# Check whether -D_FORTIFY_SOURCE=2 can be added to CPPFLAGS without macro |
| 12 |
# redefinition warnings. Some distributions (such as Gentoo Linux) enable |
| 13 |
# _FORTIFY_SOURCE globally in their compilers, leading to unnecessary |
| 14 |
# warnings in the form of |
| 15 |
# |
| 16 |
# <command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] |
| 17 |
# <built-in>: note: this is the location of the previous definition |
| 18 |
# |
| 19 |
# which is a problem if -Werror is enabled. This macro checks whether |
| 20 |
# _FORTIFY_SOURCE is already defined, and if not, adds -D_FORTIFY_SOURCE=2 |
| 21 |
# to CPPFLAGS. |
| 22 |
# |
| 23 |
# LICENSE |
| 24 |
# |
| 25 |
# Copyright (c) 2017 David Seifert <[email protected]> |
| 26 |
# |
| 27 |
# Copying and distribution of this file, with or without modification, are |
| 28 |
# permitted in any medium without royalty provided the copyright notice |
| 29 |
# and this notice are preserved. This file is offered as-is, without any |
| 30 |
# warranty. |
| 31 |
|
| 32 |
#serial 2 |
| 33 |
|
| 34 |
AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[ |
| 35 |
AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 to CPPFLAGS]) |
| 36 |
AC_LINK_IFELSE([ |
| 37 |
AC_LANG_SOURCE( |
| 38 |
[[ |
| 39 |
int main() { |
| 40 |
#ifndef _FORTIFY_SOURCE |
| 41 |
return 0; |
| 42 |
#else |
| 43 |
this_is_an_error; |
| 44 |
#endif |
| 45 |
} |
| 46 |
]] |
| 47 |
)], [ |
| 48 |
AC_MSG_RESULT([yes]) |
| 49 |
CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2" |
| 50 |
], [ |
| 51 |
AC_MSG_RESULT([no]) |
| 52 |
]) |
| 53 |
]) |