build: Merge CPPFLAGS into ALL_CFLAGS
[nasm.git] / aclocal.m4
blobf216e511ebde2b511ff89e5ad75e2e845e7f3a9a
1 dnl --------------------------------------------------------------------------
2 dnl PA_ADD_CFLAGS()
3 dnl
4 dnl Attempt to add the given option to CFLAGS, if it doesn't break compilation
5 dnl --------------------------------------------------------------------------
6 AC_DEFUN(PA_ADD_CFLAGS,
7 [AC_MSG_CHECKING([if $CC accepts $1])
8  pa_add_cflags__old_cflags="$CFLAGS"
9  CFLAGS="$CFLAGS $1"
10  AC_TRY_LINK(AC_INCLUDES_DEFAULT,
11  [printf("Hello, World!\n");],
12  [AC_MSG_RESULT([yes])
13   CFLAGS="$pa_add_cflags__old_cflags ifelse([$2],[],[$1],[$2])"],
14  [AC_MSG_RESULT([no])
15   CFLAGS="$pa_add_cflags__old_cflags"])])
17 dnl --------------------------------------------------------------------------
18 dnl PA_ADD_CLDFLAGS()
19 dnl
20 dnl Attempt to add the given option to CFLAGS and LDFLAGS,
21 dnl if it doesn't break compilation
22 dnl --------------------------------------------------------------------------
23 AC_DEFUN(PA_ADD_CLDFLAGS,
24 [AC_MSG_CHECKING([if $CC accepts $1])
25  pa_add_cldflags__old_cflags="$CFLAGS"
26  CFLAGS="$CFLAGS $1"
27  pa_add_cldflags__old_ldflags="$LDFLAGS"
28  LDFLAGS="$LDFLAGS $1"
29  AC_TRY_LINK(AC_INCLUDES_DEFAULT,
30  [printf("Hello, World!\n");],
31  [AC_MSG_RESULT([yes])
32   CFLAGS="$pa_add_cldflags__old_cflags ifelse([$2],[],[$1],[$2])"
33   LDFLAGS="$pa_add_cldflags__old_ldflags ifelse([$2],[],[$1],[$2])"],
34  [AC_MSG_RESULT([no])
35   CFLAGS="$pa_add_cldflags__old_cflags"
36   LDFLAGS="$pa_add_cldflags__old_ldflags"])])
38 dnl --------------------------------------------------------------------------
39 dnl PA_VAR
40 dnl
41 dnl Canonicalize a variable name: upper case, and fold non-C characters
42 dnl to underscores.
43 dnl --------------------------------------------------------------------------
44 AC_DEFUN(PA_VAR, [patsubst(m4_toupper([$1]),[[^A-Za-z0-9_]],[_])])
46 dnl --------------------------------------------------------------------------
47 dnl PA_HAVE_FUNC
48 dnl
49 dnl Look for a function with the specified arguments which could be
50 dnl a builtin/intrinsic function.
51 dnl --------------------------------------------------------------------------
52 AC_DEFUN(PA_HAVE_FUNC,
53 [AC_MSG_CHECKING([for $1])
54 AC_TRY_LINK(AC_INCLUDES_DEFAULT, [(void)$1$2;],
55 AC_MSG_RESULT([yes])
56 AC_DEFINE(PA_VAR([HAVE_$1]), [1],
57   [Define to 1 if you have the `$1' intrinsic function.]),
58 AC_MSG_RESULT([no]))])
60 dnl --------------------------------------------------------------------------
61 dnl PA_LIBEXT
62 dnl
63 dnl Guess the library extension based on the object extension
64 dnl --------------------------------------------------------------------------
65 AC_DEFUN(PA_LIBEXT,
66 [AC_MSG_CHECKING([for suffix of library files])
67 if test x"$LIBEXT" = x; then
68   case "$OBJEXT" in
69     obj )
70       LIBEXT=lib
71       ;;
72     *)
73       LIBEXT=a
74       ;;
75   esac
77 AC_MSG_RESULT([$LIBEXT])
78 AC_SUBST([LIBEXT])])
80 dnl --------------------------------------------------------------------------
81 dnl PA_FUNC_ATTRIBUTE
82 dnl
83 dnl See if this compiler supports the equivalent of a specific gcc
84 dnl attribute on a function, using the __attribute__(()) syntax.
85 dnl All arguments except the attribute name are optional.
86 dnl PA_FUNC_ATTRIBUTE(attribute, attribute_opts, return_type,
87 dnl                   prototype_args, call_args)
88 dnl --------------------------------------------------------------------------
89 AC_DEFUN(PA_FUNC_ATTRIBUTE,
90 [AC_MSG_CHECKING([if $CC supports the $1 function attribute])
91  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
92 AC_INCLUDES_DEFAULT
93 extern ifelse([$3],[],[void *],[$3])  __attribute__(($1$2))
94   bar(ifelse([$4],[],[int],[$4]));
95 void *foo(void);
96 void *foo(void)
98         return bar(ifelse([$5],[],[1],[$5]));
100  ])],
101  [AC_MSG_RESULT([yes])
102   AC_DEFINE(PA_VAR([HAVE_FUNC_ATTRIBUTE_$1]), 1,
103     [Define to 1 if your compiler supports __attribute__(($1)) on functions])],
104  [AC_MSG_RESULT([no])])
107 dnl --------------------------------------------------------------------------
108 dnl PA_FUNC_ATTRIBUTE_ERROR
110 dnl See if this compiler supports __attribute__((error("foo")))
111 dnl The generic version of this doesn't work as it makes the compiler
112 dnl throw an error by design.
113 dnl --------------------------------------------------------------------------
114 AC_DEFUN(PA_FUNC_ATTRIBUTE_ERROR,
115 [AC_MSG_CHECKING([if $CC supports the error function attribute])
116  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
117 AC_INCLUDES_DEFAULT
118 extern void __attribute__((error("message"))) barf(void);
119 void foo(void);
120 void foo(void)
122         if (0)
123                 barf();
125  ])],
126  [AC_MSG_RESULT([yes])
127   AC_DEFINE(PA_VAR([HAVE_FUNC_ATTRIBUTE_ERROR]), 1,
128     [Define to 1 if your compiler supports __attribute__((error)) on functions])],
129  [AC_MSG_RESULT([no])])
132 dnl --------------------------------------------------------------------------
133 dnl PA_ARG_ENABLED
134 dnl PA_ARG_DISABLED
136 dnl  Simpler-to-use versions of AC_ARG_ENABLED, that include the
137 dnl  test for $enableval and the AS_HELP_STRING definition
138 dnl --------------------------------------------------------------------------
139 AC_DEFUN(PA_ARG_ENABLED,
140 [AC_ARG_ENABLE([$1], [AS_HELP_STRING([--enable-$1],[$2])], [], [enableval=no])
141  AS_IF([test x"$enableval" != xno], [$3], [$4])
144 AC_DEFUN(PA_ARG_DISABLED,
145 [AC_ARG_ENABLE([$1],[AS_HELP_STRING([--disable-$1],[$2])], [], [enableval=yes])
146  AS_IF([test x"$enableval" = xno], [$3], [$4])
149 dnl --------------------------------------------------------------------------
150 dnl PA_ADD_HEADERS()
152 dnl Call AC_CHECK_HEADERS(), and add to ac_includes_default if found
153 dnl --------------------------------------------------------------------------
154 AC_DEFUN(_PA_ADD_HEADER,
155 [AC_CHECK_HEADERS([$1],[ac_includes_default="$ac_includes_default
156 #include <$1>"])])
158 AC_DEFUN(PA_ADD_HEADERS,
159 [m4_map_args_w([$1],[_PA_ADD_HEADER(],[)])])