1BEGIN {
2
3  # ff bits: 1(debug), 2(prerelease), 4(patched), 8(vendor) and 32(special)
4  # debug is summed based on the /Define _DEBUG
5  # prerelease is based on the -dev extension,
6  # patched is based on a non-standard "-ver" extension, 
7  # special and vendor are toggled by their args.
8  #
9  ff = 0;
10
11  file=ARGV[1];
12  desc=ARGV[2];
13  rel_h=ARGV[3];
14
15  filename = file;
16  if (match(file, /\./)) {
17    sub(/\.[^\.]*$/, "", file);
18  }
19
20  i = 4;
21  while (length(ARGV[i])) {
22    if (match(ARGV[i], /icon=/)) {
23      icon = substr(ARGV[i], 6);
24    }
25    if (match(ARGV[i], /vendor=/)) {
26      vendor = substr(ARGV[i], 8);
27      ff = ff + 8;
28    }
29    if (match(ARGV[i], /special=/)) {
30      special = substr(ARGV[i], 9);
31      ff = ff + 32;
32    }
33    i = i + 1
34  }
35
36  i = i - 1;
37  while (i) {
38    delete ARGV[i];
39    i = i - 1;
40  }
41
42  while ((getline < rel_h) > 0) {
43    if (match ($0, /^#define AP._MAJOR_VERSION/)) {
44      ver_major = $3;
45    }
46    if (match ($0, /^#define AP._MINOR_VERSION/)) {
47      ver_minor = $3;
48    }
49    if (match ($0, /^#define AP._PATCH_VERSION/)) {
50      ver_patch = $3;
51    }
52    if (match ($0, /^#define AP._IS_DEV_VERSION/)) {
53      ver_suffix = "-dev";
54      ver_build = "0";
55    }
56    if (match ($0, /^#undef AP._IS_DEV_VERSION/)) {
57      ver_build = "100";
58    }
59    if (match ($0, /^.*Copyright /)) {
60      copyright = substr($0, RLENGTH + 1);
61    }
62  }
63  ver = ver_major "." ver_minor "." ver_patch ver_suffix;
64  verc = ver_major "," ver_minor "," ver_patch "," ver_build;   
65
66  if (length(vendor)) {
67    ff = ff + 8;
68  }
69
70  if (length(icon)) {
71    print "1 ICON DISCARDABLE \"" icon "\"";
72  }
73  print "1 VERSIONINFO";
74  print " FILEVERSION " verc "";
75  print " PRODUCTVERSION " verc "";
76  print " FILEFLAGSMASK 0x3fL";
77  print "#if defined(_DEBUG)"
78  print " FILEFLAGS 0x" sprintf("%02x", ff + 1) "L";
79  print "#else"
80  print " FILEFLAGS 0x" sprintf("%02x", ff) "L";
81  print "#endif"
82  print " FILEOS 0x40004L";
83  print " FILETYPE 0x1L";
84  print " FILESUBTYPE 0x0L";
85  print "BEGIN";
86  print "  BLOCK \"StringFileInfo\"";
87  print "  BEGIN";
88  print "    BLOCK \"040904b0\"";
89  print "    BEGIN";
90  print "    VALUE \"Comments\", "\
91  "\"Licensed to the Apache Software Foundation (ASF) under one or more " \
92  "contributor license agreements.  See the NOTICE file distributed with " \
93  "this work for additional information regarding copyright ownership.  " \
94  "The ASF licenses this file to You under the Apache License, Version 2.0 " \
95  "(the \"\"License\"\"); you may not use this file except in compliance " \
96  "with the License.  You may obtain a copy of the License at\\r\\n\\r\\n" \
97  "http://www.apache.org/licenses/LICENSE-2.0\\r\\n\\r\\n" \
98  "Unless required by applicable law or agreed to in writing, software " \
99  "distributed under the License is distributed on an \"\"AS IS\"\" BASIS, " \
100  "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  " \
101  "See the License for the specific language governing permissions and " \
102  "limitations under the License.\\0\"";
103  print "      VALUE \"CompanyName\", \"Apache Software Foundation\\0\"";
104  print "      VALUE \"FileDescription\", \"" desc "\\0\"";
105  print "      VALUE \"FileVersion\", \"" ver "\\0\"";
106  print "      VALUE \"InternalName\", \"" file "\\0\"";
107  print "      VALUE \"LegalCopyright\", \"Copyright " copyright "\\0\"";
108  print "      VALUE \"OriginalFilename\", \"" filename "\\0\"";
109  if (vendor) {
110    print "      VALUE \"PrivateBuild\", \"" vendor "\\0\"";
111  }
112  if (special) {
113    print "      VALUE \"SpecialBuild\", \"" vendor "\\0\"";
114  }
115  print "      VALUE \"ProductName\", \"Apache Portable Runtime\\0\"";
116  print "      VALUE \"ProductVersion\", \"" ver "\\0\"";
117  print "    END";
118  print "  END";
119  print "  BLOCK \"VarFileInfo\"";
120  print "  BEGIN";
121  print "    VALUE \"Translation\", 0x409, 1200";
122  print "  END";
123  print "END";
124}
125