1 # Copyright (C) 1999-2006 Id Software, Inc. and contributors.
2 # For a list of contributors, see the accompanying CONTRIBUTORS file.
4 # This file is part of GtkRadiant.
6 # GtkRadiant is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # GtkRadiant is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GtkRadiant; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 # version and about message management
22 # NOTE: this module is meant to be used on all platforms, it is not SCons centric
26 # include/version.default
28 # include/version.h include/RADIANT_MAJOR include/RADIANT_MINOR
29 # the header is used by C/C++ code, the straight text file by setup
32 # for non-official builds, we have a default message
33 # otherwise, use environment variable $RADIANT_ABOUTMSG
35 # file pointed to by $RADIANT_ABOUTMSG if exists
36 # else include/aboutmsg.default
40 import sys, re, string, os
46 f = open('include/version.default', 'r')
48 line = string.split(buffer, '\n')[0]
50 sys.stdout.write("version: %s\n" % line)
51 exp = re.compile('^1\\.([^\\.]*)\\.([0-9]*)')
52 (major, minor) = exp.findall(line)[0]
53 sys.stdout.write("minor: %s major: %s\n" % (minor, major))
54 return (line, major, minor)
56 # you can pass an optional message to append to aboutmsg
57 def radiant_makeversion(append_about, root = os.getcwd()):
58 (line, major, minor) = get_version()
59 f = open(os.path.join(root, 'include/version.h'), 'w')
60 f.write('// generated header, see makeversion.py\n')
61 f.write('#define RADIANT_VERSION "%s"\n' % line)
62 f.write('#define RADIANT_MINOR_VERSION "%s"\n' % minor)
63 f.write('#define RADIANT_MAJOR_VERSION "%s"\n' % major)
65 f = open(os.path.join(root, 'include/RADIANT_MINOR'), 'w')
68 f = open(os.path.join(root, 'include/RADIANT_MAJOR'), 'w')
71 f = open(os.path.join(root, 'include/version'), 'w')
75 aboutfile = os.path.join(root, 'include/aboutmsg.default')
76 if ( os.environ.has_key('RADIANT_ABOUTMSG') ):
77 aboutfile = os.environ['RADIANT_ABOUTMSG']
79 if os.path.isfile(aboutfile):
80 sys.stdout.write("about message is in %s\n" % aboutfile)
81 f = open(aboutfile, 'r')
84 if line.endswith("\n"):
88 # optional additional message
89 if ( not append_about is None ):
91 sys.stdout.write("about: %s\n" % line)
92 f = open(os.path.join(root, 'include/aboutmsg.h'), 'w')
93 f.write('// generated header, see makeversion.py\n')
94 f.write('#define RADIANT_ABOUTMSG "%s"\n' % line)
97 # can be used as module (scons build), or by direct call
98 if __name__ == '__main__':
99 root = os.path.dirname(__file__)
100 if not os.path.isabs(root):
102 radiant_makeversion(None, root)