initial import
[vuplus_webkit] / Source / WebKit / scripts / generate-webkitversion.pl
1 #!/usr/bin/perl
2
3 # Based on make_names.pl
4 #
5 # Copyright (C) 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
6 # Copyright (C) 2009, Julien Chaffraix <jchaffraix@webkit.org>
7 # Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8 # Copyright (C) 2009 Robert Hogan <robert@roberthogan.net>
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
13 #
14 # 1.  Redistributions of source code must retain the above copyright
15 #     notice, this list of conditions and the following disclaimer.
16 # 2.  Redistributions in binary form must reproduce the above copyright
17 #     notice, this list of conditions and the following disclaimer in the
18 #     documentation and/or other materials provided with the distribution.
19 # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
20 #     its contributors may be used to endorse or promote products derived
21 #     from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
24 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
27 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34 # This script reads Version.xcconfig and returns either or both of the major and minor
35 # WebKit version numbers. It is currently used by WebKit.pri.
36
37 use strict;
38
39 use Config;
40 use Getopt::Long;
41 use File::Path;
42
43 my $usage = "generate-webkitversion --config WebKit/mac/Configurations/Version.xcconfig --outputDir <outputdir>";
44
45 my $major_version = "";
46 my $minor_version = "";
47 # The appropriate Apple-maintained Version.xcconfig file for WebKit version information is in WebKit/mac/Configurations/.
48 my $configFile = "./Soure/WebKit/mac/Configurations/Version.xcconfig";
49 my $outputDir = "";
50
51 GetOptions('config=s' => \$configFile,
52     'outputDir=s' => \$outputDir);
53
54 die "You must specify a --config <file> " unless (length($configFile));
55 die "You must specify a --outputDir <outputdir> " unless (length($outputDir));
56
57 die "./Source/WebKit/mac/Configurations/Version.xcconfig does not exist: use --config <file> to specify its correct location." unless (-e $configFile);
58 die "$outputDir/ does not exist: use --outputDir <directory> to specify the location of an output directory that exists" unless (-e "$outputDir");
59
60 unless (open INPUT, "<", $configFile) { print STDERR "File does not exist: $configFile\n";}
61 while (my $line = <INPUT>) {
62     chomp $line;
63     if ($line =~ /^MAJOR_VERSION\s+=\s+\d+;/) {
64       $line =~ s/^(MAJOR_VERSION)\s+(=)\s+(\d+);/$3/;
65       $major_version = $line;
66     }
67     if ($line =~ /^MINOR_VERSION\s+=\s+\d+;/) {
68       $line =~ s/^(MINOR_VERSION)\s+(=)\s+(\d+);/$3/;
69       $minor_version = $line;
70     }
71 }
72
73 $major_version = "531" unless (length($major_version));
74 $minor_version = "3" unless (length($minor_version));
75
76 my $webKitVersionPath = "$outputDir/WebKitVersion.h";
77
78 printWebKitVersionHeaderFile("$webKitVersionPath");
79
80 sub printLicenseHeader
81 {
82     my $F = shift;
83     print F "/*
84  * THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT.
85  *
86  *
87  * Copyright (C) 2009 Apple Computer, Inc.  All rights reserved.
88  *
89  * Redistribution and use in source and binary forms, with or without
90  * modification, are permitted provided that the following conditions
91  * are met:
92  * 1. Redistributions of source code must retain the above copyright
93  *    notice, this list of conditions and the following disclaimer.
94  * 2. Redistributions in binary form must reproduce the above copyright
95  *    notice, this list of conditions and the following disclaimer in the
96  *    documentation and/or other materials provided with the distribution.
97  *
98  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
99  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
100  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
101  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
102  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
103  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
104  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
105  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
106  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
107  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
108  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
109  */
110
111
112 ";
113 }
114
115 sub printWebKitVersionHeaderFile
116 {
117     my $headerPath = shift;
118     my $F;
119     open F, ">$headerPath";
120
121     printLicenseHeader($F);
122
123     print F "#ifndef WebKitVersion_h\n";
124     print F "#define WebKitVersion_h\n\n";
125
126     print F "#define WEBKIT_MAJOR_VERSION $major_version\n";
127     print F "#define WEBKIT_MINOR_VERSION $minor_version\n\n";
128
129     print F "#endif //WebKitVersion_h\n";
130
131     close F;
132 }
133
134
135