maint: update copyright
[gnulib.git] / m4 / host-cpu-c-abi.m4
1 # host-cpu-c-abi.m4 serial 1
2 dnl Copyright (C) 2002-2014 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible and Sam Steingold.
8
9 dnl Sets the HOST_CPU_C_ABI variable to the canonical name of the CPU with its
10 dnl C language ABI (application binary interface).
11 dnl Also defines __${HOST_CPU_C_ABI}__ as a C macro in config.h.
12 dnl
13 dnl This canonical name can be used to select a particular assembly language
14 dnl source file that will interoperate with C code on the given host.
15 dnl
16 dnl For example:
17 dnl * 'i386' and 'sparc' are different canonical names, because code for i386
18 dnl   will not run on SPARC CPUs and vice versa. They have different
19 dnl   instruction sets.
20 dnl * 'sparc' and 'sparc64' are different canonical names, because code for
21 dnl   'sparc' and code for 'sparc64' cannot be linked together: 'sparc' code
22 dnl   contains 32-bit instructions, whereas 'sparc64' code contains 64-bit
23 dnl   instructions. A process on a SPARC CPU can be in 32-bit mode or in 64-bit
24 dnl   mode, but not both.
25 dnl * 'mips' and 'mipsn32' are different canonical names, because they use
26 dnl   different argument passing and return conventions for C functions, and
27 dnl   although the instruction set of 'mips' is a large subset of the
28 dnl   instruction set of 'mipsn32'.
29 dnl * 'mipsn32' and 'mips64' are different canonical names, because they use
30 dnl   different sizes for the C types like 'int' and 'void *', and although
31 dnl   the instruction sets of 'mipsn32' and 'mips64' are the same.
32 dnl * 'arm' and 'armel' are different canonical names, because they use
33 dnl   different memory ordering for the C types like 'int', and although
34 dnl   the instruction sets of 'arm' and 'armel' are the same.
35 dnl * The same name 'i386' is used for CPUs of type i386, i486, i586
36 dnl   (Pentium), AMD K7, Pentium II, Pentium IV, etc., because
37 dnl   - Instructions that do not exist on all of these CPUs (cmpxchg,
38 dnl     MMX, SSE, SSE2, 3DNow! etc.) are not frequently used. If your
39 dnl     assembly language source files use such instructions, you will
40 dnl     need to make the distinction.
41 dnl   - Speed of execution of the common instruction set is reasonable across
42 dnl     the entire family of CPUs. If you have assembly language source files
43 dnl     that are optimized for particular CPU types (like GNU gmp has), you
44 dnl     will need to make the distinction.
45 dnl   See <http://en.wikipedia.org/wiki/X86_instruction_listings>.
46 AC_DEFUN([gl_HOST_CPU_C_ABI],
47 [
48   AC_REQUIRE([AC_CANONICAL_HOST])
49   AC_CACHE_CHECK([host CPU and C ABI], [gl_cv_host_cpu_c_abi],
50     [case "$host_cpu" in
51
52 changequote(,)dnl
53        i[4567]86 )
54 changequote([,])dnl
55          gl_cv_host_cpu_c_abi=i386
56          ;;
57
58        x86_64 )
59          # On x86_64 systems, the C compiler may still be generating
60          # 32-bit code.
61          AC_EGREP_CPP([yes],
62            [#if defined __LP64__ || defined __x86_64__ || defined __amd64__
63             yes
64             #endif],
65            [gl_cv_host_cpu_c_abi=x86_64],
66            [gl_cv_host_cpu_c_abi=i386])
67          ;;
68
69 changequote(,)dnl
70        alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] )
71 changequote([,])dnl
72          gl_cv_host_cpu_c_abi=alpha
73          ;;
74
75        arm* )
76          AC_EGREP_CPP([yes],
77            [#if defined __ARMEL__
78             yes
79             #endif],
80            [gl_cv_host_cpu_c_abi=armel],
81            [gl_cv_host_cpu_c_abi=arm])
82          ;;
83
84        hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
85          # TODO: Distinguish hppa and hppa64 correctly.
86          gl_cv_host_cpu_c_abi=hppa
87          ;;
88
89        mips* )
90          # We should also check for (_MIPS_SZPTR == 64), but gcc keeps this
91          # at 32.
92          AC_EGREP_CPP([yes],
93            [#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64)
94             yes
95             #endif],
96            [gl_cv_host_cpu_c_abi=mips64],
97            [# Strictly speaking, the MIPS ABI (-32 or -n32) is independent
98             # from the CPU identification (-mips[12] or -mips[34]). But -n32
99             # is commonly used together with -mips3, and it's easier to test
100             # the CPU identification.
101             AC_EGREP_CPP([yes],
102               [#if __mips >= 3
103                yes
104                #endif],
105               [gl_cv_host_cpu_c_abi=mipsn32],
106               [gl_cv_host_cpu_c_abi=mips])])
107          ;;
108
109        powerpc64 )
110          # On powerpc64 systems, the C compiler may still be generating
111          # 32-bit code.
112          AC_EGREP_CPP([yes],
113            [#if defined __powerpc64__ || defined _ARCH_PPC64
114             yes
115             #endif],
116            [gl_cv_host_cpu_c_abi=powerpc64],
117            [gl_cv_host_cpu_c_abi=powerpc])
118          ;;
119
120        rs6000 )
121          gl_cv_host_cpu_c_abi=powerpc
122          ;;
123
124        # TODO: Distinguish s390 and s390x correctly.
125
126        sparc | sparc64 )
127          # UltraSPARCs running Linux have `uname -m` = "sparc64", but the
128          # C compiler still generates 32-bit code.
129          AC_EGREP_CPP([yes],
130            [#if defined __sparcv9 || defined __arch64__
131             yes
132             #endif],
133            [gl_cv_host_cpu_c_abi=sparc64],
134            [gl_cv_host_cpu_c_abi=sparc])
135          ;;
136
137        *)
138          gl_cv_host_cpu_c_abi="$host_cpu"
139          ;;
140      esac
141     ])
142
143   HOST_CPU_C_ABI="$gl_cv_host_cpu_c_abi"
144   AC_SUBST([HOST_CPU_C_ABI])
145
146   # This was AC_DEFINE_UNQUOTED([__${gl_cv_host_cpu_c_abi}__]) earlier,
147   # but KAI C++ 3.2d doesn't like this.
148   cat >> confdefs.h <<EOF
149 #ifndef __${gl_cv_host_cpu_c_abi}__
150 #define __${gl_cv_host_cpu_c_abi}__ 1
151 #endif
152 EOF
153   AH_TOP([/* CPU and C ABI indicator */
154 #ifndef __i386__
155 #undef __i386__
156 #endif
157 #ifndef __x86_64__
158 #undef __x86_64__
159 #endif
160 #ifndef __alpha__
161 #undef __alpha__
162 #endif
163 #ifndef __arm__
164 #undef __arm__
165 #endif
166 #ifndef __armel__
167 #undef __armel__
168 #endif
169 #ifndef __hppa__
170 #undef __hppa__
171 #endif
172 #ifndef __hppa64__
173 #undef __hppa64__
174 #endif
175 #ifndef __ia64__
176 #undef __ia64__
177 #endif
178 #ifndef __m68k__
179 #undef __m68k__
180 #endif
181 #ifndef __mips__
182 #undef __mips__
183 #endif
184 #ifndef __mipsn32__
185 #undef __mipsn32__
186 #endif
187 #ifndef __mips64__
188 #undef __mips64__
189 #endif
190 #ifndef __powerpc__
191 #undef __powerpc__
192 #endif
193 #ifndef __powerpc64__
194 #undef __powerpc64__
195 #endif
196 #ifndef __s390__
197 #undef __s390__
198 #endif
199 #ifndef __s390x__
200 #undef __s390x__
201 #endif
202 #ifndef __sh__
203 #undef __sh__
204 #endif
205 #ifndef __sparc__
206 #undef __sparc__
207 #endif
208 #ifndef __sparc64__
209 #undef __sparc64__
210 #endif
211 ])
212
213 ])