Previous 199869 Revisions Next

r34998 Friday 13th February, 2015 at 14:25:13 UTC by Miodrag Milanović
verinfo to python (nw)
[src/build]build.mak verinfo.c verinfo.py*
[src/mess/osd/windows]windows.mak
[src/osd/windows]windows.mak
[src/ume/osd/windows]windows.mak

trunk/src/build/build.mak
r243509r243510
2020
2121MAKEDEP_TARGET = $(BUILDOUT)/makedep$(BUILD_EXE)
2222MAKEMAK_TARGET = $(BUILDOUT)/makemak$(BUILD_EXE)
23VERINFO_TARGET = $(BUILDOUT)/verinfo$(BUILD_EXE)
2423
2524MAKEDEP = $(MAKEDEP_TARGET)
2625MAKEMAK = $(MAKEMAK_TARGET)
27VERINFO = $(VERINFO_TARGET)
2826
2927ifneq ($(TERM),cygwin)
3028ifeq ($(OS),Windows_NT)
3129MAKEDEP = $(subst /,\,$(MAKEDEP_TARGET))
3230MAKEMAK = $(subst /,\,$(MAKEMAK_TARGET))
33VERINFO = $(subst /,\,$(VERINFO_TARGET))
3431endif
3532endif
3633
r243509r243510
3835BUILD += \
3936   $(MAKEDEP_TARGET) \
4037   $(MAKEMAK_TARGET) \
41   $(VERINFO_TARGET) \
4238
4339
4440
r243509r243510
7874   $(LD) $(LDFLAGS) $^ $(BASELIBS) -o $@
7975
8076
81
82#-------------------------------------------------
83# verinfo
84#-------------------------------------------------
85
86VERINFOOBJS = \
87   $(BUILDOBJ)/verinfo.o
88
89$(VERINFO_TARGET): $(VERINFOOBJS) $(LIBOCORE)
90   @echo Linking $@...
91   $(LD) $(LDFLAGS) $^ $(BASELIBS) -o $@
92
9377else
9478#-------------------------------------------------
9579# It's a CROSS_BUILD. Ensure the targets exist.
r243509r243510
9781$(MAKEDEP_TARGET):
9882   @echo $@ should be built natively. Nothing to do.
9983
100$(VERINFO_TARGET):
101   @echo $@ should be built natively. Nothing to do.
102
10384endif # CROSS_BUILD
trunk/src/build/verinfo.c
r243509r243510
1//============================================================
2//
3//  verinfo.c - Version resource emitter code
4//
5//  Copyright Nicola Salmoria and the MAME Team.
6//  Visit http://mamedev.org for licensing and usage restrictions.
7//
8//============================================================
9
10#include <stdio.h>
11#include <ctype.h>
12
13#include <string.h>
14#include <stdlib.h>
15
16typedef unsigned char UINT8;
17
18#define ARRAY_LENGTH(x)     (sizeof(x) / sizeof(x[0]))
19#define BUILD_MAME      (0)
20#define BUILD_MESS          (1)
21#define BUILD_UME           (2)
22
23//============================================================
24//  TYPE DEFINITIONS
25//============================================================
26
27struct version_info
28{
29   int version_major;
30   int version_minor;
31   int version_build;
32   int version_subbuild;
33   const char *version_string;
34   const char *author;
35   const char *comments;
36   const char *company_name;
37   const char *file_description;
38   const char *internal_name;
39   const char *legal_copyright;
40   const char *original_filename;
41   const char *product_name;
42};
43
44
45
46//============================================================
47// STATIC
48//============================================================
49
50static int build;
51
52
53//============================================================
54//  emit_version_info
55//============================================================
56
57static void emit_version_info(const version_info *v)
58{
59   printf("VS_VERSION_INFO VERSIONINFO\n");
60   printf("\tFILEVERSION %d,%d,%d,%d\n", v->version_major, v->version_minor, v->version_build, v->version_subbuild);
61   printf("\tPRODUCTVERSION %d,%d,%d,%d\n", v->version_major, v->version_minor, v->version_build, v->version_subbuild);
62   printf("\tFILEFLAGSMASK 0x3fL\n");
63#ifdef MAME_DEBUG
64   if (v->version_build == 0)
65      printf("\tFILEFLAGS VS_FF_DEBUG\n");
66   else
67      printf("\tFILEFLAGS VS_FF_PRERELEASE | VS_FF_DEBUG\n");
68#else
69   if (v->version_build == 0)
70      printf("\tFILEFLAGS 0x0L\n");
71   else
72      printf("\tFILEFLAGS VS_FF_PRERELEASE\n");
73#endif
74   printf("\tFILEOS VOS_NT_WINDOWS32\n");
75   printf("\tFILETYPE VFT_APP\n");
76   printf("\tFILESUBTYPE VFT2_UNKNOWN\n");
77   printf("BEGIN\n");
78   printf("\tBLOCK \"StringFileInfo\"\n");
79   printf("\tBEGIN\n");
80   printf("#ifdef UNICODE\n");
81   printf("\t\tBLOCK \"040904b0\"\n");
82   printf("#else\n");
83   printf("\t\tBLOCK \"040904E4\"\n");
84   printf("#endif\n");
85   printf("\t\tBEGIN\n");
86   if (v->author != NULL)
87      printf("\t\t\tVALUE \"Author\", \"%s\\0\"\n", v->author);
88   if (v->comments != NULL)
89      printf("\t\t\tVALUE \"Comments\", \"%s\\0\"\n", v->comments);
90   if (v->company_name != NULL)
91      printf("\t\t\tVALUE \"CompanyName\", \"%s\\0\"\n", v->company_name);
92   if (v->file_description != NULL)
93      printf("\t\t\tVALUE \"FileDescription\", \"%s\\0\"\n", v->file_description);
94   printf("\t\t\tVALUE \"FileVersion\", \"%d, %d, %d, %d\\0\"\n", v->version_major, v->version_minor, v->version_build, v->version_subbuild);
95   if (v->internal_name != NULL)
96      printf("\t\t\tVALUE \"InternalName\", \"%s\\0\"\n", v->internal_name);
97   if (v->legal_copyright != NULL)
98      printf("\t\t\tVALUE \"LegalCopyright\", \"%s\\0\"\n", v->legal_copyright);
99   if (v->original_filename != NULL)
100      printf("\t\t\tVALUE \"OriginalFilename\", \"%s\\0\"\n", v->original_filename);
101   if (v->product_name != NULL)
102      printf("\t\t\tVALUE \"ProductName\", \"%s\\0\"\n", v->product_name);
103   printf("\t\t\tVALUE \"ProductVersion\", \"%s\\0\"\n", v->version_string);
104   printf("\t\tEND\n");
105   printf("\tEND\n");
106   printf("\tBLOCK \"VarFileInfo\"\n");
107   printf("\tBEGIN\n");
108   printf("#ifdef UNICODE\n");
109   printf("\t\tVALUE \"Translation\", 0x409, 1200\n");
110   printf("#else\n");
111   printf("\t\tVALUE \"Translation\", 0x409, 1252\n");
112   printf("#endif\n");
113   printf("\tEND\n");
114   printf("END\n");
115}
116
117
118
119//============================================================
120//  parse_version_digit
121//============================================================
122
123static bool parse_version_digit(const char *str, int *position, int* value)
124{
125   int res = 0;
126
127   while (str[*position] != 0 && !isspace((UINT8)str[*position]) && !isdigit((UINT8)str[*position]))
128      (*position)++;
129
130   if (str[*position] != 0 && isdigit((UINT8)str[*position]))
131   {
132      res = sscanf(&str[*position], "%d", value);
133      while (isdigit((UINT8)str[*position]))
134         (*position)++;
135   }
136   return res == 1;
137}
138
139
140
141//============================================================
142//  parse_version
143//============================================================
144
145static int parse_version(char *str, int *version_major, int *version_minor, const char **version_string)
146{
147   char *version;
148   int position = 0;
149
150   // find the version string
151   version = strstr(str, "BARE_BUILD_VERSION");
152   if (version != NULL)
153      version = strchr(version, '"');
154   if (version == NULL || *version == '\0' || strchr(version, '.') == NULL)
155   {
156      fprintf(stderr, "Unable to find version string\n");
157      return 1;
158   }
159   version++;
160   *strchr(version, '"') = 0;
161
162   *version_string = version;
163   if (!parse_version_digit(version, &position, version_major))
164   {
165      fprintf(stderr, "Unable to parse major version\n");
166      return 1;
167   }
168   if (!parse_version_digit(version, &position, version_minor))
169   {
170      fprintf(stderr, "Unable to parse minor version\n");
171      return 1;
172   }
173   return 0;
174}
175
176
177
178//============================================================
179//  main
180//============================================================
181static int usage(char *me)
182{
183   fprintf(stderr, "Usage: %s [-b mame|mess|ume] <filename>\n", me);
184   return 1;
185}
186
187
188//============================================================
189//  main
190//============================================================
191
192int main(int argc, char *argv[])
193{
194   version_info v;
195   char legal_copyright[512];
196   char *buffer;
197   size_t size;
198   int opt;
199   FILE *f;
200
201   memset(&v, 0, sizeof(v));
202   build = BUILD_MAME;
203
204   // validate parameters
205   opt = 1;
206   while (opt < argc && *argv[opt] == '-')
207   {
208      if (!strcmp(argv[opt], "-b"))
209      {
210         char *p = argv[++opt];
211         if (!strcmp(p,"mame"))
212            build = BUILD_MAME;
213         else if (!strcmp(p,"mess"))
214            build = BUILD_MESS;
215         else if (!strcmp(p,"ume"))
216            build = BUILD_UME;
217         else
218            return usage(argv[0]);
219      }
220      else
221         return usage(argv[0]);
222      opt++;
223   }
224
225   if (opt != argc-1 )
226   {
227      return usage(argv[0]);
228   }
229
230   // open the file
231   f = fopen(argv[argc-1], "rb");
232   if (f == NULL)
233   {
234      fprintf(stderr, "Error opening file %s\n", argv[argc-1]);
235      return 1;
236   }
237
238   // get the file size
239   fseek(f, 0, SEEK_END);
240   size = ftell(f);
241   fseek(f, 0, SEEK_SET);
242
243   // allocate a buffer
244   buffer = (char *)malloc(size + 1);
245   if (buffer == NULL)
246   {
247      fclose(f);
248      fprintf(stderr, "Error allocating %ld bytes\n", (long) size + 1);
249      return 1;
250   }
251
252   // read the file contents and NULL-terminate
253   fread(buffer, 1, size, f);
254   fclose(f);
255   buffer[size] = 0;
256
257   // parse out version string
258   if (parse_version(buffer, &v.version_major, &v.version_minor, &v.version_string))
259   {
260      fprintf(stderr, "Error parsing version\n");
261      free(buffer);
262      return 1;
263   }
264
265   if (build == BUILD_MESS)
266   {
267      // MESS
268      v.author = "MESS Team";
269      v.comments = "Multi Emulation Super System";
270      v.company_name = "MESS Team";
271      v.file_description = "Multi Emulation Super System";
272      v.internal_name = "MESS";
273      v.original_filename = "MESS";
274      v.product_name = "MESS";
275   }
276   else if (build == BUILD_UME)
277   {
278      // UME
279      v.author = "MAME and MESS Team";
280      v.comments = "Universal Machine Emulator";
281      v.company_name = "MAME and MESS Team";
282      v.file_description = "Universal Machine Emulator";
283      v.internal_name = "UME";
284      v.original_filename = "UME";
285      v.product_name = "UME";
286   }
287   else
288   {
289      // MAME
290      v.author = "Nicola Salmoria and the MAME Team";
291      v.comments = "Multiple Arcade Machine Emulator";
292      v.company_name = "MAME Team";
293      v.file_description = "Multiple Arcade Machine Emulator";
294      v.internal_name = "MAME";
295      v.original_filename = "MAME";
296      v.product_name = "MAME";
297   }
298
299   // build legal_copyright string
300   v.legal_copyright = legal_copyright;
301   snprintf(legal_copyright, ARRAY_LENGTH(legal_copyright), "Copyright Nicola Salmoria and the MAME team");
302
303   // emit the info
304   emit_version_info(&v);
305
306   free(buffer);
307   return 0;
308}
trunk/src/build/verinfo.py
r0r243510
1#!/usr/bin/python
2
3from __future__ import with_statement
4
5import sys
6import os
7
8def usage():
9    sys.stderr.write('Usage: verinfo.py [-b mame|mess|ume] <filename>\n')
10    return 0
11   
12build = "mame"
13
14if (len(sys.argv)==1):
15   usage()
16   sys.exit(1)
17
18if (sys.argv[1]=='-b'):
19    if (sys.argv[2]=='mame'):
20        build = "mame"
21    elif (sys.argv[2]=='mess'):
22        build = "mess"
23    elif (sys.argv[2]=='ume'):
24        build = "ume"
25    else :
26      usage()
27      sys.exit(1)
28
29srcfile = sys.argv[len(sys.argv)-1]
30try:
31   fp = open(srcfile, 'rb')
32except IOError:
33   sys.stderr.write("Unable to open source file '%s'" % srcfile)
34   sys.exit(1)
35
36for line in fp.readlines():
37    if line.find("BARE_BUILD_VERSION")!=-1 and line.find('"')!=-1 and line.find('.')!=-1:
38        version_string = line[line.find('"')+1:]
39        version_string = version_string[0:version_string.find('"')]
40        break
41
42version_major = version_string[0:version_string.find('.')]
43version_minor = version_string[version_string.find('.')+1:]
44version_build = "0"
45version_subbuild = "0"
46if (build == "mame") :
47    # MESS
48    author = "MESS Team";
49    comments = "Multi Emulation Super System";
50    company_name = "MESS Team";
51    file_description = "Multi Emulation Super System";
52    internal_name = "MESS";
53    original_filename = "MESS";
54    product_name = "MESS";
55elif (build == "mess") :
56    # UME
57    author = "MAME and MESS Team"
58    comments = "Universal Machine Emulator"
59    company_name = "MAME and MESS Team"
60    file_description = "Universal Machine Emulator"
61    internal_name = "UME"
62    original_filename = "UME"
63    product_name = "UME"
64else :
65    # MAME
66    author = "Nicola Salmoria and the MAME Team"
67    comments = "Multiple Arcade Machine Emulator"
68    company_name = "MAME Team"
69    file_description = "Multiple Arcade Machine Emulator"
70    internal_name = "MAME"
71    original_filename = "MAME"
72    product_name = "MAME"
73
74legal_copyright = "Copyright Nicola Salmoria and the MAME team"
75
76print("VS_VERSION_INFO VERSIONINFO")
77print("\tFILEVERSION %s,%s,%s,%s" % (version_major, version_minor, version_build, version_subbuild))
78print("\tPRODUCTVERSION %s,%s,%s,%s" % (version_major, version_minor, version_build, version_subbuild))
79print("\tFILEFLAGSMASK 0x3fL")
80if (version_build == 0) :
81    print("\tFILEFLAGS 0x0L")
82else :
83    print("\tFILEFLAGS VS_FF_PRERELEASE")
84print("\tFILEOS VOS_NT_WINDOWS32")
85print("\tFILETYPE VFT_APP")
86print("\tFILESUBTYPE VFT2_UNKNOWN")
87print("BEGIN")
88print("\tBLOCK \"StringFileInfo\"")
89print("\tBEGIN")
90print("#ifdef UNICODE")
91print("\t\tBLOCK \"040904b0\"")
92print("#else")
93print("\t\tBLOCK \"040904E4\"")
94print("#endif")
95print("\t\tBEGIN")
96print("\t\t\tVALUE \"Author\", \"%s\\0\"" % author)
97print("\t\t\tVALUE \"Comments\", \"%s\\0\"" % comments)
98print("\t\t\tVALUE \"CompanyName\", \"%s\\0\"" % company_name)
99print("\t\t\tVALUE \"FileDescription\", \"%s\\0\"" % file_description)
100print("\t\t\tVALUE \"FileVersion\", \"%s, %s, %s, %s\\0\"" % (version_major, version_minor, version_build, version_subbuild))
101print("\t\t\tVALUE \"InternalName\", \"%s\\0\"" % internal_name)
102print("\t\t\tVALUE \"LegalCopyright\", \"%s\\0\"" % legal_copyright)
103print("\t\t\tVALUE \"OriginalFilename\", \"%s\\0\"" % original_filename)
104print("\t\t\tVALUE \"ProductName\", \"%s\\0\"" % product_name)
105print("\t\t\tVALUE \"ProductVersion\", \"%s\\0\"" % version_string)
106print("\t\tEND")
107print("\tEND")
108print("\tBLOCK \"VarFileInfo\"")
109print("\tBEGIN")
110print("#ifdef UNICODE")
111print("\t\tVALUE \"Translation\", 0x409, 1200")
112print("#else")
113print("\t\tVALUE \"Translation\", 0x409, 1252")
114print("#endif")
115print("\tEND")
116print("END")
No newline at end of file
trunk/src/mess/osd/windows/windows.mak
r243509r243510
3636
3737$(RESFILE): $(MESS_WINSRC)/mess.rc $(MESS_WINOBJ)/messvers.rc
3838
39$(MESS_WINOBJ)/messvers.rc: $(BUILDOUT)/verinfo$(BUILD_EXE) $(SRC)/version.c
39$(MESS_WINOBJ)/messvers.rc: $(SRC)/build/verinfo.py $(SRC)/version.c
4040   @echo Emitting $@...
41   @"$(BUILDOUT)/verinfo$(BUILD_EXE)" -b mess $(SRC)/version.c > $@
No newline at end of file
41   $(PYTHON) $(SRC)/build/verinfo.py -b mess $(SRC)/version.c > $@
No newline at end of file
trunk/src/osd/windows/windows.mak
r243509r243510
502502
503503$(RESFILE): $(WINSRC)/mame.rc $(WINOBJ)/mamevers.rc
504504
505$(WINOBJ)/mamevers.rc: $(BUILDOUT)/verinfo$(BUILD_EXE) $(SRC)/version.c
505$(WINOBJ)/mamevers.rc: $(SRC)/build/verinfo.py $(SRC)/version.c
506506   @echo Emitting $@...
507   @"$(BUILDOUT)/verinfo$(BUILD_EXE)" -b mame $(SRC)/version.c > $@
507   $(PYTHON) $(SRC)/build/verinfo.py -b mame $(SRC)/version.c > $@
trunk/src/ume/osd/windows/windows.mak
r243509r243510
3636
3737$(RESFILE): $(UME_WINSRC)/ume.rc $(UME_WINOBJ)/umevers.rc
3838
39$(UME_WINOBJ)/umevers.rc: $(BUILDOUT)/verinfo$(BUILD_EXE) $(SRC)/version.c
39$(UME_WINOBJ)/umevers.rc: $(SRC)/build/verinfo.py $(SRC)/version.c
4040   @echo Emitting $@...
41   @"$(BUILDOUT)/verinfo$(BUILD_EXE)" -b ume $(SRC)/version.c > $@
No newline at end of file
41   $(PYTHON) $(SRC)/build/verinfo.py -b ume $(SRC)/version.c > $@
No newline at end of file


Previous 199869 Revisions Next


© 1997-2024 The MAME Team