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
37use strict;
38
39use Config;
40use Getopt::Long;
41use File::Path;
42use Switch;
43
44my $usage = "generate-webkitversion --config WebKit/mac/Configurations/Version.xcconfig --outputDir <outputdir>";
45
46my $major_version = "";
47my $minor_version = "";
48# The appropriate Apple-maintained Version.xcconfig file for WebKit version information is in WebKit/mac/Configurations/.
49my $configFile = "./Soure/WebKit/mac/Configurations/Version.xcconfig";
50my $outputDir = "";
51
52GetOptions('config=s' => \$configFile,
53    'outputDir=s' => \$outputDir);
54
55die "You must specify a --config <file> " unless (length($configFile));
56die "You must specify a --outputDir <outputdir> " unless (length($outputDir));
57
58die "./Source/WebKit/mac/Configurations/Version.xcconfig does not exist: use --config <file> to specify its correct location." unless (-e $configFile);
59die "$outputDir/ does not exist: use --outputDir <directory> to specify the location of an output directory that exists" unless (-e "$outputDir");
60
61unless (open INPUT, "<", $configFile) { print STDERR "File does not exist: $configFile\n";}
62while (my $line = <INPUT>) {
63    chomp $line;
64    if ($line =~ /^MAJOR_VERSION\s+=\s+\d+;/) {
65      $line =~ s/^(MAJOR_VERSION)\s+(=)\s+(\d+);/$3/;
66      $major_version = $line;
67    }
68    if ($line =~ /^MINOR_VERSION\s+=\s+\d+;/) {
69      $line =~ s/^(MINOR_VERSION)\s+(=)\s+(\d+);/$3/;
70      $minor_version = $line;
71    }
72}
73
74$major_version = "531" unless (length($major_version));
75$minor_version = "3" unless (length($minor_version));
76
77my $webKitVersionPath = "$outputDir/WebKitVersion.h";
78
79printWebKitVersionHeaderFile("$webKitVersionPath");
80
81sub printLicenseHeader
82{
83    my $F = shift;
84    print F "/*
85 * THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT.
86 *
87 *
88 * Copyright (C) 2009 Apple Computer, Inc.  All rights reserved.
89 *
90 * Redistribution and use in source and binary forms, with or without
91 * modification, are permitted provided that the following conditions
92 * are met:
93 * 1. Redistributions of source code must retain the above copyright
94 *    notice, this list of conditions and the following disclaimer.
95 * 2. Redistributions in binary form must reproduce the above copyright
96 *    notice, this list of conditions and the following disclaimer in the
97 *    documentation and/or other materials provided with the distribution.
98 *
99 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
100 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
102 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
103 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
104 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
105 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
106 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
107 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
108 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
109 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
110 */
111
112
113";
114}
115
116sub printWebKitVersionHeaderFile
117{
118    my $headerPath = shift;
119    my $F;
120    open F, ">$headerPath";
121
122    printLicenseHeader($F);
123
124    print F "#ifndef WebKitVersion_h\n";
125    print F "#define WebKitVersion_h\n\n";
126
127    print F "#define WEBKIT_MAJOR_VERSION $major_version\n";
128    print F "#define WEBKIT_MINOR_VERSION $minor_version\n\n";
129
130    print F "#endif //WebKitVersion_h\n";
131
132    close F;
133}
134
135
136
137