generate-webkitversion.pl 5.3 KB

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