ohair@425: # ohair@425: # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. ohair@425: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@425: # ohair@425: # This code is free software; you can redistribute it and/or modify it ohair@425: # under the terms of the GNU General Public License version 2 only, as ohair@425: # published by the Free Software Foundation. Oracle designates this ohair@425: # particular file as subject to the "Classpath" exception as provided ohair@425: # by Oracle in the LICENSE file that accompanied this code. ohair@425: # ohair@425: # This code is distributed in the hope that it will be useful, but WITHOUT ohair@425: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@425: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@425: # version 2 for more details (a copy is included in the LICENSE file that ohair@425: # accompanied this code). ohair@425: # ohair@425: # You should have received a copy of the GNU General Public License version ohair@425: # 2 along with this work; if not, write to the Free Software Foundation, ohair@425: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@425: # ohair@425: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@425: # or visit www.oracle.com if you need additional information or have any ohair@425: # questions. ohair@425: # ohair@425: erikj@458: AC_DEFUN_ONCE([BDEPS_SCAN_FOR_BUILDDEPS], ohair@425: [ ohair@425: define(LIST_OF_BUILD_DEPENDENCIES,) ohair@425: if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then ohair@425: if test "x$with_builddeps_conf" != x; then ohair@425: AC_MSG_CHECKING([for supplied builddeps configuration file]) ohair@425: builddepsfile=$with_builddeps_conf ohair@425: if test -s $builddepsfile; then ohair@425: . $builddepsfile ohair@425: AC_MSG_RESULT([loaded!]) ohair@425: else erikj@445: AC_MSG_ERROR([The given builddeps conf file $with_builddeps_conf could not be loaded!]) ohair@425: fi ohair@425: else ohair@425: AC_MSG_CHECKING([for builddeps.conf files in sources...]) ohair@425: builddepsfile=`mktemp` ohair@425: touch $builddepsfile ohair@425: # Put all found confs into a single file. ohair@425: find ${SRC_ROOT} -name builddeps.conf -exec cat \{\} \; >> $builddepsfile ohair@425: # Source the file to acquire the variables ohair@425: if test -s $builddepsfile; then ohair@425: . $builddepsfile ohair@425: AC_MSG_RESULT([found at least one!]) ohair@425: else erikj@445: AC_MSG_ERROR([Could not find any builddeps.conf at all!]) ohair@425: fi ohair@425: fi erikj@458: # Create build and target names that use _ instead of "-" and ".". ohair@425: # This is necessary to use them in variable names. ohair@478: build_var=`echo ${OPENJDK_BUILD_AUTOCONF_NAME} | tr '-' '_' | tr '.' '_'` ohair@478: target_var=`echo ${OPENJDK_TARGET_AUTOCONF_NAME} | tr '-' '_' | tr '.' '_'` erikj@458: # Extract rewrite information for build and target ohair@425: eval rewritten_build=\${REWRITE_${build_var}} ohair@425: if test "x$rewritten_build" = x; then ohair@478: rewritten_build=${OPENJDK_BUILD_AUTOCONF_NAME} ohair@425: echo Build stays the same $rewritten_build ohair@425: else ohair@425: echo Rewriting build for builddeps into $rewritten_build ohair@425: fi erikj@458: eval rewritten_target=\${REWRITE_${target_var}} erikj@458: if test "x$rewritten_target" = x; then ohair@478: rewritten_target=${OPENJDK_TARGET_AUTOCONF_NAME} erikj@458: echo Target stays the same $rewritten_target ohair@425: else erikj@458: echo Rewriting target for builddeps into $rewritten_target ohair@425: fi ohair@425: rewritten_build_var=`echo ${rewritten_build} | tr '-' '_' | tr '.' '_'` erikj@458: rewritten_target_var=`echo ${rewritten_target} | tr '-' '_' | tr '.' '_'` ohair@425: fi ohair@425: AC_CHECK_PROGS(BDEPS_UNZIP, [7z unzip]) ohair@425: if test "x$BDEPS_UNZIP" = x7z; then ohair@425: BDEPS_UNZIP="7z x" ohair@425: fi ohair@425: ohair@425: AC_CHECK_PROGS(BDEPS_FTP, [wget lftp ftp]) ohair@425: ]) ohair@425: ohair@425: AC_DEFUN([BDEPS_FTPGET], ohair@425: [ ohair@425: # $1 is the ftp://abuilddeps.server.com/libs/cups.zip ohair@425: # $2 is the local file name for the downloaded file. ohair@425: VALID_TOOL=no ohair@425: if test "x$BDEPS_FTP" = xwget; then ohair@425: VALID_TOOL=yes ohair@425: wget -O $2 $1 ohair@425: fi ohair@425: if test "x$BDEPS_FTP" = xlftp; then ohair@425: VALID_TOOL=yes ohair@425: lftp -c "get $1 -o $2" ohair@425: fi ohair@425: if test "x$BDEPS_FTP" = xftp; then ohair@425: VALID_TOOL=yes ohair@425: FTPSERVER=`echo $1 | cut -f 3 -d '/'` ohair@425: FTPPATH=`echo $1 | cut -f 4- -d '/'` ohair@425: FTPUSERPWD=${FTPSERVER%%@*} ohair@425: if test "x$FTPSERVER" != "x$FTPUSERPWD"; then ohair@425: FTPUSER=${userpwd%%:*} ohair@425: FTPPWD=${userpwd#*@} ohair@425: FTPSERVER=${FTPSERVER#*@} ohair@425: else ohair@425: FTPUSER=ftp ohair@425: FTPPWD=ftp ohair@425: fi ohair@425: # the "pass" command does not work on some ohair@425: # ftp clients (read ftp.exe) but if it works, ohair@425: # passive mode is better! ohair@425: (\ ohair@425: echo "user $FTPUSER $FTPPWD" ;\ ohair@425: echo "pass" ;\ ohair@425: echo "bin" ;\ ohair@425: echo "get $FTPPATH $2" ;\ ohair@425: ) | ftp -in $FTPSERVER ohair@425: fi ohair@425: if test "x$VALID_TOOL" != xyes; then erikj@445: AC_MSG_ERROR([I do not know how to use the tool: $BDEPS_FTP]) ohair@425: fi ohair@425: ]) ohair@425: ohair@425: AC_DEFUN([BDEPS_CHECK_MODULE], ohair@425: [ ohair@425: define([LIST_OF_BUILD_DEPENDENCIES],LIST_OF_BUILD_DEPENDENCIES[$2=$3'\n']) ohair@425: if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then ohair@425: # Source the builddeps file again, to make sure it uses the latest variables! ohair@425: . $builddepsfile erikj@458: # Look for a target and build machine specific resource! erikj@458: eval resource=\${builddep_$2_BUILD_${rewritten_build_var}_TARGET_${rewritten_target_var}} ohair@425: if test "x$resource" = x; then erikj@458: # Ok, lets instead look for a target specific resource erikj@458: eval resource=\${builddep_$2_TARGET_${rewritten_target_var}} ohair@425: fi ohair@425: if test "x$resource" = x; then ohair@425: # Ok, lets instead look for a build specific resource ohair@425: eval resource=\${builddep_$2_BUILD_${rewritten_build_var}} ohair@425: fi ohair@425: if test "x$resource" = x; then ohair@425: # Ok, lets instead look for a generic resource ohair@425: # (The $2 comes from M4 and not the shell, thus no need for eval here.) ohair@425: resource=${builddep_$2} ohair@425: fi ohair@425: if test "x$resource" != x; then ohair@425: AC_MSG_NOTICE([Using builddeps $resource for $2]) ohair@425: # If the resource in the builddeps.conf file is an existing directory, ohair@425: # for example /java/linux/cups ohair@425: if test -d ${resource}; then ohair@425: depdir=${resource} ohair@425: else ohair@425: BDEPS_FETCH($2, $resource, $with_builddeps_server, $with_builddeps_dir, depdir) ohair@425: fi ohair@425: # Source the builddeps file again, because in the previous command, the depdir ohair@425: # was updated to point at the current build dependency install directory. ohair@425: . $builddepsfile ohair@425: # Now extract variables from the builddeps.conf files. ohair@425: theroot=${builddep_$2_ROOT} ohair@425: thecflags=${builddep_$2_CFLAGS} ohair@425: thelibs=${builddep_$2_LIBS} ohair@425: if test "x$depdir" = x; then erikj@445: AC_MSG_ERROR([Could not download build dependency $2]) ohair@425: fi ohair@425: $1=$depdir ohair@425: if test "x$theroot" != x; then ohair@425: $1="$theroot" ohair@425: fi ohair@425: if test "x$thecflags" != x; then ohair@425: $1_CFLAGS="$thecflags" ohair@425: fi ohair@425: if test "x$thelibs" != x; then ohair@425: $1_LIBS="$thelibs" ohair@425: fi ohair@425: m4_default([$4], [:]) ohair@425: m4_ifvaln([$5], [else $5]) ohair@425: fi ohair@425: m4_ifvaln([$5], [else $5]) ohair@425: fi ohair@425: ]) ohair@425: ohair@425: AC_DEFUN([BDEPS_FETCH], ohair@425: [ ohair@425: # $1 is for example mymodule ohair@425: # $2 is for example libs/general/libmymod_1_2_3.zip ohair@425: # $3 is for example ftp://mybuilddeps.myserver.com/builddeps ohair@425: # $4 is for example /localhome/builddeps ohair@425: # $5 is the name of the variable into which we store the depdir, eg MYMOD ohair@425: # Will download ftp://mybuilddeps.myserver.com/builddeps/libs/general/libmymod_1_2_3.zip and ohair@425: # unzip into the directory: /localhome/builddeps/libmymod_1_2_3 ohair@425: filename=`basename $2` ohair@425: filebase=`echo $filename | sed 's/\.[[^\.]]*$//'` ohair@425: filebase=${filename%%.*} ohair@425: extension=${filename#*.} ohair@425: installdir=$4/$filebase ohair@425: if test ! -f $installdir/$filename.unpacked; then ohair@425: AC_MSG_NOTICE([Downloading build dependency $1 from $3/$2 and installing into $installdir]) ohair@425: if test ! -d $installdir; then ohair@425: mkdir -p $installdir ohair@425: fi ohair@425: if test ! -d $installdir; then erikj@445: AC_MSG_ERROR([Could not create directory $installdir]) ohair@425: fi ohair@425: tmpfile=`mktemp $installdir/$1.XXXXXXXXX` ohair@425: touch $tmpfile ohair@425: if test ! -f $tmpfile; then erikj@445: AC_MSG_ERROR([Could not create files in directory $installdir]) ohair@425: fi ohair@425: BDEPS_FTPGET([$3/$2] , [$tmpfile]) ohair@425: mv $tmpfile $installdir/$filename ohair@425: if test ! -s $installdir/$filename; then erikj@445: AC_MSG_ERROR([Could not download $3/$2]) ohair@425: fi ohair@425: case "$extension" in ohair@425: zip) echo "Unzipping $installdir/$filename..." ohair@425: (cd $installdir ; rm -f $installdir/$filename.unpacked ; $BDEPS_UNZIP $installdir/$filename > /dev/null && touch $installdir/$filename.unpacked) ohair@425: ;; ohair@425: tar.gz) echo "Untaring $installdir/$filename..." ohair@425: (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked) ohair@425: ;; ohair@425: tgz) echo "Untaring $installdir/$filename..." ohair@425: (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked) ohair@425: ;; erikj@445: *) AC_MSG_ERROR([Cannot handle build depency archive with extension $extension]) ohair@425: ;; ohair@425: esac ohair@425: fi ohair@425: if test -f $installdir/$filename.unpacked; then ohair@425: $5=$installdir ohair@425: fi ohair@425: ]) erikj@458: erikj@458: AC_DEFUN_ONCE([BDEPS_CONFIGURE_BUILDDEPS], erikj@458: [ erikj@458: AC_ARG_WITH(builddeps-conf, [AS_HELP_STRING([--with-builddeps-conf], erikj@458: [use this configuration file for the builddeps])]) erikj@458: erikj@458: AC_ARG_WITH(builddeps-server, [AS_HELP_STRING([--with-builddeps-server], ohair@494: [download and use build dependencies from this server url])]) erikj@458: erikj@458: AC_ARG_WITH(builddeps-dir, [AS_HELP_STRING([--with-builddeps-dir], ohair@494: [store downloaded build dependencies here @<:@/localhome/builddeps@:>@])], erikj@458: [], erikj@458: [with_builddeps_dir=/localhome/builddeps]) erikj@458: erikj@458: AC_ARG_WITH(builddeps-group, [AS_HELP_STRING([--with-builddeps-group], erikj@458: [chgrp the downloaded build dependencies to this group])]) erikj@458: ])