common/autoconf/builddeps.m4

Tue, 10 Apr 2012 08:18:28 -0700

author
ohair
date
Tue, 10 Apr 2012 08:18:28 -0700
changeset 425
e1830598f0b7
child 445
efd26e051e50
permissions
-rw-r--r--

7074397: Build infrastructure changes (makefile re-write)
Summary: New makefiles transition, old and new living side by side for now.
Reviewed-by: ohair, jjg, dholmes, ohrstrom, erikj, ihse, tgranat, ykantser
Contributed-by: ohrstrom <fredrik.ohrstrom@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>

ohair@425 1 #
ohair@425 2 # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@425 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@425 4 #
ohair@425 5 # This code is free software; you can redistribute it and/or modify it
ohair@425 6 # under the terms of the GNU General Public License version 2 only, as
ohair@425 7 # published by the Free Software Foundation. Oracle designates this
ohair@425 8 # particular file as subject to the "Classpath" exception as provided
ohair@425 9 # by Oracle in the LICENSE file that accompanied this code.
ohair@425 10 #
ohair@425 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@425 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@425 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@425 14 # version 2 for more details (a copy is included in the LICENSE file that
ohair@425 15 # accompanied this code).
ohair@425 16 #
ohair@425 17 # You should have received a copy of the GNU General Public License version
ohair@425 18 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@425 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@425 20 #
ohair@425 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@425 22 # or visit www.oracle.com if you need additional information or have any
ohair@425 23 # questions.
ohair@425 24 #
ohair@425 25
ohair@425 26 AC_DEFUN([BDEPS_SCAN_FOR_BUILDDEPS],
ohair@425 27 [
ohair@425 28 define(LIST_OF_BUILD_DEPENDENCIES,)
ohair@425 29 if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then
ohair@425 30 if test "x$with_builddeps_conf" != x; then
ohair@425 31 AC_MSG_CHECKING([for supplied builddeps configuration file])
ohair@425 32 builddepsfile=$with_builddeps_conf
ohair@425 33 if test -s $builddepsfile; then
ohair@425 34 . $builddepsfile
ohair@425 35 AC_MSG_RESULT([loaded!])
ohair@425 36 else
ohair@425 37 AC_ERROR([The given builddeps conf file $with_builddeps_conf could not be loaded!])
ohair@425 38 fi
ohair@425 39 else
ohair@425 40 AC_MSG_CHECKING([for builddeps.conf files in sources...])
ohair@425 41 builddepsfile=`mktemp`
ohair@425 42 touch $builddepsfile
ohair@425 43 # Put all found confs into a single file.
ohair@425 44 find ${SRC_ROOT} -name builddeps.conf -exec cat \{\} \; >> $builddepsfile
ohair@425 45 # Source the file to acquire the variables
ohair@425 46 if test -s $builddepsfile; then
ohair@425 47 . $builddepsfile
ohair@425 48 AC_MSG_RESULT([found at least one!])
ohair@425 49 else
ohair@425 50 AC_ERROR([Could not find any builddeps.conf at all!])
ohair@425 51 fi
ohair@425 52 fi
ohair@425 53 # Create build and host names that use _ instead of "-" and ".".
ohair@425 54 # This is necessary to use them in variable names.
ohair@425 55 build_var=`echo ${build} | tr '-' '_' | tr '.' '_'`
ohair@425 56 host_var=`echo ${host} | tr '-' '_' | tr '.' '_'`
ohair@425 57 # Extract rewrite information for build and host
ohair@425 58 eval rewritten_build=\${REWRITE_${build_var}}
ohair@425 59 if test "x$rewritten_build" = x; then
ohair@425 60 rewritten_build=${build}
ohair@425 61 echo Build stays the same $rewritten_build
ohair@425 62 else
ohair@425 63 echo Rewriting build for builddeps into $rewritten_build
ohair@425 64 fi
ohair@425 65 eval rewritten_host=\${REWRITE_${host_var}}
ohair@425 66 if test "x$rewritten_host" = x; then
ohair@425 67 rewritten_host=${host}
ohair@425 68 echo Host stays the same $rewritten_host
ohair@425 69 else
ohair@425 70 echo Rewriting host for builddeps into $rewritten_host
ohair@425 71 fi
ohair@425 72 rewritten_build_var=`echo ${rewritten_build} | tr '-' '_' | tr '.' '_'`
ohair@425 73 rewritten_host_var=`echo ${rewritten_host} | tr '-' '_' | tr '.' '_'`
ohair@425 74 fi
ohair@425 75 AC_CHECK_PROGS(BDEPS_UNZIP, [7z unzip])
ohair@425 76 if test "x$BDEPS_UNZIP" = x7z; then
ohair@425 77 BDEPS_UNZIP="7z x"
ohair@425 78 fi
ohair@425 79
ohair@425 80 AC_CHECK_PROGS(BDEPS_FTP, [wget lftp ftp])
ohair@425 81 ])
ohair@425 82
ohair@425 83 AC_DEFUN([BDEPS_FTPGET],
ohair@425 84 [
ohair@425 85 # $1 is the ftp://abuilddeps.server.com/libs/cups.zip
ohair@425 86 # $2 is the local file name for the downloaded file.
ohair@425 87 VALID_TOOL=no
ohair@425 88 if test "x$BDEPS_FTP" = xwget; then
ohair@425 89 VALID_TOOL=yes
ohair@425 90 wget -O $2 $1
ohair@425 91 fi
ohair@425 92 if test "x$BDEPS_FTP" = xlftp; then
ohair@425 93 VALID_TOOL=yes
ohair@425 94 lftp -c "get $1 -o $2"
ohair@425 95 fi
ohair@425 96 if test "x$BDEPS_FTP" = xftp; then
ohair@425 97 VALID_TOOL=yes
ohair@425 98 FTPSERVER=`echo $1 | cut -f 3 -d '/'`
ohair@425 99 FTPPATH=`echo $1 | cut -f 4- -d '/'`
ohair@425 100 FTPUSERPWD=${FTPSERVER%%@*}
ohair@425 101 if test "x$FTPSERVER" != "x$FTPUSERPWD"; then
ohair@425 102 FTPUSER=${userpwd%%:*}
ohair@425 103 FTPPWD=${userpwd#*@}
ohair@425 104 FTPSERVER=${FTPSERVER#*@}
ohair@425 105 else
ohair@425 106 FTPUSER=ftp
ohair@425 107 FTPPWD=ftp
ohair@425 108 fi
ohair@425 109 # the "pass" command does not work on some
ohair@425 110 # ftp clients (read ftp.exe) but if it works,
ohair@425 111 # passive mode is better!
ohair@425 112 (\
ohair@425 113 echo "user $FTPUSER $FTPPWD" ;\
ohair@425 114 echo "pass" ;\
ohair@425 115 echo "bin" ;\
ohair@425 116 echo "get $FTPPATH $2" ;\
ohair@425 117 ) | ftp -in $FTPSERVER
ohair@425 118 fi
ohair@425 119 if test "x$VALID_TOOL" != xyes; then
ohair@425 120 AC_ERROR([I do not know how to use the tool: $BDEPS_FTP])
ohair@425 121 fi
ohair@425 122 ])
ohair@425 123
ohair@425 124 AC_DEFUN([BDEPS_CHECK_MODULE],
ohair@425 125 [
ohair@425 126 define([LIST_OF_BUILD_DEPENDENCIES],LIST_OF_BUILD_DEPENDENCIES[$2=$3'\n'])
ohair@425 127 if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then
ohair@425 128 # Source the builddeps file again, to make sure it uses the latest variables!
ohair@425 129 . $builddepsfile
ohair@425 130 # Look for a host and build machine specific resource!
ohair@425 131 eval resource=\${builddep_$2_BUILD_${rewritten_build_var}_HOST_${rewritten_host_var}}
ohair@425 132 if test "x$resource" = x; then
ohair@425 133 # Ok, lets instead look for a host specific resource
ohair@425 134 eval resource=\${builddep_$2_HOST_${rewritten_host_var}}
ohair@425 135 fi
ohair@425 136 if test "x$resource" = x; then
ohair@425 137 # Ok, lets instead look for a build specific resource
ohair@425 138 eval resource=\${builddep_$2_BUILD_${rewritten_build_var}}
ohair@425 139 fi
ohair@425 140 if test "x$resource" = x; then
ohair@425 141 # Ok, lets instead look for a generic resource
ohair@425 142 # (The $2 comes from M4 and not the shell, thus no need for eval here.)
ohair@425 143 resource=${builddep_$2}
ohair@425 144 fi
ohair@425 145 if test "x$resource" != x; then
ohair@425 146 AC_MSG_NOTICE([Using builddeps $resource for $2])
ohair@425 147 # If the resource in the builddeps.conf file is an existing directory,
ohair@425 148 # for example /java/linux/cups
ohair@425 149 if test -d ${resource}; then
ohair@425 150 depdir=${resource}
ohair@425 151 else
ohair@425 152 BDEPS_FETCH($2, $resource, $with_builddeps_server, $with_builddeps_dir, depdir)
ohair@425 153 fi
ohair@425 154 # Source the builddeps file again, because in the previous command, the depdir
ohair@425 155 # was updated to point at the current build dependency install directory.
ohair@425 156 . $builddepsfile
ohair@425 157 # Now extract variables from the builddeps.conf files.
ohair@425 158 theroot=${builddep_$2_ROOT}
ohair@425 159 thecflags=${builddep_$2_CFLAGS}
ohair@425 160 thelibs=${builddep_$2_LIBS}
ohair@425 161 if test "x$depdir" = x; then
ohair@425 162 AC_ERROR([Could not download build dependency $2])
ohair@425 163 fi
ohair@425 164 $1=$depdir
ohair@425 165 if test "x$theroot" != x; then
ohair@425 166 $1="$theroot"
ohair@425 167 fi
ohair@425 168 if test "x$thecflags" != x; then
ohair@425 169 $1_CFLAGS="$thecflags"
ohair@425 170 fi
ohair@425 171 if test "x$thelibs" != x; then
ohair@425 172 $1_LIBS="$thelibs"
ohair@425 173 fi
ohair@425 174 m4_default([$4], [:])
ohair@425 175 m4_ifvaln([$5], [else $5])
ohair@425 176 fi
ohair@425 177 m4_ifvaln([$5], [else $5])
ohair@425 178 fi
ohair@425 179 ])
ohair@425 180
ohair@425 181 AC_DEFUN([BDEPS_FETCH],
ohair@425 182 [
ohair@425 183 # $1 is for example mymodule
ohair@425 184 # $2 is for example libs/general/libmymod_1_2_3.zip
ohair@425 185 # $3 is for example ftp://mybuilddeps.myserver.com/builddeps
ohair@425 186 # $4 is for example /localhome/builddeps
ohair@425 187 # $5 is the name of the variable into which we store the depdir, eg MYMOD
ohair@425 188 # Will download ftp://mybuilddeps.myserver.com/builddeps/libs/general/libmymod_1_2_3.zip and
ohair@425 189 # unzip into the directory: /localhome/builddeps/libmymod_1_2_3
ohair@425 190 filename=`basename $2`
ohair@425 191 filebase=`echo $filename | sed 's/\.[[^\.]]*$//'`
ohair@425 192 filebase=${filename%%.*}
ohair@425 193 extension=${filename#*.}
ohair@425 194 installdir=$4/$filebase
ohair@425 195 if test ! -f $installdir/$filename.unpacked; then
ohair@425 196 AC_MSG_NOTICE([Downloading build dependency $1 from $3/$2 and installing into $installdir])
ohair@425 197 if test ! -d $installdir; then
ohair@425 198 mkdir -p $installdir
ohair@425 199 fi
ohair@425 200 if test ! -d $installdir; then
ohair@425 201 AC_ERROR([Could not create directory $installdir])
ohair@425 202 fi
ohair@425 203 tmpfile=`mktemp $installdir/$1.XXXXXXXXX`
ohair@425 204 touch $tmpfile
ohair@425 205 if test ! -f $tmpfile; then
ohair@425 206 AC_ERROR([Could not create files in directory $installdir])
ohair@425 207 fi
ohair@425 208 BDEPS_FTPGET([$3/$2] , [$tmpfile])
ohair@425 209 mv $tmpfile $installdir/$filename
ohair@425 210 if test ! -s $installdir/$filename; then
ohair@425 211 AC_ERROR([Could not download $3/$2])
ohair@425 212 fi
ohair@425 213 case "$extension" in
ohair@425 214 zip) echo "Unzipping $installdir/$filename..."
ohair@425 215 (cd $installdir ; rm -f $installdir/$filename.unpacked ; $BDEPS_UNZIP $installdir/$filename > /dev/null && touch $installdir/$filename.unpacked)
ohair@425 216 ;;
ohair@425 217 tar.gz) echo "Untaring $installdir/$filename..."
ohair@425 218 (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked)
ohair@425 219 ;;
ohair@425 220 tgz) echo "Untaring $installdir/$filename..."
ohair@425 221 (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked)
ohair@425 222 ;;
ohair@425 223 *) AC_ERROR([Cannot handle build depency archive with extension $extension])
ohair@425 224 ;;
ohair@425 225 esac
ohair@425 226 fi
ohair@425 227 if test -f $installdir/$filename.unpacked; then
ohair@425 228 $5=$installdir
ohair@425 229 fi
ohair@425 230 ])
ohair@425 231

mercurial