builddeps.m4 10.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#
# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

26
AC_DEFUN_ONCE([BDEPS_SCAN_FOR_BUILDDEPS],
27 28 29 30 31 32 33 34 35 36
[
    define(LIST_OF_BUILD_DEPENDENCIES,)
    if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then
        if test "x$with_builddeps_conf" != x; then
            AC_MSG_CHECKING([for supplied builddeps configuration file])
            builddepsfile=$with_builddeps_conf        
            if test -s $builddepsfile; then
                . $builddepsfile
                AC_MSG_RESULT([loaded!])
            else
37
               AC_MSG_ERROR([The given builddeps conf file $with_builddeps_conf could not be loaded!])
38 39 40 41 42 43 44 45 46 47 48 49
           fi
        else
            AC_MSG_CHECKING([for builddeps.conf files in sources...])
            builddepsfile=`mktemp`
            touch $builddepsfile
            # Put all found confs into a single file.
            find ${SRC_ROOT} -name builddeps.conf -exec cat \{\} \; >> $builddepsfile
            # Source the file to acquire the variables
            if test -s $builddepsfile; then
                . $builddepsfile
                AC_MSG_RESULT([found at least one!])
            else
50
               AC_MSG_ERROR([Could not find any builddeps.conf at all!])
51 52
           fi
        fi
53
        # Create build and target names that use _ instead of "-" and ".".
54
        # This is necessary to use them in variable names.
55 56 57
        build_var=`echo ${OPENJDK_BUILD_SYSTEM} | tr '-' '_' | tr '.' '_'`
        target_var=`echo ${OPENJDK_TARGET_SYSTEM} | tr '-' '_' | tr '.' '_'`
        # Extract rewrite information for build and target
58 59
        eval rewritten_build=\${REWRITE_${build_var}}
        if test "x$rewritten_build" = x; then
60
            rewritten_build=${OPENJDK_BUILD_SYSTEM}
61 62 63 64
            echo Build stays the same $rewritten_build
        else
            echo Rewriting build for builddeps into $rewritten_build
        fi
65 66 67 68
        eval rewritten_target=\${REWRITE_${target_var}}
        if test "x$rewritten_target" = x; then
            rewritten_target=${OPENJDK_TARGET_SYSTEM}
            echo Target stays the same $rewritten_target
69
        else
70
            echo Rewriting target for builddeps into $rewritten_target
71 72
        fi
        rewritten_build_var=`echo ${rewritten_build} | tr '-' '_' | tr '.' '_'`
73
        rewritten_target_var=`echo ${rewritten_target} | tr '-' '_' | tr '.' '_'`        
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    fi
    AC_CHECK_PROGS(BDEPS_UNZIP, [7z unzip])
    if test "x$BDEPS_UNZIP" = x7z; then
        BDEPS_UNZIP="7z x"
    fi

    AC_CHECK_PROGS(BDEPS_FTP, [wget lftp ftp]) 
])

AC_DEFUN([BDEPS_FTPGET],
[
    # $1 is the ftp://abuilddeps.server.com/libs/cups.zip
    # $2 is the local file name for the downloaded file.
    VALID_TOOL=no
    if test "x$BDEPS_FTP" = xwget; then
       VALID_TOOL=yes
       wget -O $2 $1
    fi
    if test "x$BDEPS_FTP" = xlftp; then
       VALID_TOOL=yes
       lftp -c "get $1 -o $2"
    fi
    if test "x$BDEPS_FTP" = xftp; then
        VALID_TOOL=yes
        FTPSERVER=`echo $1 | cut -f 3 -d '/'`
        FTPPATH=`echo $1 | cut -f 4- -d '/'`
        FTPUSERPWD=${FTPSERVER%%@*}
        if test "x$FTPSERVER" != "x$FTPUSERPWD"; then
            FTPUSER=${userpwd%%:*}
            FTPPWD=${userpwd#*@}
            FTPSERVER=${FTPSERVER#*@}
        else
            FTPUSER=ftp
            FTPPWD=ftp
        fi
        # the "pass" command does not work on some
        # ftp clients (read ftp.exe) but if it works,
        # passive mode is better!
        (\
            echo "user $FTPUSER $FTPPWD"        ;\
            echo "pass"                         ;\
            echo "bin"                          ;\
            echo "get $FTPPATH $2"              ;\
        ) | ftp -in $FTPSERVER
    fi
    if test "x$VALID_TOOL" != xyes; then
120
       AC_MSG_ERROR([I do not know how to use the tool: $BDEPS_FTP])
121 122 123 124 125 126 127 128 129
    fi
])

AC_DEFUN([BDEPS_CHECK_MODULE],
[
    define([LIST_OF_BUILD_DEPENDENCIES],LIST_OF_BUILD_DEPENDENCIES[$2=$3'\n'])
    if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then
        # Source the builddeps file again, to make sure it uses the latest variables!
        . $builddepsfile
130 131
        # Look for a target and build machine specific resource!
        eval resource=\${builddep_$2_BUILD_${rewritten_build_var}_TARGET_${rewritten_target_var}}
132
        if test "x$resource" = x; then
133 134
            # Ok, lets instead look for a target specific resource
            eval resource=\${builddep_$2_TARGET_${rewritten_target_var}}
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
        fi
        if test "x$resource" = x; then
            # Ok, lets instead look for a build specific resource
            eval resource=\${builddep_$2_BUILD_${rewritten_build_var}}
        fi
        if test "x$resource" = x; then
            # Ok, lets instead look for a generic resource
            # (The $2 comes from M4 and not the shell, thus no need for eval here.)
            resource=${builddep_$2}
        fi
        if test "x$resource" != x; then
            AC_MSG_NOTICE([Using builddeps $resource for $2])
	    # If the resource in the builddeps.conf file is an existing directory,
	    # for example /java/linux/cups
	    if test -d ${resource}; then
	       depdir=${resource}
	    else
		BDEPS_FETCH($2, $resource, $with_builddeps_server, $with_builddeps_dir, depdir)
	    fi
            # Source the builddeps file again, because in the previous command, the depdir
            # was updated to point at the current build dependency install directory.
            . $builddepsfile
            # Now extract variables from the builddeps.conf files.
            theroot=${builddep_$2_ROOT}
            thecflags=${builddep_$2_CFLAGS}
            thelibs=${builddep_$2_LIBS}
            if test "x$depdir" = x; then
162
                AC_MSG_ERROR([Could not download build dependency $2])
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
            fi
            $1=$depdir
            if test "x$theroot" != x; then
               $1="$theroot"
            fi
            if test "x$thecflags" != x; then
               $1_CFLAGS="$thecflags"
            fi
            if test "x$thelibs" != x; then
               $1_LIBS="$thelibs"
            fi
            m4_default([$4], [:])
            m4_ifvaln([$5], [else $5])
        fi
        m4_ifvaln([$5], [else $5])
    fi
])

AC_DEFUN([BDEPS_FETCH],
[
# $1 is for example mymodule
# $2 is for example libs/general/libmymod_1_2_3.zip
# $3 is for example ftp://mybuilddeps.myserver.com/builddeps
# $4 is for example /localhome/builddeps
# $5 is the name of the variable into which we store the depdir, eg MYMOD
# Will download ftp://mybuilddeps.myserver.com/builddeps/libs/general/libmymod_1_2_3.zip and
# unzip into the directory: /localhome/builddeps/libmymod_1_2_3
    filename=`basename $2`
    filebase=`echo $filename | sed 's/\.[[^\.]]*$//'`
    filebase=${filename%%.*}
    extension=${filename#*.}
    installdir=$4/$filebase
    if test ! -f $installdir/$filename.unpacked; then
        AC_MSG_NOTICE([Downloading build dependency $1 from $3/$2 and installing into $installdir])
        if test ! -d $installdir; then
            mkdir -p $installdir
        fi
        if test ! -d $installdir; then
201
            AC_MSG_ERROR([Could not create directory $installdir])
202 203 204 205
        fi
        tmpfile=`mktemp $installdir/$1.XXXXXXXXX`
        touch $tmpfile    
        if test ! -f $tmpfile; then
206
            AC_MSG_ERROR([Could not create files in directory $installdir])
207 208 209 210
        fi
        BDEPS_FTPGET([$3/$2] , [$tmpfile])
        mv $tmpfile $installdir/$filename
        if test ! -s $installdir/$filename; then 
211
            AC_MSG_ERROR([Could not download $3/$2])
212 213 214 215 216 217 218 219 220 221 222
        fi
        case "$extension" in
            zip)  echo "Unzipping $installdir/$filename..."
               (cd $installdir ; rm -f $installdir/$filename.unpacked ; $BDEPS_UNZIP $installdir/$filename > /dev/null && touch $installdir/$filename.unpacked)
            ;;
            tar.gz) echo "Untaring $installdir/$filename..."
               (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked)
            ;;
            tgz) echo "Untaring $installdir/$filename..."
               (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked)
            ;;
223
            *) AC_MSG_ERROR([Cannot handle build depency archive with extension $extension])
224 225 226 227 228 229 230
            ;;
        esac
    fi
    if test -f $installdir/$filename.unpacked; then
        $5=$installdir
    fi
])
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

AC_DEFUN_ONCE([BDEPS_CONFIGURE_BUILDDEPS],
[
AC_ARG_WITH(builddeps-conf, [AS_HELP_STRING([--with-builddeps-conf],
    [use this configuration file for the builddeps])])

AC_ARG_WITH(builddeps-server, [AS_HELP_STRING([--with-builddeps-server],
    [download and use build dependencies from this server url, e.g. --with-builddeps-server=ftp://example.com/dir])])

AC_ARG_WITH(builddeps-dir, [AS_HELP_STRING([--with-builddeps-dir],
    [store downloaded build dependencies here @<:@d/localhome/builddeps@:>@])],
    [],
    [with_builddeps_dir=/localhome/builddeps])

AC_ARG_WITH(builddeps-group, [AS_HELP_STRING([--with-builddeps-group],
    [chgrp the downloaded build dependencies to this group])])

AC_ARG_ENABLE([list-builddeps], [AS_HELP_STRING([--enable-list-builddeps],
	[list all build dependencies known to the configure script])],
	[LIST_BUILDDEPS="${enableval}"], [LIST_BUILDDEPS='no'])

if test "x$LIST_BUILDDEPS" = xyes; then
    echo
    echo List of build dependencies known to the configure script,
    echo that can be used in builddeps.conf files:
    cat $AUTOCONF_DIR/*.ac $AUTOCONF_DIR/*.m4 | grep BDEPS_CHECK_MODUL[E]\( | cut -f 2 -d ',' | tr -d ' ' | sort
    echo
    exit 1
fi
])