Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(915)

Side by Side Diff: pylib/gyp/generator/make.py

Issue 150166: Make dependencies standalone. Doesn't actually work because of autogenerated... Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Notes: 3 # Notes:
4 # 4 #
5 # This is all roughly based on the Makefile system used by the Linux 5 # This is all roughly based on the Makefile system used by the Linux
6 # kernel, but is a non-recursive make -- we put the entire dependency 6 # kernel, but is a non-recursive make -- we put the entire dependency
7 # graph in front of make and let it figure it out. 7 # graph in front of make and let it figure it out.
8 # 8 #
9 # The code below generates a separate .mk file for each target, but 9 # The code below generates a separate .mk file for each target, but
10 # all are sourced by the top-level Makefile. This means that all 10 # all are sourced by the top-level Makefile. This means that all
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 # C++ apps need to be linked with g++. Not sure what's appropriate. 87 # C++ apps need to be linked with g++. Not sure what's appropriate.
88 LD := $(CXX) 88 LD := $(CXX)
89 RANLIB ?= ranlib 89 RANLIB ?= ranlib
90 90
91 # Flags to make gcc output dependency info. Note that you need to be 91 # Flags to make gcc output dependency info. Note that you need to be
92 # careful here to use the flags that ccache and distcc can understand. 92 # careful here to use the flags that ccache and distcc can understand.
93 # We write to a temporary dep file first and then rename at the end 93 # We write to a temporary dep file first and then rename at the end
94 # so we can't end up with a broken dep file. 94 # so we can't end up with a broken dep file.
95 depfile = $@.d 95 depfile = $@.d
96 DEPFLAGS = -MMD -MF $(depfile).tmp 96 DEPFLAGS = -MMD -MF $(depfile).tmp
97 DEPFLAGS2 = -MM
97 98
98 # We have to fixup the deps output in a few ways. 99 # We have to fixup the deps output in a few ways.
99 # First, the file output should to mention the proper .o file. 100 # First, the file output should to mention the proper .o file.
100 # ccache or distcc lose the path to the target, so we convert a rule of 101 # ccache or distcc lose the path to the target, so we convert a rule of
101 # the form: 102 # the form:
102 # foobar.o: DEP1 DEP2 103 # foobar.o: DEP1 DEP2
103 # into 104 # into
104 # path/to/foobar.o: DEP1 DEP2 105 # path/to/foobar.o: DEP1 DEP2
105 # Additionally, we want to make missing files not cause us to needlessly 106 # Additionally, we want to make missing files not cause us to needlessly
106 # rebuild. We want to rewrite 107 # rebuild. We want to rewrite
107 # foobar.o: DEP1 DEP2 \ 108 # foobar.o: DEP1 DEP2 \
108 # DEP3 109 # DEP3
109 # to 110 # to
110 # DEP1 DEP2: 111 # DEP1 DEP2:
111 # DEP3: 112 # DEP3:
112 # so if the files are missing, they're just considered phony rules. 113 # so if the files are missing, they're just considered phony rules.
113 # We have to do some pretty insane escaping to get those backslashes 114 # We have to do some pretty insane escaping to get those backslashes
114 # and dollar signs past Python, make, the shell, and sed at the same time.""" 115 # and dollar signs past Python, make, the shell, and sed at the same time."""
115 r""" 116 r"""
116 define fixup_dep 117 define fixup_dep
117 sed -i -e "s|^$(notdir $@)|$@|" $(depfile).tmp 118 sed -i -e "s|^$(notdir $@)|$@|" $(depfile).tmp
119 sed -i -e "s|^$@:|$@ $(depfile):|" $(depfile).tmp
118 sed -e "s|^[^:]*: *||" -e "s| *\\\\$$||" -e 's|^ *||' \ 120 sed -e "s|^[^:]*: *||" -e "s| *\\\\$$||" -e 's|^ *||' \
119 -e "/./s|$$|:|" $(depfile).tmp >> $(depfile).tmp 121 -e "/./s|$$|:|" $(depfile).tmp >> $(depfile).tmp
120 mv $(depfile).tmp $(depfile) 122 mv $(depfile).tmp $(depfile)
121 endef 123 endef
124
125 define fixup_dep2
126 echo 1 = $(1)
127 sed -i -e "s|^$(notdir $(1))|$(1)|" $@.tmp
128 sed -i -e "s|^$(1):|$(1) $@:|" $@.tmp
129 sed -e "s|^[^:]*: *||" -e "s| *\\\\$$||" -e 's|^ *||' \
130 -e "/./s|$$|:|" $@.tmp >> $@.tmp
131 mv $@.tmp $@
132 endef
122 """ 133 """
123 """ 134 """
124 # Command definitions: 135 # Command definitions:
125 # - cmd_foo is the actual command to run; 136 # - cmd_foo is the actual command to run;
126 # - quiet_cmd_foo is the brief-output summary of the command. 137 # - quiet_cmd_foo is the brief-output summary of the command.
127 138
128 quiet_cmd_cc = CC $@ 139 quiet_cmd_cc = CC $@
129 cmd_cc = $(CC) $(CFLAGS) $(DEPFLAGS) -c -o $@ $< 140 cmd_cc = $(CC) $(CFLAGS) $(DEPFLAGS) -c -o $@ $<
130 141
142 quiet_cmd_cc_deps = CC_DEPS $@
143 cmd_cc_deps = $(CC) $(CFLAGS) $(DEPFLAGS2) -E $< > $@.tmp
144
131 quiet_cmd_cxx = CXX $@ 145 quiet_cmd_cxx = CXX $@
132 cmd_cxx = $(CXX) $(CXXFLAGS) $(DEPFLAGS) -c -o $@ $< 146 cmd_cxx = $(CXX) $(CXXFLAGS) $(DEPFLAGS) -c -o $@ $<
133 147
148 quiet_cmd_cxx_deps = CXX_DEPS $@
149 cmd_cxx_deps = $(CXX) $(CXXFLAGS) $(DEPFLAGS2) -E $< > $@.tmp
150
134 quiet_cmd_ar = AR $@ 151 quiet_cmd_ar = AR $@
135 cmd_ar = $(AR) rc $@ $(filter %.o,$^) 152 cmd_ar = $(AR) rc $@ $(filter %.o,$^)
136 153
137 quiet_cmd_ranlib = RANLIB $@ 154 quiet_cmd_ranlib = RANLIB $@
138 cmd_ranlib = $(RANLIB) $@ 155 cmd_ranlib = $(RANLIB) $@
139 156
140 quiet_cmd_touch = TOUCH $@ 157 quiet_cmd_touch = TOUCH $@
141 cmd_touch = touch $@ 158 cmd_touch = touch $@
142 159
143 quiet_cmd_copy = COPY $@ 160 quiet_cmd_copy = COPY $@
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 $(call do_cmd,cxx) 199 $(call do_cmd,cxx)
183 @$(fixup_dep) 200 @$(fixup_dep)
184 201
185 # Try building from generated source, too. 202 # Try building from generated source, too.
186 $(obj)/%.o: $(obj)/%.cc 203 $(obj)/%.o: $(obj)/%.cc
187 $(call do_cmd,cxx) 204 $(call do_cmd,cxx)
188 @$(fixup_dep) 205 @$(fixup_dep)
189 $(obj)/%.o: $(obj)/%.cpp 206 $(obj)/%.o: $(obj)/%.cpp
190 $(call do_cmd,cxx) 207 $(call do_cmd,cxx)
191 @$(fixup_dep) 208 @$(fixup_dep)
209
210 # Build dependencies
211 $(obj)/%.o.d: %.c
212 $(call do_cmd,cc_deps)
213 $(call fixup_dep2,$(patsubst %.d,%,$@))
214
215 $(obj)/%.o.d: %.cc
216 $(call do_cmd,cxx_deps)
217 $(call fixup_dep2,$(patsubst %.d,%,$@))
218
192 """) 219 """)
193 220
194 # This gets added to the very beginning of the Makefile, setting the root 221 # This gets added to the very beginning of the Makefile, setting the root
195 # directory as computed by gyp. 222 # directory as computed by gyp.
196 SHARED_HEADER_ROOTDIR = ("""\ 223 SHARED_HEADER_ROOTDIR = ("""\
197 # The root of the project. 224 # The root of the project.
198 rootdir ?= %s 225 rootdir ?= %s
199 226
200 """) 227 """)
201 228
202 SHARED_FOOTER = """\ 229 SHARED_FOOTER = """\
203 # Add in dependency-tracking rules. $(all_targets) is all targets in 230 # Add in dependency-tracking rules. $(all_targets) is all targets in
204 # our tree. First, only consider targets that already have been 231 # our tree. First, only consider targets that already have been
205 # built, as unbuilt targets will be built regardless of dependency 232 # built, as unbuilt targets will be built regardless of dependency
206 # info: 233 # info:
207 all_targets := $(wildcard $(sort $(all_targets))) 234 # *** THIS IS A BAD IDEA - GENERATED DEPENDENCIES WILL NOT BE BUILT IF
235 # YOU DO THIS ***
236 #all_targets := $(wildcard $(sort $(all_targets)))
237
238 # A target to make dependencies
239 deps: $(all_deps)
240
208 # Of those, only consider the ones with .d (dependency) info: 241 # Of those, only consider the ones with .d (dependency) info:
209 d_files := $(wildcard $(foreach f,$(all_targets),$(f).d)) 242 d_files := $(wildcard $(foreach f,$(all_targets),$(f).d))
210 ifneq ($(d_files),) 243 ifneq ($(d_files),)
211 include $(d_files) 244 include $(d_files)
212 endif 245 endif
213 """ 246 """
214 247
215 header = """\ 248 header = """\
216 # This file is generated by gyp; do not edit. 249 # This file is generated by gyp; do not edit.
217 250
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 self.WriteLn("# Flags passed to only C++ (and not C) files."); 468 self.WriteLn("# Flags passed to only C++ (and not C) files.");
436 self.WriteList(config.get('cflags_cc'), 'CFLAGS_CC_%s' % configname) 469 self.WriteList(config.get('cflags_cc'), 'CFLAGS_CC_%s' % configname)
437 includes = config.get('include_dirs') 470 includes = config.get('include_dirs')
438 if includes: 471 if includes:
439 includes = map(self.Absolutify, includes) 472 includes = map(self.Absolutify, includes)
440 self.WriteList(includes, 'INCS_%s' % configname, prefix='-I') 473 self.WriteList(includes, 'INCS_%s' % configname, prefix='-I')
441 474
442 sources = filter(Compilable, sources) 475 sources = filter(Compilable, sources)
443 objs = map(Objectify, map(self.Absolutify, map(Target, sources))) 476 objs = map(Objectify, map(self.Absolutify, map(Target, sources)))
444 self.WriteList(objs, 'OBJS') 477 self.WriteList(objs, 'OBJS')
478 self.WriteLn('DEPS := $(foreach o,$(OBJS),$(o).d)')
479 self.WriteLn();
445 480
446 self.WriteLn('# Add to the list of files we specially track ' 481 self.WriteLn('# Add to the list of files we specially track '
447 'dependencies for.') 482 'dependencies for.')
448 self.WriteLn('all_targets += $(OBJS)') 483 self.WriteLn('all_targets += $(OBJS)')
484 self.WriteLn('all_deps += $(DEPS)');
449 self.WriteLn() 485 self.WriteLn()
450 486
451 # Make sure our dependencies are built first. 487 # Make sure our dependencies are built first.
452 if deps: 488 if deps:
453 self.WriteMakeRule(['$(OBJS)'], deps, 489 self.WriteMakeRule(['$(OBJS)'], deps,
454 comment = 'Make sure our dependencies are built ' 490 comment = 'Make sure our dependencies are built '
455 'before any of us.', 491 'before any of us.',
456 order_only = True) 492 order_only = True)
457 493
458 # Make sure the actions and rules run first. 494 # Make sure the actions and rules run first.
459 # If they generate any extra headers etc., the per-.o file dep tracking 495 # If they generate any extra headers etc., the per-.o file dep tracking
460 # will catch the proper rebuilds, so order only is still ok here. 496 # will catch the proper rebuilds, so order only is still ok here.
461 if extra_outputs: 497 if extra_outputs:
462 self.WriteMakeRule(['$(OBJS)'], extra_outputs, 498 self.WriteMakeRule(['$(OBJS)'], extra_outputs,
463 comment = 'Make sure our actions/rules run ' 499 comment = 'Make sure our actions/rules run '
464 'before any of us.', 500 'before any of us.',
465 order_only = True) 501 order_only = True)
466 502
467 if objs: 503 if objs:
468 extra_link_deps.append('$(OBJS)') 504 extra_link_deps.append('$(OBJS)')
469 self.WriteLn("""\ 505 self.WriteLn("""\
470 # CFLAGS et al overrides must be target-local. 506 # CFLAGS et al overrides must be target-local.
471 # See "Target-specific Variable Values" in the GNU Make manual.""") 507 # See "Target-specific Variable Values" in the GNU Make manual.""")
472 self.WriteLn("$(OBJS): CFLAGS := $(CFLAGS_$(BUILDTYPE)) " 508 self.WriteLn("$(OBJS): CFLAGS := $(CFLAGS_$(BUILDTYPE)) "
473 "$(CFLAGS_C_$(BUILDTYPE)) " 509 "$(CFLAGS_C_$(BUILDTYPE)) "
474 "$(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE))") 510 "$(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE))")
475 self.WriteLn("$(OBJS): CXXFLAGS := $(CFLAGS_$(BUILDTYPE)) " 511 self.WriteLn("$(OBJS): CXXFLAGS := $(CFLAGS_$(BUILDTYPE)) "
476 "$(CFLAGS_CC_$(BUILDTYPE)) " 512 "$(CFLAGS_CC_$(BUILDTYPE)) "
477 "$(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE))") 513 "$(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE))")
514 self.WriteLn("$(DEPS): CFLAGS := $(CFLAGS_$(BUILDTYPE)) "
515 "$(CFLAGS_C_$(BUILDTYPE)) "
516 "$(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE))")
517 self.WriteLn("$(DEPS): CXXFLAGS := $(CFLAGS_$(BUILDTYPE)) "
518 "$(CFLAGS_CC_$(BUILDTYPE)) "
519 "$(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE))")
478 520
479 self.WriteLn() 521 self.WriteLn()
480 522
481 523
482 def ComputeOutput(self, spec): 524 def ComputeOutput(self, spec):
483 output = None 525 output = None
484 target = spec['target_name'] 526 target = spec['target_name']
485 if self.type == 'static_library': 527 if self.type == 'static_library':
486 target = 'lib%s.a' % target 528 target = 'lib%s.a' % target
487 elif self.type in ('loadable_module', 'shared_library'): 529 elif self.type in ('loadable_module', 'shared_library'):
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 spec = target_dicts[qualified_target] 671 spec = target_dicts[qualified_target]
630 configs = spec['configurations'] 672 configs = spec['configurations']
631 673
632 writer = MakefileWriter() 674 writer = MakefileWriter()
633 writer.Write(qualified_target, output_file, options.depth, spec, configs) 675 writer.Write(qualified_target, output_file, options.depth, spec, configs)
634 root_makefile.write('include ' + output_file + "\n") 676 root_makefile.write('include ' + output_file + "\n")
635 677
636 root_makefile.write(SHARED_FOOTER) 678 root_makefile.write(SHARED_FOOTER)
637 679
638 root_makefile.close() 680 root_makefile.close()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698