initial commit
[JIRC.git] / node_modules / jsdom / node_modules / contextify / build / Makefile
1 # We borrow heavily from the kernel build setup, though we are simpler since
2 # we don't have Kconfig tweaking settings on us.
3
4 # The implicit make rules have it looking for RCS files, among other things.
5 # We instead explicitly write all the rules we care about.
6 # It's even quicker (saves ~200ms) to pass -r on the command line.
7 MAKEFLAGS=-r
8
9 # The source directory tree.
10 srcdir := ..
11 abs_srcdir := $(abspath $(srcdir))
12
13 # The name of the builddir.
14 builddir_name ?= .
15
16 # The V=1 flag on command line makes us verbosely print command lines.
17 ifdef V
18 quiet=
19 else
20 quiet=quiet_
21 endif
22
23 # Specify BUILDTYPE=Release on the command line for a release build.
24 BUILDTYPE ?= Release
25
26 # Directory all our build output goes into.
27 # Note that this must be two directories beneath src/ for unit tests to pass,
28 # as they reach into the src/ directory for data with relative paths.
29 builddir ?= $(builddir_name)/$(BUILDTYPE)
30 abs_builddir := $(abspath $(builddir))
31 depsdir := $(builddir)/.deps
32
33 # Object output directory.
34 obj := $(builddir)/obj
35 abs_obj := $(abspath $(obj))
36
37 # We build up a list of every single one of the targets so we can slurp in the
38 # generated dependency rule Makefiles in one pass.
39 all_deps :=
40
41
42
43 # C++ apps need to be linked with g++.
44 #
45 # Note: flock is used to seralize linking. Linking is a memory-intensive
46 # process so running parallel links can often lead to thrashing. To disable
47 # the serialization, override LINK via an envrionment variable as follows:
48 #
49 # export LINK=g++
50 #
51 # This will allow make to invoke N linker processes as specified in -jN.
52 LINK ?= ./gyp-mac-tool flock $(builddir)/linker.lock $(CXX)
53
54 CC.target ?= $(CC)
55 CFLAGS.target ?= $(CFLAGS)
56 CXX.target ?= $(CXX)
57 CXXFLAGS.target ?= $(CXXFLAGS)
58 LINK.target ?= $(LINK)
59 LDFLAGS.target ?= $(LDFLAGS)
60 AR.target ?= $(AR)
61 ARFLAGS.target ?= crs
62
63 # N.B.: the logic of which commands to run should match the computation done
64 # in gyp's make.py where ARFLAGS.host etc. is computed.
65 # TODO(evan): move all cross-compilation logic to gyp-time so we don't need
66 # to replicate this environment fallback in make as well.
67 CC.host ?= gcc
68 CFLAGS.host ?=
69 CXX.host ?= g++
70 CXXFLAGS.host ?=
71 LINK.host ?= g++
72 LDFLAGS.host ?=
73 AR.host ?= ar
74 ARFLAGS.host := crs
75
76 # Define a dir function that can handle spaces.
77 # http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions
78 # "leading spaces cannot appear in the text of the first argument as written.
79 # These characters can be put into the argument value by variable substitution."
80 empty :=
81 space := $(empty) $(empty)
82
83 # http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces
84 replace_spaces = $(subst $(space),?,$1)
85 unreplace_spaces = $(subst ?,$(space),$1)
86 dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1)))
87
88 # Flags to make gcc output dependency info. Note that you need to be
89 # careful here to use the flags that ccache and distcc can understand.
90 # We write to a dep file on the side first and then rename at the end
91 # so we can't end up with a broken dep file.
92 depfile = $(depsdir)/$(call replace_spaces,$@).d
93 DEPFLAGS = -MMD -MF $(depfile).raw
94
95 # We have to fixup the deps output in a few ways.
96 # (1) the file output should mention the proper .o file.
97 # ccache or distcc lose the path to the target, so we convert a rule of
98 # the form:
99 # foobar.o: DEP1 DEP2
100 # into
101 # path/to/foobar.o: DEP1 DEP2
102 # (2) we want missing files not to cause us to fail to build.
103 # We want to rewrite
104 # foobar.o: DEP1 DEP2 \
105 # DEP3
106 # to
107 # DEP1:
108 # DEP2:
109 # DEP3:
110 # so if the files are missing, they're just considered phony rules.
111 # We have to do some pretty insane escaping to get those backslashes
112 # and dollar signs past make, the shell, and sed at the same time.
113 # Doesn't work with spaces, but that's fine: .d files have spaces in
114 # their names replaced with other characters.
115 define fixup_dep
116 # The depfile may not exist if the input file didn't have any #includes.
117 touch $(depfile).raw
118 # Fixup path as in (1).
119 sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile)
120 # Add extra rules as in (2).
121 # We remove slashes and replace spaces with new lines;
122 # remove blank lines;
123 # delete the first line and append a colon to the remaining lines.
124 sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\
125 grep -v '^$$' |\
126 sed -e 1d -e 's|$$|:|' \
127 >> $(depfile)
128 rm $(depfile).raw
129 endef
130
131 # Command definitions:
132 # - cmd_foo is the actual command to run;
133 # - quiet_cmd_foo is the brief-output summary of the command.
134
135 quiet_cmd_cc = CC($(TOOLSET)) $@
136 cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $@ $<
137
138 quiet_cmd_cxx = CXX($(TOOLSET)) $@
139 cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
140
141 quiet_cmd_objc = CXX($(TOOLSET)) $@
142 cmd_objc = $(CC.$(TOOLSET)) $(GYP_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
143
144 quiet_cmd_objcxx = CXX($(TOOLSET)) $@
145 cmd_objcxx = $(CXX.$(TOOLSET)) $(GYP_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
146
147 # Commands for precompiled header files.
148 quiet_cmd_pch_c = CXX($(TOOLSET)) $@
149 cmd_pch_c = $(CC.$(TOOLSET)) $(GYP_PCH_CFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
150 quiet_cmd_pch_cc = CXX($(TOOLSET)) $@
151 cmd_pch_cc = $(CC.$(TOOLSET)) $(GYP_PCH_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
152 quiet_cmd_pch_m = CXX($(TOOLSET)) $@
153 cmd_pch_m = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
154 quiet_cmd_pch_mm = CXX($(TOOLSET)) $@
155 cmd_pch_mm = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
156
157 # gyp-mac-tool is written next to the root Makefile by gyp.
158 # Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
159 # already.
160 quiet_cmd_mac_tool = MACTOOL $(4) $<
161 cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@"
162
163 quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@
164 cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4)
165
166 quiet_cmd_infoplist = INFOPLIST $@
167 cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
168
169 quiet_cmd_touch = TOUCH $@
170 cmd_touch = touch $@
171
172 quiet_cmd_copy = COPY $@
173 # send stderr to /dev/null to ignore messages when linking directories.
174 cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp -af "$<" "$@")
175
176 quiet_cmd_alink = LIBTOOL-STATIC $@
177 cmd_alink = rm -f $@ && ./gyp-mac-tool filter-libtool libtool -static -o $@ $(filter %.o,$^)
178
179 quiet_cmd_link = LINK($(TOOLSET)) $@
180 cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
181
182 # TODO(thakis): Find out and document the difference between shared_library and
183 # loadable_module on mac.
184 quiet_cmd_solink = SOLINK($(TOOLSET)) $@
185 cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
186
187 # TODO(thakis): The solink_module rule is likely wrong. Xcode seems to pass
188 # -bundle -single_module here (for osmesa.so).
189 quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
190 cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
191
192
193 # Define an escape_quotes function to escape single quotes.
194 # This allows us to handle quotes properly as long as we always use
195 # use single quotes and escape_quotes.
196 escape_quotes = $(subst ','\'',$(1))
197 # This comment is here just to include a ' to unconfuse syntax highlighting.
198 # Define an escape_vars function to escape '$' variable syntax.
199 # This allows us to read/write command lines with shell variables (e.g.
200 # $LD_LIBRARY_PATH), without triggering make substitution.
201 escape_vars = $(subst $$,$$$$,$(1))
202 # Helper that expands to a shell command to echo a string exactly as it is in
203 # make. This uses printf instead of echo because printf's behaviour with respect
204 # to escape sequences is more portable than echo's across different shells
205 # (e.g., dash, bash).
206 exact_echo = printf '%s\n' '$(call escape_quotes,$(1))'
207
208 # Helper to compare the command we're about to run against the command
209 # we logged the last time we ran the command. Produces an empty
210 # string (false) when the commands match.
211 # Tricky point: Make has no string-equality test function.
212 # The kernel uses the following, but it seems like it would have false
213 # positives, where one string reordered its arguments.
214 # arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
215 # $(filter-out $(cmd_$@), $(cmd_$(1))))
216 # We instead substitute each for the empty string into the other, and
217 # say they're equal if both substitutions produce the empty string.
218 # .d files contain ? instead of spaces, take that into account.
219 command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\
220 $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1))))
221
222 # Helper that is non-empty when a prerequisite changes.
223 # Normally make does this implicitly, but we force rules to always run
224 # so we can check their command lines.
225 # $? -- new prerequisites
226 # $| -- order-only dependencies
227 prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?))
228
229 # Helper that executes all postbuilds, and deletes the output file when done
230 # if any of the postbuilds failed.
231 define do_postbuilds
232 @E=0;\
233 for p in $(POSTBUILDS); do\
234 eval $$p;\
235 F=$$?;\
236 if [ $$F -ne 0 ]; then\
237 E=$$F;\
238 fi;\
239 done;\
240 if [ $$E -ne 0 ]; then\
241 rm -rf "$@";\
242 exit $$E;\
243 fi
244 endef
245
246 # do_cmd: run a command via the above cmd_foo names, if necessary.
247 # Should always run for a given target to handle command-line changes.
248 # Second argument, if non-zero, makes it do asm/C/C++ dependency munging.
249 # Third argument, if non-zero, makes it do POSTBUILDS processing.
250 # Note: We intentionally do NOT call dirx for depfile, since it contains ? for
251 # spaces already and dirx strips the ? characters.
252 define do_cmd
253 $(if $(or $(command_changed),$(prereq_changed)),
254 @$(call exact_echo, $($(quiet)cmd_$(1)))
255 @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))"
256 $(if $(findstring flock,$(word 2,$(cmd_$1))),
257 @$(cmd_$(1))
258 @echo " $(quiet_cmd_$(1)): Finished",
259 @$(cmd_$(1))
260 )
261 @$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile)
262 @$(if $(2),$(fixup_dep))
263 $(if $(and $(3), $(POSTBUILDS)),
264 $(call do_postbuilds)
265 )
266 )
267 endef
268
269 # Declare the "all" target first so it is the default,
270 # even though we don't have the deps yet.
271 .PHONY: all
272 all:
273
274 # make looks for ways to re-generate included makefiles, but in our case, we
275 # don't have a direct way. Explicitly telling make that it has nothing to do
276 # for them makes it go faster.
277 %.d: ;
278
279 # Use FORCE_DO_CMD to force a target to run. Should be coupled with
280 # do_cmd.
281 .PHONY: FORCE_DO_CMD
282 FORCE_DO_CMD:
283
284 TOOLSET := target
285 # Suffix rules, putting all outputs into $(obj).
286 $(obj).$(TOOLSET)/%.o: $(srcdir)/%.c FORCE_DO_CMD
287 @$(call do_cmd,cc,1)
288 $(obj).$(TOOLSET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD
289 @$(call do_cmd,cxx,1)
290 $(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD
291 @$(call do_cmd,cxx,1)
292 $(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD
293 @$(call do_cmd,cxx,1)
294 $(obj).$(TOOLSET)/%.o: $(srcdir)/%.m FORCE_DO_CMD
295 @$(call do_cmd,objc,1)
296 $(obj).$(TOOLSET)/%.o: $(srcdir)/%.mm FORCE_DO_CMD
297 @$(call do_cmd,objcxx,1)
298 $(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD
299 @$(call do_cmd,cc,1)
300 $(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD
301 @$(call do_cmd,cc,1)
302
303 # Try building from generated source, too.
304 $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD
305 @$(call do_cmd,cc,1)
306 $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD
307 @$(call do_cmd,cxx,1)
308 $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD
309 @$(call do_cmd,cxx,1)
310 $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD
311 @$(call do_cmd,cxx,1)
312 $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.m FORCE_DO_CMD
313 @$(call do_cmd,objc,1)
314 $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.mm FORCE_DO_CMD
315 @$(call do_cmd,objcxx,1)
316 $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD
317 @$(call do_cmd,cc,1)
318 $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD
319 @$(call do_cmd,cc,1)
320
321 $(obj).$(TOOLSET)/%.o: $(obj)/%.c FORCE_DO_CMD
322 @$(call do_cmd,cc,1)
323 $(obj).$(TOOLSET)/%.o: $(obj)/%.cc FORCE_DO_CMD
324 @$(call do_cmd,cxx,1)
325 $(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD
326 @$(call do_cmd,cxx,1)
327 $(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD
328 @$(call do_cmd,cxx,1)
329 $(obj).$(TOOLSET)/%.o: $(obj)/%.m FORCE_DO_CMD
330 @$(call do_cmd,objc,1)
331 $(obj).$(TOOLSET)/%.o: $(obj)/%.mm FORCE_DO_CMD
332 @$(call do_cmd,objcxx,1)
333 $(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD
334 @$(call do_cmd,cc,1)
335 $(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD
336 @$(call do_cmd,cc,1)
337
338
339 ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
340 $(findstring $(join ^,$(prefix)),\
341 $(join ^,contextify.target.mk)))),)
342 include contextify.target.mk
343 endif
344
345 quiet_cmd_regen_makefile = ACTION Regenerating $@
346 cmd_regen_makefile = /Users/toby/.node-gyp/0.8.11/tools/gyp/gyp -fmake --ignore-environment "--toplevel-dir=." -I/Users/toby/Documents/shell/nodebot/node_modules/jsdom/node_modules/contextify/build/config.gypi -I/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/Users/toby/.node-gyp/0.8.11/common.gypi "--depth=." "-Goutput_dir=." "--generator-output=build" "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/toby/.node-gyp/0.8.11" "-Dmodule_root_dir=/Users/toby/Documents/shell/nodebot/node_modules/jsdom/node_modules/contextify" binding.gyp
347 Makefile: $(srcdir)/../../../../../../../../../usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi $(srcdir)/build/config.gypi $(srcdir)/binding.gyp $(srcdir)/../../../../../../../.node-gyp/0.8.11/common.gypi
348 $(call do_cmd,regen_makefile)
349
350 # "all" is a concatenation of the "all" targets from all the included
351 # sub-makefiles. This is just here to clarify.
352 all:
353
354 # Add in dependency-tracking rules. $(all_deps) is the list of every single
355 # target in our tree. Only consider the ones with .d (dependency) info:
356 d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d))
357 ifneq ($(d_files),)
358 include $(d_files)
359 endif