common/autoconf/builddeps.m4

changeset 0
75a576e87639
child 1133
50aaf272884f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/common/autoconf/builddeps.m4	Wed Apr 27 01:39:08 2016 +0800
     1.3 @@ -0,0 +1,247 @@
     1.4 +#
     1.5 +# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 +#
     1.8 +# This code is free software; you can redistribute it and/or modify it
     1.9 +# under the terms of the GNU General Public License version 2 only, as
    1.10 +# published by the Free Software Foundation.  Oracle designates this
    1.11 +# particular file as subject to the "Classpath" exception as provided
    1.12 +# by Oracle in the LICENSE file that accompanied this code.
    1.13 +#
    1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 +# version 2 for more details (a copy is included in the LICENSE file that
    1.18 +# accompanied this code).
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License version
    1.21 +# 2 along with this work; if not, write to the Free Software Foundation,
    1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 +#
    1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 +# or visit www.oracle.com if you need additional information or have any
    1.26 +# questions.
    1.27 +#
    1.28 +
    1.29 +AC_DEFUN_ONCE([BDEPS_SCAN_FOR_BUILDDEPS],
    1.30 +[
    1.31 +  define(LIST_OF_BUILD_DEPENDENCIES,)
    1.32 +  if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then
    1.33 +    if test "x$with_builddeps_conf" != x; then
    1.34 +      AC_MSG_CHECKING([for supplied builddeps configuration file])
    1.35 +      builddepsfile=$with_builddeps_conf
    1.36 +      if test -s $builddepsfile; then
    1.37 +        . $builddepsfile
    1.38 +        AC_MSG_RESULT([loaded!])
    1.39 +      else
    1.40 +        AC_MSG_ERROR([The given builddeps conf file $with_builddeps_conf could not be loaded!])
    1.41 +      fi
    1.42 +    else
    1.43 +      AC_MSG_CHECKING([for builddeps.conf files in sources...])
    1.44 +      builddepsfile=`mktemp`
    1.45 +      touch $builddepsfile
    1.46 +      # Put all found confs into a single file.
    1.47 +      find ${SRC_ROOT} -name builddeps.conf -exec cat \{\} \; >> $builddepsfile
    1.48 +      # Source the file to acquire the variables
    1.49 +      if test -s $builddepsfile; then
    1.50 +        . $builddepsfile
    1.51 +        AC_MSG_RESULT([found at least one!])
    1.52 +      else
    1.53 +        AC_MSG_ERROR([Could not find any builddeps.conf at all!])
    1.54 +      fi
    1.55 +    fi
    1.56 +    # Create build and target names that use _ instead of "-" and ".".
    1.57 +    # This is necessary to use them in variable names.
    1.58 +    build_var=`echo ${OPENJDK_BUILD_AUTOCONF_NAME} | tr '-' '_' | tr '.' '_'`
    1.59 +    target_var=`echo ${OPENJDK_TARGET_AUTOCONF_NAME} | tr '-' '_' | tr '.' '_'`
    1.60 +    # Extract rewrite information for build and target
    1.61 +    eval rewritten_build=\${REWRITE_${build_var}}
    1.62 +    if test "x$rewritten_build" = x; then
    1.63 +      rewritten_build=${OPENJDK_BUILD_AUTOCONF_NAME}
    1.64 +      echo Build stays the same $rewritten_build
    1.65 +    else
    1.66 +      echo Rewriting build for builddeps into $rewritten_build
    1.67 +    fi
    1.68 +    eval rewritten_target=\${REWRITE_${target_var}}
    1.69 +    if test "x$rewritten_target" = x; then
    1.70 +      rewritten_target=${OPENJDK_TARGET_AUTOCONF_NAME}
    1.71 +      echo Target stays the same $rewritten_target
    1.72 +    else
    1.73 +      echo Rewriting target for builddeps into $rewritten_target
    1.74 +    fi
    1.75 +    rewritten_build_var=`echo ${rewritten_build} | tr '-' '_' | tr '.' '_'`
    1.76 +    rewritten_target_var=`echo ${rewritten_target} | tr '-' '_' | tr '.' '_'`
    1.77 +  fi
    1.78 +  AC_CHECK_PROGS(BDEPS_UNZIP, [7z unzip])
    1.79 +  if test "x$BDEPS_UNZIP" = x7z; then
    1.80 +    BDEPS_UNZIP="7z x"
    1.81 +  fi
    1.82 +
    1.83 +  AC_CHECK_PROGS(BDEPS_FTP, [wget lftp ftp])
    1.84 +])
    1.85 +
    1.86 +AC_DEFUN([BDEPS_FTPGET],
    1.87 +[
    1.88 +  # $1 is the ftp://abuilddeps.server.com/libs/cups.zip
    1.89 +  # $2 is the local file name for the downloaded file.
    1.90 +  VALID_TOOL=no
    1.91 +  if test "x$BDEPS_FTP" = xwget; then
    1.92 +    VALID_TOOL=yes
    1.93 +    wget -O $2 $1
    1.94 +  fi
    1.95 +  if test "x$BDEPS_FTP" = xlftp; then
    1.96 +    VALID_TOOL=yes
    1.97 +    lftp -c "get $1 -o $2"
    1.98 +  fi
    1.99 +  if test "x$BDEPS_FTP" = xftp; then
   1.100 +    VALID_TOOL=yes
   1.101 +    FTPSERVER=`echo $1 | cut -f 3 -d '/'`
   1.102 +    FTPPATH=`echo $1 | cut -f 4- -d '/'`
   1.103 +    FTPUSERPWD=${FTPSERVER%%@*}
   1.104 +    if test "x$FTPSERVER" != "x$FTPUSERPWD"; then
   1.105 +      FTPUSER=${userpwd%%:*}
   1.106 +      FTPPWD=${userpwd#*@}
   1.107 +      FTPSERVER=${FTPSERVER#*@}
   1.108 +    else
   1.109 +      FTPUSER=ftp
   1.110 +      FTPPWD=ftp
   1.111 +    fi
   1.112 +    # the "pass" command does not work on some
   1.113 +    # ftp clients (read ftp.exe) but if it works,
   1.114 +    # passive mode is better!
   1.115 +    ( \
   1.116 +        echo "user $FTPUSER $FTPPWD"        ; \
   1.117 +        echo "pass"                         ; \
   1.118 +        echo "bin"                          ; \
   1.119 +        echo "get $FTPPATH $2"              ; \
   1.120 +    ) | ftp -in $FTPSERVER
   1.121 +  fi
   1.122 +  if test "x$VALID_TOOL" != xyes; then
   1.123 +    AC_MSG_ERROR([I do not know how to use the tool: $BDEPS_FTP])
   1.124 +  fi
   1.125 +])
   1.126 +
   1.127 +AC_DEFUN([BDEPS_CHECK_MODULE],
   1.128 +[
   1.129 +  define([LIST_OF_BUILD_DEPENDENCIES],LIST_OF_BUILD_DEPENDENCIES[$2=$3'\n'])
   1.130 +  if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then
   1.131 +    # Source the builddeps file again, to make sure it uses the latest variables!
   1.132 +    . $builddepsfile
   1.133 +    # Look for a target and build machine specific resource!
   1.134 +    eval resource=\${builddep_$2_BUILD_${rewritten_build_var}_TARGET_${rewritten_target_var}}
   1.135 +    if test "x$resource" = x; then
   1.136 +      # Ok, lets instead look for a target specific resource
   1.137 +      eval resource=\${builddep_$2_TARGET_${rewritten_target_var}}
   1.138 +    fi
   1.139 +    if test "x$resource" = x; then
   1.140 +      # Ok, lets instead look for a build specific resource
   1.141 +      eval resource=\${builddep_$2_BUILD_${rewritten_build_var}}
   1.142 +    fi
   1.143 +    if test "x$resource" = x; then
   1.144 +      # Ok, lets instead look for a generic resource
   1.145 +      # (The $2 comes from M4 and not the shell, thus no need for eval here.)
   1.146 +      resource=${builddep_$2}
   1.147 +    fi
   1.148 +    if test "x$resource" != x; then
   1.149 +      AC_MSG_NOTICE([Using builddeps $resource for $2])
   1.150 +      # If the resource in the builddeps.conf file is an existing directory,
   1.151 +      # for example /java/linux/cups
   1.152 +      if test -d ${resource}; then
   1.153 +        depdir=${resource}
   1.154 +      else
   1.155 +        BDEPS_FETCH($2, $resource, $with_builddeps_server, $with_builddeps_dir, depdir)
   1.156 +      fi
   1.157 +      # Source the builddeps file again, because in the previous command, the depdir
   1.158 +      # was updated to point at the current build dependency install directory.
   1.159 +      . $builddepsfile
   1.160 +      # Now extract variables from the builddeps.conf files.
   1.161 +      theroot=${builddep_$2_ROOT}
   1.162 +      thecflags=${builddep_$2_CFLAGS}
   1.163 +      thelibs=${builddep_$2_LIBS}
   1.164 +      if test "x$depdir" = x; then
   1.165 +        AC_MSG_ERROR([Could not download build dependency $2])
   1.166 +      fi
   1.167 +      $1=$depdir
   1.168 +      if test "x$theroot" != x; then
   1.169 +        $1="$theroot"
   1.170 +      fi
   1.171 +      if test "x$thecflags" != x; then
   1.172 +        $1_CFLAGS="$thecflags"
   1.173 +      fi
   1.174 +      if test "x$thelibs" != x; then
   1.175 +        $1_LIBS="$thelibs"
   1.176 +      fi
   1.177 +      m4_default([$4], [:])
   1.178 +      m4_ifvaln([$5], [else $5])
   1.179 +    fi
   1.180 +    m4_ifvaln([$5], [else $5])
   1.181 +  fi
   1.182 +])
   1.183 +
   1.184 +AC_DEFUN([BDEPS_FETCH],
   1.185 +[
   1.186 +  # $1 is for example mymodule
   1.187 +  # $2 is for example libs/general/libmymod_1_2_3.zip
   1.188 +  # $3 is for example ftp://mybuilddeps.myserver.com/builddeps
   1.189 +  # $4 is for example /localhome/builddeps
   1.190 +  # $5 is the name of the variable into which we store the depdir, eg MYMOD
   1.191 +  # Will download ftp://mybuilddeps.myserver.com/builddeps/libs/general/libmymod_1_2_3.zip and
   1.192 +  # unzip into the directory: /localhome/builddeps/libmymod_1_2_3
   1.193 +  filename=`basename $2`
   1.194 +  filebase=`echo $filename | sed 's/\.[[^\.]]*$//'`
   1.195 +  filebase=${filename%%.*}
   1.196 +  extension=${filename#*.}
   1.197 +  installdir=$4/$filebase
   1.198 +  if test ! -f $installdir/$filename.unpacked; then
   1.199 +    AC_MSG_NOTICE([Downloading build dependency $1 from $3/$2 and installing into $installdir])
   1.200 +    if test ! -d $installdir; then
   1.201 +      mkdir -p $installdir
   1.202 +    fi
   1.203 +    if test ! -d $installdir; then
   1.204 +      AC_MSG_ERROR([Could not create directory $installdir])
   1.205 +    fi
   1.206 +    tmpfile=`mktemp $installdir/$1.XXXXXXXXX`
   1.207 +    touch $tmpfile
   1.208 +    if test ! -f $tmpfile; then
   1.209 +      AC_MSG_ERROR([Could not create files in directory $installdir])
   1.210 +    fi
   1.211 +    BDEPS_FTPGET([$3/$2] , [$tmpfile])
   1.212 +    mv $tmpfile $installdir/$filename
   1.213 +    if test ! -s $installdir/$filename; then
   1.214 +      AC_MSG_ERROR([Could not download $3/$2])
   1.215 +    fi
   1.216 +    case "$extension" in
   1.217 +      zip)  echo "Unzipping $installdir/$filename..."
   1.218 +        (cd $installdir ; rm -f $installdir/$filename.unpacked ; $BDEPS_UNZIP $installdir/$filename > /dev/null && touch $installdir/$filename.unpacked)
   1.219 +        ;;
   1.220 +      tar.gz) echo "Untaring $installdir/$filename..."
   1.221 +        (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked)
   1.222 +        ;;
   1.223 +      tgz) echo "Untaring $installdir/$filename..."
   1.224 +        (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked)
   1.225 +        ;;
   1.226 +      *) AC_MSG_ERROR([Cannot handle build depency archive with extension $extension])
   1.227 +        ;;
   1.228 +    esac
   1.229 +  fi
   1.230 +  if test -f $installdir/$filename.unpacked; then
   1.231 +    $5=$installdir
   1.232 +  fi
   1.233 +])
   1.234 +
   1.235 +AC_DEFUN_ONCE([BDEPS_CONFIGURE_BUILDDEPS],
   1.236 +[
   1.237 +  AC_ARG_WITH(builddeps-conf, [AS_HELP_STRING([--with-builddeps-conf],
   1.238 +      [use this configuration file for the builddeps])])
   1.239 +
   1.240 +  AC_ARG_WITH(builddeps-server, [AS_HELP_STRING([--with-builddeps-server],
   1.241 +      [download and use build dependencies from this server url])])
   1.242 +
   1.243 +  AC_ARG_WITH(builddeps-dir, [AS_HELP_STRING([--with-builddeps-dir],
   1.244 +      [store downloaded build dependencies here @<:@/localhome/builddeps@:>@])],
   1.245 +      [],
   1.246 +      [with_builddeps_dir=/localhome/builddeps])
   1.247 +
   1.248 +  AC_ARG_WITH(builddeps-group, [AS_HELP_STRING([--with-builddeps-group],
   1.249 +      [chgrp the downloaded build dependencies to this group])])
   1.250 +])

mercurial