common/autoconf/platform.m4

changeset 425
e1830598f0b7
child 445
efd26e051e50
equal deleted inserted replaced
419:42f275168fa5 425:e1830598f0b7
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 AC_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
48 AC_DEFUN([CHECK_NONEMPTY],
49 [
50 # Test that variable $1 is not empty.
51 if test "" = "[$]$1"; then AC_ERROR(Could not find translit($1,A-Z,a-z) !); fi
52 ])
53
54 AC_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
65 AC_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
90 AC_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_ERROR([You cannot have spaces in $2! "[$]$1"])
101 fi
102 fi
103 ])
104
105 AC_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
127 AC_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
172 AC_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
202 AC_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_TRY_COMPILE([], [], [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
241 AC_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,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
282 AC_DEFUN([EXTRACT_VARS_FROM_OS_TO],
283 [
284 EXTRACT_VARS_FROM_OS($2)
285 $1_OS="$VAR_OS"
286 $1_OS_FAMILY="$VAR_OS_FAMILY"
287 $1_OS_API="$VAR_OS_API"
288
289 AC_SUBST($1_OS)
290 AC_SUBST($1_OS_FAMILY)
291 AC_SUBST($1_OS_API)
292
293 if test "x$$1_OS_API" = xposix; then
294 LEGACY_$1_OS_API="solaris"
295 fi
296 if test "x$$1_OS_API" = xwinapi; then
297 LEGACY_$1_OS_API="windows"
298 fi
299 AC_SUBST(LEGACY_$1_OS_API)
300 ])
301
302 AC_DEFUN([EXTRACT_VARS_FROM_CPU_TO],
303 [
304 EXTRACT_VARS_FROM_CPU($2)
305 $1_CPU="$VAR_CPU"
306 $1_CPU_ARCH="$VAR_CPU_ARCH"
307 $1_CPU_BITS="$VAR_CPU_BITS"
308 $1_CPU_ENDIAN="$VAR_CPU_ENDIAN"
309
310 AC_SUBST($1_CPU)
311 AC_SUBST($1_CPU_ARCH)
312 AC_SUBST($1_CPU_BITS)
313 AC_SUBST($1_CPU_ENDIAN)
314
315 # Also store the legacy naming of the cpu.
316 # Ie i586 and amd64 instead of ia32 and x64
317 LEGACY_$1_CPU1="$VAR_LEGACY_CPU"
318 AC_SUBST(LEGACY_$1_CPU1)
319
320 # And the second legacy naming of the cpu.
321 # Ie i386 and amd64 instead of ia32 and x64.
322 LEGACY_$1_CPU2="$LEGACY_$1_CPU1"
323 if test "x$LEGACY_$1_CPU1" = xi586; then
324 LEGACY_$1_CPU2=i386
325 fi
326 AC_SUBST(LEGACY_$1_CPU2)
327
328 # And the third legacy naming of the cpu.
329 # Ie only amd64 or sparcv9, used for the ISA_DIR on Solaris.
330 LEGACY_$1_CPU3=""
331 if test "x$$1_CPU" = xx64; then
332 LEGACY_$1_CPU3=amd64
333 fi
334 if test "x$$1_CPU" = xsparcv9; then
335 LEGACY_$1_CPU3=sparvc9
336 fi
337 AC_SUBST(LEGACY_$1_CPU3)
338 ])
339
340 AC_DEFUN([EXTRACT_VARS_FROM_CPU],
341 [
342 # First argument is the cpu name from the trip/quad
343 case "$1" in
344 x86_64)
345 VAR_CPU=x64
346 VAR_CPU_ARCH=x86
347 VAR_CPU_BITS=64
348 VAR_CPU_ENDIAN=little
349 VAR_LEGACY_CPU=amd64
350 ;;
351 i?86)
352 VAR_CPU=ia32
353 VAR_CPU_ARCH=x86
354 VAR_CPU_BITS=32
355 VAR_CPU_ENDIAN=little
356 VAR_LEGACY_CPU=i586
357 ;;
358 alpha*)
359 VAR_CPU=alpha
360 VAR_CPU_ARCH=alpha
361 VAR_CPU_BITS=64
362 VAR_CPU_ENDIAN=big
363 VAR_LEGACY_CPU=alpha
364 ;;
365 arm*)
366 VAR_CPU=arm
367 VAR_CPU_ARCH=arm
368 VAR_CPU_BITS=3264
369 VAR_CPU_ENDIAN=big
370 VAR_LEGACY_CPU=arm
371 ;;
372 mips)
373 VAR_CPU=mips
374 VAR_CPU_ARCH=mips
375 VAR_CPU_BITS=woot
376 VAR_CPU_ENDIAN=woot
377 VAR_LEGACY_CPU=mips
378 ;;
379 mipsel)
380 VAR_CPU=mipsel
381 VAR_CPU_ARCH=mips
382 VAR_CPU_BITS=woot
383 VAR_CPU_ENDIAN=woot
384 VAR_LEGACY_CPU=mipsel
385 ;;
386 powerpc)
387 VAR_CPU=ppc
388 VAR_CPU_ARCH=ppc
389 VAR_CPU_BITS=32
390 VAR_CPU_ENDIAN=big
391 VAR_LEGACY_CPU=ppc
392 ;;
393 powerpc64)
394 VAR_CPU=ppc64
395 VAR_CPU_ARCH=ppc
396 VAR_CPU_BITS=64
397 VAR_CPU_ENDIAN=32
398 VAR_LEGACY_CPU=ppc64
399 ;;
400 sparc)
401 VAR_CPU=sparc
402 VAR_CPU_ARCH=sparc
403 VAR_CPU_BITS=32
404 VAR_CPU_ENDIAN=big
405 VAR_LEGACY_CPU=sparc
406 ;;
407 sparc64)
408 VAR_CPU=sparcv9
409 VAR_CPU_ARCH=sparc
410 VAR_CPU_BITS=64
411 VAR_CPU_ENDIAN=big
412 VAR_LEGACY_CPU=sparc_sparcv9
413 ;;
414 s390)
415 VAR_CPU=s390
416 VAR_CPU_ARCH=s390
417 VAR_CPU_BITS=32
418 VAR_CPU_ENDIAN=woot
419 VAR_LEGACY_CPU=s390
420 VAR_LEGACY_CPU=s390
421 ;;
422 s390x)
423 VAR_CPU=s390x
424 VAR_CPU_ARCH=s390
425 VAR_CPU_BITS=64
426 VAR_CPU_ENDIAN=woot
427 VAR_LEGACY_CPU=s390x
428 ;;
429 *)
430 AC_ERROR([unsupported cpu $1])
431 ;;
432 esac
433
434 # Workaround cygwin not knowing about 64 bit.
435 if test "x$VAR_OS" = "xwindows"; then
436 if test "x$PROCESSOR_IDENTIFIER" != "x"; then
437 PROC_ARCH=`echo $PROCESSOR_IDENTIFIER | $CUT -f1 -d' '`
438 case "$PROC_ARCH" in
439 intel64|Intel64|INTEL64|em64t|EM64T|amd64|AMD64|8664|x86_64)
440 VAR_CPU=x64
441 VAR_CPU_BITS=64
442 VAR_LEGACY_CPU=amd64
443 ;;
444 esac
445 fi
446 fi
447
448 if test "x$VAR_CPU_ARCH" = "xx86"; then
449 if test "x$with_data_model" = "x64"; then
450 VAR_CPU=x64
451 VAR_CPU_BITS=64
452 VAR_LEGACY_CPU=amd64
453 fi
454 if test "x$with_data_model" = "x32"; then
455 VAR_CPU=ia32
456 VAR_CPU_BITS=32
457 VAR_LEGACY_CPU=i586
458 fi
459 fi
460 ])
461
462 AC_DEFUN([EXTRACT_VARS_FROM_OS],
463 [
464 case "$1" in
465 *linux*)
466 VAR_OS=linux
467 VAR_OS_API=posix
468 VAR_OS_FAMILY=gnu
469 ;;
470 *solaris*)
471 VAR_OS=solaris
472 VAR_OS_API=posix
473 VAR_OS_FAMILY=sysv
474 ;;
475 *darwin*)
476 VAR_OS=macosx
477 VAR_OS_API=posix
478 VAR_OS_FAMILY=bsd
479 ;;
480 *bsd*)
481 VAR_OS=bsd
482 VAR_OS_API=posix
483 VAR_OS_FAMILY=bsd
484 ;;
485 *cygwin*|*windows*)
486 VAR_OS=windows
487 VAR_OS_API=winapi
488 VAR_OS_FAMILY=windows
489 ;;
490 *)
491 AC_MSG_ERROR([unsupported host operating system $1])
492 ;;
493 esac
494 ])
495
496 AC_DEFUN([CHECK_COMPILER_VERSION],
497 [
498 # Test the compilers that their versions are new enough.
499 # AC_MSG_CHECKING([version of GCC])
500 gcc_ver=`${CC} -dumpversion`
501 gcc_major_ver=`echo ${gcc_ver}|cut -d'.' -f1`
502 gcc_minor_ver=`echo ${gcc_ver}|cut -d'.' -f2`
503 # AM_CONDITIONAL(GCC_OLD, test ! ${gcc_major_ver} -ge 4 -a ${gcc_minor_ver} -ge 3)
504 # AC_MSG_RESULT([${gcc_ver} (major version ${gcc_major_ver}, minor version ${gcc_minor_ver})])
505 ])
506
507 # Fixes paths on windows hosts to be mixed mode short.
508 AC_DEFUN([WIN_FIX_PATH],
509 [
510 if test "x$BUILD_OS" = "xwindows"; then
511 AC_PATH_PROG(CYGPATH, cygpath)
512 tmp="[$]$1"
513 # Convert to C:/ mixed style path without spaces.
514 tmp=`$CYGPATH -s -m "$tmp"`
515 $1="$tmp"
516 fi
517 ])

mercurial