Makefile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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_touch = TOUCH $@
  111. cmd_touch = touch $@
  112. quiet_cmd_copy = COPY $@
  113. # send stderr to /dev/null to ignore messages when linking directories.
  114. cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp -af "$<" "$@")
  115. quiet_cmd_symlink = SYMLINK $@
  116. cmd_symlink = ln -sf "$<" "$@"
  117. quiet_cmd_alink = AR($(TOOLSET)) $@
  118. cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
  119. quiet_cmd_alink_thin = AR($(TOOLSET)) $@
  120. cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
  121. # Due to circular dependencies between libraries :(, we wrap the
  122. # special "figure out circular dependencies" flags around the entire
  123. # input list during linking.
  124. quiet_cmd_link = LINK($(TOOLSET)) $@
  125. cmd_link = $(LINK.$(TOOLSET)) -o $@ $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
  126. # Note: this does not handle spaces in paths
  127. define xargs
  128. $(1) $(word 1,$(2))
  129. $(if $(word 2,$(2)),$(call xargs,$(1),$(wordlist 2,$(words $(2)),$(2))))
  130. endef
  131. define write-to-file
  132. @: >$(1)
  133. $(call xargs,@printf "%s\n" >>$(1),$(2))
  134. endef
  135. OBJ_FILE_LIST := ar-file-list
  136. define create_archive
  137. rm -f $(1) $(1).$(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
  138. $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
  139. $(AR.$(TOOLSET)) crs $(1) @$(1).$(OBJ_FILE_LIST)
  140. endef
  141. define create_thin_archive
  142. rm -f $(1) $(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
  143. $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
  144. $(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST)
  145. endef
  146. # We support two kinds of shared objects (.so):
  147. # 1) shared_library, which is just bundling together many dependent libraries
  148. # into a link line.
  149. # 2) loadable_module, which is generating a module intended for dlopen().
  150. #
  151. # They differ only slightly:
  152. # In the former case, we want to package all dependent code into the .so.
  153. # In the latter case, we want to package just the API exposed by the
  154. # outermost module.
  155. # This means shared_library uses --whole-archive, while loadable_module doesn't.
  156. # (Note that --whole-archive is incompatible with the --start-group used in
  157. # normal linking.)
  158. # Other shared-object link notes:
  159. # - Set SONAME to the library filename so our binaries don't reference
  160. # the local, absolute paths used on the link command-line.
  161. quiet_cmd_solink = SOLINK($(TOOLSET)) $@
  162. cmd_solink = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
  163. quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
  164. cmd_solink_module = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
  165. # Define an escape_quotes function to escape single quotes.
  166. # This allows us to handle quotes properly as long as we always use
  167. # use single quotes and escape_quotes.
  168. escape_quotes = $(subst ','\'',$(1))
  169. # This comment is here just to include a ' to unconfuse syntax highlighting.
  170. # Define an escape_vars function to escape '$' variable syntax.
  171. # This allows us to read/write command lines with shell variables (e.g.
  172. # $LD_LIBRARY_PATH), without triggering make substitution.
  173. escape_vars = $(subst $$,$$$$,$(1))
  174. # Helper that expands to a shell command to echo a string exactly as it is in
  175. # make. This uses printf instead of echo because printf's behaviour with respect
  176. # to escape sequences is more portable than echo's across different shells
  177. # (e.g., dash, bash).
  178. exact_echo = printf '%s\n' '$(call escape_quotes,$(1))'
  179. # Helper to compare the command we're about to run against the command
  180. # we logged the last time we ran the command. Produces an empty
  181. # string (false) when the commands match.
  182. # Tricky point: Make has no string-equality test function.
  183. # The kernel uses the following, but it seems like it would have false
  184. # positives, where one string reordered its arguments.
  185. # arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
  186. # $(filter-out $(cmd_$@), $(cmd_$(1))))
  187. # We instead substitute each for the empty string into the other, and
  188. # say they're equal if both substitutions produce the empty string.
  189. # .d files contain ? instead of spaces, take that into account.
  190. command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\
  191. $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1))))
  192. # Helper that is non-empty when a prerequisite changes.
  193. # Normally make does this implicitly, but we force rules to always run
  194. # so we can check their command lines.
  195. # $? -- new prerequisites
  196. # $| -- order-only dependencies
  197. prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?))
  198. # Helper that executes all postbuilds until one fails.
  199. define do_postbuilds
  200. @E=0;\
  201. for p in $(POSTBUILDS); do\
  202. eval $$p;\
  203. E=$$?;\
  204. if [ $$E -ne 0 ]; then\
  205. break;\
  206. fi;\
  207. done;\
  208. if [ $$E -ne 0 ]; then\
  209. rm -rf "$@";\
  210. exit $$E;\
  211. fi
  212. endef
  213. # do_cmd: run a command via the above cmd_foo names, if necessary.
  214. # Should always run for a given target to handle command-line changes.
  215. # Second argument, if non-zero, makes it do asm/C/C++ dependency munging.
  216. # Third argument, if non-zero, makes it do POSTBUILDS processing.
  217. # Note: We intentionally do NOT call dirx for depfile, since it contains ? for
  218. # spaces already and dirx strips the ? characters.
  219. define do_cmd
  220. $(if $(or $(command_changed),$(prereq_changed)),
  221. @$(call exact_echo, $($(quiet)cmd_$(1)))
  222. @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))"
  223. $(if $(findstring flock,$(word 1,$(cmd_$1))),
  224. @$(cmd_$(1))
  225. @echo " $(quiet_cmd_$(1)): Finished",
  226. @$(cmd_$(1))
  227. )
  228. @$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile)
  229. @$(if $(2),$(fixup_dep))
  230. $(if $(and $(3), $(POSTBUILDS)),
  231. $(call do_postbuilds)
  232. )
  233. )
  234. endef
  235. # Declare the "all" target first so it is the default,
  236. # even though we don't have the deps yet.
  237. .PHONY: all
  238. all:
  239. # make looks for ways to re-generate included makefiles, but in our case, we
  240. # don't have a direct way. Explicitly telling make that it has nothing to do
  241. # for them makes it go faster.
  242. %.d: ;
  243. # Use FORCE_DO_CMD to force a target to run. Should be coupled with
  244. # do_cmd.
  245. .PHONY: FORCE_DO_CMD
  246. FORCE_DO_CMD:
  247. TOOLSET := target
  248. # Suffix rules, putting all outputs into $(obj).
  249. $(obj).$(TOOLSET)/%.o: $(srcdir)/%.c FORCE_DO_CMD
  250. @$(call do_cmd,cc,1)
  251. $(obj).$(TOOLSET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD
  252. @$(call do_cmd,cxx,1)
  253. $(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD
  254. @$(call do_cmd,cxx,1)
  255. $(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD
  256. @$(call do_cmd,cxx,1)
  257. $(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD
  258. @$(call do_cmd,cc,1)
  259. $(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD
  260. @$(call do_cmd,cc,1)
  261. # Try building from generated source, too.
  262. $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD
  263. @$(call do_cmd,cc,1)
  264. $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD
  265. @$(call do_cmd,cxx,1)
  266. $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD
  267. @$(call do_cmd,cxx,1)
  268. $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD
  269. @$(call do_cmd,cxx,1)
  270. $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD
  271. @$(call do_cmd,cc,1)
  272. $(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD
  273. @$(call do_cmd,cc,1)
  274. $(obj).$(TOOLSET)/%.o: $(obj)/%.c FORCE_DO_CMD
  275. @$(call do_cmd,cc,1)
  276. $(obj).$(TOOLSET)/%.o: $(obj)/%.cc FORCE_DO_CMD
  277. @$(call do_cmd,cxx,1)
  278. $(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD
  279. @$(call do_cmd,cxx,1)
  280. $(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD
  281. @$(call do_cmd,cxx,1)
  282. $(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD
  283. @$(call do_cmd,cc,1)
  284. $(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD
  285. @$(call do_cmd,cc,1)
  286. ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
  287. $(findstring $(join ^,$(prefix)),\
  288. $(join ^,better_sqlite3.target.mk)))),)
  289. include better_sqlite3.target.mk
  290. endif
  291. ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
  292. $(findstring $(join ^,$(prefix)),\
  293. $(join ^,deps/locate_sqlite3.target.mk)))),)
  294. include deps/locate_sqlite3.target.mk
  295. endif
  296. ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
  297. $(findstring $(join ^,$(prefix)),\
  298. $(join ^,deps/sqlite3.target.mk)))),)
  299. include deps/sqlite3.target.mk
  300. endif
  301. ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
  302. $(findstring $(join ^,$(prefix)),\
  303. $(join ^,test_extension.target.mk)))),)
  304. include test_extension.target.mk
  305. endif
  306. quiet_cmd_regen_makefile = ACTION Regenerating $@
  307. cmd_regen_makefile = cd $(srcdir); /usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/root/.cache/node-gyp/22.22.2" "-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/root/.cache/node-gyp/22.22.2/<(target_arch)/node.lib" "-Dmodule_root_dir=/root/.openclaw/workspace/ssl-manager/backend/node_modules/better-sqlite3" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/root/.openclaw/workspace/ssl-manager/backend/node_modules/better-sqlite3/build/config.gypi -I/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/root/.cache/node-gyp/22.22.2/include/node/common.gypi "--toplevel-dir=." binding.gyp
  308. Makefile: $(srcdir)/../../../../../../../usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi $(srcdir)/../../../../../../.cache/node-gyp/22.22.2/include/node/common.gypi $(srcdir)/binding.gyp $(srcdir)/build/config.gypi $(srcdir)/deps/common.gypi $(srcdir)/deps/defines.gypi $(srcdir)/deps/sqlite3.gyp
  309. $(call do_cmd,regen_makefile)
  310. # "all" is a concatenation of the "all" targets from all the included
  311. # sub-makefiles. This is just here to clarify.
  312. all:
  313. # Add in dependency-tracking rules. $(all_deps) is the list of every single
  314. # target in our tree. Only consider the ones with .d (dependency) info:
  315. d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d))
  316. ifneq ($(d_files),)
  317. include $(d_files)
  318. endif