9 parser = OptionParser(usage=
"ERROR: Usage %prog <project> <version> <outputfile>")
10 parser.add_option(
"-q",
"--quiet", action=
"store_true",
11 help=
"Do not print messages.")
12 opts, args = parser.parse_args()
14 parser.error(
"wrong number of arguments")
16 project, version, outputfile = args
18 print "Creating %s for %s %s" % (outputfile, project, version)
20 if version.startswith(
'HEAD'):
21 majver, minver, patver = 999, 999, 0
23 m = re.match(
"(v|([A-Za-z]+\-))(?P<maj_ver>[0-9]+)(r|\-)(?P<min_ver>[0-9]+)(?:(p|\-)(?P<pat_ver>[0-9]+))?", version)
24 majver = int(m.groupdict()[
'maj_ver'])
25 minver = int(m.groupdict()[
'min_ver'])
26 patver = int(m.groupdict()[
'pat_ver']
or 0)
28 outdir = os.path.dirname(outputfile)
29 if not os.path.exists(outdir):
31 print "Creating directory", outdir
35 outputdata =
"""#ifndef %(proj)s_VERSION
36 /* Automatically generated file: do not modify! */
37 #ifndef CALC_GAUDI_VERSION
38 #define CALC_GAUDI_VERSION(maj,min) (((maj) << 16) + (min))
40 #define %(proj)s_MAJOR_VERSION %(maj)d
41 #define %(proj)s_MINOR_VERSION %(min)d
42 #define %(proj)s_PATCH_VERSION %(pat)d
43 #define %(proj)s_VERSION CALC_GAUDI_VERSION(%(proj)s_MAJOR_VERSION,%(proj)s_MINOR_VERSION)
45 """ % {
'proj': project.upper(),
'min': minver,
'maj': majver,
'pat': patver }
49 f = open(outputfile,
"r")
56 if outputdata != olddata:
57 open(outputfile,
"w").write(outputdata)