platform.m4 revision 476:2ba6f4da4bf3
1#
2# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# This code is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 only, as
7# published by the Free Software Foundation.  Oracle designates this
8# particular file as subject to the "Classpath" exception as provided
9# by Oracle in the LICENSE file that accompanied this code.
10#
11# This code is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14# version 2 for more details (a copy is included in the LICENSE file that
15# accompanied this code).
16#
17# You should have received a copy of the GNU General Public License version
18# 2 along with this work; if not, write to the Free Software Foundation,
19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22# or visit www.oracle.com if you need additional information or have any
23# questions.
24#
25
26# Support macro for PLATFORM_EXTRACT_TARGET_AND_BUILD.
27# Converts autoconf style CPU name to OpenJDK style, into
28# VAR_CPU, VAR_CPU_ARCH, VAR_CPU_BITS and VAR_CPU_ENDIAN.
29AC_DEFUN([PLATFORM_EXTRACT_VARS_FROM_CPU],
30[
31  # First argument is the cpu name from the trip/quad
32  case "$1" in
33    x86_64)
34      VAR_CPU=x86_64
35      VAR_CPU_ARCH=x86
36      VAR_CPU_BITS=64
37      VAR_CPU_ENDIAN=little
38      ;;
39    i?86)
40      VAR_CPU=x86
41      VAR_CPU_ARCH=x86
42      VAR_CPU_BITS=32
43      VAR_CPU_ENDIAN=little
44      ;;
45    arm*)
46      VAR_CPU=arm
47      VAR_CPU_ARCH=arm
48      VAR_CPU_BITS=32
49      VAR_CPU_ENDIAN=little
50      ;;
51    powerpc)
52      VAR_CPU=ppc
53      VAR_CPU_ARCH=ppc
54      VAR_CPU_BITS=32
55      VAR_CPU_ENDIAN=big
56       ;;
57    powerpc64)
58      VAR_CPU=ppc64
59      VAR_CPU_ARCH=ppc
60      VAR_CPU_BITS=64
61      VAR_CPU_ENDIAN=big
62       ;;
63    sparc)
64      VAR_CPU=sparc
65      VAR_CPU_ARCH=sparc
66      VAR_CPU_BITS=32
67      VAR_CPU_ENDIAN=big
68       ;;
69    sparcv9)
70      VAR_CPU=sparcv9
71      VAR_CPU_ARCH=sparc
72      VAR_CPU_BITS=64
73      VAR_CPU_ENDIAN=big
74       ;;
75    *)
76      AC_MSG_ERROR([unsupported cpu $1])
77      ;;
78  esac
79])
80
81# Support macro for PLATFORM_EXTRACT_TARGET_AND_BUILD.
82# Converts autoconf style OS name to OpenJDK style, into
83# VAR_OS and VAR_OS_API.
84AC_DEFUN([PLATFORM_EXTRACT_VARS_FROM_OS],
85[
86  case "$1" in
87    *linux*)
88      VAR_OS=linux
89      VAR_OS_API=posix
90      ;;
91    *solaris*)
92      VAR_OS=solaris
93      VAR_OS_API=posix
94      ;;
95    *darwin*)
96      VAR_OS=macosx
97      VAR_OS_API=posix
98      ;;
99    *bsd*)
100      VAR_OS=bsd
101      VAR_OS_API=posix
102      ;;
103    *cygwin*|*windows*)
104      VAR_OS=windows
105      VAR_OS_API=winapi
106      ;;
107    *)
108      AC_MSG_ERROR([unsupported operating system $1])
109      ;;
110  esac
111])
112
113# Expects $host_os $host_cpu $build_os and $build_cpu
114# and $with_target_bits to have been setup!
115#
116# Translate the standard triplet(quadruplet) definition
117# of the target/build system into OPENJDK_TARGET_OS, OPENJDK_TARGET_CPU,
118# OPENJDK_BUILD_OS, etc.
119AC_DEFUN([PLATFORM_EXTRACT_TARGET_AND_BUILD],
120[
121    # Copy the autoconf trip/quadruplet verbatim to OPENJDK_TARGET_AUTOCONF_NAME
122    # (from the autoconf "host") and OPENJDK_BUILD_AUTOCONF_NAME
123    # Note that we might later on rewrite e.g. OPENJDK_TARGET_CPU due to reduced build,
124    # but this will not change the value of OPENJDK_TARGET_AUTOCONF_NAME.     
125    OPENJDK_TARGET_AUTOCONF_NAME="$host"
126    OPENJDK_BUILD_AUTOCONF_NAME="$build"
127    AC_SUBST(OPENJDK_TARGET_AUTOCONF_NAME)
128    AC_SUBST(OPENJDK_BUILD_AUTOCONF_NAME)
129
130    # Convert the autoconf OS/CPU value to our own data, into the VAR_OS/CPU variables.
131    PLATFORM_EXTRACT_VARS_FROM_OS($host_os)
132    PLATFORM_EXTRACT_VARS_FROM_CPU($host_cpu)
133    # ... and setup our own variables. (Do this explicitely to facilitate searching)
134    OPENJDK_TARGET_OS="$VAR_OS"
135    OPENJDK_TARGET_OS_API="$VAR_OS_API"
136    OPENJDK_TARGET_CPU="$VAR_CPU"
137    OPENJDK_TARGET_CPU_ARCH="$VAR_CPU_ARCH"
138    OPENJDK_TARGET_CPU_BITS="$VAR_CPU_BITS"
139    OPENJDK_TARGET_CPU_ENDIAN="$VAR_CPU_ENDIAN"
140    AC_SUBST(OPENJDK_TARGET_OS)
141    AC_SUBST(OPENJDK_TARGET_OS_API)
142    AC_SUBST(OPENJDK_TARGET_CPU)
143    AC_SUBST(OPENJDK_TARGET_CPU_ARCH)
144    AC_SUBST(OPENJDK_TARGET_CPU_BITS)
145    AC_SUBST(OPENJDK_TARGET_CPU_ENDIAN)
146
147    # Convert the autoconf OS/CPU value to our own data, into the VAR_OS/CPU variables.
148    PLATFORM_EXTRACT_VARS_FROM_OS($build_os)
149    PLATFORM_EXTRACT_VARS_FROM_CPU($build_cpu)
150    # ..and setup our own variables. (Do this explicitely to facilitate searching)
151    OPENJDK_BUILD_OS="$VAR_OS"
152    OPENJDK_BUILD_OS_API="$VAR_OS_API"
153    OPENJDK_BUILD_CPU="$VAR_CPU"
154    OPENJDK_BUILD_CPU_ARCH="$VAR_CPU_ARCH"
155    OPENJDK_BUILD_CPU_BITS="$VAR_CPU_BITS"
156    OPENJDK_BUILD_CPU_ENDIAN="$VAR_CPU_ENDIAN"
157    AC_SUBST(OPENJDK_BUILD_OS)
158    AC_SUBST(OPENJDK_BUILD_OS_API)
159    AC_SUBST(OPENJDK_BUILD_CPU)
160    AC_SUBST(OPENJDK_BUILD_CPU_ARCH)
161    AC_SUBST(OPENJDK_BUILD_CPU_BITS)
162    AC_SUBST(OPENJDK_BUILD_CPU_ENDIAN)
163])
164
165# Check if a reduced build (32-bit on 64-bit platforms) is requested, and modify behaviour
166# accordingly. Must be done after setting up build and target system, but before
167# doing anything else with these values.
168AC_DEFUN([PLATFORM_SETUP_TARGET_CPU_BITS],
169[
170  AC_ARG_WITH(target-bits, [AS_HELP_STRING([--with-target-bits],
171     [build 32-bit or 64-bit binaries (for platforms that support it), e.g. --with-target-bits=32 @<:@guessed@:>@])])
172
173  # We have three types of compiles:
174  # native  == normal compilation, target system == build system
175  # cross   == traditional cross compilation, target system != build system; special toolchain needed
176  # reduced == using native compilers, but with special flags (e.g. -m32) to produce 32-bit builds on 64-bit machines
177  #
178  if test "x$OPENJDK_BUILD_AUTOCONF_NAME" != "x$OPENJDK_TARGET_AUTOCONF_NAME"; then
179    # We're doing a proper cross-compilation
180    COMPILE_TYPE="cross"
181  else
182    COMPILE_TYPE="native"
183  fi
184
185  if test "x$with_target_bits" != x; then
186    if test "x$COMPILE_TYPE" = "xcross"; then
187      AC_MSG_ERROR([It is not possible to combine --with-target-bits=X and proper cross-compilation. Choose either.])
188    fi
189
190    if test "x$with_target_bits" = x32 && test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
191      # A reduced build is requested
192      COMPILE_TYPE="reduced"
193      OPENJDK_TARGET_CPU_BITS=32
194      if test "x$OPENJDK_TARGET_CPU_ARCH" = "xx86"; then
195        OPENJDK_TARGET_CPU=x86
196      elif test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
197        OPENJDK_TARGET_CPU=sparc
198      else
199        AC_MSG_ERROR([Reduced build (--with-target-bits=32) is only supported on x86_64 and sparcv9])
200      fi 
201    elif test "x$with_target_bits" = x64 && test "x$OPENJDK_TARGET_CPU_BITS" = x32; then
202      AC_MSG_ERROR([It is not possible to use --with-target-bits=64 on a 32 bit system. Use proper cross-compilation instead.])
203    elif test "x$with_target_bits" = "x$OPENJDK_TARGET_CPU_BITS"; then
204      AC_MSG_NOTICE([--with-target-bits are set to build platform address size; argument has no meaning])
205    else
206      AC_MSG_ERROR([--with-target-bits can only be 32 or 64, you specified $with_target_bits!])
207    fi
208  fi
209  AC_SUBST(COMPILE_TYPE)
210
211AC_MSG_CHECKING([for compilation type])
212AC_MSG_RESULT([$COMPILE_TYPE])
213])
214
215    # Setup the legacy variables, for controlling the old makefiles.
216    #
217AC_DEFUN([PLATFORM_SETUP_LEGACY_VARS],
218[
219    # Also store the legacy naming of the cpu.
220    # Ie i586 and amd64 instead of x86 and x86_64
221    OPENJDK_TARGET_CPU_LEGACY="$OPENJDK_TARGET_CPU"
222    if test "x$OPENJDK_TARGET_CPU" = xx86; then 
223      OPENJDK_TARGET_CPU_LEGACY="i586"
224    elif test "x$OPENJDK_TARGET_OS" != xmacosx && test "x$OPENJDK_TARGET_CPU" = xx86_64; then 
225      # On all platforms except MacOSX replace x86_64 with amd64.
226      OPENJDK_TARGET_CPU_LEGACY="amd64"
227    fi
228    AC_SUBST(OPENJDK_TARGET_CPU_LEGACY)
229
230    # And the second legacy naming of the cpu.
231    # Ie i386 and amd64 instead of x86 and x86_64.
232    OPENJDK_TARGET_CPU_LEGACY_LIB="$OPENJDK_TARGET_CPU"
233    if test "x$OPENJDK_TARGET_CPU" = xx86; then 
234      OPENJDK_TARGET_CPU_LEGACY_LIB="i386"
235    elif test "x$OPENJDK_TARGET_CPU" = xx86_64; then 
236      OPENJDK_TARGET_CPU_LEGACY_LIB="amd64"
237    fi
238    AC_SUBST(OPENJDK_TARGET_CPU_LEGACY_LIB)
239
240    # This is the name of the cpu (but using i386 and amd64 instead of
241    # x86 and x86_64, respectively), preceeded by a /, to be used when
242    # locating libraries. On macosx, it's empty, though.
243    OPENJDK_TARGET_CPU_LIBDIR="/$OPENJDK_TARGET_CPU_LEGACY_LIB"
244    if test "x$OPENJDK_TARGET_OS" = xmacosx; then
245        OPENJDK_TARGET_CPU_LIBDIR=""
246    fi
247    AC_SUBST(OPENJDK_TARGET_CPU_LIBDIR)
248
249    # OPENJDK_TARGET_CPU_ISADIR is normally empty. On 64-bit Solaris systems, it is set to
250    # /amd64 or /sparcv9. This string is appended to some library paths, like this:
251    # /usr/lib${OPENJDK_TARGET_CPU_ISADIR}/libexample.so
252    OPENJDK_TARGET_CPU_ISADIR=""
253    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
254      if test "x$OPENJDK_TARGET_CPU" = xx86_64; then 
255          OPENJDK_TARGET_CPU_ISADIR="/amd64"
256      elif test "x$OPENJDK_TARGET_CPU" = xsparcv9; then 
257          OPENJDK_TARGET_CPU_ISADIR="/sparcv9"
258      fi
259    fi
260    AC_SUBST(OPENJDK_TARGET_CPU_ISADIR)
261
262    # Setup OPENJDK_TARGET_CPU_OSARCH, which is used to set the os.arch Java system property
263    OPENJDK_TARGET_CPU_OSARCH="$OPENJDK_TARGET_CPU"
264    if test "x$OPENJDK_TARGET_OS" = xlinux && test "x$OPENJDK_TARGET_CPU" = xx86; then
265      # On linux only, we replace x86 with i386.
266      OPENJDK_TARGET_CPU_OSARCH="i386"
267    elif test "x$OPENJDK_TARGET_OS" != xmacosx && test "x$OPENJDK_TARGET_CPU" = xx86_64; then
268      # On all platforms except macosx, we replace x86_64 with amd64.
269      OPENJDK_TARGET_CPU_OSARCH="amd64"
270    fi
271    AC_SUBST(OPENJDK_TARGET_CPU_OSARCH)
272
273    OPENJDK_TARGET_CPU_JLI="$OPENJDK_TARGET_CPU"
274    if test "x$OPENJDK_TARGET_CPU" = xx86; then 
275      OPENJDK_TARGET_CPU_JLI="i386"
276    elif test "x$OPENJDK_TARGET_OS" != xmacosx && test "x$OPENJDK_TARGET_CPU" = xx86_64; then
277      # On all platforms except macosx, we replace x86_64 with amd64.
278      OPENJDK_TARGET_CPU_JLI="amd64"
279    fi
280    # Now setup the -D flags for building libjli.
281    OPENJDK_TARGET_CPU_JLI_CFLAGS="-DLIBARCHNAME='\"$OPENJDK_TARGET_CPU_JLI\"'"
282    if test "x$OPENJDK_TARGET_OS" = xsolaris; then
283      if test "x$OPENJDK_TARGET_CPU_ARCH" = xsparc; then
284        OPENJDK_TARGET_CPU_JLI_CFLAGS="$OPENJDK_TARGET_CPU_JLI_CFLAGS -DLIBARCH32NAME='\"sparc\"' -DLIBARCH64NAME='\"sparcv9\"'"
285      elif test "x$OPENJDK_TARGET_CPU_ARCH" = xx86; then 
286        OPENJDK_TARGET_CPU_JLI_CFLAGS="$OPENJDK_TARGET_CPU_JLI_CFLAGS -DLIBARCH32NAME='\"i386\"' -DLIBARCH64NAME='\"amd64\"'"
287      fi
288    fi
289    AC_SUBST(OPENJDK_TARGET_CPU_JLI_CFLAGS)
290
291    # Setup OPENJDK_TARGET_OS_API_DIR, used in source paths.
292    if test "x$OPENJDK_TARGET_OS_API" = xposix; then
293        OPENJDK_TARGET_OS_API_DIR="solaris"
294    fi
295    if test "x$OPENJDK_TARGET_OS_API" = xwinapi; then
296        OPENJDK_TARGET_OS_API_DIR="windows"
297    fi
298    AC_SUBST(OPENJDK_TARGET_OS_API_DIR)
299
300    if test "x$OPENJDK_TARGET_CPU_BITS" = x64; then
301        A_LP64="LP64:="
302        ADD_LP64="-D_LP64=1"
303    fi
304    AC_SUBST(LP64,$A_LP64)
305
306    if test "x$COMPILE_TYPE" = "xcross"; then
307      # FIXME: ... or should this include reduced builds..?
308      DEFINE_CROSS_COMPILE_ARCH="CROSS_COMPILE_ARCH:=$OPENJDK_TARGET_CPU_LEGACY"
309    else
310      DEFINE_CROSS_COMPILE_ARCH=""
311    fi
312    AC_SUBST(DEFINE_CROSS_COMPILE_ARCH)
313])
314
315AC_DEFUN([PLATFORM_SET_RELEASE_FILE_OS_VALUES],
316[
317    if test "x$OPENJDK_TARGET_OS" = "xsolaris"; then
318       REQUIRED_OS_NAME=SunOS
319       REQUIRED_OS_VERSION=5.10
320    fi
321    if test "x$OPENJDK_TARGET_OS" = "xlinux"; then
322       REQUIRED_OS_NAME=Linux
323       REQUIRED_OS_VERSION=2.6
324    fi
325    if test "x$OPENJDK_TARGET_OS" = "xwindows"; then
326        REQUIRED_OS_NAME=Windows
327        if test "x$OPENJDK_TARGET_CPU_BITS" = "x64"; then
328            REQUIRED_OS_VERSION=5.2
329        else
330            REQUIRED_OS_VERSION=5.1
331        fi
332    fi
333    if test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
334        REQUIRED_OS_NAME=Darwin
335        REQUIRED_OS_VERSION=11.2
336    fi
337
338    AC_SUBST(REQUIRED_OS_NAME)
339    AC_SUBST(REQUIRED_OS_VERSION)
340])
341
342#%%% Build and target systems %%%
343AC_DEFUN_ONCE([PLATFORM_SETUP_OPENJDK_BUILD_AND_TARGET],
344[
345# Figure out the build and target systems. # Note that in autoconf terminology, "build" is obvious, but "target"
346# is confusing; it assumes you are cross-compiling a cross-compiler (!)  and "target" is thus the target of the
347# product you're building. The target of this build is called "host". Since this is confusing to most people, we
348# have not adopted that system, but use "target" as the platform we are building for. In some places though we need
349# to use the configure naming style.
350AC_CANONICAL_BUILD
351AC_CANONICAL_HOST
352AC_CANONICAL_TARGET
353
354PLATFORM_EXTRACT_TARGET_AND_BUILD
355PLATFORM_SETUP_TARGET_CPU_BITS
356PLATFORM_SET_RELEASE_FILE_OS_VALUES
357PLATFORM_SETUP_LEGACY_VARS
358])
359
360AC_DEFUN_ONCE([PLATFORM_SETUP_OPENJDK_BUILD_OS_VERSION],
361[
362###############################################################################
363
364# Note that this is the build platform OS version!
365
366OS_VERSION="`uname -r | ${SED} 's!\.! !g' | ${SED} 's!-! !g'`"
367OS_VERSION_MAJOR="`${ECHO} ${OS_VERSION} | ${CUT} -f 1 -d ' '`"
368OS_VERSION_MINOR="`${ECHO} ${OS_VERSION} | ${CUT} -f 2 -d ' '`"
369OS_VERSION_MICRO="`${ECHO} ${OS_VERSION} | ${CUT} -f 3 -d ' '`"
370AC_SUBST(OS_VERSION_MAJOR)
371AC_SUBST(OS_VERSION_MINOR)
372AC_SUBST(OS_VERSION_MICRO)
373])
374
375# Support macro for PLATFORM_SETUP_OPENJDK_TARGET_BITS.
376# Add -mX to various FLAGS variables.
377AC_DEFUN([PLATFORM_SET_COMPILER_TARGET_BITS_FLAGS],
378[
379  # keep track of c/cxx flags that we added outselves...
380  #   to prevent emitting warning...
381  ADDED_CFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}"
382  ADDED_CXXFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}"
383  ADDED_LDFLAGS=" -m${OPENJDK_TARGET_CPU_BITS}"
384
385  CFLAGS="${CFLAGS}${ADDED_CFLAGS}"
386  CXXFLAGS="${CXXFLAGS}${ADDED_CXXFLAGS}"
387  LDFLAGS="${LDFLAGS}${ADDED_LDFLAGS}"
388
389  CFLAGS_JDK="${CFLAGS_JDK}${ADDED_CFLAGS}"
390  CXXFLAGS_JDK="${CXXFLAGS_JDK}${ADDED_CXXFLAGS}"
391  LDFLAGS_JDK="${LDFLAGS_JDK}${ADDED_LDFLAGS}"
392])
393
394AC_DEFUN_ONCE([PLATFORM_SETUP_OPENJDK_TARGET_BITS],
395[
396###############################################################################
397#
398# Now we check if libjvm.so will use 32 or 64 bit pointers for the C/C++ code.
399# (The JVM can use 32 or 64 bit Java pointers but that decision
400# is made at runtime.)
401#
402if test "x$OPENJDK_TARGET_OS" = xsolaris; then
403  # Always specify -m flags on Solaris
404  PLATFORM_SET_COMPILER_TARGET_BITS_FLAGS
405elif test "x$COMPILE_TYPE" = xreduced; then
406  if test "x$OPENJDK_TARGET_OS" != xwindows; then
407    # Specify -m if running reduced on other Posix platforms
408    PLATFORM_SET_COMPILER_TARGET_BITS_FLAGS
409  fi
410fi
411
412# Make compilation sanity check
413AC_CHECK_HEADERS([stdio.h], , [
414  AC_MSG_NOTICE([Failed to compile stdio.h. This likely implies missing compile dependencies.])
415  if test "x$COMPILE_TYPE" = xreduced; then
416    AC_MSG_NOTICE([You are doing a reduced build. Check that you have 32-bit libraries installed.])
417  elif test "x$COMPILE_TYPE" = xcross; then
418    AC_MSG_NOTICE([You are doing a cross-compilation. Check that you have all target platform libraries installed.])
419  fi
420  AC_MSG_ERROR([Cannot continue.])
421])
422
423AC_CHECK_SIZEOF([int *], [1111])
424
425if test "x$SIZEOF_INT_P" != "x$ac_cv_sizeof_int_p"; then
426  # Workaround autoconf bug, see http://lists.gnu.org/archive/html/autoconf/2010-07/msg00004.html
427  SIZEOF_INT_P="$ac_cv_sizeof_int_p"
428fi
429
430if test "x$SIZEOF_INT_P" = x; then 
431    # The test failed, lets stick to the assumed value.
432    AC_MSG_WARN([The number of bits in the target could not be determined, using $OPENJDK_TARGET_CPU_BITS.])
433else
434    TESTED_TARGET_CPU_BITS=`expr 8 \* $SIZEOF_INT_P`
435
436    if test "x$TESTED_TARGET_CPU_BITS" != "x$OPENJDK_TARGET_CPU_BITS"; then
437        AC_MSG_ERROR([The tested number of bits in the target ($TESTED_TARGET_CPU_BITS) differs from the number of bits expected to be found in the target ($OPENJDK_TARGET_CPU_BITS)])
438    fi
439fi
440
441AC_MSG_CHECKING([for target address size])
442AC_MSG_RESULT([$OPENJDK_TARGET_CPU_BITS bits])
443])
444
445AC_DEFUN_ONCE([PLATFORM_SETUP_OPENJDK_TARGET_ENDIANNESS],
446[
447###############################################################################
448#
449# Is the target little of big endian?
450#
451AC_C_BIGENDIAN([ENDIAN="big"],[ENDIAN="little"],[ENDIAN="unknown"],[ENDIAN="universal_endianness"])
452
453if test "x$ENDIAN" = xuniversal_endianness; then
454    AC_MSG_ERROR([Building with both big and little endianness is not supported])
455fi
456if test "x$ENDIAN" != "x$OPENJDK_TARGET_CPU_ENDIAN"; then
457    AC_MSG_ERROR([The tested endian in the target ($ENDIAN) differs from the endian expected to be found in the target ($OPENJDK_TARGET_CPU_ENDIAN)])
458fi
459])
460