1 #
   2 # Copyright (c) 2015, 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 #
  25 
  26 ###############################################################################
  27 #
  28 # Setup version numbers
  29 #
  30 
  31 # Verify that a given string represents a valid version number, and assign it
  32 # to a variable.
  33 
  34 # Argument 1: the variable to assign to
  35 # Argument 2: the value given by the user
  36 AC_DEFUN([JDKVER_CHECK_AND_SET_NUMBER],
  37 [
  38   # Additional [] needed to keep m4 from mangling shell constructs.
  39   if [ ! [[ "$2" =~ ^0*([1-9][0-9]*)|(0)$ ]] ] ; then
  40     AC_MSG_ERROR(["$2" is not a valid numerical value for $1])
  41   fi
  42   # Extract the version number without leading zeros.
  43   cleaned_value=${BASH_REMATCH[[1]]}
  44   if test "x$cleaned_value" = x; then
  45     # Special case for zero
  46     cleaned_value=${BASH_REMATCH[[2]]}
  47   fi
  48 
  49   if test $cleaned_value -gt 255; then
  50     AC_MSG_ERROR([$1 is given as $2. This is greater than 255 which is not allowed.])
  51   fi
  52   if test "x$cleaned_value" != "x$2"; then
  53     AC_MSG_WARN([Value for $1 has been sanitized from '$2' to '$cleaned_value'])
  54   fi
  55   $1=$cleaned_value
  56 ])
  57 
  58 AC_DEFUN_ONCE([JDKVER_SETUP_JDK_VERSION_NUMBERS],
  59 [
  60   # Warn user that old version arguments are deprecated.
  61   BASIC_DEPRECATED_ARG_WITH([milestone])
  62   BASIC_DEPRECATED_ARG_WITH([update-version])
  63   BASIC_DEPRECATED_ARG_WITH([user-release-suffix])
  64   BASIC_DEPRECATED_ARG_WITH([build-number])
  65 
  66   # Source the version numbers file
  67   . $AUTOCONF_DIR/version-numbers
  68 
  69   # Some non-version number information is set in that file
  70   AC_SUBST(LAUNCHER_NAME)
  71   AC_SUBST(PRODUCT_NAME)
  72   AC_SUBST(PRODUCT_SUFFIX)
  73   AC_SUBST(JDK_RC_PLATFORM_NAME)
  74   AC_SUBST(COMPANY_NAME)
  75   AC_SUBST(MACOSX_BUNDLE_NAME_BASE)
  76   AC_SUBST(MACOSX_BUNDLE_ID_BASE)
  77 
  78   # Override version from arguments
  79 
  80   # If --with-version-string is set, process it first. It is possible to
  81   # override parts with more specific flags, since these are processed later.
  82   AC_ARG_WITH(version-string, [AS_HELP_STRING([--with-version-string],
  83       [Set version string @<:@calculated@:>@])])
  84   if test "x$with_version_string" = xyes; then
  85     AC_MSG_ERROR([--with-version-string must have a value])
  86   elif test "x$with_version_string" != x; then
  87     # Additional [] needed to keep m4 from mangling shell constructs.
  88     if [ [[ $with_version_string =~ ^([0-9]+)(\.([0-9]+))?(\.([0-9]+))?(\.([0-9]+))?(-([a-zA-Z]+))?((\+)([0-9]+)?(-([-a-zA-Z0-9.]+))?)?$ ]] ]; then
  89       VERSION_MAJOR=${BASH_REMATCH[[1]]}
  90       VERSION_MINOR=${BASH_REMATCH[[3]]}
  91       VERSION_SECURITY=${BASH_REMATCH[[5]]}
  92       VERSION_PATCH=${BASH_REMATCH[[7]]}
  93       VERSION_PRE=${BASH_REMATCH[[9]]}
  94       version_plus_separator=${BASH_REMATCH[[11]]}
  95       VERSION_BUILD=${BASH_REMATCH[[12]]}
  96       VERSION_OPT=${BASH_REMATCH[[14]]}
  97       # Unspecified numerical fields are interpreted as 0.
  98       if test "x$VERSION_MINOR" = x; then
  99         VERSION_MINOR=0
 100       fi
 101       if test "x$VERSION_SECURITY" = x; then
 102         VERSION_SECURITY=0
 103       fi
 104       if test "x$VERSION_PATCH" = x; then
 105         VERSION_PATCH=0
 106       fi
 107       if test "x$version_plus_separator" != x \
 108           && test "x$VERSION_BUILD$VERSION_OPT" = x; then
 109         AC_MSG_ERROR([Version string contains + but both 'BUILD' and 'OPT' are missing])
 110       fi
 111       # Stop the version part process from setting default values.
 112       # We still allow them to explicitely override though.
 113       NO_DEFAULT_VERSION_PARTS=true
 114     else
 115       AC_MSG_ERROR([--with-version-string fails to parse as a valid version string: $with_version_string])
 116     fi
 117   fi
 118 
 119   AC_ARG_WITH(version-pre, [AS_HELP_STRING([--with-version-pre],
 120       [Set the base part of the version 'PRE' field (pre-release identifier) @<:@'internal'@:>@])],
 121       [with_version_pre_present=true], [with_version_pre_present=false])
 122 
 123   if test "x$with_version_pre_present" = xtrue; then
 124     if test "x$with_version_pre" = xyes; then
 125       AC_MSG_ERROR([--with-version-pre must have a value])
 126     elif test "x$with_version_pre" = xno; then
 127       # Interpret --without-* as empty string instead of the literal "no"
 128       VERSION_PRE=
 129     else
 130       # Only [a-zA-Z] is allowed in the VERSION_PRE. Outer [ ] to quote m4.
 131       [ VERSION_PRE=`$ECHO "$with_version_pre" | $TR -c -d '[a-z][A-Z]'` ]
 132       if test "x$VERSION_PRE" != "x$with_version_pre"; then
 133         AC_MSG_WARN([--with-version-pre value has been sanitized from '$with_version_pre' to '$VERSION_PRE'])
 134       fi
 135     fi
 136   else
 137     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 138       # Default is to use "internal" as pre
 139       VERSION_PRE="internal"
 140     fi
 141   fi
 142 
 143   AC_ARG_WITH(version-opt, [AS_HELP_STRING([--with-version-opt],
 144       [Set version 'OPT' field (build metadata) @<:@<timestamp>.<user>.<dirname>@:>@])],
 145       [with_version_opt_present=true], [with_version_opt_present=false])
 146 
 147   if test "x$with_version_opt_present" = xtrue; then
 148     if test "x$with_version_opt" = xyes; then
 149       AC_MSG_ERROR([--with-version-opt must have a value])
 150     elif test "x$with_version_opt" = xno; then
 151       # Interpret --without-* as empty string instead of the literal "no"
 152       VERSION_OPT=
 153     else
 154       # Only [-.a-zA-Z0-9] is allowed in the VERSION_OPT. Outer [ ] to quote m4.
 155       [ VERSION_OPT=`$ECHO "$with_version_opt" | $TR -c -d '[a-z][A-Z][0-9].-'` ]
 156       if test "x$VERSION_OPT" != "x$with_version_opt"; then
 157         AC_MSG_WARN([--with-version-opt value has been sanitized from '$with_version_opt' to '$VERSION_OPT'])
 158       fi
 159     fi
 160   else
 161     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 162       # Default is to calculate a string like this <timestamp>.<username>.<base dir name>
 163       timestamp=`$DATE '+%Y-%m-%d-%H%M%S'`
 164       # Outer [ ] to quote m4.
 165       [ username=`$ECHO "$USER" | $TR -d -c '[a-z][A-Z][0-9]'` ]
 166       [ basedirname=`$BASENAME "$TOPDIR" | $TR -d -c '[a-z][A-Z][0-9].-'` ]
 167       VERSION_OPT="$timestamp.$username.$basedirname"
 168     fi
 169   fi
 170 
 171   AC_ARG_WITH(version-build, [AS_HELP_STRING([--with-version-build],
 172       [Set version 'BUILD' field (build number) @<:@not specified@:>@])],
 173       [with_version_build_present=true], [with_version_build_present=false])
 174 
 175   if test "x$with_version_build_present" = xtrue; then
 176     if test "x$with_version_build" = xyes; then
 177       AC_MSG_ERROR([--with-version-build must have a value])
 178     elif test "x$with_version_build" = xno; then
 179       # Interpret --without-* as empty string instead of the literal "no"
 180       VERSION_BUILD=
 181     elif test "x$with_version_build" = x; then
 182       VERSION_BUILD=
 183     else
 184       JDKVER_CHECK_AND_SET_NUMBER(VERSION_BUILD, $with_version_build)
 185     fi
 186   else
 187     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 188       # Default is to not have a build number.
 189       VERSION_BUILD=""
 190       # FIXME: Until all code can cope with an empty VERSION_BUILD, set it to 0.
 191       VERSION_BUILD=0
 192     fi
 193   fi
 194 
 195   AC_ARG_WITH(version-major, [AS_HELP_STRING([--with-version-major],
 196       [Set version 'MAJOR' field (first number) @<:@current source value@:>@])],
 197       [with_version_major_present=true], [with_version_major_present=false])
 198 
 199   if test "x$with_version_major_present" = xtrue; then
 200     if test "x$with_version_major" = xyes; then
 201       AC_MSG_ERROR([--with-version-major must have a value])
 202     else
 203       JDKVER_CHECK_AND_SET_NUMBER(VERSION_MAJOR, $with_version_major)
 204     fi
 205   else
 206     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 207       # Default is to get value from version-numbers
 208       VERSION_MAJOR="$DEFAULT_VERSION_MAJOR"
 209     fi
 210   fi
 211 
 212   AC_ARG_WITH(version-minor, [AS_HELP_STRING([--with-version-minor],
 213       [Set version 'MINOR' field (second number) @<:@current source value@:>@])],
 214       [with_version_minor_present=true], [with_version_minor_present=false])
 215 
 216   if test "x$with_version_minor_present" = xtrue; then
 217     if test "x$with_version_minor" = xyes; then
 218       AC_MSG_ERROR([--with-version-minor must have a value])
 219     elif test "x$with_version_minor" = xno; then
 220       # Interpret --without-* as empty string (i.e. 0) instead of the literal "no"
 221       VERSION_MINOR=0
 222     elif test "x$with_version_minor" = x; then
 223       VERSION_MINOR=0
 224     else
 225       JDKVER_CHECK_AND_SET_NUMBER(VERSION_MINOR, $with_version_minor)
 226     fi
 227   else
 228     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 229       # Default is 0, if unspecified
 230       VERSION_MINOR=0
 231     fi
 232   fi
 233 
 234   AC_ARG_WITH(version-security, [AS_HELP_STRING([--with-version-security],
 235       [Set version 'SECURITY' field (third number) @<:@current source value@:>@])],
 236       [with_version_security_present=true], [with_version_security_present=false])
 237 
 238   if test "x$with_version_security_present" = xtrue; then
 239     if test "x$with_version_security" = xyes; then
 240       AC_MSG_ERROR([--with-version-security must have a value])
 241     elif test "x$with_version_security" = xno; then
 242       # Interpret --without-* as empty string (i.e. 0) instead of the literal "no"
 243       VERSION_SECURITY=0
 244     elif test "x$with_version_security" = x; then
 245       VERSION_SECURITY=0
 246     else
 247       JDKVER_CHECK_AND_SET_NUMBER(VERSION_SECURITY, $with_version_security)
 248     fi
 249   else
 250     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 251       # Default is 0, if unspecified
 252       VERSION_SECURITY=0
 253     fi
 254   fi
 255 
 256   AC_ARG_WITH(version-patch, [AS_HELP_STRING([--with-version-patch],
 257       [Set version 'PATCH' field (fourth number) @<:@not specified@:>@])],
 258       [with_version_patch_present=true], [with_version_patch_present=false])
 259 
 260   if test "x$with_version_patch_present" = xtrue; then
 261     if test "x$with_version_patch" = xyes; then
 262       AC_MSG_ERROR([--with-version-patch must have a value])
 263     elif test "x$with_version_patch" = xno; then
 264       # Interpret --without-* as empty string (i.e. 0) instead of the literal "no"
 265       VERSION_PATCH=0
 266     elif test "x$with_version_patch" = x; then
 267       VERSION_PATCH=0
 268     else
 269       JDKVER_CHECK_AND_SET_NUMBER(VERSION_PATCH, $with_version_patch)
 270     fi
 271   else
 272     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 273       # Default is 0, if unspecified
 274       VERSION_PATCH=0
 275     fi
 276   fi
 277 
 278   # Calculate derived version properties
 279 
 280   # Set VERSION_IS_GA based on if VERSION_PRE has a value
 281   if test "x$VERSION_PRE" = x; then
 282     VERSION_IS_GA=true
 283   else
 284     VERSION_IS_GA=false
 285   fi
 286 
 287   # VERSION_NUMBER but always with exactly 4 positions, with 0 for empty positions.
 288   VERSION_NUMBER_FOUR_POSITIONS=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_SECURITY.$VERSION_PATCH
 289 
 290   stripped_version_number=$VERSION_NUMBER_FOUR_POSITIONS
 291   # Strip trailing zeroes from stripped_version_number
 292   for i in 1 2 3 ; do stripped_version_number=${stripped_version_number%.0} ; done
 293   VERSION_NUMBER=$stripped_version_number
 294 
 295   # The complete version string, with additional build information
 296   if test "x$VERSION_BUILD$VERSION_OPT" = x; then
 297     VERSION_STRING=$VERSION_NUMBER${VERSION_PRE:+-$VERSION_PRE}
 298   else
 299     # If either build or opt is set, we need a + separator
 300     VERSION_STRING=$VERSION_NUMBER${VERSION_PRE:+-$VERSION_PRE}+$VERSION_BUILD${VERSION_OPT:+-$VERSION_OPT}
 301   fi
 302 
 303   # The short version string, just VERSION_NUMBER and PRE, if present.
 304   VERSION_SHORT=$VERSION_NUMBER${VERSION_PRE:+-$VERSION_PRE}
 305 
 306   AC_MSG_CHECKING([for version string])
 307   AC_MSG_RESULT([$VERSION_STRING])
 308 
 309   AC_SUBST(VERSION_MAJOR)
 310   AC_SUBST(VERSION_MINOR)
 311   AC_SUBST(VERSION_SECURITY)
 312   AC_SUBST(VERSION_PATCH)
 313   AC_SUBST(VERSION_PRE)
 314   AC_SUBST(VERSION_BUILD)
 315   AC_SUBST(VERSION_OPT)
 316   AC_SUBST(VERSION_NUMBER)
 317   AC_SUBST(VERSION_NUMBER_FOUR_POSITIONS)
 318   AC_SUBST(VERSION_STRING)
 319   AC_SUBST(VERSION_SHORT)
 320   AC_SUBST(VERSION_IS_GA)
 321 ])