Makefile 13 KB

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