version.py
Go to the documentation of this file.
1 #
2 # SConstruct
3 #
4 # Copyright (c) 2016 Jeremy Garff <jer @ jers.net>
5 #
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without modification, are permitted
9 # provided that the following conditions are met:
10 #
11 # 1. Redistributions of source code must retain the above copyright notice, this list of
12 # conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright notice, this list
14 # of conditions and the following disclaimer in the documentation and/or other materials
15 # provided with the distribution.
16 # 3. Neither the name of the owner nor the names of its contributors may be used to endorse
17 # or promote products derived from this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
22 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #
28 
29 import SCons, os
30 
31 def version_flags(env):
32  if not env['V']:
33  env['VERSIONCOMSTR'] = 'Version ${TARGET}'
34 
36  def generate_version_header(target, source, env):
37  headername = os.path.basename(target[0].abspath)
38  headerdef = headername.replace('.', '_').replace('-', '_').upper()
39 
40  try:
41  version = open(source[0].abspath, 'r').readline().strip().split('.')
42  except:
43  version = [ '0', '0', '0' ]
44 
45  f = open(headername, 'w')
46  f.write('/* Auto Generated Header built by version.py - DO NOT MODIFY */\n')
47  f.write('\n')
48  f.write('#ifndef __%s__\n' % (headerdef))
49  f.write('#define __%s__\n' % (headerdef))
50  f.write('\n')
51  f.write('#define VERSION_MAJOR %s\n' % version[0])
52  f.write('#define VERSION_MINOR %s\n' % version[1])
53  f.write('#define VERSION_MICRO %s\n' % version[2])
54  f.write('\n')
55  f.write('#endif /* __%s__ */\n' % (headerdef))
56  f.close()
57 
58  env.Append(BUILDERS = {
59  'Version' : SCons.Builder.Builder(
60  action = SCons.Action.Action(generate_version_header, '${VERSIONCOMSTR}'),
61  suffix = '.h',
62  ),
63  })
64 
65 def exists(env):
66  return 1
67 
68 def generate(env, **kwargs):
69  [f(env) for f in (version_flags, version_builders)]
70 
71 
def exists(env)
Definition: version.py:65
def version_builders(env)
Definition: version.py:35
def version_flags(env)
Definition: version.py:31
def generate(env, kwargs)
Definition: version.py:68


ws281x
Author(s): Alexey Rogachevskiy , Oleg Kalachev
autogenerated on Wed Jun 15 2022 02:46:00