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([ADD_JVM_ARG_IF_OK],
  27 [
  28     # Test if $1 is a valid argument to $3 (often is $JAVA passed as $3)
  29     # If so, then append $1 to $2
  30     FOUND_WARN=`$3 $1 -version 2>&1 | grep -i warn`
  31     FOUND_VERSION=`$3 $1 -version 2>&1 | grep " version \""`
  32     if test "x$FOUND_VERSION" != x && test "x$FOUND_WARN" = x; then
  33         $2="[$]$2 $1"
  34     fi
  35 ])
  36 
  37 AC_DEFUN([WHICHCMD],
  38 [
  39     # Translate "gcc -E" into "`which gcc` -E" ie
  40     # extract the full path to the binary and at the
  41     # same time maintain any arguments passed to it.
  42     # The command MUST exist in the path, or else!
  43     tmp="[$]$1"
  44     car="${tmp%% *}"
  45     tmp="[$]$1 EOL"
  46     cdr="${tmp#* }"
  47     # On windows we want paths without spaces.
  48     if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
  49         WHICHCMD_SPACESAFE(car)
  50     else
  51         # "which" is not portable, but is used here
  52         # because we know that the command exists!
  53         car=`which $car`
  54     fi
  55     if test "x$cdr" != xEOL; then
  56         $1="$car ${cdr% *}"
  57     else
  58         $1="$car"
  59     fi
  60 ])
  61 
  62 AC_DEFUN([SPACESAFE],
  63 [
  64     # Fail with message $2 if var $1 contains a path with no spaces in it.
  65     # Unless on Windows, where we can rewrite the path.
  66     HAS_SPACE=`echo "[$]$1" | grep " "`
  67     if test "x$HAS_SPACE" != x; then
  68         if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
  69             $1=`$CYGPATH -s -m -a "[$]$1"`
  70             $1=`$CYGPATH -u "[$]$1"`            
  71         else
  72             AC_MSG_ERROR([You cannot have spaces in $2! "[$]$1"])
  73         fi
  74     fi
  75 ])
  76 
  77 AC_DEFUN([WHICHCMD_SPACESAFE],
  78 [
  79     # Translate long cygdrive or C:\sdfsf path
  80     # into a short mixed mode path that has no
  81     # spaces in it.
  82     tmp="[$]$1"
  83     
  84     if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
  85         tmp=`$CYGPATH -u "[$]$1"`
  86         tmp=`which "$tmp"`
  87         # If file exists with .exe appended, that's the real filename
  88         # and cygpath needs that to convert to short style path.
  89         if test -f "${tmp}.exe"; then
  90            tmp="${tmp}.exe"
  91         elif test -f "${tmp}.cmd"; then
  92            tmp="${tmp}.cmd"
  93         fi
  94         # Convert to C:/ mixed style path without spaces.
  95          tmp=`$CYGPATH -s -m "$tmp"`
  96     fi
  97     $1="$tmp"
  98 ])
  99 
 100 AC_DEFUN([REMOVE_SYMBOLIC_LINKS],
 101 [
 102     if test "x$OPENJDK_BUILD_OS" != xwindows; then
 103         # Follow a chain of symbolic links. Use readlink
 104         # where it exists, else fall back to horribly
 105         # complicated shell code.
 106         AC_PATH_PROG(READLINK, readlink)
 107         if test "x$READLINK_TESTED" != yes; then
 108             # On MacOSX there is a readlink tool with a different
 109             # purpose than the GNU readlink tool. Check the found readlink.
 110             ISGNU=`$READLINK --help 2>&1 | grep GNU`
 111             if test "x$ISGNU" = x; then
 112                  # A readlink that we do not know how to use.
 113                  # Are there other non-GNU readlinks out there?
 114                  READLINK_TESTED=yes
 115                  READLINK=
 116             fi
 117         fi
 118 
 119         if test "x$READLINK" != x; then
 120             $1=`$READLINK -f [$]$1`
 121         else
 122             STARTDIR=$PWD
 123             COUNTER=0
 124             DIR=`dirname [$]$1`
 125             FIL=`basename [$]$1`
 126             while test $COUNTER -lt 20; do
 127                 ISLINK=`ls -l $DIR/$FIL | grep '\->' | sed -e 's/.*-> \(.*\)/\1/'`
 128                 if test "x$ISLINK" == x; then
 129                     # This is not a symbolic link! We are done!
 130                     break
 131                 fi
 132                 # The link might be relative! We have to use cd to travel safely.
 133                 cd $DIR
 134                 cd `dirname $ISLINK`
 135                 DIR=`pwd`
 136                 FIL=`basename $ISLINK`
 137                 let COUNTER=COUNTER+1
 138             done
 139             cd $STARTDIR
 140             $1=$DIR/$FIL
 141         fi
 142     fi
 143 ])
 144 
 145 AC_DEFUN_ONCE([BASIC_INIT],
 146 [
 147 # Save the original command line. This is passed to us by the wrapper configure script.
 148 AC_SUBST(CONFIGURE_COMMAND_LINE)
 149 DATE_WHEN_CONFIGURED=`LANG=C date`
 150 AC_SUBST(DATE_WHEN_CONFIGURED)
 151 
 152 # Locate the directory of this script.
 153 SCRIPT="[$]0"
 154 REMOVE_SYMBOLIC_LINKS(SCRIPT)        
 155 AUTOCONF_DIR=`dirname [$]0`
 156 ])
 157 
 158 AC_DEFUN_ONCE([BASIC_SETUP_PATHS],
 159 [
 160 # Where is the source? It is located two levels above the configure script.
 161 CURDIR="$PWD"
 162 cd "$AUTOCONF_DIR/../.."
 163 SRC_ROOT="`pwd`"
 164 if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
 165     SRC_ROOT_LENGTH=`pwd|wc -m`
 166     if test $SRC_ROOT_LENGTH -gt 100; then
 167         AC_MSG_ERROR([Your base path is too long. It is $SRC_ROOT_LENGTH characters long, but only 100 is supported])
 168     fi
 169 fi
 170 AC_SUBST(SRC_ROOT)
 171 cd "$CURDIR"
 172 
 173 SPACESAFE(SRC_ROOT,[the path to the source root])
 174 SPACESAFE(CURDIR,[the path to the current directory])
 175 ])
 176 
 177 AC_DEFUN_ONCE([BASIC_SETUP_SEARCHPATH],
 178 [
 179 if test "x$OPENJDK_BUILD_OS" = "xsolaris"; then
 180     # Add extra search paths on solaris for utilities like ar and as etc...
 181     PATH="$PATH:/usr/ccs/bin:/usr/sfw/bin:/opt/csw/bin"
 182 fi
 183 ])
 184 
 185 AC_DEFUN_ONCE([BASIC_SETUP_PATH_SEP],
 186 [
 187 # For cygwin we need cygpath first, since it is used everywhere.
 188 AC_PATH_PROG(CYGPATH, cygpath)
 189 PATH_SEP=":"
 190 if test "x$OPENJDK_BUILD_OS" = "xwindows"; then
 191     if test "x$CYGPATH" = x; then
 192         AC_MSG_ERROR([Something is wrong with your cygwin installation since I cannot find cygpath.exe in your path])
 193     fi
 194     PATH_SEP=";"
 195 fi
 196 AC_SUBST(PATH_SEP)
 197 ])
 198 
 199 AC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR],
 200 [
 201 
 202 AC_ARG_WITH(conf-name, [AS_HELP_STRING([--with-conf-name],
 203         [use this as the name of the configuration, overriding the generated default])],
 204         [ CONF_NAME=${with_conf_name} ])
 205 
 206 # Test from where we are running configure, in or outside of src root.
 207 if test "x$CURDIR" = "x$SRC_ROOT" || test "x$CURDIR" = "x$SRC_ROOT/common" || test "x$CURDIR" = "x$SRC_ROOT/common/autoconf" || test "x$CURDIR" = "x$SRC_ROOT/common/makefiles" ; then
 208     # We are running configure from the src root.
 209     # Create a default ./build/target-variant-debuglevel output root.
 210     if test "x${CONF_NAME}" = x; then
 211         CONF_NAME="${OPENJDK_TARGET_OS}-${OPENJDK_TARGET_CPU}-${JDK_VARIANT}-${ANDED_JVM_VARIANTS}-${DEBUG_LEVEL}"
 212     fi
 213     OUTPUT_ROOT="$SRC_ROOT/build/${CONF_NAME}"
 214     mkdir -p "$OUTPUT_ROOT"
 215     if test ! -d "$OUTPUT_ROOT"; then
 216         AC_MSG_ERROR([Could not create build directory $OUTPUT_ROOT])
 217     fi
 218 else
 219     # We are running configure from outside of the src dir.
 220     # Then use the current directory as output dir!
 221     # If configuration is situated in normal build directory, just use the build
 222     # directory name as configuration name, otherwise use the complete path.
 223     if test "x${CONF_NAME}" = x; then
 224         CONF_NAME=`$ECHO $CURDIR | $SED -e "s!^${SRC_ROOT}/build/!!"`
 225     fi
 226     OUTPUT_ROOT="$CURDIR"
 227 fi
 228 
 229 SPACESAFE(OUTPUT_ROOT,[the path to the output root])
 230 
 231 AC_SUBST(SPEC, $OUTPUT_ROOT/spec.gmk)
 232 AC_SUBST(CONF_NAME, $CONF_NAME)
 233 AC_SUBST(OUTPUT_ROOT, $OUTPUT_ROOT)
 234 
 235 # Most of the probed defines are put into config.h
 236 AC_CONFIG_HEADERS([$OUTPUT_ROOT/config.h:$AUTOCONF_DIR/config.h.in])
 237 # The spec.gmk file contains all variables for the make system.
 238 AC_CONFIG_FILES([$OUTPUT_ROOT/spec.gmk:$AUTOCONF_DIR/spec.gmk.in])
 239 # The spec.sh file contains variables for compare{images|-objects}.sh scrips.
 240 AC_CONFIG_FILES([$OUTPUT_ROOT/spec.sh:$AUTOCONF_DIR/spec.sh.in])
 241 # The generated Makefile knows where the spec.gmk is and where the source is.
 242 # You can run make from the OUTPUT_ROOT, or from the top-level Makefile
 243 # which will look for generated configurations
 244 AC_CONFIG_FILES([$OUTPUT_ROOT/Makefile:$AUTOCONF_DIR/Makefile.in])
 245 
 246 # Save the arguments given to us
 247 echo "$CONFIGURE_COMMAND_LINE" > $OUTPUT_ROOT/configure-arguments
 248 ])
 249 
 250 AC_DEFUN_ONCE([BASIC_SETUP_LOGGING],
 251 [
 252 # Setup default logging of stdout and stderr to build.log in the output root.
 253 BUILD_LOG='$(OUTPUT_ROOT)/build.log'
 254 BUILD_LOG_PREVIOUS='$(OUTPUT_ROOT)/build.log.old'
 255 BUILD_LOG_WRAPPER='$(SH) $(SRC_ROOT)/common/bin/logger.sh $(BUILD_LOG)'
 256 AC_SUBST(BUILD_LOG)
 257 AC_SUBST(BUILD_LOG_PREVIOUS)
 258 AC_SUBST(BUILD_LOG_WRAPPER)
 259 ])
 260 
 261 
 262 #%%% Simple tools %%%
 263 
 264 AC_DEFUN([BASIC_CHECK_FIND_DELETE],
 265 [
 266     # Test if find supports -delete
 267     AC_MSG_CHECKING([if find supports -delete])
 268     FIND_DELETE="-delete"
 269 
 270     DELETEDIR=`mktemp -d tmp.XXXXXXXXXX` || (echo Could not create temporary directory!; exit $?)
 271 
 272     echo Hejsan > $DELETEDIR/TestIfFindSupportsDelete
 273 
 274     TEST_DELETE=`$FIND "$DELETEDIR" -name TestIfFindSupportsDelete $FIND_DELETE 2>&1`
 275     if test -f $DELETEDIR/TestIfFindSupportsDelete; then
 276         # No, it does not.
 277         rm $DELETEDIR/TestIfFindSupportsDelete
 278         FIND_DELETE="-exec rm \{\} \+"
 279         AC_MSG_RESULT([no])    
 280     else
 281         AC_MSG_RESULT([yes])    
 282     fi
 283     rmdir $DELETEDIR
 284 ])
 285 
 286 AC_DEFUN([CHECK_NONEMPTY],
 287 [
 288     # Test that variable $1 is not empty.
 289     if test "" = "[$]$1"; then AC_MSG_ERROR(Could not find translit($1,A-Z,a-z) !); fi
 290 ])
 291 
 292 AC_DEFUN_ONCE([BASIC_SETUP_TOOLS],
 293 [
 294 # Start with tools that do not need have cross compilation support
 295 # and can be expected to be found in the default PATH. These tools are
 296 # used by configure. Nor are these tools expected to be found in the
 297 # devkit from the builddeps server either, since they are
 298 # needed to download the devkit. 
 299 AC_PROG_AWK
 300 CHECK_NONEMPTY(AWK)
 301 AC_PATH_PROG(CAT, cat)
 302 CHECK_NONEMPTY(CAT)
 303 AC_PATH_PROG(CHMOD, chmod)
 304 CHECK_NONEMPTY(CHMOD)
 305 AC_PATH_PROG(CP, cp)
 306 CHECK_NONEMPTY(CP)
 307 AC_PATH_PROG(CPIO, cpio)
 308 CHECK_NONEMPTY(CPIO)
 309 AC_PATH_PROG(CUT, cut)
 310 CHECK_NONEMPTY(CUT)
 311 AC_PATH_PROG(DATE, date)
 312 CHECK_NONEMPTY(DATE)
 313 AC_PATH_PROG(DF, df)
 314 CHECK_NONEMPTY(DF)
 315 AC_PATH_PROG(DIFF, diff)
 316 CHECK_NONEMPTY(DIFF)
 317 # Warning echo is really, really unportable!!!!! Different
 318 # behaviour in bash and dash and in a lot of other shells!
 319 # Use printf for serious work! 
 320 AC_PATH_PROG(ECHO, echo)
 321 CHECK_NONEMPTY(ECHO)
 322 AC_PROG_EGREP
 323 CHECK_NONEMPTY(EGREP)
 324 AC_PROG_FGREP
 325 CHECK_NONEMPTY(FGREP)
 326 
 327 AC_PATH_PROG(FIND, find)
 328 CHECK_NONEMPTY(FIND)
 329 BASIC_CHECK_FIND_DELETE
 330 AC_SUBST(FIND_DELETE)
 331 
 332 AC_PROG_GREP
 333 CHECK_NONEMPTY(GREP)
 334 AC_PATH_PROG(HEAD, head)
 335 CHECK_NONEMPTY(HEAD)
 336 AC_PATH_PROG(LN, ln)
 337 CHECK_NONEMPTY(LN)
 338 AC_PATH_PROG(LS, ls)
 339 CHECK_NONEMPTY(LS)
 340 AC_PATH_PROGS(MAKE, [gmake make])
 341 CHECK_NONEMPTY(MAKE)
 342 MAKE_VERSION=`$MAKE --version | head -n 1 | grep '3.8[[12346789]]'`
 343 if test "x$MAKE_VERSION" = x; then
 344     AC_MSG_ERROR([You must use GNU make 3.81 or newer! Please put it in the path, or add e.g. MAKE=/opt/gmake3.81/make as argument to configure.])
 345 fi
 346 AC_PATH_PROG(MKDIR, mkdir)
 347 CHECK_NONEMPTY(MKDIR)
 348 AC_PATH_PROG(MV, mv)
 349 CHECK_NONEMPTY(MV)
 350 AC_PATH_PROGS(NAWK, [nawk gawk awk])
 351 CHECK_NONEMPTY(NAWK)
 352 AC_PATH_PROG(PRINTF, printf)
 353 CHECK_NONEMPTY(PRINTF)
 354 AC_PATH_PROG(THEPWDCMD, pwd)
 355 AC_PATH_PROG(RM, rm)
 356 CHECK_NONEMPTY(RM)
 357 RM="$RM -f"
 358 AC_PROG_SED
 359 CHECK_NONEMPTY(SED)
 360 AC_PATH_PROG(SH, sh)
 361 CHECK_NONEMPTY(SH)
 362 AC_PATH_PROG(SORT, sort)
 363 CHECK_NONEMPTY(SORT)
 364 AC_PATH_PROG(TAR, tar)
 365 CHECK_NONEMPTY(TAR)
 366 AC_PATH_PROG(TAIL, tail)
 367 CHECK_NONEMPTY(TAIL)
 368 AC_PATH_PROG(TEE, tee)
 369 CHECK_NONEMPTY(TEE)
 370 AC_PATH_PROG(TR, tr)
 371 CHECK_NONEMPTY(TR)
 372 AC_PATH_PROG(TOUCH, touch)
 373 CHECK_NONEMPTY(TOUCH)
 374 AC_PATH_PROG(WC, wc)
 375 CHECK_NONEMPTY(WC)
 376 AC_PATH_PROG(XARGS, xargs)
 377 CHECK_NONEMPTY(XARGS)
 378 AC_PATH_PROG(ZIP, zip)
 379 CHECK_NONEMPTY(ZIP)
 380 AC_PATH_PROG(UNZIP, unzip)
 381 CHECK_NONEMPTY(UNZIP)
 382 AC_PATH_PROG(LDD, ldd)
 383 if test "x$LDD" = "x"; then
 384     # List shared lib dependencies is used for
 385     # debug output and checking for forbidden dependencies.
 386     # We can build without it.
 387     LDD="true"
 388 fi
 389 AC_PATH_PROG(OTOOL, otool)
 390 if test "x$OTOOL" = "x"; then
 391    OTOOL="true"
 392 fi
 393 AC_PATH_PROG(READELF, readelf)
 394 AC_PATH_PROG(EXPR, expr)
 395 CHECK_NONEMPTY(EXPR)
 396 AC_PATH_PROG(FILE, file)
 397 CHECK_NONEMPTY(FILE)
 398 AC_PATH_PROG(HG, hg)
 399 ])
 400 
 401 
 402 
 403 AC_DEFUN_ONCE([BASIC_COMPILE_UNCYGDRIVE],
 404 [
 405 # When using cygwin, we need a wrapper binary that renames
 406 # /cygdrive/c/ arguments into c:/ arguments and peeks into
 407 # @files and rewrites these too! This wrapper binary is
 408 # called uncygdrive.exe.
 409 UNCYGDRIVE=
 410 if test "x$OPENJDK_BUILD_OS" = xwindows; then
 411     AC_MSG_CHECKING([if uncygdrive can be created])
 412     UNCYGDRIVE_SRC=`$CYGPATH -m $SRC_ROOT/common/src/uncygdrive.c`
 413     rm -f $OUTPUT_ROOT/uncygdrive*
 414     UNCYGDRIVE=`$CYGPATH -m $OUTPUT_ROOT/uncygdrive.exe`
 415     cd $OUTPUT_ROOT
 416     $CC $UNCYGDRIVE_SRC /Fe$UNCYGDRIVE > $OUTPUT_ROOT/uncygdrive1.log 2>&1
 417     cd $CURDIR
 418 
 419     if test ! -x $OUTPUT_ROOT/uncygdrive.exe; then 
 420         AC_MSG_RESULT([no])
 421         cat $OUTPUT_ROOT/uncygdrive1.log
 422         AC_MSG_ERROR([Could not create $OUTPUT_ROOT/uncygdrive.exe])
 423     fi
 424     AC_MSG_RESULT([$UNCYGDRIVE])
 425     AC_MSG_CHECKING([if uncygdrive.exe works])
 426     cd $OUTPUT_ROOT
 427     $UNCYGDRIVE $CC $SRC_ROOT/common/src/uncygdrive.c /Fe$OUTPUT_ROOT/uncygdrive2.exe > $OUTPUT_ROOT/uncygdrive2.log 2>&1 
 428     cd $CURDIR
 429     if test ! -x $OUTPUT_ROOT/uncygdrive2.exe; then 
 430         AC_MSG_RESULT([no])
 431         cat $OUTPUT_ROOT/uncygdrive2.log
 432         AC_MSG_ERROR([Uncygdrive did not work!])
 433     fi
 434     AC_MSG_RESULT([yes])
 435     rm -f $OUTPUT_ROOT/uncygdrive?.??? $OUTPUT_ROOT/uncygdrive.obj
 436 fi
 437 
 438 AC_SUBST(UNCYGDRIVE)
 439 ])
 440 
 441 
 442 # Check if build directory is on local disk.
 443 # Argument 1: directory to test
 444 # Argument 2: what to do if it is on local disk
 445 # Argument 3: what to do otherwise (remote disk or failure)
 446 AC_DEFUN([BASIC_CHECK_DIR_ON_LOCAL_DISK],
 447 [
 448         # df -l lists only local disks; if the given directory is not found then
 449         # a non-zero exit code is given
 450         if $DF -l $1 > /dev/null 2>&1; then
 451           $2
 452         else
 453           $3
 454         fi
 455 ])
 456 
 457 AC_DEFUN_ONCE([BASIC_TEST_USABILITY_ISSUES],
 458 [
 459 
 460 AC_MSG_CHECKING([if build directory is on local disk])
 461 BASIC_CHECK_DIR_ON_LOCAL_DISK($OUTPUT_ROOT,
 462   [OUTPUT_DIR_IS_LOCAL="yes"],
 463   [OUTPUT_DIR_IS_LOCAL="no"])
 464 AC_MSG_RESULT($OUTPUT_DIR_IS_LOCAL)
 465 
 466 # Check if the user has any old-style ALT_ variables set.
 467 FOUND_ALT_VARIABLES=`env | grep ^ALT_`
 468 
 469 # Before generating output files, test if they exist. If they do, this is a reconfigure.
 470 # Since we can't properly handle the dependencies for this, warn the user about the situation
 471 if test -e $OUTPUT_ROOT/spec.gmk; then
 472   IS_RECONFIGURE=yes
 473 else
 474   IS_RECONFIGURE=no
 475 fi
 476 
 477 if test -e $SRC_ROOT/build/.hide-configure-performance-hints; then
 478   HIDE_PERFORMANCE_HINTS=yes
 479 else
 480   HIDE_PERFORMANCE_HINTS=no
 481   # Hide it the next time around...
 482   $TOUCH $SRC_ROOT/build/.hide-configure-performance-hints > /dev/null 2>&1
 483 fi
 484 
 485 ])