Thu, 01 Aug 2013 17:24:26 -0700
Merge
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 #
26 AC_DEFUN_ONCE([BDEPS_SCAN_FOR_BUILDDEPS],
27 [
28 define(LIST_OF_BUILD_DEPENDENCIES,)
29 if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then
30 if test "x$with_builddeps_conf" != x; then
31 AC_MSG_CHECKING([for supplied builddeps configuration file])
32 builddepsfile=$with_builddeps_conf
33 if test -s $builddepsfile; then
34 . $builddepsfile
35 AC_MSG_RESULT([loaded!])
36 else
37 AC_MSG_ERROR([The given builddeps conf file $with_builddeps_conf could not be loaded!])
38 fi
39 else
40 AC_MSG_CHECKING([for builddeps.conf files in sources...])
41 builddepsfile=`mktemp`
42 touch $builddepsfile
43 # Put all found confs into a single file.
44 find ${SRC_ROOT} -name builddeps.conf -exec cat \{\} \; >> $builddepsfile
45 # Source the file to acquire the variables
46 if test -s $builddepsfile; then
47 . $builddepsfile
48 AC_MSG_RESULT([found at least one!])
49 else
50 AC_MSG_ERROR([Could not find any builddeps.conf at all!])
51 fi
52 fi
53 # Create build and target names that use _ instead of "-" and ".".
54 # This is necessary to use them in variable names.
55 build_var=`echo ${OPENJDK_BUILD_AUTOCONF_NAME} | tr '-' '_' | tr '.' '_'`
56 target_var=`echo ${OPENJDK_TARGET_AUTOCONF_NAME} | tr '-' '_' | tr '.' '_'`
57 # Extract rewrite information for build and target
58 eval rewritten_build=\${REWRITE_${build_var}}
59 if test "x$rewritten_build" = x; then
60 rewritten_build=${OPENJDK_BUILD_AUTOCONF_NAME}
61 echo Build stays the same $rewritten_build
62 else
63 echo Rewriting build for builddeps into $rewritten_build
64 fi
65 eval rewritten_target=\${REWRITE_${target_var}}
66 if test "x$rewritten_target" = x; then
67 rewritten_target=${OPENJDK_TARGET_AUTOCONF_NAME}
68 echo Target stays the same $rewritten_target
69 else
70 echo Rewriting target for builddeps into $rewritten_target
71 fi
72 rewritten_build_var=`echo ${rewritten_build} | tr '-' '_' | tr '.' '_'`
73 rewritten_target_var=`echo ${rewritten_target} | tr '-' '_' | tr '.' '_'`
74 fi
75 AC_CHECK_PROGS(BDEPS_UNZIP, [7z unzip])
76 if test "x$BDEPS_UNZIP" = x7z; then
77 BDEPS_UNZIP="7z x"
78 fi
80 AC_CHECK_PROGS(BDEPS_FTP, [wget lftp ftp])
81 ])
83 AC_DEFUN([BDEPS_FTPGET],
84 [
85 # $1 is the ftp://abuilddeps.server.com/libs/cups.zip
86 # $2 is the local file name for the downloaded file.
87 VALID_TOOL=no
88 if test "x$BDEPS_FTP" = xwget; then
89 VALID_TOOL=yes
90 wget -O $2 $1
91 fi
92 if test "x$BDEPS_FTP" = xlftp; then
93 VALID_TOOL=yes
94 lftp -c "get $1 -o $2"
95 fi
96 if test "x$BDEPS_FTP" = xftp; then
97 VALID_TOOL=yes
98 FTPSERVER=`echo $1 | cut -f 3 -d '/'`
99 FTPPATH=`echo $1 | cut -f 4- -d '/'`
100 FTPUSERPWD=${FTPSERVER%%@*}
101 if test "x$FTPSERVER" != "x$FTPUSERPWD"; then
102 FTPUSER=${userpwd%%:*}
103 FTPPWD=${userpwd#*@}
104 FTPSERVER=${FTPSERVER#*@}
105 else
106 FTPUSER=ftp
107 FTPPWD=ftp
108 fi
109 # the "pass" command does not work on some
110 # ftp clients (read ftp.exe) but if it works,
111 # passive mode is better!
112 (\
113 echo "user $FTPUSER $FTPPWD" ;\
114 echo "pass" ;\
115 echo "bin" ;\
116 echo "get $FTPPATH $2" ;\
117 ) | ftp -in $FTPSERVER
118 fi
119 if test "x$VALID_TOOL" != xyes; then
120 AC_MSG_ERROR([I do not know how to use the tool: $BDEPS_FTP])
121 fi
122 ])
124 AC_DEFUN([BDEPS_CHECK_MODULE],
125 [
126 define([LIST_OF_BUILD_DEPENDENCIES],LIST_OF_BUILD_DEPENDENCIES[$2=$3'\n'])
127 if test "x$with_builddeps_server" != x || test "x$with_builddeps_conf" != x; then
128 # Source the builddeps file again, to make sure it uses the latest variables!
129 . $builddepsfile
130 # Look for a target and build machine specific resource!
131 eval resource=\${builddep_$2_BUILD_${rewritten_build_var}_TARGET_${rewritten_target_var}}
132 if test "x$resource" = x; then
133 # Ok, lets instead look for a target specific resource
134 eval resource=\${builddep_$2_TARGET_${rewritten_target_var}}
135 fi
136 if test "x$resource" = x; then
137 # Ok, lets instead look for a build specific resource
138 eval resource=\${builddep_$2_BUILD_${rewritten_build_var}}
139 fi
140 if test "x$resource" = x; then
141 # Ok, lets instead look for a generic resource
142 # (The $2 comes from M4 and not the shell, thus no need for eval here.)
143 resource=${builddep_$2}
144 fi
145 if test "x$resource" != x; then
146 AC_MSG_NOTICE([Using builddeps $resource for $2])
147 # If the resource in the builddeps.conf file is an existing directory,
148 # for example /java/linux/cups
149 if test -d ${resource}; then
150 depdir=${resource}
151 else
152 BDEPS_FETCH($2, $resource, $with_builddeps_server, $with_builddeps_dir, depdir)
153 fi
154 # Source the builddeps file again, because in the previous command, the depdir
155 # was updated to point at the current build dependency install directory.
156 . $builddepsfile
157 # Now extract variables from the builddeps.conf files.
158 theroot=${builddep_$2_ROOT}
159 thecflags=${builddep_$2_CFLAGS}
160 thelibs=${builddep_$2_LIBS}
161 if test "x$depdir" = x; then
162 AC_MSG_ERROR([Could not download build dependency $2])
163 fi
164 $1=$depdir
165 if test "x$theroot" != x; then
166 $1="$theroot"
167 fi
168 if test "x$thecflags" != x; then
169 $1_CFLAGS="$thecflags"
170 fi
171 if test "x$thelibs" != x; then
172 $1_LIBS="$thelibs"
173 fi
174 m4_default([$4], [:])
175 m4_ifvaln([$5], [else $5])
176 fi
177 m4_ifvaln([$5], [else $5])
178 fi
179 ])
181 AC_DEFUN([BDEPS_FETCH],
182 [
183 # $1 is for example mymodule
184 # $2 is for example libs/general/libmymod_1_2_3.zip
185 # $3 is for example ftp://mybuilddeps.myserver.com/builddeps
186 # $4 is for example /localhome/builddeps
187 # $5 is the name of the variable into which we store the depdir, eg MYMOD
188 # Will download ftp://mybuilddeps.myserver.com/builddeps/libs/general/libmymod_1_2_3.zip and
189 # unzip into the directory: /localhome/builddeps/libmymod_1_2_3
190 filename=`basename $2`
191 filebase=`echo $filename | sed 's/\.[[^\.]]*$//'`
192 filebase=${filename%%.*}
193 extension=${filename#*.}
194 installdir=$4/$filebase
195 if test ! -f $installdir/$filename.unpacked; then
196 AC_MSG_NOTICE([Downloading build dependency $1 from $3/$2 and installing into $installdir])
197 if test ! -d $installdir; then
198 mkdir -p $installdir
199 fi
200 if test ! -d $installdir; then
201 AC_MSG_ERROR([Could not create directory $installdir])
202 fi
203 tmpfile=`mktemp $installdir/$1.XXXXXXXXX`
204 touch $tmpfile
205 if test ! -f $tmpfile; then
206 AC_MSG_ERROR([Could not create files in directory $installdir])
207 fi
208 BDEPS_FTPGET([$3/$2] , [$tmpfile])
209 mv $tmpfile $installdir/$filename
210 if test ! -s $installdir/$filename; then
211 AC_MSG_ERROR([Could not download $3/$2])
212 fi
213 case "$extension" in
214 zip) echo "Unzipping $installdir/$filename..."
215 (cd $installdir ; rm -f $installdir/$filename.unpacked ; $BDEPS_UNZIP $installdir/$filename > /dev/null && touch $installdir/$filename.unpacked)
216 ;;
217 tar.gz) echo "Untaring $installdir/$filename..."
218 (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked)
219 ;;
220 tgz) echo "Untaring $installdir/$filename..."
221 (cd $installdir ; rm -f $installdir/$filename.unpacked ; tar xzf $installdir/$filename && touch $installdir/$filename.unpacked)
222 ;;
223 *) AC_MSG_ERROR([Cannot handle build depency archive with extension $extension])
224 ;;
225 esac
226 fi
227 if test -f $installdir/$filename.unpacked; then
228 $5=$installdir
229 fi
230 ])
232 AC_DEFUN_ONCE([BDEPS_CONFIGURE_BUILDDEPS],
233 [
234 AC_ARG_WITH(builddeps-conf, [AS_HELP_STRING([--with-builddeps-conf],
235 [use this configuration file for the builddeps])])
237 AC_ARG_WITH(builddeps-server, [AS_HELP_STRING([--with-builddeps-server],
238 [download and use build dependencies from this server url])])
240 AC_ARG_WITH(builddeps-dir, [AS_HELP_STRING([--with-builddeps-dir],
241 [store downloaded build dependencies here @<:@/localhome/builddeps@:>@])],
242 [],
243 [with_builddeps_dir=/localhome/builddeps])
245 AC_ARG_WITH(builddeps-group, [AS_HELP_STRING([--with-builddeps-group],
246 [chgrp the downloaded build dependencies to this group])])
247 ])