1 | # |
---|
2 | # RTEMS Project (https://www.rtems.org/) |
---|
3 | # |
---|
4 | # Copyright (c) 2015-2016 Chris Johns <chrisj@rtems.org>. All rights reserved. |
---|
5 | # |
---|
6 | # Redistribution and use in source and binary forms, with or without |
---|
7 | # modification, are permitted provided that the following conditions |
---|
8 | # are met: |
---|
9 | # 1. Redistributions of source code must retain the above copyright |
---|
10 | # notice, this list of conditions and the following disclaimer. |
---|
11 | # 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | # notice, this list of conditions and the following disclaimer in the |
---|
13 | # documentation and/or other materials provided with the distribution. |
---|
14 | # |
---|
15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
16 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
17 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
18 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
19 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
20 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
21 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
22 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
23 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
25 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
26 | |
---|
27 | # |
---|
28 | # RTEMS LibBSD is a transparent source build of the FreeBSD kernel source for RTEMS. |
---|
29 | # |
---|
30 | # To use see README.waf shipped with this file. |
---|
31 | # |
---|
32 | |
---|
33 | from __future__ import print_function |
---|
34 | |
---|
35 | rtems_version = "5" |
---|
36 | |
---|
37 | try: |
---|
38 | import rtems_waf.rtems as rtems |
---|
39 | except: |
---|
40 | print("error: no rtems_waf git submodule; see README.waf") |
---|
41 | import sys |
---|
42 | sys.exit(1) |
---|
43 | |
---|
44 | import libbsd |
---|
45 | import waf_libbsd |
---|
46 | import os.path |
---|
47 | import runpy |
---|
48 | import sys |
---|
49 | try: |
---|
50 | import configparser |
---|
51 | except ImportError: |
---|
52 | import ConfigParser as configparser |
---|
53 | import waflib.Options |
---|
54 | |
---|
55 | builders = {} |
---|
56 | |
---|
57 | BUILDSET_DIR = "buildset" |
---|
58 | BUILDSET_DEFAULT = "buildset/default.ini" |
---|
59 | |
---|
60 | def load_ini(conf, f): |
---|
61 | ini = configparser.ConfigParser() |
---|
62 | ini.read(f) |
---|
63 | if not ini.has_section('general'): |
---|
64 | conf.fatal("'{}' is missing a general section.".format(f)) |
---|
65 | if not ini.has_option('general', 'name'): |
---|
66 | conf.fatal("'{}' is missing a general/name.".format(f)) |
---|
67 | if ini.has_option('general', 'extends'): |
---|
68 | extends = ini.get('general', 'extends') |
---|
69 | extendfile = None |
---|
70 | basepath = os.path.dirname(f) |
---|
71 | if os.path.isfile(os.path.join(basepath, extends)): |
---|
72 | extendfile = os.path.join(basepath, extends) |
---|
73 | elif os.path.isfile(os.path.join(BUILDSET_DIR, extends)): |
---|
74 | extendfile = os.path.join(BUILDSET_DIR, extends) |
---|
75 | else: |
---|
76 | conf.fatal("'{}': Invalid file given for general/extends:'{}'" |
---|
77 | .format(f, extends)) |
---|
78 | base = load_ini(conf, extendfile) |
---|
79 | for s in ini.sections(): |
---|
80 | if not base.has_section(s): |
---|
81 | base.add_section(s) |
---|
82 | for o in ini.options(s): |
---|
83 | val = ini.get(s, o) |
---|
84 | base.set(s, o, val) |
---|
85 | ini = base |
---|
86 | return ini |
---|
87 | |
---|
88 | def load_config(conf, f): |
---|
89 | ini = load_ini(conf, f) |
---|
90 | config = {} |
---|
91 | |
---|
92 | config['name'] = ini.get('general', 'name') |
---|
93 | |
---|
94 | config['modules-enabled'] = [] |
---|
95 | mods = [] |
---|
96 | if ini.has_section('modules'): |
---|
97 | mods = ini.options('modules') |
---|
98 | for mod in mods: |
---|
99 | if ini.getboolean('modules', mod): |
---|
100 | config['modules-enabled'].append(mod) |
---|
101 | return config |
---|
102 | |
---|
103 | def update_builders(ctx, buildset_opt): |
---|
104 | global builders |
---|
105 | builders = {} |
---|
106 | |
---|
107 | buildsets = [] |
---|
108 | if buildset_opt == []: |
---|
109 | buildset_opt.append(BUILDSET_DEFAULT) |
---|
110 | for bs in buildset_opt: |
---|
111 | if os.path.isdir(bs): |
---|
112 | for f in os.listdir(bs): |
---|
113 | if f[-4:] == ".ini": |
---|
114 | buildsets += [os.path.join(bs,f)] |
---|
115 | else: |
---|
116 | for f in bs.split(','): |
---|
117 | buildsets += [f] |
---|
118 | |
---|
119 | for bs in buildsets: |
---|
120 | builder = waf_libbsd.Builder() |
---|
121 | libbsd.load(builder) |
---|
122 | bsconfig = load_config(ctx, bs) |
---|
123 | bsname = bsconfig['name'] |
---|
124 | builder.updateConfiguration(bsconfig) |
---|
125 | builder.generate(rtems_version) |
---|
126 | builders[bsname]=builder |
---|
127 | |
---|
128 | def bsp_init(ctx, env, contexts): |
---|
129 | # This function generates the builders and adds build-xxx, clean-xxx and |
---|
130 | # install-xxx targets for them. |
---|
131 | |
---|
132 | if not 'buildset' in env.options: |
---|
133 | # This happens if 'waf configure' hasn't been executed. In that case we |
---|
134 | # create the builders during the configure phase. After the first time |
---|
135 | # 'waf configure' is executed 'buildset' is read from the .lock_xxx |
---|
136 | # file. In that case the builders are overwritten during configure |
---|
137 | # phase. This is not really the cleanest solution but it works. |
---|
138 | return |
---|
139 | |
---|
140 | update_builders(ctx, env.options['buildset']) |
---|
141 | for builder in builders: |
---|
142 | # Update the contextes for build variants |
---|
143 | for y in contexts: |
---|
144 | newcmd = y.cmd + '-' + builder |
---|
145 | newvariant = y.variant + '-' + builder |
---|
146 | class context(y): |
---|
147 | cmd = newcmd |
---|
148 | variant = newvariant |
---|
149 | libbsd_buildset_name = builder |
---|
150 | |
---|
151 | # Transform the commands to per build variant commands |
---|
152 | commands = [] |
---|
153 | for cmd in waflib.Options.commands: |
---|
154 | if cmd.startswith(('build', 'clean', 'install')): |
---|
155 | for builder in builders: |
---|
156 | commands += [cmd + '-' + builder] |
---|
157 | else: |
---|
158 | commands += [cmd] |
---|
159 | waflib.Options.commands = commands |
---|
160 | |
---|
161 | def init(ctx): |
---|
162 | rtems.init(ctx, version = rtems_version, long_commands = True, |
---|
163 | bsp_init = bsp_init) |
---|
164 | |
---|
165 | def options(opt): |
---|
166 | rtems.options(opt) |
---|
167 | opt.add_option("--enable-auto-regen", |
---|
168 | action = "store_true", |
---|
169 | default = False, |
---|
170 | dest = "auto_regen", |
---|
171 | help = "Enable auto-regeneration of LEX, RPC and YACC files.") |
---|
172 | opt.add_option("--enable-warnings", |
---|
173 | action = "store_true", |
---|
174 | default = False, |
---|
175 | dest = "warnings", |
---|
176 | help = "Enable all warnings. The default is quiet builds.") |
---|
177 | opt.add_option("--net-test-config", |
---|
178 | default = "config.inc", |
---|
179 | dest = "net_config", |
---|
180 | help = "Network test configuration.") |
---|
181 | opt.add_option("--freebsd-options", |
---|
182 | action = "store", |
---|
183 | default = "", |
---|
184 | dest = "freebsd_options", |
---|
185 | help = "Set FreeBSD options (developer option).") |
---|
186 | opt.add_option("--optimization", |
---|
187 | action = "store", |
---|
188 | default = "2", |
---|
189 | dest = "optimization", |
---|
190 | help = "Set optimization level to OPTIMIZATION (-On compiler flag). Default is 2 (-O2).") |
---|
191 | opt.add_option("--buildset", |
---|
192 | action = "append", |
---|
193 | default = [], |
---|
194 | dest = "buildset", |
---|
195 | help = "Select build sets to build. If set to a directory, all .ini file in this directory will be used.") |
---|
196 | |
---|
197 | def bsp_configure(conf, arch_bsp): |
---|
198 | conf.check(header_name = "dlfcn.h", features = "c") |
---|
199 | conf.check(header_name = "rtems/pci.h", features = "c", mandatory = False) |
---|
200 | if not rtems.check_posix(conf): |
---|
201 | conf.fatal("RTEMS kernel POSIX support is disabled; configure RTEMS with --enable-posix") |
---|
202 | if rtems.check_networking(conf): |
---|
203 | conf.fatal("RTEMS kernel contains the old network support; configure RTEMS with --disable-networking") |
---|
204 | env = conf.env.derive() |
---|
205 | for builder in builders: |
---|
206 | ab = conf.env.RTEMS_ARCH_BSP |
---|
207 | variant = ab + "-" + builder |
---|
208 | conf.msg('Configure variant: ', variant) |
---|
209 | conf.setenv(variant, env) |
---|
210 | builders[builder].bsp_configure(conf, arch_bsp) |
---|
211 | conf.setenv(ab) |
---|
212 | |
---|
213 | def configure(conf): |
---|
214 | if conf.options.auto_regen: |
---|
215 | conf.find_program("lex", mandatory = True) |
---|
216 | conf.find_program("rpcgen", mandatory = True) |
---|
217 | conf.find_program("yacc", mandatory = True) |
---|
218 | conf.env.AUTO_REGEN = conf.options.auto_regen |
---|
219 | conf.env.WARNINGS = conf.options.warnings |
---|
220 | conf.env.NET_CONFIG = conf.options.net_config |
---|
221 | conf.env.FREEBSD_OPTIONS =conf.options.freebsd_options |
---|
222 | conf.env.OPTIMIZATION = conf.options.optimization |
---|
223 | conf.env.BUILDSET = conf.options.buildset |
---|
224 | if len(conf.env.BUILDSET) == 0: |
---|
225 | conf.env.BUILDSET += [BUILDSET_DEFAULT] |
---|
226 | update_builders(conf, conf.env.BUILDSET) |
---|
227 | rtems.configure(conf, bsp_configure) |
---|
228 | |
---|
229 | def build(bld): |
---|
230 | rtems.build(bld) |
---|
231 | builders[bld.libbsd_buildset_name].build(bld) |
---|