platform.m4 revision 443:efd26e051e50
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
26AC_DEFUN([CHECK_FIND_DELETE],
27[
28    # Test if find supports -delete
29    AC_MSG_CHECKING([if find supports -delete])
30    FIND_DELETE="-delete"
31
32    DELETEDIR=`mktemp -d tmp.XXXXXXXXXX` || (echo Could not create temporary directory!; exit $?)
33
34    echo Hejsan > $DELETEDIR/TestIfFindSupportsDelete
35
36    TEST_DELETE=`$FIND "$DELETEDIR" -name TestIfFindSupportsDelete $FIND_DELETE 2>&1`
37    if test -f $DELETEDIR/TestIfFindSupportsDelete; then
38        # No, it does not.
39        rm $DELETEDIR/TestIfFindSupportsDelete
40        FIND_DELETE="-exec rm \{\} \+"
41        AC_MSG_RESULT([no])    
42    else
43        AC_MSG_RESULT([yes])    
44    fi
45    rmdir $DELETEDIR
46])
47
48AC_DEFUN([CHECK_NONEMPTY],
49[
50    # Test that variable $1 is not empty.
51    if test "" = "[$]$1"; then AC_MSG_ERROR(Could not find translit($1,A-Z,a-z) !); fi
52])
53
54AC_DEFUN([ADD_JVM_ARG_IF_OK],
55[
56    # Test if $1 is a valid argument to $3 (often is $JAVA passed as $3)
57    # If so, then append $1 to $2
58    FOUND_WARN=`$3 $1 -version 2>&1 | grep -i warn`
59    FOUND_VERSION=`$3 $1 -version 2>&1 | grep " version \""`
60    if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then
61        $2="[$]$2 $1"
62    fi
63])
64
65AC_DEFUN([WHICHCMD],
66[
67    # Translate "gcc -E" into "`which gcc` -E" ie
68    # extract the full path to the binary and at the
69    # same time maintain any arguments passed to it.
70    # The command MUST exist in the path, or else!
71    tmp="[$]$1"
72    car="${tmp%% *}"
73    tmp="[$]$1 EOL"
74    cdr="${tmp#* }"
75    # On windows we want paths without spaces.
76    if test "x$BUILD_OS" = "xwindows"; then
77        WHICHCMD_SPACESAFE(car)
78    else
79        # "which" is not portable, but is used here
80        # because we know that the command exists!
81        car=`which $car`
82    fi
83    if test "x$cdr" != xEOL; then
84        $1="$car ${cdr% *}"
85    else
86        $1="$car"
87    fi
88])
89
90AC_DEFUN([SPACESAFE],
91[
92    # Fail with message $2 if var $1 contains a path with no spaces in it.
93    # Unless on Windows, where we can rewrite the path.
94    HAS_SPACE=`echo "[$]$1" | grep " "`
95    if test "x$HAS_SPACE" != x; then
96        if test "x$BUILD_OS" = "xwindows"; then
97            $1=`$CYGPATH -s -m -a "[$]$1"`
98            $1=`$CYGPATH -u "[$]$1"`            
99        else
100            AC_MSG_ERROR([You cannot have spaces in $2! "[$]$1"])
101        fi
102    fi
103])
104
105AC_DEFUN([WHICHCMD_SPACESAFE],
106[
107    # Translate long cygdrive or C:\sdfsf path
108    # into a short mixed mode path that has no
109    # spaces in it.
110    tmp="[$]$1"
111    if test "x$BUILD_OS" = "xwindows"; then
112        tmp=`$CYGPATH -u "[$]$1"`
113        tmp=`which "$tmp"`
114        # If file exists with .exe appended, that's the real filename
115        # and cygpath needs that to convert to short style path.
116        if test -f "${tmp}.exe"; then
117           tmp="${tmp}.exe"
118        elif test -f "${tmp}.cmd"; then
119           tmp="${tmp}.cmd"
120        fi
121        # Convert to C:/ mixed style path without spaces.
122         tmp=`$CYGPATH -s -m "$tmp"`
123    fi
124    $1="$tmp"
125])
126
127AC_DEFUN([REMOVE_SYMBOLIC_LINKS],
128[
129    if test "x$BUILD_OS" != xwindows; then
130        # Follow a chain of symbolic links. Use readlink
131        # where it exists, else fall back to horribly
132        # complicated shell code.
133        AC_PATH_PROG(READLINK, readlink)
134        if test "x$READLINK_TESTED" != yes; then
135            # On MacOSX there is a readlink tool with a different
136            # purpose than the GNU readlink tool. Check the found readlink.
137            ISGNU=`$READLINK --help 2>&1 | grep GNU`
138            if test "x$ISGNU" = x; then
139                 # A readlink that we do not know how to use.
140                 # Are there other non-GNU readlinks out there?
141                 READLINK_TESTED=yes
142                 READLINK=
143            fi
144        fi
145
146        if test "x$READLINK" != x; then
147            $1=`$READLINK -f [$]$1`
148        else
149            STARTDIR=$PWD
150            COUNTER=0
151            DIR=`dirname [$]$1`
152            FIL=`basename [$]$1`
153            while test $COUNTER -lt 20; do
154                ISLINK=`ls -l $DIR/$FIL | grep '\->' | sed -e 's/.*-> \(.*\)/\1/'`
155                if test "x$ISLINK" == x; then
156                    # This is not a symbolic link! We are done!
157                    break
158                fi
159                # The link might be relative! We have to use cd to travel safely.
160                cd $DIR
161                cd `dirname $ISLINK`
162                DIR=`pwd`
163                FIL=`basename $ISLINK`
164                let COUNTER=COUNTER+1
165            done
166            cd $STARTDIR
167            $1=$DIR/$FIL
168        fi
169    fi
170])
171
172AC_DEFUN([TESTFOR_PROG_CCACHE],
173[
174    AC_ARG_ENABLE([ccache],
175	      [AS_HELP_STRING([--disable-ccache],
176	      		      [use ccache to speed up recompilations @<:@enabled@:>@])],
177              [ENABLE_CCACHE=${enable_ccache}], [ENABLE_CCACHE=yes])
178    if test "x$ENABLE_CCACHE" = xyes; then
179        AC_PATH_PROG(CCACHE, ccache)
180    else
181        AC_MSG_CHECKING([for ccache])
182        AC_MSG_RESULT([explicitly disabled])    
183        CCACHE=
184    fi    
185    AC_SUBST(CCACHE)
186
187    AC_ARG_WITH([ccache-dir],
188	      [AS_HELP_STRING([--with-ccache-dir],
189	      		      [where to store ccache files @<:@~/.ccache@:>@])])
190
191    if test "x$with_ccache_dir" != x; then
192        # When using a non home ccache directory, assume the use is to share ccache files
193        # with other users. Thus change the umask.
194        SET_CCACHE_DIR="CCACHE_DIR=$with_ccache_dir CCACHE_UMASK=002"
195    fi
196    CCACHE_FOUND=""
197    if test "x$CCACHE" != x; then
198        SETUP_CCACHE_USAGE
199    fi    
200])
201
202AC_DEFUN([SETUP_CCACHE_USAGE],
203[
204    if test "x$CCACHE" != x; then
205        CCACHE_FOUND="true"
206        # Only use ccache if it is 3.1.4 or later, which supports
207        # precompiled headers.
208        AC_MSG_CHECKING([if ccache supports precompiled headers])
209        HAS_GOOD_CCACHE=`($CCACHE --version | head -n 1 | grep -E 3.1.@<:@456789@:>@) 2> /dev/null`
210        if test "x$HAS_GOOD_CCACHE" = x; then
211            AC_MSG_RESULT([no, disabling ccache])
212            CCACHE=
213        else
214            AC_MSG_RESULT([yes])
215            AC_MSG_CHECKING([if C-compiler supports ccache precompiled headers])
216            PUSHED_FLAGS="$CXXFLAGS"
217            CXXFLAGS="-fpch-preprocess $CXXFLAGS"
218            AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [CC_KNOWS_CCACHE_TRICK=yes], [CC_KNOWS_CCACHE_TRICK=no])
219            CXXFLAGS="$PUSHED_FLAGS"
220            if test "x$CC_KNOWS_CCACHE_TRICK" = xyes; then
221                AC_MSG_RESULT([yes])
222            else
223                AC_MSG_RESULT([no, disabling ccaching of precompiled headers])
224                CCACHE=
225            fi
226        fi
227    fi
228
229    if test "x$CCACHE" != x; then
230        CCACHE_SLOPPINESS=time_macros
231        CCACHE="CCACHE_COMPRESS=1 $SET_CCACHE_DIR CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS $CCACHE"
232        CCACHE_FLAGS=-fpch-preprocess
233
234        if test "x$SET_CCACHE_DIR" != x; then
235            mkdir -p $CCACHE_DIR > /dev/null 2>&1
236	    chmod a+rwxs $CCACHE_DIR > /dev/null 2>&1
237        fi
238    fi
239])
240
241AC_DEFUN([EXTRACT_HOST_AND_BUILD_AND_LEGACY_VARS],
242[
243    # Expects $host_os $host_cpu $build_os and $build_cpu
244    # and $with_data_model to have been setup!
245    #
246    # Translate the standard triplet(quadruplet) definition
247    # of the host/build system into
248    # HOST_OS=aix,bsd,hpux,linux,macosx,solaris,windows
249    # HOST_OS_FAMILY=bsd,gnu,sysv,win32,wince
250    # HOST_OS_API=posix,winapi
251    # 
252    # HOST_CPU=ia32,x64,sparc,sparcv9,arm,arm64,ppc,ppc64
253    # HOST_CPU_ARCH=x86,sparc,pcc,arm
254    # HOST_CPU_BITS=32,64
255    # HOST_CPU_ENDIAN=big,little
256    #
257    # The same values are setup for BUILD_...
258    # 
259    # And the legacy variables, for controlling the old makefiles.
260    # LEGACY_HOST_CPU1=i586,amd64/x86_64,sparc,sparcv9,arm,arm64...
261    # LEGACY_HOST_CPU2=i386,amd64,sparc,sparcv9,arm,arm64...
262    # LEGACY_HOST_CPU3=sparcv9,amd64 (but only on solaris)
263    # LEGACY_HOST_OS_API=solaris,windows
264    #
265    # We also copy the autoconf trip/quadruplet
266    # verbatim to HOST and BUILD
267    AC_SUBST(HOST, ${host})
268    AC_SUBST(BUILD, ${build})
269    
270    EXTRACT_VARS_FROM_OS_TO(HOST,$host_os)
271    EXTRACT_VARS_FROM_CPU_TO(HOST,$host_cpu)
272
273    EXTRACT_VARS_FROM_OS_TO(BUILD,$build_os)
274    EXTRACT_VARS_FROM_CPU_TO(BUILD,$build_cpu)
275
276    if test "x$HOST_OS" != xsolaris; then
277        LEGACY_HOST_CPU3=""
278        LEGACY_BUILD_CPU3=""
279    fi
280
281    # On MacOSX and MacOSX only, we have a different name for the x64 CPU in ARCH (LEGACY_HOST_CPU1) ...
282    if test "x$HOST_OS" = xmacosx && test "x$HOST_CPU" = xx64; then
283        LEGACY_HOST_CPU1="x86_64"
284    fi
285
286    SET_RELEASE_FILE_OS_VALUES()
287])
288
289AC_DEFUN([EXTRACT_VARS_FROM_OS_TO],
290[
291    EXTRACT_VARS_FROM_OS($2)
292    $1_OS="$VAR_OS"
293    $1_OS_FAMILY="$VAR_OS_FAMILY"
294    $1_OS_API="$VAR_OS_API"
295
296    AC_SUBST($1_OS)
297    AC_SUBST($1_OS_FAMILY)
298    AC_SUBST($1_OS_API)
299
300    if test "x$$1_OS_API" = xposix; then
301        LEGACY_$1_OS_API="solaris"
302    fi
303    if test "x$$1_OS_API" = xwinapi; then
304        LEGACY_$1_OS_API="windows"
305    fi
306    AC_SUBST(LEGACY_$1_OS_API)    
307])
308
309AC_DEFUN([EXTRACT_VARS_FROM_CPU_TO],
310[
311    EXTRACT_VARS_FROM_CPU($2)
312    $1_CPU="$VAR_CPU"
313    $1_CPU_ARCH="$VAR_CPU_ARCH"
314    $1_CPU_BITS="$VAR_CPU_BITS"
315    $1_CPU_ENDIAN="$VAR_CPU_ENDIAN"
316
317    AC_SUBST($1_CPU)
318    AC_SUBST($1_CPU_ARCH)
319    AC_SUBST($1_CPU_BITS)
320    AC_SUBST($1_CPU_ENDIAN)
321    
322    # Also store the legacy naming of the cpu.
323    # Ie i586 and amd64 instead of ia32 and x64
324    LEGACY_$1_CPU1="$VAR_LEGACY_CPU"
325    AC_SUBST(LEGACY_$1_CPU1)
326
327    # And the second legacy naming of the cpu.
328    # Ie i386 and amd64 instead of ia32 and x64.
329    LEGACY_$1_CPU2="$LEGACY_$1_CPU1"
330    if test "x$LEGACY_$1_CPU1" = xi586; then 
331        LEGACY_$1_CPU2=i386
332    fi
333    AC_SUBST(LEGACY_$1_CPU2)
334
335    # And the third legacy naming of the cpu.
336    # Ie only amd64 or sparcv9, used for the ISA_DIR on Solaris.
337    LEGACY_$1_CPU3=""
338    if test "x$$1_CPU" = xx64; then 
339        LEGACY_$1_CPU3=amd64
340    fi
341    if test "x$$1_CPU" = xsparcv9; then 
342        LEGACY_$1_CPU3=sparvc9
343    fi
344    AC_SUBST(LEGACY_$1_CPU3)
345])
346
347AC_DEFUN([EXTRACT_VARS_FROM_CPU],
348[
349  # First argument is the cpu name from the trip/quad
350  case "$1" in
351    x86_64)
352      VAR_CPU=x64
353      VAR_CPU_ARCH=x86
354      VAR_CPU_BITS=64
355      VAR_CPU_ENDIAN=little
356      VAR_LEGACY_CPU=amd64
357      ;;
358    i?86)
359      VAR_CPU=ia32
360      VAR_CPU_ARCH=x86
361      VAR_CPU_BITS=32
362      VAR_CPU_ENDIAN=little
363      VAR_LEGACY_CPU=i586
364      ;;
365    alpha*)
366      VAR_CPU=alpha
367      VAR_CPU_ARCH=alpha
368      VAR_CPU_BITS=64
369      VAR_CPU_ENDIAN=big
370      VAR_LEGACY_CPU=alpha
371      ;;
372    arm*)
373      VAR_CPU=arm
374      VAR_CPU_ARCH=arm
375      VAR_CPU_BITS=3264
376      VAR_CPU_ENDIAN=big
377      VAR_LEGACY_CPU=arm
378      ;;
379    mips)
380      VAR_CPU=mips
381      VAR_CPU_ARCH=mips
382      VAR_CPU_BITS=woot
383      VAR_CPU_ENDIAN=woot
384      VAR_LEGACY_CPU=mips
385       ;;
386    mipsel)
387      VAR_CPU=mipsel
388      VAR_CPU_ARCH=mips
389      VAR_CPU_BITS=woot
390      VAR_CPU_ENDIAN=woot
391      VAR_LEGACY_CPU=mipsel
392       ;;
393    powerpc)
394      VAR_CPU=ppc
395      VAR_CPU_ARCH=ppc
396      VAR_CPU_BITS=32
397      VAR_CPU_ENDIAN=big
398      VAR_LEGACY_CPU=ppc
399       ;;
400    powerpc64)
401      VAR_CPU=ppc64
402      VAR_CPU_ARCH=ppc
403      VAR_CPU_BITS=64
404      VAR_CPU_ENDIAN=32
405      VAR_LEGACY_CPU=ppc64
406       ;;
407    sparc)
408      VAR_CPU=sparc
409      VAR_CPU_ARCH=sparc
410      VAR_CPU_BITS=32
411      VAR_CPU_ENDIAN=big
412      VAR_LEGACY_CPU=sparc
413       ;;
414    sparc64)
415      VAR_CPU=sparcv9
416      VAR_CPU_ARCH=sparc
417      VAR_CPU_BITS=64
418      VAR_CPU_ENDIAN=big
419      VAR_LEGACY_CPU=sparc_sparcv9
420       ;;
421    s390)
422      VAR_CPU=s390
423      VAR_CPU_ARCH=s390
424      VAR_CPU_BITS=32
425      VAR_CPU_ENDIAN=woot
426      VAR_LEGACY_CPU=s390
427      VAR_LEGACY_CPU=s390
428       ;;
429    s390x)
430      VAR_CPU=s390x
431      VAR_CPU_ARCH=s390
432      VAR_CPU_BITS=64
433      VAR_CPU_ENDIAN=woot
434      VAR_LEGACY_CPU=s390x
435       ;;
436    *)
437      AC_MSG_ERROR([unsupported cpu $1])
438      ;;
439  esac
440
441  # Workaround cygwin not knowing about 64 bit.
442  if test "x$VAR_OS" = "xwindows"; then
443      if test "x$PROCESSOR_IDENTIFIER" != "x"; then
444          PROC_ARCH=`echo $PROCESSOR_IDENTIFIER | $CUT -f1 -d' '`
445          case "$PROC_ARCH" in
446            intel64|Intel64|INTEL64|em64t|EM64T|amd64|AMD64|8664|x86_64)
447              VAR_CPU=x64
448              VAR_CPU_BITS=64
449              VAR_LEGACY_CPU=amd64
450              ;;
451          esac
452      fi
453  fi
454
455  if test "x$VAR_CPU_ARCH" = "xx86"; then
456      if test "x$with_data_model" = "x64"; then
457          VAR_CPU=x64
458          VAR_CPU_BITS=64
459          VAR_LEGACY_CPU=amd64
460      fi
461      if test "x$with_data_model" = "x32"; then
462          VAR_CPU=ia32
463          VAR_CPU_BITS=32
464          VAR_LEGACY_CPU=i586
465      fi
466  fi 
467])
468
469AC_DEFUN([EXTRACT_VARS_FROM_OS],
470[
471  case "$1" in
472    *linux*)
473      VAR_OS=linux
474      VAR_OS_API=posix
475      VAR_OS_FAMILY=gnu
476      ;;
477    *solaris*)
478      VAR_OS=solaris
479      VAR_OS_API=posix
480      VAR_OS_FAMILY=sysv
481      ;;
482    *darwin*)
483      VAR_OS=macosx
484      VAR_OS_API=posix
485      VAR_OS_FAMILY=bsd
486      ;;
487    *bsd*)
488      VAR_OS=bsd
489      VAR_OS_API=posix
490      VAR_OS_FAMILY=bsd
491      ;;
492    *cygwin*|*windows*)
493      VAR_OS=windows
494      VAR_OS_API=winapi
495      VAR_OS_FAMILY=windows
496      ;;
497    *)
498      AC_MSG_ERROR([unsupported host operating system $1])
499      ;;
500  esac
501])
502
503AC_DEFUN([CHECK_COMPILER_VERSION],
504[
505    # Test the compilers that their versions are new enough.
506#    AC_MSG_CHECKING([version of GCC])
507    gcc_ver=`${CC} -dumpversion`
508    gcc_major_ver=`echo ${gcc_ver}|cut -d'.' -f1`
509    gcc_minor_ver=`echo ${gcc_ver}|cut -d'.' -f2`
510#    AM_CONDITIONAL(GCC_OLD, test ! ${gcc_major_ver} -ge 4 -a ${gcc_minor_ver} -ge 3)
511#    AC_MSG_RESULT([${gcc_ver} (major version ${gcc_major_ver}, minor version ${gcc_minor_ver})])
512]) 
513
514# Fixes paths on windows hosts to be mixed mode short.
515AC_DEFUN([WIN_FIX_PATH],
516[
517    if test "x$BUILD_OS" = "xwindows"; then
518        AC_PATH_PROG(CYGPATH, cygpath)
519        tmp="[$]$1"
520        # Convert to C:/ mixed style path without spaces.
521        tmp=`$CYGPATH -s -m "$tmp"`
522        $1="$tmp"
523    fi
524])
525
526AC_DEFUN([SET_RELEASE_FILE_OS_VALUES],
527[
528    if test "x$HOST_OS" = "xsolaris"; then
529       REQUIRED_OS_NAME=SunOS
530       REQUIRED_OS_VERSION=5.10
531    fi
532    if test "x$HOST_OS" = "xlinux"; then
533       REQUIRED_OS_NAME=Linux
534       REQUIRED_OS_VERSION=2.6
535    fi
536    if test "x$HOST_OS" = "xwindows"; then
537        REQUIRED_OS_NAME=Windows
538        REQUIRED_OS_VERSION=5.1
539    fi
540    if test "x$HOST_OS" = "xmacosx"; then
541        REQUIRED_OS_NAME=Darwin
542        REQUIRED_OS_VERSION=11.2
543    fi
544
545    AC_SUBST(REQUIRED_OS_NAME)
546    AC_SUBST(REQUIRED_OS_VERSION)
547])
548