summaryrefslogtreecommitdiff
path: root/build/ac-macros/compiler.m4
blob: f42a30d486ecfa2db6296dab858f338af98d66c9 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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=""

  if test "$GCC" = "yes"; then
    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])
      ])
    ])
  fi

  CMODEFLAGS="$CFLAGS"
  CFLAGS=""

  if test "$GCC" = "yes"; then
    dnl Find flags to silence all warnings
    SVN_CFLAGS_ADD_IFELSE([-w])
  fi

  CNOWARNFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS_KEEP"

  AC_SUBST(CMODEFLAGS)
  AC_SUBST(CNOWARNFLAGS)
  AC_SUBST(CMAINTAINERFLAGS)
  AC_SUBST(CUSERFLAGS)

  if test "$GCC" = "yes"; then
    dnl Tell clang to not accept unknown warning flags
    SVN_CFLAGS_ADD_IFELSE([-Werror=unknown-warning-option])
  fi
])


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

  if test "$GXX" = "yes"; then
    dnl Find flags to force C++98 mode
                  dnl g++ and clang++
    SVN_CXXFLAGS_ADD_IFELSE([-std=c++98])
  fi

  CXXMODEFLAGS="$CXXFLAGS"
  CXXFLAGS=""

  if test "$GXX" = "yes"; then
    dnl Find flags to silence all warnings
    SVN_CXXFLAGS_ADD_IFELSE([-w])
  fi

  CXXNOWARNFLAGS="$CXXFLAGS"
  CXXFLAGS="$CXXFLAGS_KEEP"

  AC_SUBST(CXXMODEFLAGS)
  AC_SUBST(CXXNOWARNFLAGS)
  AC_SUBST(CXXMAINTAINERFLAGS)
  AC_SUBST(CXXUSERFLAGS)

  if test "$GXX" = "yes"; then
    dnl Tell clang++ to not accept unknown warning flags
    SVN_CXXFLAGS_ADD_IFELSE([-Werror=unknown-warning-option])
  fi
])

dnl The KWallet provider needs to use C++11 mode when using KDE 5
AC_DEFUN([SVN_CXX_MODE_SETUP11],
[
  CXXFLAGS_KEEP="$CXXFLAGS"
  CXXFLAGS=""

  if test "$GXX" = "yes"; then
    SVN_CXXFLAGS_ADD_IFELSE([-std=c++11])
  fi

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