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