| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import buildbot_common | 6 import buildbot_common |
| 7 import make_rules | 7 import make_rules |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 from make_rules import BuildDefineList, BuildLibList, BuildToolDict | 12 from make_rules import BuildDefineList, BuildLibList, BuildToolDict |
| 13 from make_rules import GetBuildRule, BUILD_RULES | 13 from make_rules import BuildIncludeList, GetBuildRule, BUILD_RULES |
| 14 | 14 |
| 15 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 15 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 16 SDK_SRC_DIR = os.path.dirname(SCRIPT_DIR) | 16 SDK_SRC_DIR = os.path.dirname(SCRIPT_DIR) |
| 17 SDK_EXAMPLE_DIR = os.path.join(SDK_SRC_DIR, 'examples') | 17 SDK_EXAMPLE_DIR = os.path.join(SDK_SRC_DIR, 'examples') |
| 18 SDK_DIR = os.path.dirname(SDK_SRC_DIR) | 18 SDK_DIR = os.path.dirname(SDK_SRC_DIR) |
| 19 SRC_DIR = os.path.dirname(SDK_DIR) | 19 SRC_DIR = os.path.dirname(SDK_DIR) |
| 20 OUT_DIR = os.path.join(SRC_DIR, 'out') | 20 OUT_DIR = os.path.join(SRC_DIR, 'out') |
| 21 PPAPI_DIR = os.path.join(SRC_DIR, 'ppapi') | 21 PPAPI_DIR = os.path.join(SRC_DIR, 'ppapi') |
| 22 | 22 |
| 23 # Add SDK make tools scripts to the python path. | 23 # Add SDK make tools scripts to the python path. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 For the given target, toolset and architecture, returns a rule to generate | 138 For the given target, toolset and architecture, returns a rule to generate |
| 139 the object files for the set of sources. | 139 the object files for the set of sources. |
| 140 | 140 |
| 141 Returns: | 141 Returns: |
| 142 Returns a tuple containin the objects and the rule. | 142 Returns a tuple containin the objects and the rule. |
| 143 """ | 143 """ |
| 144 rules = '' | 144 rules = '' |
| 145 name = target['NAME'] | 145 name = target['NAME'] |
| 146 object_sets = [] | 146 object_sets = [] |
| 147 | 147 |
| 148 defines = target.get('DEFINES', []) | 148 defs = BuildDefineList(tool, target.get('DEFINES', [])) |
| 149 defs = BuildDefineList(tool, defines) | 149 includes = BuildIncludeList(tool, target.get('INCLUDES', [])) |
| 150 | 150 |
| 151 if srcs['.c']: | 151 if srcs['.c']: |
| 152 replace = BuildToolDict(tool, name, arch, 'c', DEFLIST=defs) | 152 replace = BuildToolDict(tool, name, arch, 'c', |
| 153 DEFLIST=defs, INCLUDELIST=includes) |
| 153 compile_rule = GetBuildRule(tool, 'CC') | 154 compile_rule = GetBuildRule(tool, 'CC') |
| 154 rules += Replace(compile_rule, replace) | 155 rules += Replace(compile_rule, replace) |
| 155 object_sets.append('$(%s)' % replace['<OBJS>']) | 156 object_sets.append('$(%s)' % replace['<OBJS>']) |
| 156 | 157 |
| 157 if srcs['.cc']: | 158 if srcs['.cc']: |
| 158 replace = BuildToolDict(tool, name, arch, 'cc', DEFLIST=defs) | 159 replace = BuildToolDict(tool, name, arch, 'cc', |
| 160 DEFLIST=defs, INCLUDELIST=includes) |
| 159 compile_rule = GetBuildRule(tool, 'CXX') | 161 compile_rule = GetBuildRule(tool, 'CXX') |
| 160 rules += Replace(compile_rule, replace) | 162 rules += Replace(compile_rule, replace) |
| 161 object_sets.append('$(%s)' % replace['<OBJS>']) | 163 object_sets.append('$(%s)' % replace['<OBJS>']) |
| 162 | 164 |
| 163 return (' '.join(object_sets), rules) | 165 return (' '.join(object_sets), rules) |
| 164 | 166 |
| 165 | 167 |
| 166 def GenerateLink(target, tool, arch, objs): | 168 def GenerateLink(target, tool, arch, objs): |
| 167 """Generate a Link target. | 169 """Generate a Link target. |
| 168 | 170 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 197 tc, tc, tc) | 199 tc, tc, tc) |
| 198 main = None | 200 main = None |
| 199 for target in desc['TARGETS']: | 201 for target in desc['TARGETS']: |
| 200 name = target['NAME'] | 202 name = target['NAME'] |
| 201 srcs = GetSourcesDict(target['SOURCES']) | 203 srcs = GetSourcesDict(target['SOURCES']) |
| 202 for arch in BUILD_RULES[tc]['ARCHES']: | 204 for arch in BUILD_RULES[tc]['ARCHES']: |
| 203 objs, comp_rule = GenerateCompile(target, tc, arch, srcs) | 205 objs, comp_rule = GenerateCompile(target, tc, arch, srcs) |
| 204 targs, link_rule = GenerateLink(target, tc, arch, objs) | 206 targs, link_rule = GenerateLink(target, tc, arch, objs) |
| 205 rules += comp_rule + link_rule | 207 rules += comp_rule + link_rule |
| 206 clean.append(objs) | 208 clean.append(objs) |
| 209 if target['TYPE'] == 'lib': |
| 210 all_targets.append(targs) |
| 207 | 211 |
| 208 if target['TYPE'] == 'main': | 212 if target['TYPE'] == 'main': |
| 209 main = target | 213 main = target |
| 210 elif target['TYPE'] == 'lib': | |
| 211 all_targets.append(targs) | |
| 212 | 214 |
| 213 if main: | 215 if main: |
| 214 targs, nmf_rule = GenerateNMF(main, tc) | 216 targs, nmf_rule = GenerateNMF(main, tc) |
| 215 rules += nmf_rule | 217 rules += nmf_rule |
| 216 all_targets.append(targs) | 218 all_targets.append(targs) |
| 217 rules += '\n.PHONY : clean\nclean:\n\t$(RM) $(DEPFILES) ' + ' '.join(clean) | 219 rules += '\n.PHONY : clean\nclean:\n\t$(RM) $(DEPFILES) ' + ' '.join(clean) |
| 218 rules += '\n\n-include $(DEPFILES)' | 220 rules += '\n\n-include $(DEPFILES)' |
| 219 return ' '.join(all_targets), rules | 221 return ' '.join(all_targets), rules |
| 220 | 222 |
| 221 | 223 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 DSC_FORMAT = { | 264 DSC_FORMAT = { |
| 263 'TOOLS' : (list, ['newlib', 'glibc', 'pnacl', 'win'], True), | 265 'TOOLS' : (list, ['newlib', 'glibc', 'pnacl', 'win'], True), |
| 264 'PREREQ' : (list, '', False), | 266 'PREREQ' : (list, '', False), |
| 265 'TARGETS' : (list, { | 267 'TARGETS' : (list, { |
| 266 'NAME': (str, '', True), | 268 'NAME': (str, '', True), |
| 267 'TYPE': (str, ['main', 'nexe', 'lib', 'so'], True), | 269 'TYPE': (str, ['main', 'nexe', 'lib', 'so'], True), |
| 268 'SOURCES': (list, '', True), | 270 'SOURCES': (list, '', True), |
| 269 'CCFLAGS': (list, '', False), | 271 'CCFLAGS': (list, '', False), |
| 270 'CXXFLAGS': (list, '', False), | 272 'CXXFLAGS': (list, '', False), |
| 271 'LDFLAGS': (list, '', False), | 273 'LDFLAGS': (list, '', False), |
| 274 'INCLUDES': (list, '', False), |
| 272 'LIBS' : (list, '', False) | 275 'LIBS' : (list, '', False) |
| 273 }, True), | 276 }, True), |
| 274 'HEADERS': (list, { | 277 'HEADERS': (list, { |
| 275 'FILES': (list, '', True), | 278 'FILES': (list, '', True), |
| 276 'DEST': (str, '', True), | 279 'DEST': (str, '', True), |
| 277 }, False), | 280 }, False), |
| 278 'SEARCH': (list, '', False), | 281 'SEARCH': (list, '', False), |
| 279 'POST': (str, '', False), | 282 'POST': (str, '', False), |
| 280 'PRE': (str, '', False), | 283 'PRE': (str, '', False), |
| 281 'DEST': (str, ['examples', 'src'], True), | 284 'DEST': (str, ['examples', 'src', 'testing'], True), |
| 282 'NAME': (str, '', False), | 285 'NAME': (str, '', False), |
| 283 'DATA': (list, '', False), | 286 'DATA': (list, '', False), |
| 284 'TITLE': (str, '', False), | 287 'TITLE': (str, '', False), |
| 285 'DESC': (str, '', False), | 288 'DESC': (str, '', False), |
| 286 'INFO': (str, '', False), | 289 'INFO': (str, '', False), |
| 287 'EXPERIMENTAL': (bool, [True, False], False) | 290 'EXPERIMENTAL': (bool, [True, False], False) |
| 288 } | 291 } |
| 289 | 292 |
| 290 | 293 |
| 291 def ErrorMsgFunc(text): | 294 def ErrorMsgFunc(text): |
| (...skipping 27 matching lines...) Expand all Loading... |
| 319 key, exp_type.__name__.upper(), type(value).__name__.upper())) | 322 key, exp_type.__name__.upper(), type(value).__name__.upper())) |
| 320 failed = True | 323 failed = True |
| 321 continue | 324 continue |
| 322 | 325 |
| 323 # Verify the value is non-empty if required | 326 # Verify the value is non-empty if required |
| 324 if required and not value: | 327 if required and not value: |
| 325 ErrorMsg('Expected non-empty value for %s.' % key) | 328 ErrorMsg('Expected non-empty value for %s.' % key) |
| 326 failed = True | 329 failed = True |
| 327 continue | 330 continue |
| 328 | 331 |
| 332 # If it's a bool, the expected values are always True or False. |
| 333 if exp_type is bool: |
| 334 continue |
| 335 |
| 329 # If it's a string and there are expected values, make sure it matches | 336 # If it's a string and there are expected values, make sure it matches |
| 330 if exp_type is str: | 337 if exp_type is str: |
| 331 if type(exp_value) is list and exp_value: | 338 if type(exp_value) is list and exp_value: |
| 332 if value not in exp_value: | 339 if value not in exp_value: |
| 333 ErrorMsg('Value %s not expected for %s.' % (value, key)) | 340 ErrorMsg('Value %s not expected for %s.' % (value, key)) |
| 334 failed = True | 341 failed = True |
| 335 continue | 342 continue |
| 336 | 343 |
| 337 # if it's a list, then we need to validate the values | 344 # if it's a list, then we need to validate the values |
| 338 if exp_type is list: | 345 if exp_type is list: |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 toolchains.append(platform) | 552 toolchains.append(platform) |
| 546 | 553 |
| 547 if not args: | 554 if not args: |
| 548 ErrorExit('Please specify one or more projects to generate Makefiles for.') | 555 ErrorExit('Please specify one or more projects to generate Makefiles for.') |
| 549 | 556 |
| 550 # By default support newlib and glibc | 557 # By default support newlib and glibc |
| 551 if not toolchains: | 558 if not toolchains: |
| 552 toolchains = ['newlib', 'glibc'] | 559 toolchains = ['newlib', 'glibc'] |
| 553 print 'Using default toolchains: ' + ' '.join(toolchains) | 560 print 'Using default toolchains: ' + ' '.join(toolchains) |
| 554 | 561 |
| 555 examples = [] | 562 master_projects = {} |
| 556 libs = [] | |
| 557 for filename in args: | 563 for filename in args: |
| 558 desc = LoadProject(filename, toolchains) | 564 desc = LoadProject(filename, toolchains) |
| 559 if not desc: | 565 if not desc: |
| 560 print 'Skipping %s, not in [%s].' % (filename, ', '.join(toolchains)) | 566 print 'Skipping %s, not in [%s].' % (filename, ', '.join(toolchains)) |
| 561 continue | 567 continue |
| 562 | 568 |
| 563 if desc.get('EXPERIMENTAL', False) and not options.experimental: | 569 if desc.get('EXPERIMENTAL', False) and not options.experimental: |
| 564 print 'Skipping %s, experimental only.' % (filename,) | 570 print 'Skipping %s, experimental only.' % (filename,) |
| 565 continue | 571 continue |
| 566 | 572 |
| 567 srcroot = os.path.dirname(os.path.abspath(filename)) | 573 srcroot = os.path.dirname(os.path.abspath(filename)) |
| 568 if not ProcessProject(srcroot, options.dstroot, desc, toolchains): | 574 if not ProcessProject(srcroot, options.dstroot, desc, toolchains): |
| 569 ErrorExit('\n*** Failed to process project: %s ***' % filename) | 575 ErrorExit('\n*** Failed to process project: %s ***' % filename) |
| 570 | 576 |
| 571 # if this is an example add it to the master make and update the html | 577 # if this is an example update the html |
| 572 if desc['DEST'] == 'examples': | 578 if desc['DEST'] == 'examples': |
| 573 examples.append(desc['NAME']) | |
| 574 ProcessHTML(srcroot, options.dstroot, desc, toolchains) | 579 ProcessHTML(srcroot, options.dstroot, desc, toolchains) |
| 575 | 580 |
| 576 # if this is a library add it to the master make | 581 # Create a list of projects for each DEST. This will be used to generate a |
| 577 if desc['DEST'] == 'src': | 582 # master makefile. |
| 578 libs.append(desc['NAME']) | 583 master_projects.setdefault(desc['DEST'], []).append(desc['NAME']) |
| 579 | 584 |
| 580 if options.master: | 585 if options.master: |
| 581 master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile') | 586 master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile') |
| 582 master_out = os.path.join(options.dstroot, 'examples', 'Makefile') | 587 for dest, projects in master_projects.iteritems(): |
| 583 GenerateMasterMakefile(master_in, master_out, examples) | 588 master_out = os.path.join(options.dstroot, dest, 'Makefile') |
| 584 master_out = os.path.join(options.dstroot, 'src', 'Makefile') | 589 GenerateMasterMakefile(master_in, master_out, projects) |
| 585 GenerateMasterMakefile(master_in, master_out, libs) | |
| 586 return 0 | 590 return 0 |
| 587 | 591 |
| 588 | 592 |
| 589 if __name__ == '__main__': | 593 if __name__ == '__main__': |
| 590 sys.exit(main(sys.argv[1:])) | 594 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |