summaryrefslogtreecommitdiff
path: root/build/ac-macros/compiler.m4
blob: 117bc1888d7060508c9f2cac12c9923be5385293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
dnl ===================================================================
dnl   Licensed to the Apache Software Foundation (ASF) under one
dnl   or more contributor license agreements.  See the NOTICE file
dnl   distributed with this work for additional information
dnl   regarding copyright ownership.  The ASF licenses this file
dnl   to you under the Apache License, Version 2.0 (the
dnl   "License"); you may not use this file except in compliance
dnl   with the License.  You may obtain a copy of the License at
dnl
dnl     http://www.apache.org/licenses/LICENSE-2.0
dnl
dnl   Unless required by applicable law or agreed to in writing,
dnl   software distributed under the License is distributed on an
dnl   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
dnl   KIND, either express or implied.  See the License for the
dnl   specific language governing permissions and limitations
dnl   under the License.
dnl ===================================================================
dnl
dnl SVN_CFLAGS_ADD_IFELSE(option, success, failure)
dnl
dnl   Check if the C compiler accepts $option. If it does, prepend it
dnl   to CFLAGS and execute $success; otherwise execute $failure.
dnl
dnl SVN_CXXFLAGS_ADD_IFELSE(option, success, failure)
dnl
dnl   Like SVN_CFLAGS_ADD_IFELSE, but for C++ and CXXFLAGS.
dnl
dnl SVN_PROG_CC: Customized replacement for AC_PROG_CC
dnl SVN_PROG_CXX: Customized replacement for AC_PROG_CXX

AC_DEFUN([_SVN_XXFLAGS_ADD_IFELSE],
[
  _svn_xxflags__save="[$][$3]"
  AC_LANG_PUSH([$1])
  AC_MSG_CHECKING([if [$][$2] accepts $5])
  [$3]="$5 [$][$3]"
  dnl Compiling is not enough: Solaris cc accepts invalid options at
  dnl compile-time and just warns, assuming they are for the linker,
  dnl but they cause errors at link-time.
  AC_LINK_IFELSE([AC_LANG_SOURCE([$4])],[
    AC_MSG_RESULT([yes])
    $6
  ],[
    AC_MSG_RESULT([no])
    [$3]="$_svn_xxflags__save"
    $7
  ])
  AC_LANG_POP([$1])
])

AC_DEFUN([SVN_CFLAGS_ADD_IFELSE],
  [_SVN_XXFLAGS_ADD_IFELSE([C],[CC],[CFLAGS],[[int main(void){return 0;}]],[$1],[$2],[$3])])

AC_DEFUN([SVN_CXXFLAGS_ADD_IFELSE],
  [_SVN_XXFLAGS_ADD_IFELSE([C++],[CXX],[CXXFLAGS],[[int main(){}]],[$1],[$2],[$3])])


AC_DEFUN([SVN_CC_MODE_SETUP],
[
  CFLAGS_KEEP="$CFLAGS"
  CFLAGS=""

  dnl Find flags to force C90 mode
                dnl gcc and clang
  SVN_CFLAGS_ADD_IFELSE([-std=c90],[],[
    SVN_CFLAGS_ADD_IFELSE([-std=c89],[],[
      SVN_CFLAGS_ADD_IFELSE([-ansi])
    ])
  ])

  CMODEFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS_KEEP"
  AC_SUBST(CMODEFLAGS)
  AC_SUBST(CMAINTAINERFLAGS)

  dnl Tell clang to not accept unknown warning flags
  SVN_CFLAGS_ADD_IFELSE([-Werror=unknown-warning-option])
])


AC_DEFUN([SVN_CXX_MODE_SETUP],
[
  CXXFLAGS_KEEP="$CXXFLAGS"
  CXXFLAGS=""

  dnl Find flags to force C++98 mode
                dnl g++ and clang++
  SVN_CXXFLAGS_ADD_IFELSE([-std=c++98])

  CXXMODEFLAGS="$CXXFLAGS"
  CXXFLAGS="$CXXFLAGS_KEEP"
  AC_SUBST(CXXMODEFLAGS)
  AC_SUBST(CXXMAINTAINERFLAGS)

  dnl Tell clang++ to not accept unknown warning flags
  SVN_CXXFLAGS_ADD_IFELSE([-Werror=unknown-warning-option])
])