Makefile 14 KB

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