Commit a2441774 authored by sbc@chromium.org's avatar sbc@chromium.org

add dependancy generatation to generated Makefiles

This is implemented by passing -MMD to gcc and then including the
generated .d files in the Makefile.

BUG=139161
TEST=
NOTRY=true

Review URL: https://chromiumcodereview.appspot.com/10821050

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148640 0039d316-1c4b-4281-b951-d872f2087c98
parent 1c76dc3c
...@@ -27,7 +27,7 @@ import getos ...@@ -27,7 +27,7 @@ import getos
SUPPORTED_HOSTS = ['win'] SUPPORTED_HOSTS = ['win']
def ErrorExit(text): def ErrorExit(text):
sys.stderr.write(text + '\n') ErrorMsgFunc(text)
sys.exit(1) sys.exit(1)
...@@ -87,7 +87,7 @@ def GetSourcesDict(sources): ...@@ -87,7 +87,7 @@ def GetSourcesDict(sources):
else: else:
source_map[key] = [] source_map[key] = []
return source_map return source_map
def GetPlatforms(plat_list, plat_filter): def GetPlatforms(plat_list, plat_filter):
platforms = [] platforms = []
...@@ -101,7 +101,7 @@ def GenerateToolDefaults(desc, tools): ...@@ -101,7 +101,7 @@ def GenerateToolDefaults(desc, tools):
defaults = '' defaults = ''
for tool in tools: for tool in tools:
defaults += BUILD_RULES[tool]['DEFS'] defaults += BUILD_RULES[tool]['DEFS']
return defaults return defaults
def GenerateSettings(desc, tools): def GenerateSettings(desc, tools):
...@@ -137,7 +137,7 @@ def GenerateCompile(target, tool, arch, srcs): ...@@ -137,7 +137,7 @@ def GenerateCompile(target, tool, arch, srcs):
For the given target, toolset and architecture, returns a rule to generate For the given target, toolset and architecture, returns a rule to generate
the object files for the set of sources. the object files for the set of sources.
Returns: Returns:
Returns a tuple containin the objects and the rule. Returns a tuple containin the objects and the rule.
""" """
...@@ -159,6 +159,7 @@ def GenerateCompile(target, tool, arch, srcs): ...@@ -159,6 +159,7 @@ def GenerateCompile(target, tool, arch, srcs):
compile_rule = GetBuildRule(tool, 'CXX') compile_rule = GetBuildRule(tool, 'CXX')
rules += Replace(compile_rule, replace) rules += Replace(compile_rule, replace)
object_sets.append('$(%s)' % replace['<OBJS>']) object_sets.append('$(%s)' % replace['<OBJS>'])
return (' '.join(object_sets), rules) return (' '.join(object_sets), rules)
...@@ -168,13 +169,13 @@ def GenerateLink(target, tool, arch, objs): ...@@ -168,13 +169,13 @@ def GenerateLink(target, tool, arch, objs):
Returns: Returns:
Returns a tuple containing the rule and target. Returns a tuple containing the rule and target.
""" """
targ_type = target['TYPE'] targ_type = target['TYPE']
link_rule = GetBuildRule(tool, targ_type.upper()) link_rule = GetBuildRule(tool, targ_type.upper())
libs = target.get('LIBS', []) libs = target.get('LIBS', [])
libs = BuildLibList(tool, libs) libs = BuildLibList(tool, libs)
replace = BuildToolDict(tool, target['NAME'], arch, 'nexe', replace = BuildToolDict(tool, target['NAME'], arch, 'nexe',
OBJS=objs, LIBLIST=libs) OBJS=objs, LIBLIST=libs)
rule = Replace(link_rule, replace) rule = Replace(link_rule, replace)
target_out = GetTarget(tool, targ_type, replace) target_out = GetTarget(tool, targ_type, replace)
return target_out, rule return target_out, rule
...@@ -213,11 +214,11 @@ def GenerateRules(desc, tools): ...@@ -213,11 +214,11 @@ def GenerateRules(desc, tools):
targs, nmf_rule = GenerateNMF(main, tc) targs, nmf_rule = GenerateNMF(main, tc)
rules += nmf_rule rules += nmf_rule
all_targets.append(targs) all_targets.append(targs)
rules += '\n.PHONY : clean\nclean:\n\t$(RM) ' + ' '.join(clean) rules += '\n.PHONY : clean\nclean:\n\t$(RM) $(DEPFILES) ' + ' '.join(clean)
rules += '\n\n-include $(DEPFILES)'
return ' '.join(all_targets), rules return ' '.join(all_targets), rules
def GenerateTargets(desc, tools): def GenerateTargets(desc, tools):
targets = [] targets = []
rules = '' rules = ''
...@@ -257,7 +258,6 @@ def GenerateReplacements(desc, tools): ...@@ -257,7 +258,6 @@ def GenerateReplacements(desc, tools):
} }
# 'KEY' : ( <TYPE>, [Accepted Values], <Required?>) # 'KEY' : ( <TYPE>, [Accepted Values], <Required?>)
DSC_FORMAT = { DSC_FORMAT = {
'TOOLS' : (list, ['newlib', 'glibc', 'pnacl', 'win'], True), 'TOOLS' : (list, ['newlib', 'glibc', 'pnacl', 'win'], True),
...@@ -310,7 +310,7 @@ def ValidateFormat(src, format, ErrorMsg=ErrorMsgFunc): ...@@ -310,7 +310,7 @@ def ValidateFormat(src, format, ErrorMsg=ErrorMsgFunc):
continue continue
exp_type, exp_value, required = format[key] exp_type, exp_value, required = format[key]
value = src[key] value = src[key]
# Verify the key is of the expected type # Verify the key is of the expected type
if exp_type != type(value): if exp_type != type(value):
...@@ -409,7 +409,7 @@ def IsNexe(desc): ...@@ -409,7 +409,7 @@ def IsNexe(desc):
def ProcessHTML(srcroot, dstroot, desc, toolchains): def ProcessHTML(srcroot, dstroot, desc, toolchains):
name = desc['NAME'] name = desc['NAME']
outdir = os.path.join(dstroot, desc['DEST'], name) outdir = os.path.join(dstroot, desc['DEST'], name)
srcfile = os.path.join(srcroot, 'index.html') srcfile = os.path.join(srcroot, 'index.html')
tools = GetPlatforms(toolchains, desc['TOOLS']) tools = GetPlatforms(toolchains, desc['TOOLS'])
for tool in tools: for tool in tools:
...@@ -426,17 +426,17 @@ def ProcessHTML(srcroot, dstroot, desc, toolchains): ...@@ -426,17 +426,17 @@ def ProcessHTML(srcroot, dstroot, desc, toolchains):
srcfile = os.path.join(SDK_SRC_DIR, 'build_tools', 'redirect.html') srcfile = os.path.join(SDK_SRC_DIR, 'build_tools', 'redirect.html')
dstfile = os.path.join(outdir, 'index.html') dstfile = os.path.join(outdir, 'index.html')
WriteReplaced(srcfile, dstfile, replace) WriteReplaced(srcfile, dstfile, replace)
def LoadProject(filename, toolchains): def LoadProject(filename, toolchains):
"""Generate a Master Makefile that builds all examples. """Generate a Master Makefile that builds all examples.
Load a project desciption file, verifying it conforms and checking Load a project desciption file, verifying it conforms and checking
if it matches the set of requested toolchains. Return None if the if it matches the set of requested toolchains. Return None if the
project is filtered out.""" project is filtered out."""
print '\n\nProcessing %s...' % filename print '\n\nProcessing %s...' % filename
# Default src directory is the directory the description was found in # Default src directory is the directory the description was found in
desc = open(filename, 'r').read() desc = open(filename, 'r').read()
desc = eval(desc, {}, {}) desc = eval(desc, {}, {})
...@@ -511,7 +511,7 @@ def GenerateMasterMakefile(in_path, out_path, projects): ...@@ -511,7 +511,7 @@ def GenerateMasterMakefile(in_path, out_path, projects):
outdir = os.path.dirname(os.path.abspath(out_path)) outdir = os.path.dirname(os.path.abspath(out_path))
pepperdir = os.path.dirname(outdir) pepperdir = os.path.dirname(outdir)
AddMakeBat(pepperdir, outdir) AddMakeBat(pepperdir, outdir)
def main(argv): def main(argv):
parser = optparse.OptionParser() parser = optparse.OptionParser()
...@@ -541,6 +541,9 @@ def main(argv): ...@@ -541,6 +541,9 @@ def main(argv):
if options.host: if options.host:
toolchains.append(platform) toolchains.append(platform)
if not args:
ErrorExit('Please specify one or more projects to generate Makefiles for.')
# By default support newlib and glibc # By default support newlib and glibc
if not toolchains: if not toolchains:
toolchains = ['newlib', 'glibc'] toolchains = ['newlib', 'glibc']
......
...@@ -12,7 +12,7 @@ NEWLIB_CC?=$(TC_PATH)/$(OSNAME)_x86_newlib/bin/i686-nacl-gcc -c ...@@ -12,7 +12,7 @@ NEWLIB_CC?=$(TC_PATH)/$(OSNAME)_x86_newlib/bin/i686-nacl-gcc -c
NEWLIB_CXX?=$(TC_PATH)/$(OSNAME)_x86_newlib/bin/i686-nacl-g++ -c -std=gnu++98 NEWLIB_CXX?=$(TC_PATH)/$(OSNAME)_x86_newlib/bin/i686-nacl-g++ -c -std=gnu++98
NEWLIB_LINK?=$(TC_PATH)/$(OSNAME)_x86_newlib/bin/i686-nacl-g++ -Wl,-as-needed NEWLIB_LINK?=$(TC_PATH)/$(OSNAME)_x86_newlib/bin/i686-nacl-g++ -Wl,-as-needed
NEWLIB_DUMP?=$(TC_PATH)/$(OSNAME)_x86_newlib/x86_64-nacl/bin/objdump NEWLIB_DUMP?=$(TC_PATH)/$(OSNAME)_x86_newlib/x86_64-nacl/bin/objdump
NEWLIB_CCFLAGS?=-O0 -g -pthread $(NACL_WARNINGS) NEWLIB_CCFLAGS?=-O0 -MMD -g -pthread $(NACL_WARNINGS)
NEWLIB_LDFLAGS?=-g -pthread NEWLIB_LDFLAGS?=-g -pthread
""" """
...@@ -23,7 +23,7 @@ GLIBC_LINK?=$(TC_PATH)/$(OSNAME)_x86_glibc/bin/i686-nacl-g++ -Wl,-as-needed ...@@ -23,7 +23,7 @@ GLIBC_LINK?=$(TC_PATH)/$(OSNAME)_x86_glibc/bin/i686-nacl-g++ -Wl,-as-needed
GLIBC_DUMP?=$(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/bin/objdump GLIBC_DUMP?=$(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/bin/objdump
GLIBC_PATHS:=-L $(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/lib32 GLIBC_PATHS:=-L $(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/lib32
GLIBC_PATHS+=-L $(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/lib GLIBC_PATHS+=-L $(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/lib
GLIBC_CCFLAGS?=-O0 -g -pthread $(NACL_WARNINGS) GLIBC_CCFLAGS?=-O0 -MMD -g -pthread $(NACL_WARNINGS)
GLIBC_LDFLAGS?=-g -pthread GLIBC_LDFLAGS?=-g -pthread
""" """
...@@ -33,7 +33,7 @@ PNACL_CXX?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-clang++ -c -std=gnu++ ...@@ -33,7 +33,7 @@ PNACL_CXX?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-clang++ -c -std=gnu++
PNACL_LINK?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-clang++ PNACL_LINK?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-clang++
PNACL_DUMP?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/objdump PNACL_DUMP?=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/objdump
PNACL_CCFLAGS?=-O0 -g -pthread $(NACL_WARNINGS) PNACL_CCFLAGS?=-O0 -g -pthread $(NACL_WARNINGS)
PNACL_LDFLAGS?=-g -pthread PNACL_CCFLAGS?=-O0 -MMD -g -pthread $(NACL_WARNINGS)
TRANSLATE:=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-translate TRANSLATE:=$(TC_PATH)/$(OSNAME)_x86_pnacl/newlib/bin/pnacl-translate
""" """
...@@ -51,12 +51,14 @@ WIN_LDFLAGS=/LIBPATH:$(NACL_SDK_ROOT)/lib/win_x86_32_host ...@@ -51,12 +51,14 @@ WIN_LDFLAGS=/LIBPATH:$(NACL_SDK_ROOT)/lib/win_x86_32_host
# #
NACL_CC_RULE = """ NACL_CC_RULE = """
<OBJS>:=$(patsubst %.<ext>, <tc>/%_<ARCH>.o,$(<PROJ>_<EXT>)) <OBJS>:=$(patsubst %.<ext>, <tc>/%_<ARCH>.o,$(<PROJ>_<EXT>))
DEPFILES+=$(<OBJS>:.o=.d)
$(<OBJS>) : <tc>/%_<ARCH>.o : %.<ext> $(THIS_MAKE) | <tc> $(<OBJS>) : <tc>/%_<ARCH>.o : %.<ext> $(THIS_MAKE) | <tc>
<TAB>$(<CC>) -o $@ $< <MACH> $(<PROJ>_<EXT>FLAGS) -DTCNAME=<tc> $(<TC>_CCFLAGS) <DEFLIST> <TAB>$(<CC>) -o $@ $< <MACH> $(<PROJ>_<EXT>FLAGS) -DTCNAME=<tc> $(<TC>_CCFLAGS) <DEFLIST>
""" """
SO_CC_RULE = """ SO_CC_RULE = """
<OBJS>:=$(patsubst %.<ext>, <tc>/%_<ARCH>.o,$(<PROJ>_<EXT>)) <OBJS>:=$(patsubst %.<ext>, <tc>/%_<ARCH>.o,$(<PROJ>_<EXT>))
DEPFILES+=$(<OBJS>:.o=.d)
$(<OBJS>) : <tc>/%_<ARCH>.o : %.<ext> $(THIS_MAKE) | <tc> $(<OBJS>) : <tc>/%_<ARCH>.o : %.<ext> $(THIS_MAKE) | <tc>
<TAB>$(<CC>) -o $@ $< <MACH> -fPIC $(<PROJ>_<EXT>FLAGS) -DTCNAME=<tc> $(<TC>_CCFLAGS) <DEFLIST> <TAB>$(<CC>) -o $@ $< <MACH> -fPIC $(<PROJ>_<EXT>FLAGS) -DTCNAME=<tc> $(<TC>_CCFLAGS) <DEFLIST>
""" """
...@@ -271,7 +273,7 @@ def BuildToolDict(toolchain, project, arch = {}, ext='nexe', **kwargs): ...@@ -271,7 +273,7 @@ def BuildToolDict(toolchain, project, arch = {}, ext='nexe', **kwargs):
# Add other passed in replacements # Add other passed in replacements
for key in kwargs: for key in kwargs:
replace['<%s>' % key] = kwargs[key] replace['<%s>' % key] = kwargs[key]
if '<OBJS>' not in replace: if '<OBJS>' not in replace:
if replace.get('<ARCH>', ''): if replace.get('<ARCH>', ''):
replace['<OBJS>'] = '%s_%s_%s_%s_O' % (TC, PROJ, replace['<ARCH>'], EXT) replace['<OBJS>'] = '%s_%s_%s_%s_O' % (TC, PROJ, replace['<ARCH>'], EXT)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment