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