1 #
   2 # Copyright (c) 2015, 2017, 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   BASIC_DEPRECATED_ARG_WITH([version-major])
  66   BASIC_DEPRECATED_ARG_WITH([version-minor])
  67   BASIC_DEPRECATED_ARG_WITH([version-security])
  68 
  69   # Source the version numbers file
  70   . $AUTOCONF_DIR/version-numbers
  71 
  72   # Some non-version number information is set in that file
  73   AC_SUBST(LAUNCHER_NAME)
  74   AC_SUBST(PRODUCT_NAME)
  75   AC_SUBST(PRODUCT_SUFFIX)
  76   AC_SUBST(JDK_RC_PLATFORM_NAME)
  77   AC_SUBST(HOTSPOT_VM_DISTRO)
  78   AC_SUBST(MACOSX_BUNDLE_NAME_BASE)
  79   AC_SUBST(MACOSX_BUNDLE_ID_BASE)
  80 
  81   # The vendor name, if any
  82   AC_ARG_WITH(vendor-name, [AS_HELP_STRING([--with-vendor-name],
  83       [Set vendor name @<:@not specified@:>@])])
  84   if test "x$with_vendor_name" = xyes; then
  85     AC_MSG_ERROR([--with-vendor-name must have a value])
  86   elif [ ! [[ $with_vendor_name =~ ^[[:print:]]*$ ]] ]; then
  87     AC_MSG_ERROR([--with--vendor-name contains non-printing characters: $with_vendor_name])
  88   else
  89     COMPANY_NAME="$with_vendor_name"
  90   fi
  91   AC_SUBST(COMPANY_NAME)
  92 
  93   # Override version from arguments
  94 
  95   # If --with-version-string is set, process it first. It is possible to
  96   # override parts with more specific flags, since these are processed later.
  97   AC_ARG_WITH(version-string, [AS_HELP_STRING([--with-version-string],
  98       [Set version string @<:@calculated@:>@])])
  99   if test "x$with_version_string" = xyes; then
 100     AC_MSG_ERROR([--with-version-string must have a value])
 101   elif test "x$with_version_string" != x; then
 102     # Additional [] needed to keep m4 from mangling shell constructs.
 103     if [ [[ $with_version_string =~ ^([0-9]+)(\.([0-9]+))?(\.([0-9]+))?(\.([0-9]+))?(-([a-zA-Z]+))?((\+)([0-9]+)?(-([-a-zA-Z0-9.]+))?)?$ ]] ]; then
 104       VERSION_FEATURE=${BASH_REMATCH[[1]]}
 105       VERSION_INTERIM=${BASH_REMATCH[[3]]}
 106       VERSION_UPDATE=${BASH_REMATCH[[5]]}
 107       VERSION_PATCH=${BASH_REMATCH[[7]]}
 108       VERSION_PRE=${BASH_REMATCH[[9]]}
 109       version_plus_separator=${BASH_REMATCH[[11]]}
 110       VERSION_BUILD=${BASH_REMATCH[[12]]}
 111       VERSION_OPT=${BASH_REMATCH[[14]]}
 112       # Unspecified numerical fields are interpreted as 0.
 113       if test "x$VERSION_INTERIM" = x; then
 114         VERSION_INTERIM=0
 115       fi
 116       if test "x$VERSION_UPDATE" = x; then
 117         VERSION_UPDATE=0
 118       fi
 119       if test "x$VERSION_PATCH" = x; then
 120         VERSION_PATCH=0
 121       fi
 122       if test "x$version_plus_separator" != x \
 123           && test "x$VERSION_BUILD$VERSION_OPT" = x; then
 124         AC_MSG_ERROR([Version string contains + but both 'BUILD' and 'OPT' are missing])
 125       fi
 126       # Stop the version part process from setting default values.
 127       # We still allow them to explicitly override though.
 128       NO_DEFAULT_VERSION_PARTS=true
 129     else
 130       AC_MSG_ERROR([--with-version-string fails to parse as a valid version string: $with_version_string])
 131     fi
 132   fi
 133 
 134   AC_ARG_WITH(version-pre, [AS_HELP_STRING([--with-version-pre],
 135       [Set the base part of the version 'PRE' field (pre-release identifier) @<:@'internal'@:>@])],
 136       [with_version_pre_present=true], [with_version_pre_present=false])
 137 
 138   if test "x$with_version_pre_present" = xtrue; then
 139     if test "x$with_version_pre" = xyes; then
 140       AC_MSG_ERROR([--with-version-pre must have a value])
 141     elif test "x$with_version_pre" = xno; then
 142       # Interpret --without-* as empty string instead of the literal "no"
 143       VERSION_PRE=
 144     else
 145       # Only [a-zA-Z] is allowed in the VERSION_PRE. Outer [ ] to quote m4.
 146       [ VERSION_PRE=`$ECHO "$with_version_pre" | $TR -c -d '[a-z][A-Z]'` ]
 147       if test "x$VERSION_PRE" != "x$with_version_pre"; then
 148         AC_MSG_WARN([--with-version-pre value has been sanitized from '$with_version_pre' to '$VERSION_PRE'])
 149       fi
 150     fi
 151   else
 152     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 153       # Default is to use "internal" as pre
 154       VERSION_PRE="internal"
 155     fi
 156   fi
 157 
 158   AC_ARG_WITH(version-opt, [AS_HELP_STRING([--with-version-opt],
 159       [Set version 'OPT' field (build metadata) @<:@<timestamp>.<user>.<dirname>@:>@])],
 160       [with_version_opt_present=true], [with_version_opt_present=false])
 161 
 162   if test "x$with_version_opt_present" = xtrue; then
 163     if test "x$with_version_opt" = xyes; then
 164       AC_MSG_ERROR([--with-version-opt must have a value])
 165     elif test "x$with_version_opt" = xno; then
 166       # Interpret --without-* as empty string instead of the literal "no"
 167       VERSION_OPT=
 168     else
 169       # Only [-.a-zA-Z0-9] is allowed in the VERSION_OPT. Outer [ ] to quote m4.
 170       [ VERSION_OPT=`$ECHO "$with_version_opt" | $TR -c -d '[a-z][A-Z][0-9].-'` ]
 171       if test "x$VERSION_OPT" != "x$with_version_opt"; then
 172         AC_MSG_WARN([--with-version-opt value has been sanitized from '$with_version_opt' to '$VERSION_OPT'])
 173       fi
 174     fi
 175   else
 176     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 177       # Default is to calculate a string like this 'adhoc.<username>.<base dir name>'
 178       # Outer [ ] to quote m4.
 179       [ basedirname=`$BASENAME "$TOPDIR" | $TR -d -c '[a-z][A-Z][0-9].-'` ]
 180       VERSION_OPT="adhoc.$USERNAME.$basedirname"
 181     fi
 182   fi
 183 
 184   AC_ARG_WITH(version-build, [AS_HELP_STRING([--with-version-build],
 185       [Set version 'BUILD' field (build number) @<:@not specified@:>@])],
 186       [with_version_build_present=true], [with_version_build_present=false])
 187 
 188   if test "x$with_version_build_present" = xtrue; then
 189     if test "x$with_version_build" = xyes; then
 190       AC_MSG_ERROR([--with-version-build must have a value])
 191     elif test "x$with_version_build" = xno; then
 192       # Interpret --without-* as empty string instead of the literal "no"
 193       VERSION_BUILD=
 194     elif test "x$with_version_build" = x; then
 195       VERSION_BUILD=
 196     else
 197       JDKVER_CHECK_AND_SET_NUMBER(VERSION_BUILD, $with_version_build)
 198     fi
 199   else
 200     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 201       # Default is to not have a build number.
 202       VERSION_BUILD=""
 203       # FIXME: Until all code can cope with an empty VERSION_BUILD, set it to 0.
 204       VERSION_BUILD=0
 205     fi
 206   fi
 207 
 208   AC_ARG_WITH(version-feature, [AS_HELP_STRING([--with-version-feature],
 209       [Set version 'FEATURE' field (first number) @<:@current source value@:>@])],
 210       [with_version_feature_present=true], [with_version_feature_present=false])
 211 
 212   if test "x$with_version_feature_present" = xtrue; then
 213     if test "x$with_version_feature" = xyes; then
 214       AC_MSG_ERROR([--with-version-feature must have a value])
 215     else
 216       JDKVER_CHECK_AND_SET_NUMBER(VERSION_FEATURE, $with_version_feature)
 217     fi
 218   else
 219     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 220       # Default is to get value from version-numbers
 221       VERSION_FEATURE="$DEFAULT_VERSION_FEATURE"
 222     fi
 223   fi
 224 
 225   AC_ARG_WITH(version-interim, [AS_HELP_STRING([--with-version-interim],
 226       [Set version 'INTERIM' field (second number) @<:@current source value@:>@])],
 227       [with_version_interim_present=true], [with_version_interim_present=false])
 228 
 229   if test "x$with_version_interim_present" = xtrue; then
 230     if test "x$with_version_interim" = xyes; then
 231       AC_MSG_ERROR([--with-version-interim must have a value])
 232     elif test "x$with_version_interim" = xno; then
 233       # Interpret --without-* as empty string (i.e. 0) instead of the literal "no"
 234       VERSION_INTERIM=0
 235     elif test "x$with_version_interim" = x; then
 236       VERSION_INTERIM=0
 237     else
 238       JDKVER_CHECK_AND_SET_NUMBER(VERSION_INTERIM, $with_version_interim)
 239     fi
 240   else
 241     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 242       # Default is 0, if unspecified
 243       VERSION_INTERIM=$DEFAULT_VERSION_INTERIM
 244     fi
 245   fi
 246 
 247   AC_ARG_WITH(version-update, [AS_HELP_STRING([--with-version-update],
 248       [Set version 'UPDATE' field (third number) @<:@current source value@:>@])],
 249       [with_version_update_present=true], [with_version_update_present=false])
 250 
 251   if test "x$with_version_update_present" = xtrue; then
 252     if test "x$with_version_update" = xyes; then
 253       AC_MSG_ERROR([--with-version-update must have a value])
 254     elif test "x$with_version_update" = xno; then
 255       # Interpret --without-* as empty string (i.e. 0) instead of the literal "no"
 256       VERSION_UPDATE=0
 257     elif test "x$with_version_update" = x; then
 258       VERSION_UPDATE=0
 259     else
 260       JDKVER_CHECK_AND_SET_NUMBER(VERSION_UPDATE, $with_version_update)
 261     fi
 262   else
 263     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 264       # Default is 0, if unspecified
 265       VERSION_UPDATE=$DEFAULT_VERSION_UPDATE
 266     fi
 267   fi
 268 
 269   AC_ARG_WITH(version-patch, [AS_HELP_STRING([--with-version-patch],
 270       [Set version 'PATCH' field (fourth number) @<:@not specified@:>@])],
 271       [with_version_patch_present=true], [with_version_patch_present=false])
 272 
 273   if test "x$with_version_patch_present" = xtrue; then
 274     if test "x$with_version_patch" = xyes; then
 275       AC_MSG_ERROR([--with-version-patch must have a value])
 276     elif test "x$with_version_patch" = xno; then
 277       # Interpret --without-* as empty string (i.e. 0) instead of the literal "no"
 278       VERSION_PATCH=0
 279     elif test "x$with_version_patch" = x; then
 280       VERSION_PATCH=0
 281     else
 282       JDKVER_CHECK_AND_SET_NUMBER(VERSION_PATCH, $with_version_patch)
 283     fi
 284   else
 285     if test "x$NO_DEFAULT_VERSION_PARTS" != xtrue; then
 286       # Default is 0, if unspecified
 287       VERSION_PATCH=$DEFAULT_VERSION_PATCH
 288     fi
 289   fi
 290 
 291   # Calculate derived version properties
 292 
 293   # Set VERSION_IS_GA based on if VERSION_PRE has a value
 294   if test "x$VERSION_PRE" = x; then
 295     VERSION_IS_GA=true
 296   else
 297     VERSION_IS_GA=false
 298   fi
 299 
 300   # VERSION_NUMBER but always with exactly 4 positions, with 0 for empty positions.
 301   VERSION_NUMBER_FOUR_POSITIONS=$VERSION_FEATURE.$VERSION_INTERIM.$VERSION_UPDATE.$VERSION_PATCH
 302 
 303   stripped_version_number=$VERSION_NUMBER_FOUR_POSITIONS
 304   # Strip trailing zeroes from stripped_version_number
 305   for i in 1 2 3 ; do stripped_version_number=${stripped_version_number%.0} ; done
 306   VERSION_NUMBER=$stripped_version_number
 307 
 308   # The complete version string, with additional build information
 309   if test "x$VERSION_BUILD$VERSION_OPT" = x; then
 310     VERSION_STRING=$VERSION_NUMBER${VERSION_PRE:+-$VERSION_PRE}
 311   else
 312     # If either build or opt is set, we need a + separator
 313     VERSION_STRING=$VERSION_NUMBER${VERSION_PRE:+-$VERSION_PRE}+$VERSION_BUILD${VERSION_OPT:+-$VERSION_OPT}
 314   fi
 315 
 316   # The short version string, just VERSION_NUMBER and PRE, if present.
 317   VERSION_SHORT=$VERSION_NUMBER${VERSION_PRE:+-$VERSION_PRE}
 318 
 319   # The version date
 320   AC_ARG_WITH(version-date, [AS_HELP_STRING([--with-version-date],
 321       [Set version date @<:@current source value@:>@])])
 322   if test "x$with_version_date" = xyes; then
 323     AC_MSG_ERROR([--with-version-date must have a value])
 324   elif test "x$with_version_date" != x; then
 325     if [ ! [[ $with_version_date =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] ]; then
 326       AC_MSG_ERROR(["$with_version_date" is not a valid version date]) 
 327     else
 328       VERSION_DATE="$with_version_date"
 329     fi
 330   else
 331     VERSION_DATE="$DEFAULT_VERSION_DATE"
 332   fi
 333 
 334   # The vendor version string, if any
 335   AC_ARG_WITH(vendor-version-string, [AS_HELP_STRING([--with-vendor-version-string],
 336       [Set vendor version string @<:@not specified@:>@])])
 337   if test "x$with_vendor_version_string" = xyes; then
 338     AC_MSG_ERROR([--with-vendor-version-string must have a value])
 339   elif [ ! [[ $with_vendor_version_string =~ ^[[:graph:]]*$ ]] ]; then
 340     AC_MSG_ERROR([--with--vendor-version-string contains non-graphical characters: $with_vendor_version_string])
 341   else
 342     VENDOR_VERSION_STRING="$with_vendor_version_string"
 343   fi
 344 
 345   AC_MSG_CHECKING([for version string])
 346   AC_MSG_RESULT([$VERSION_STRING])
 347 
 348   AC_SUBST(VERSION_FEATURE)
 349   AC_SUBST(VERSION_INTERIM)
 350   AC_SUBST(VERSION_UPDATE)
 351   AC_SUBST(VERSION_PATCH)
 352   AC_SUBST(VERSION_PRE)
 353   AC_SUBST(VERSION_BUILD)
 354   AC_SUBST(VERSION_OPT)
 355   AC_SUBST(VERSION_NUMBER)
 356   AC_SUBST(VERSION_NUMBER_FOUR_POSITIONS)
 357   AC_SUBST(VERSION_STRING)
 358   AC_SUBST(VERSION_SHORT)
 359   AC_SUBST(VERSION_IS_GA)
 360   AC_SUBST(VERSION_DATE)
 361   AC_SUBST(VENDOR_VERSION_STRING)
 362 ])