source: rtems-tools/wscript @ 0c5db2d

5
Last change on this file since 0c5db2d was c5286cd, checked in by Chris Johns <chrisj@…>, on 04/10/18 at 03:59:11

waf: Add getcwd() to sys.path as waf has changed.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2014-2018 Chris Johns (chrisj@rtems.org)
4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions are met:
10#
11# 1. Redistributions of source code must retain the above copyright notice,
12# this list of conditions and the following disclaimer.
13#
14# 2. Redistributions in binary form must reproduce the above copyright notice,
15# this list of conditions and the following disclaimer in the documentation
16# and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29#
30
31import os.path
32
33import wafwindows
34
35subdirs = ['rtemstoolkit',
36           'linkers',
37           'tester',
38           'tools/gdb/python']
39
40def get_version(ctx):
41    version = '5'
42    revision = 'not_released'
43    release = '%s.%s' % (version, revision)
44    if os.path.exists('VERSION'):
45        try:
46            import configparser
47        except ImportError:
48            import ConfigParser as configparser
49        v = configparser.SafeConfigParser()
50        v.read('VERSION')
51        release = v.get('version', 'release')
52    else:
53        #
54        # waf after 1.9.9 does not place the current directory in Python's
55        # system path which means importing the RTEMS toolkit
56        # fails. Temporarily add it so we can import the git module.
57        #
58        import sys
59        current_sys_path = sys.path
60        try:
61            sys.path = [os.getcwd()] + sys.path
62            from rtemstoolkit import git
63        finally:
64            sys.path = current_sys_path
65        repo = git.repo('.')
66        if repo.valid():
67            head = repo.head()
68            if repo.dirty():
69                modified = '_modified'
70            else:
71                modified = ''
72            release = '%s.%s%s' % (version, head[0:12], modified)
73    last_dot = release.rfind('.')
74    if last_dot == -1:
75        ctx.fatal('invalid VERSION file')
76    revision = release[0:last_dot]
77    return revision, release
78
79def recurse(ctx):
80    for sd in subdirs:
81        ctx.recurse(sd)
82
83def options(ctx):
84    ctx.add_option('--c-opts',
85                   default = '-O2',
86                   dest='c_opts',
87                   help = 'Set build options, default: -O2.')
88    ctx.add_option('--host',
89                   default = 'native',
90                   dest='host',
91                   help = 'Set host to build for, default: none.')
92    recurse(ctx)
93
94def init(ctx):
95    wafwindows.set_compilers()
96    try:
97        import waflib.Options
98        import waflib.ConfigSet
99        env = waflib.ConfigSet.ConfigSet()
100        env.load(waflib.Options.lockfile)
101        check_options(ctx, env.options['host'])
102        recurse(ctx)
103    except:
104        pass
105
106def shutdown(ctx):
107    pass
108
109def configure(ctx):
110    try:
111        ctx.load("doxygen", tooldir = 'waf-tools')
112    except:
113        pass
114    ctx.env.RTEMS_VERSION, ctx.env.RTEMS_RELEASE = get_version(ctx)
115    ctx.start_msg('Version')
116    ctx.end_msg('%s (%s)' % (ctx.env.RTEMS_RELEASE, ctx.env.RTEMS_VERSION))
117    ctx.env.C_OPTS = ctx.options.c_opts.split(',')
118    check_options(ctx, ctx.options.host)
119    #
120    # Common Python check.
121    #
122    ctx.load('python')
123    ctx.check_python_version((2,6,6))
124    #
125    # Installing the PYO,PYC seems broken on 1.8.19. The path is wrong.
126    #
127    ctx.env.PYO = 0
128    ctx.env.PYC = 0
129    recurse(ctx)
130
131def build(ctx):
132    if os.path.exists('VERSION'):
133        ctx.install_files('${PREFIX}/share/rtems/rtemstoolkit', ['VERSION'])
134    recurse(ctx)
135
136def install(ctx):
137    recurse(ctx)
138
139def clean(ctx):
140    recurse(ctx)
141
142def rebuild(ctx):
143    import waflib.Options
144    waflib.Options.commands.extend(['clean', 'build'])
145
146def check_options(ctx, host):
147    if host in ['mingw32']:
148        ctx.env.HOST = host
149        ctx.env.CC = '%s-gcc' % (host)
150        ctx.env.CXX = '%s-g++' % (host)
151        ctx.env.AR = '%s-ar' % (host)
152        ctx.env.PYTHON = 'python'
153    elif host is not 'native':
154        ctx.fatal('unknown host: %s' % (host));
155
156#
157# The doxy command.
158#
159from waflib import Build
160class doxy(Build.BuildContext):
161    fun = 'build'
162    cmd = 'doxy'
Note: See TracBrowser for help on using the repository browser.