3 # Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # Trim any trailing \r or \n from the given variable.
30 local old_value=$(eval echo "\$$1");
31 local value=$(echo "$old_value" | sed 's/[\r\n]*$//')
35 if [[ -n "$WEBKIT_LIBRARIES" ]]; then
36 FALLBACK_VERSION_PATH=`cygpath -u "$WEBKIT_LIBRARIES\\tools\\scripts\\VERSION"`
37 FALLBACK_VERSION=$(cat "$FALLBACK_VERSION_PATH");
39 COPYRIGHT_END_YEAR_PATH=`cygpath -u "$WEBKIT_LIBRARIES\\tools\\scripts\\COPYRIGHT-END-YEAR"`
40 COPYRIGHT_END_YEAR=$(cat "$COPYRIGHT_END_YEAR_PATH");
41 chomp COPYRIGHT_END_YEAR
44 OUTPUT_FILE=$(cygpath -u "$1")/include/autoversion.h
45 mkdir -p "$(dirname "$OUTPUT_FILE")"
47 # Take the initial version number from RC_ProjectSourceVersion if it
48 # exists, otherwise fall back to the version number stored in the source.
49 ENVIRONMENT_VERSION=${RC_ProjectSourceVersion:-$RC_PROJECTSOURCEVERSION};
51 PROPOSED_VERSION=${ENVIRONMENT_VERSION:-$FALLBACK_VERSION}
52 chomp PROPOSED_VERSION
54 # Split out the three components of the dotted version number. We pad
55 # the input with trailing dots to handle the case where the input version
56 # has fewer components than we expect.
57 BUILD_MAJOR_VERSION=$(echo "$PROPOSED_VERSION.." | cut -d '.' -f 1)
58 BUILD_MINOR_VERSION=$(echo "$PROPOSED_VERSION.." | cut -d '.' -f 2)
59 BUILD_TINY_VERSION=$(echo "$PROPOSED_VERSION.." | cut -d '.' -f 3)
61 # Cut the major component down to three characters by dropping any
62 # extra leading digits, then adjust the major version portion of the
63 # version string to match.
64 CHARACTERS_TO_DROP=$(( ${#BUILD_MAJOR_VERSION} > 3 ? ${#BUILD_MAJOR_VERSION} - 3 : 0 ))
65 BUILD_MAJOR_VERSION=${BUILD_MAJOR_VERSION:$CHARACTERS_TO_DROP}
66 PROPOSED_VERSION=${PROPOSED_VERSION:$CHARACTERS_TO_DROP}
68 # Have the minor and tiny components default to zero if not present.
69 BUILD_MINOR_VERSION=${BUILD_MINOR_VERSION:-0}
70 BUILD_TINY_VERSION=${BUILD_TINY_VERSION:-0}
72 # Split the first component further by using the first digit for the
73 # major version and the remaining two characters as the minor version.
74 # The minor version is shifted down to the tiny version, with the tiny
75 # version becoming the variant version.
76 MAJOR_VERSION=${BUILD_MAJOR_VERSION:0:1}
77 MINOR_VERSION=${BUILD_MAJOR_VERSION:1}
78 TINY_VERSION=${BUILD_MINOR_VERSION}
79 VARIANT_VERSION=${BUILD_TINY_VERSION}
81 VERSION_TEXT=${PROPOSED_VERSION}
82 VERSION_TEXT_SHORT=${VERSION_TEXT}
84 if [ -z ${ENVIRONMENT_VERSION} ]; then
85 # If we didn't pull the version number from the environment then we're doing
86 # an engineering build and we'll stamp the build with some more information.
89 SVN_REVISION=$(svn info | grep '^Revision' | sed 's/^Revision: //')
94 VERSION_TEXT_SHORT="${VERSION_TEXT_SHORT}+"
95 VERSION_TEXT="${VERSION_TEXT_SHORT} ${USER} - ${BUILD_DATE} - r${SVN_REVISION}"
98 cat > "$OUTPUT_FILE" <<EOF
99 #define __VERSION_TEXT__ "${VERSION_TEXT}"
100 #define __BUILD_NUMBER__ "${VERSION_TEXT}"
101 #define __BUILD_NUMBER_SHORT__ "${VERSION_TEXT_SHORT}"
102 #define __VERSION_MAJOR__ ${MAJOR_VERSION}
103 #define __VERSION_MINOR__ ${MINOR_VERSION}
104 #define __VERSION_TINY__ ${TINY_VERSION}
105 #define __VERSION_BUILD__ ${VARIANT_VERSION}
106 #define __BUILD_NUMBER_MAJOR__ ${BUILD_MAJOR_VERSION}
107 #define __BUILD_NUMBER_MINOR__ ${BUILD_MINOR_VERSION}
108 #define __BUILD_NUMBER_VARIANT__ ${BUILD_TINY_VERSION}
109 #define __SVN_REVISION__ ${SVN_REVISION}
112 if [[ -n "${COPYRIGHT_END_YEAR}" ]]; then
113 cat >> "$OUTPUT_FILE" <<EOF
114 #define __COPYRIGHT_YEAR_END_TEXT__ "${COPYRIGHT_END_YEAR}"