1 | # |
---|
2 | # Copyright (c) 2015 Chris Johns <chrisj@rtems.org>. All rights reserved. |
---|
3 | # |
---|
4 | # Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. |
---|
5 | # |
---|
6 | # embedded brains GmbH |
---|
7 | # Dornierstr. 4 |
---|
8 | # 82178 Puchheim |
---|
9 | # Germany |
---|
10 | # <info@embedded-brains.de> |
---|
11 | # |
---|
12 | # Copyright (c) 2012 OAR Corporation. All rights reserved. |
---|
13 | # |
---|
14 | # Redistribution and use in source and binary forms, with or without |
---|
15 | # modification, are permitted provided that the following conditions |
---|
16 | # are met: |
---|
17 | # 1. Redistributions of source code must retain the above copyright |
---|
18 | # notice, this list of conditions and the following disclaimer. |
---|
19 | # 2. Redistributions in binary form must reproduce the above copyright |
---|
20 | # notice, this list of conditions and the following disclaimer in the |
---|
21 | # documentation and/or other materials provided with the distribution. |
---|
22 | # |
---|
23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
27 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
34 | |
---|
35 | import tempfile |
---|
36 | |
---|
37 | import builder |
---|
38 | |
---|
39 | class SourceFileFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
40 | |
---|
41 | def __init__(self, cflags = None): |
---|
42 | self.cflags = cflags |
---|
43 | |
---|
44 | def compose(self, path): |
---|
45 | fragment = 'LIB_C_FILES += ' + path + '\n' |
---|
46 | if self.cflags != None: |
---|
47 | fragment = fragment + path[:-1] + 'o: ' + path + '\n' \ |
---|
48 | + '\t$(CC) $(CPPFLAGS) $(CFLAGS) ' + self.cflags + ' -c $< -o $@\n' |
---|
49 | return fragment |
---|
50 | |
---|
51 | class TestFragementComposer(builder.BuildSystemFragmentComposer): |
---|
52 | |
---|
53 | def __init__(self, testName, fileFragments, runTest = True, netTest = False): |
---|
54 | self.testName = testName |
---|
55 | self.fileFragments = fileFragments |
---|
56 | self.runTest = runTest |
---|
57 | self.netTest = netTest |
---|
58 | |
---|
59 | def compose(self, path): |
---|
60 | makefileFragment = '' |
---|
61 | testPrefix = 'TEST_' + self.testName.upper() |
---|
62 | testOFiles = testPrefix + '_O_FILES' |
---|
63 | testDFiles = testPrefix + '_D_FILES' |
---|
64 | testDir = 'testsuite/' + self.testName |
---|
65 | testExe = testDir + '/' + self.testName + '.exe' |
---|
66 | testMap = testDir + '/' + self.testName + '.map' |
---|
67 | testCollection = 'TESTS' |
---|
68 | if self.netTest: |
---|
69 | testCollection = 'NET_' + testCollection |
---|
70 | makefileFragment += '\n' + testPrefix + ' = ' + testExe + '\n' \ |
---|
71 | + testOFiles + ' =\n' \ |
---|
72 | + testDFiles + ' =\n' |
---|
73 | for fileFragment in self.fileFragments: |
---|
74 | makefileFragment += testOFiles + ' += ' + testDir + '/' + fileFragment + '.o\n' \ |
---|
75 | + testDFiles + ' += ' + testDir + '/' + fileFragment + '.d\n' |
---|
76 | makefileFragment += '$(' + testPrefix + '): $(' + testOFiles + ') $(LIB)\n' \ |
---|
77 | '\t$(LINK.c) -Wl,-Map,' + testMap + ' $^ -lm -lz -o $@\n' \ |
---|
78 | + testCollection + ' += $(' + testPrefix + ')\n' \ |
---|
79 | 'O_FILES += $(' + testOFiles + ')\n' \ |
---|
80 | 'D_FILES += $(' + testDFiles + ')\n' |
---|
81 | if self.runTest: |
---|
82 | makefileFragment += 'RUN_' + testCollection + ' += $(' + testPrefix + ')\n' |
---|
83 | return makefileFragment |
---|
84 | |
---|
85 | class KVMSymbolsFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
86 | |
---|
87 | def compose(self, path): |
---|
88 | return 'LIB_GEN_FILES += ' + path + '\n' \ |
---|
89 | 'LIB_C_FILES += ' + path + '\n' \ |
---|
90 | + path + ': rtemsbsd/rtems/generate_kvm_symbols\n' \ |
---|
91 | '\t./$< > $@\n' |
---|
92 | |
---|
93 | class RPCGENFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
94 | |
---|
95 | def compose(self, path): |
---|
96 | headerPath = path[:-2] + '.h' |
---|
97 | return headerPath + ': ' + path + '\n' \ |
---|
98 | '\t rm -f $@\n' \ |
---|
99 | '\t rpcgen -h -o $@ $<\n' |
---|
100 | |
---|
101 | class RouteKeywordsFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
102 | |
---|
103 | def compose(self, path): |
---|
104 | headerPath = path + '.h' |
---|
105 | tmpPath = path + '.tmp' |
---|
106 | return headerPath + ': ' + path + '\n' \ |
---|
107 | '\tsed -e \'/^#/d\' -e \'/^$$/d\' $< > ' + tmpPath + '\n' \ |
---|
108 | '\tLC_ALL=C tr \'a-z\' \'A-Z\' < ' + tmpPath + ' | paste ' + tmpPath + ' - | \\\n' \ |
---|
109 | '\tawk \'{ if (NF > 1) printf "#define\\tK_%s\\t%d\\n\\t{\\"%s\\", K_%s},\\n", $$2, NR, $$1, $$2 }\' > $@\n' \ |
---|
110 | '\trm -f ' + tmpPath + '\n' |
---|
111 | |
---|
112 | class LexFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
113 | |
---|
114 | def __init__(self, sym, dep): |
---|
115 | self.sym = sym |
---|
116 | self.dep = dep |
---|
117 | |
---|
118 | def compose(self, path): |
---|
119 | src = path[:-2] + '.c' |
---|
120 | dep = path[:path.rfind('/')] + '/' + self.dep |
---|
121 | return 'LIB_C_FILES += ' + src + '\n' \ |
---|
122 | + src + ': ' + path + ' ' + dep + '\n' \ |
---|
123 | '\t${LEX} -P ' + self.sym + ' -t $< | sed -e \'/YY_BUF_SIZE/s/16384/1024/\' > $@\n' |
---|
124 | |
---|
125 | class YaccFragmentComposer(builder.BuildSystemFragmentComposer): |
---|
126 | |
---|
127 | def __init__(self, sym, header): |
---|
128 | self.sym = sym |
---|
129 | self.header = header |
---|
130 | |
---|
131 | def compose(self, path): |
---|
132 | src = path[:-2] + '.c' |
---|
133 | hdr = path[:path.rfind('/')] + '/' + self.header |
---|
134 | return 'LIB_C_FILES += ' + src + '\n' \ |
---|
135 | + src + ': ' + path + '\n' \ |
---|
136 | '\tyacc -b ' + self.sym + ' -d -p ' + self.sym + ' $<\n' \ |
---|
137 | '\tsed -e ''/YY_BUF_SIZE/s/16384/1024/'' < ' + self.sym + '.tab.c > $@\n' \ |
---|
138 | '\trm -f ' + self.sym + '.tab.c\n' \ |
---|
139 | '\tmv ' + self.sym + '.tab.h ' + hdr + '\n' |
---|
140 | |
---|
141 | # Module Manager - Collection of Modules |
---|
142 | class ModuleManager(builder.ModuleManager): |
---|
143 | |
---|
144 | def setGenerators(self): |
---|
145 | self.generator['convert'] = builder.Converter |
---|
146 | self.generator['no-convert'] = builder.NoConverter |
---|
147 | |
---|
148 | self.generator['file'] = builder.File |
---|
149 | |
---|
150 | self.generator['path'] = builder.PathComposer |
---|
151 | self.generator['freebsd-path'] = builder.FreeBSDPathComposer |
---|
152 | self.generator['rtems-path'] = builder.RTEMSPathComposer |
---|
153 | self.generator['cpu-path'] = builder.CPUDependentPathComposer |
---|
154 | self.generator['target-src-cpu--path'] = builder.TargetSourceCPUDependentPathComposer |
---|
155 | |
---|
156 | self.generator['source'] = SourceFileFragmentComposer |
---|
157 | self.generator['test'] = TestFragementComposer |
---|
158 | self.generator['kvm-symbols'] = KVMSymbolsFragmentComposer |
---|
159 | self.generator['rpc-gen'] = RPCGENFragmentComposer |
---|
160 | self.generator['route-keywords'] = RouteKeywordsFragmentComposer |
---|
161 | self.generator['lex'] = LexFragmentComposer |
---|
162 | self.generator['yacc'] = YaccFragmentComposer |
---|
163 | |
---|
164 | def generate(self): |
---|
165 | data = 'include config.inc\n' \ |
---|
166 | '\n' \ |
---|
167 | 'RTEMS_MAKEFILE_PATH = $(PREFIX)/$(TARGET)/$(BSP)\n' \ |
---|
168 | 'include $(RTEMS_MAKEFILE_PATH)/Makefile.inc\n' \ |
---|
169 | 'include $(RTEMS_CUSTOM)\n' \ |
---|
170 | 'include $(PROJECT_ROOT)/make/leaf.cfg\n' \ |
---|
171 | '\n' \ |
---|
172 | 'COMMON_FLAGS += -fno-strict-aliasing\n' \ |
---|
173 | 'COMMON_FLAGS += -ffreestanding\n' \ |
---|
174 | 'COMMON_FLAGS += -fno-common\n' \ |
---|
175 | 'COMMON_FLAGS += -Irtemsbsd/include\n' \ |
---|
176 | 'COMMON_FLAGS += -Irtemsbsd/$(RTEMS_CPU)/include\n' \ |
---|
177 | 'COMMON_FLAGS += -Ifreebsd/sys\n' \ |
---|
178 | 'COMMON_FLAGS += -Ifreebsd/sys/$(RTEMS_CPU)/include\n' \ |
---|
179 | 'COMMON_FLAGS += -Ifreebsd/sys/contrib/altq\n' \ |
---|
180 | 'COMMON_FLAGS += -Ifreebsd/sys/contrib/pf\n' \ |
---|
181 | 'COMMON_FLAGS += -Ifreebsd/include\n' \ |
---|
182 | 'COMMON_FLAGS += -Ifreebsd/lib/libc/include\n' \ |
---|
183 | 'COMMON_FLAGS += -Ifreebsd/lib/libc/isc/include\n' \ |
---|
184 | 'COMMON_FLAGS += -Ifreebsd/lib/libc/resolv\n' \ |
---|
185 | 'COMMON_FLAGS += -Ifreebsd/lib/libutil\n' \ |
---|
186 | 'COMMON_FLAGS += -Ifreebsd/lib/libkvm\n' \ |
---|
187 | 'COMMON_FLAGS += -Ifreebsd/lib/libmemstat\n' \ |
---|
188 | 'COMMON_FLAGS += -Ifreebsd/lib/libipsec\n' \ |
---|
189 | 'COMMON_FLAGS += -Irtemsbsd/sys\n' \ |
---|
190 | 'COMMON_FLAGS += -ImDNSResponder/mDNSCore\n' \ |
---|
191 | 'COMMON_FLAGS += -ImDNSResponder/mDNSShared\n' \ |
---|
192 | 'COMMON_FLAGS += -ImDNSResponder/mDNSPosix\n' \ |
---|
193 | 'COMMON_FLAGS += -Itestsuite/include\n' \ |
---|
194 | 'COMMON_FLAGS += -Wall\n' \ |
---|
195 | 'COMMON_FLAGS += -Wno-format\n' \ |
---|
196 | 'COMMON_FLAGS += -MT $@ -MD -MP -MF $(basename $@).d\n' \ |
---|
197 | 'CFLAGS += $(COMMON_FLAGS)\n' \ |
---|
198 | 'CFLAGS += -std=gnu11\n' \ |
---|
199 | 'CXXFLAGS += $(COMMON_FLAGS)\n' \ |
---|
200 | 'CXXFLAGS += -std=gnu++11\n' \ |
---|
201 | 'NEED_DUMMY_PIC_IRQ=yes\n' \ |
---|
202 | '\n' \ |
---|
203 | 'TEST_NETWORK_CONFIG = testsuite/include/rtems/bsd/test/network-config.h\n' \ |
---|
204 | '\n' \ |
---|
205 | 'TESTS =\n' \ |
---|
206 | 'RUN_TESTS =\n' \ |
---|
207 | '\n' \ |
---|
208 | 'NET_TESTS =\n' \ |
---|
209 | 'RUN_NET_TESTS =\n' \ |
---|
210 | '\n' \ |
---|
211 | 'O_FILES =\n' \ |
---|
212 | 'D_FILES =\n' \ |
---|
213 | '\n' \ |
---|
214 | 'LIB = libbsd.a\n' \ |
---|
215 | 'LIB_GEN_FILES =\n' \ |
---|
216 | 'LIB_C_FILES =\n' \ |
---|
217 | 'LIB_CXX_FILES =\n' \ |
---|
218 | 'LIB_CXX_FILES += rtemsbsd/rtems/rtems-bsd-cxx.cc\n' |
---|
219 | for mn in self.getModules(): |
---|
220 | m = self[mn] |
---|
221 | if m.conditionalOn != "none": |
---|
222 | data += 'ifneq ($(' + m.conditionalOn + '),yes)\n' |
---|
223 | for f in m.files: |
---|
224 | data += f.getFragment() |
---|
225 | for cpu, files in sorted(m.cpuDependentSourceFiles.items()): |
---|
226 | data += 'ifeq ($(RTEMS_CPU), ' + cpu + ')\n' |
---|
227 | for f in files: |
---|
228 | data += f.getFragment() |
---|
229 | if cpu in ("arm", "i386", "lm32", "mips", "powerpc", "sparc", "m68k"): |
---|
230 | data += 'NEED_DUMMY_PIC_IRQ=no\n' |
---|
231 | data += 'endif\n' |
---|
232 | if m.conditionalOn != "none": |
---|
233 | data += 'endif # ' + m.conditionalOn +'\n' |
---|
234 | data += '\n' \ |
---|
235 | 'ifeq ($(NEED_DUMMY_PIC_IRQ),yes)\n' \ |
---|
236 | 'CFLAGS += -I rtems-dummy-pic-irq/include\n' \ |
---|
237 | 'endif\n' \ |
---|
238 | 'LIB_O_FILES = $(LIB_C_FILES:%.c=%.o) $(LIB_CXX_FILES:%.cc=%.o)\n' \ |
---|
239 | 'O_FILES += $(LIB_O_FILES)\n' \ |
---|
240 | 'D_FILES += $(LIB_C_FILES:%.c=%.d) $(LIB_CXX_FILES:%.cc=%.d)\n' \ |
---|
241 | '\n' \ |
---|
242 | 'all: $(LIB) $(TESTS) $(TEST_NETWORK_CONFIG) $(NET_TESTS)\n' \ |
---|
243 | '\n' \ |
---|
244 | '$(LIB): $(LIB_GEN_FILES) $(LIB_O_FILES)\n' \ |
---|
245 | '\trm -f $@\n' \ |
---|
246 | '\t$(AR) rcu $@ $^\n' \ |
---|
247 | '\n' \ |
---|
248 | 'run_tests: $(RUN_TESTS)\n' \ |
---|
249 | '\t$(TEST_RUNNER) $^\n' \ |
---|
250 | '\tcheck_endof\n' \ |
---|
251 | '\n' \ |
---|
252 | 'run_net_tests: $(RUN_NET_TESTS)\n' \ |
---|
253 | '\t$(TEST_RUNNER) -N -T $(NET_TAP_INTERFACE) $^\n' \ |
---|
254 | '\tcheck_endof\n' \ |
---|
255 | '\n' \ |
---|
256 | '$(TEST_NETWORK_CONFIG): $(TEST_NETWORK_CONFIG).in config.inc\n' \ |
---|
257 | '\tsed -e \'s/@NET_CFG_SELF_IP@/$(NET_CFG_SELF_IP)/\' \\\n' \ |
---|
258 | '\t-e \'s/@NET_CFG_NETMASK@/$(NET_CFG_NETMASK)/\' \\\n' \ |
---|
259 | '\t-e \'s/@NET_CFG_PEER_IP@/$(NET_CFG_PEER_IP)/\' \\\n' \ |
---|
260 | '\t-e \'s/@NET_CFG_GATEWAY_IP@/$(NET_CFG_GATEWAY_IP)/\' \\\n' \ |
---|
261 | '\t< $< > $@\n' \ |
---|
262 | '\n' \ |
---|
263 | 'CPU_SED = sed\n' \ |
---|
264 | 'CPU_SED += -e \'/arm/d\'\n' \ |
---|
265 | 'CPU_SED += -e \'/i386/d\'\n' \ |
---|
266 | 'CPU_SED += -e \'/powerpc/d\'\n' \ |
---|
267 | 'CPU_SED += -e \'/mips/d\'\n' \ |
---|
268 | 'CPU_SED += -e \'/sparc64/d\'\n' \ |
---|
269 | '\n' \ |
---|
270 | 'LIB_DIR = $(INSTALL_BASE)/lib\n' \ |
---|
271 | 'INCLUDE_DIR = $(INSTALL_BASE)/lib/include\n' \ |
---|
272 | '\n' \ |
---|
273 | 'install: $(LIB)\n' \ |
---|
274 | '\tinstall -d $(LIB_DIR)\n' \ |
---|
275 | '\tinstall -m 644 $(LIB) $(LIB_DIR)\n' \ |
---|
276 | '\tcd rtemsbsd/include ; for i in `find . -type d` ; do \\\n' \ |
---|
277 | '\t install -d $(INCLUDE_DIR)/$$i ; \\\n' \ |
---|
278 | '\t install -m 644 $$i/*.h $(INCLUDE_DIR)/$$i ; done\n' \ |
---|
279 | '\tcd freebsd/include ; for i in `find . -type d` ; do \\\n' \ |
---|
280 | '\t install -d $(INCLUDE_DIR)/$$i ; \\\n' \ |
---|
281 | '\t install -m 644 $$i/*.h $(INCLUDE_DIR)/$$i ; done\n' \ |
---|
282 | '\tcd freebsd/sys/contrib/altq ; \\\n' \ |
---|
283 | '\t install -d $(INCLUDE_DIR)/altq ; \\\n' \ |
---|
284 | '\t install -m 644 altq/*.h $(INCLUDE_DIR)/altq\n' \ |
---|
285 | '\tfor i in bsm cam net net80211 netatalk netinet netinet6 netipsec sys vm ; do \\\n' \ |
---|
286 | '\t install -d $(INCLUDE_DIR)/$$i ; \\\n' \ |
---|
287 | '\t install -m 644 freebsd/sys/$$i/*.h $(INCLUDE_DIR)/$$i ; done\n' \ |
---|
288 | '\tcd freebsd/sys/dev/mii ; \\\n' \ |
---|
289 | '\t install -d $(INCLUDE_DIR)/dev/mii ; \\\n' \ |
---|
290 | '\t install -m 644 *.h $(INCLUDE_DIR)/dev/mii\n' \ |
---|
291 | '\tinstall -m 644 mDNSResponder/mDNSCore/mDNSDebug.h $(INCLUDE_DIR)\n' \ |
---|
292 | '\tinstall -m 644 mDNSResponder/mDNSCore/mDNSEmbeddedAPI.h $(INCLUDE_DIR)\n' \ |
---|
293 | '\tinstall -m 644 mDNSResponder/mDNSShared/dns_sd.h $(INCLUDE_DIR)\n' \ |
---|
294 | '\tinstall -m 644 mDNSResponder/mDNSPosix/mDNSPosix.h $(INCLUDE_DIR)\n' \ |
---|
295 | '\n' \ |
---|
296 | 'clean:\n' \ |
---|
297 | '\trm -f $(LIB_GEN_FILES) $(LIB) $(TESTS) $(O_FILES) $(D_FILES)\n' \ |
---|
298 | '\trm -f libbsd.html\n' \ |
---|
299 | '\n' \ |
---|
300 | '-include $(D_FILES)\n' \ |
---|
301 | '\n' \ |
---|
302 | 'doc: libbsd.html\n' \ |
---|
303 | '\n' \ |
---|
304 | 'libbsd.html: libbsd.txt\n' \ |
---|
305 | '\tasciidoc -o libbsd.html libbsd.txt\n' |
---|
306 | try: |
---|
307 | out = tempfile.NamedTemporaryFile(delete = False) |
---|
308 | out.write(data) |
---|
309 | out.close() |
---|
310 | makefile = builder.RTEMS_DIR + '/Makefile' |
---|
311 | builder.processIfDifferent(out.name, makefile, "Makefile") |
---|
312 | finally: |
---|
313 | try: |
---|
314 | os.remove(out.name) |
---|
315 | except: |
---|
316 | pass |
---|