~ubuntu-branches/ubuntu/saucy/mozjs17/saucy-proposed

« back to all changes in this revision

Viewing changes to js/src/build/autoconf/compiler-opts.m4

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl This Source Code Form is subject to the terms of the Mozilla Public
 
2
dnl License, v. 2.0. If a copy of the MPL was not distributed with this
 
3
dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
4
 
 
5
dnl Add compiler specific options
 
6
 
 
7
AC_DEFUN([MOZ_DEFAULT_COMPILER],
 
8
[
 
9
dnl Default to MSVC for win32 and gcc-4.2 for darwin
 
10
dnl ==============================================================
 
11
if test -z "$CROSS_COMPILE"; then
 
12
case "$target" in
 
13
*-mingw*)
 
14
    if test -z "$CC"; then CC=cl; fi
 
15
    if test -z "$CXX"; then CXX=cl; fi
 
16
    if test -z "$CPP"; then CPP="cl -E -nologo"; fi
 
17
    if test -z "$CXXCPP"; then CXXCPP="cl -TP -E -nologo"; ac_cv_prog_CXXCPP="$CXXCPP"; fi
 
18
    if test -z "$LD"; then LD=link; fi
 
19
    if test -z "$AS"; then
 
20
        case "${target_cpu}" in
 
21
        i*86)
 
22
            AS=ml;
 
23
            ;;
 
24
        x86_64)
 
25
            AS=ml64;
 
26
            ;;
 
27
        esac
 
28
    fi
 
29
    if test -z "$MIDL"; then MIDL=midl; fi
 
30
 
 
31
    # need override this flag since we don't use $(LDFLAGS) for this.
 
32
    if test -z "$HOST_LDFLAGS" ; then
 
33
        HOST_LDFLAGS=" "
 
34
    fi
 
35
    ;;
 
36
*-darwin*)
 
37
    # we prefer gcc-4.2 over gcc on older darwin, so
 
38
    # use that specific version if it's available.
 
39
    # On newer versions of darwin, gcc is llvm-gcc while gcc-4.2 is the plain
 
40
    # one, so we also try that first. If that fails, we fall back to clang
 
41
    # as llvm-gcc is an unsupported dead end.
 
42
    MOZ_PATH_PROGS(CC, $CC gcc-4.2 clang gcc)
 
43
    MOZ_PATH_PROGS(CXX, $CXX g++-4.2 clang++ g++)
 
44
    IS_LLVM_GCC=$($CC -v 2>&1 | grep llvm-gcc)
 
45
    if test -n "$IS_LLVM_GCC"
 
46
    then
 
47
      echo llvm-gcc is known to be broken, please use gcc-4.2 or clang.
 
48
      exit 1
 
49
    fi
 
50
    ;;
 
51
esac
 
52
fi
 
53
])
 
54
 
 
55
dnl ============================================================================
 
56
dnl C++ rtti
 
57
dnl We don't use it in the code, but it can be usefull for debugging, so give
 
58
dnl the user the option of enabling it.
 
59
dnl ============================================================================
 
60
AC_DEFUN([MOZ_RTTI],
 
61
[
 
62
MOZ_ARG_ENABLE_BOOL(cpp-rtti,
 
63
[  --enable-cpp-rtti       Enable C++ RTTI ],
 
64
[ _MOZ_USE_RTTI=1 ],
 
65
[ _MOZ_USE_RTTI= ])
 
66
 
 
67
if test -z "$_MOZ_USE_RTTI"; then
 
68
    if test "$GNU_CC"; then
 
69
        CXXFLAGS="$CXXFLAGS -fno-rtti"
 
70
    else
 
71
        case "$target" in
 
72
        *-mingw*)
 
73
            CXXFLAGS="$CXXFLAGS -GR-"
 
74
        esac
 
75
    fi
 
76
fi
 
77
])
 
78
 
 
79
dnl A high level macro for selecting compiler options.
 
80
AC_DEFUN([MOZ_COMPILER_OPTS],
 
81
[
 
82
  MOZ_RTTI
 
83
if test "$CLANG_CXX"; then
 
84
    ## We disable return-type-c-linkage because jsval is defined as a C++ type but is
 
85
    ## returned by C functions. This is possible because we use knowledge about the ABI
 
86
    ## to typedef it to a C type with the same layout when the headers are included
 
87
    ## from C.
 
88
    ##
 
89
    ## mismatched-tags is disabled (bug 780474) mostly because it's useless.
 
90
    ## Worse, it's not supported by gcc, so it will cause tryserver bustage
 
91
    ## without any easy way for non-Clang users to check for it.
 
92
    _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-unknown-warning-option -Wno-return-type-c-linkage -Wno-mismatched-tags"
 
93
fi
 
94
 
 
95
if test "$GNU_CC"; then
 
96
    CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
 
97
    CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections -fno-exceptions"
 
98
fi
 
99
 
 
100
dnl ========================================================
 
101
dnl = Identical Code Folding
 
102
dnl ========================================================
 
103
 
 
104
MOZ_ARG_DISABLE_BOOL(icf,
 
105
[  --disable-icf          Disable Identical Code Folding],
 
106
    MOZ_DISABLE_ICF=1,
 
107
    MOZ_DISABLE_ICF= )
 
108
 
 
109
if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$MOZ_DISABLE_ICF"; then
 
110
    AC_CACHE_CHECK([whether the linker supports Identical Code Folding],
 
111
        LD_SUPPORTS_ICF,
 
112
        [echo 'int foo() {return 42;}' \
 
113
              'int bar() {return 42;}' \
 
114
              'int main() {return foo() - bar();}' > conftest.${ac_ext}
 
115
        # If the linker supports ICF, foo and bar symbols will have
 
116
        # the same address
 
117
        if AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS -Wl,--icf=safe -ffunction-sections conftest.${ac_ext} $LIBS 1>&2]) &&
 
118
           test -s conftest${ac_exeext} &&
 
119
           objdump -t conftest${ac_exeext} | awk changequote(<<, >>)'{a[<<$>>6] = <<$>>1} END {if (a["foo"] && (a["foo"] != a["bar"])) { exit 1 }}'changequote([, ]); then
 
120
            LD_SUPPORTS_ICF=yes
 
121
        else
 
122
            LD_SUPPORTS_ICF=no
 
123
        fi
 
124
        rm -rf conftest*])
 
125
    if test "$LD_SUPPORTS_ICF" = yes; then
 
126
        _SAVE_LDFLAGS="$LDFLAGS -Wl,--icf=safe"
 
127
        LDFLAGS="$LDFLAGS -Wl,--icf=safe -Wl,--print-icf-sections"
 
128
        AC_TRY_LINK([], [],
 
129
                    [LD_PRINT_ICF_SECTIONS=-Wl,--print-icf-sections],
 
130
                    [LD_PRINT_ICF_SECTIONS=])
 
131
        AC_SUBST([LD_PRINT_ICF_SECTIONS])
 
132
        LDFLAGS="$_SAVE_LDFLAGS"
 
133
    fi
 
134
fi
 
135
 
 
136
dnl ========================================================
 
137
dnl = Automatically remove dead symbols
 
138
dnl ========================================================
 
139
 
 
140
if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -n "$MOZ_DEBUG_FLAGS"; then
 
141
   dnl See bug 670659
 
142
   AC_CACHE_CHECK([whether removing dead symbols breaks debugging],
 
143
       GC_SECTIONS_BREAKS_DEBUG_RANGES,
 
144
       [echo 'int foo() {return 42;}' \
 
145
             'int bar() {return 1;}' \
 
146
             'int main() {return foo();}' > conftest.${ac_ext}
 
147
        if AC_TRY_COMMAND([${CC-cc} -o conftest.${ac_objext} $CFLAGS $MOZ_DEBUG_FLAGS -c conftest.${ac_ext} 1>&2]) &&
 
148
           AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS $MOZ_DEBUG_FLAGS -Wl,--gc-sections conftest.${ac_objext} $LIBS 1>&2]) &&
 
149
           test -s conftest${ac_exeext} -a -s conftest.${ac_objext}; then
 
150
            if test "`$PYTHON "$_topsrcdir"/build/autoconf/check_debug_ranges.py conftest.${ac_objext} conftest.${ac_ext}`" = \
 
151
                    "`$PYTHON "$_topsrcdir"/build/autoconf/check_debug_ranges.py conftest${ac_exeext} conftest.${ac_ext}`"; then
 
152
                GC_SECTIONS_BREAKS_DEBUG_RANGES=no
 
153
            else
 
154
                GC_SECTIONS_BREAKS_DEBUG_RANGES=yes
 
155
            fi
 
156
        else
 
157
             dnl We really don't expect to get here, but just in case
 
158
             GC_SECTIONS_BREAKS_DEBUG_RANGES="no, but it's broken in some other way"
 
159
        fi
 
160
        rm -rf conftest*])
 
161
    if test "$GC_SECTIONS_BREAKS_DEBUG_RANGES" = no; then
 
162
        DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections"
 
163
    fi
 
164
fi
 
165
 
 
166
])
 
167
 
 
168
dnl GCC and clang will fail if given an unknown warning option like -Wfoobar. 
 
169
dnl But later versions won't fail if given an unknown negated warning option
 
170
dnl like -Wno-foobar.  So when we are check for support of negated warning 
 
171
dnl options, we actually test the positive form, but add the negated form to 
 
172
dnl the flags variable.
 
173
 
 
174
AC_DEFUN([MOZ_C_SUPPORTS_WARNING],
 
175
[
 
176
    AC_CACHE_CHECK(whether the C compiler supports $1$2, $3,
 
177
        [
 
178
            AC_LANG_SAVE
 
179
            AC_LANG_C
 
180
            _SAVE_CFLAGS="$CFLAGS"
 
181
            CFLAGS="$CFLAGS -Werror -W$2"
 
182
            AC_TRY_COMPILE([],
 
183
                           [return(0);],
 
184
                           $3="yes",
 
185
                           $3="no")
 
186
            CFLAGS="$_SAVE_CFLAGS"
 
187
            AC_LANG_RESTORE
 
188
        ])
 
189
    if test "${$3}" = "yes"; then
 
190
        _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} $1$2"
 
191
    fi
 
192
])
 
193
 
 
194
AC_DEFUN([MOZ_CXX_SUPPORTS_WARNING],
 
195
[
 
196
    AC_CACHE_CHECK(whether the C++ compiler supports $1$2, $3,
 
197
        [
 
198
            AC_LANG_SAVE
 
199
            AC_LANG_CPLUSPLUS
 
200
            _SAVE_CXXFLAGS="$CXXFLAGS"
 
201
            CXXFLAGS="$CXXFLAGS -Werror -W$2"
 
202
            AC_TRY_COMPILE([],
 
203
                           [return(0);],
 
204
                           $3="yes",
 
205
                           $3="no")
 
206
            CXXFLAGS="$_SAVE_CXXFLAGS"
 
207
            AC_LANG_RESTORE
 
208
        ])
 
209
    if test "${$3}" = "yes"; then
 
210
        _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} $1$2"
 
211
    fi
 
212
])