wsba-hockey 1.0.2__py3-none-any.whl → 1.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. wsba_hockey/data_pipelines.py +183 -0
  2. wsba_hockey/evidence/weakside-breakout/node_modules/duckdb/vendor.py +146 -0
  3. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/flatted.py +149 -0
  4. wsba_hockey/evidence/weakside-breakout/node_modules/flatted/python/test.py +63 -0
  5. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  6. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  7. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  8. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  9. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  10. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  11. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  12. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  13. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  14. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +690 -0
  15. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common.py +661 -0
  16. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  17. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  18. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  19. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  20. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  21. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  22. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  23. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  24. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  25. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  26. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  27. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  28. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  29. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2714 -0
  30. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3981 -0
  31. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  32. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  33. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  34. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  35. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  36. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input.py +3130 -0
  37. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  38. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  39. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  40. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  41. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  42. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  43. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  44. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  45. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  46. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  47. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  48. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  49. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  50. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  51. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  52. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  53. wsba_hockey/evidence/weakside-breakout/node_modules/node-gyp/update-gyp.py +64 -0
  54. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  55. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +367 -0
  56. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  57. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1270 -0
  58. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  59. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  60. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  61. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  62. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  63. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +666 -0
  64. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common.py +654 -0
  65. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +78 -0
  66. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +165 -0
  67. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +109 -0
  68. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  69. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  70. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +808 -0
  71. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  72. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1321 -0
  73. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +120 -0
  74. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  75. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +464 -0
  76. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  77. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +58 -0
  78. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2518 -0
  79. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3978 -0
  80. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  81. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2936 -0
  82. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +55 -0
  83. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1394 -0
  84. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  85. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input.py +3137 -0
  86. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  87. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  88. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1271 -0
  89. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  90. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  91. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +374 -0
  92. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  93. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  94. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3197 -0
  95. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  96. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/setup.py +42 -0
  97. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/test_gyp.py +260 -0
  98. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/graphviz.py +102 -0
  99. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_gyp.py +156 -0
  100. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_sln.py +181 -0
  101. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/gyp/tools/pretty_vcproj.py +339 -0
  102. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/test/fixtures/test-charmap.py +31 -0
  103. wsba_hockey/evidence/weakside-breakout/node_modules/sqlite3/node_modules/node-gyp/update-gyp.py +46 -0
  104. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/app.py +401 -0
  105. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/game_stats/name_fix.py +47 -0
  106. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/app.py +108 -0
  107. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/plot.py +93 -0
  108. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/heatmaps/rink_plot.py +245 -0
  109. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/app.py +145 -0
  110. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/plot.py +77 -0
  111. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/matchups/rink_plot.py +245 -0
  112. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/app.py +389 -0
  113. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/plot.py +70 -0
  114. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/pbp/rink_plot.py +245 -0
  115. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/app.py +110 -0
  116. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/plot.py +58 -0
  117. wsba_hockey/evidence/weakside-breakout/wsba_nhl_apps/wsba_nhl_apps/skater/rink_plot.py +245 -0
  118. wsba_hockey/tools/agg.py +242 -53
  119. wsba_hockey/tools/plotting.py +15 -20
  120. wsba_hockey/tools/scraping.py +149 -258
  121. wsba_hockey/tools/xg_model.py +370 -298
  122. wsba_hockey/workspace.py +22 -101
  123. wsba_hockey/wsba_main.py +494 -147
  124. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/METADATA +2 -2
  125. wsba_hockey-1.0.4.dist-info/RECORD +135 -0
  126. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/WHEEL +1 -1
  127. wsba_hockey/stats/calculate_viz/shot_impact.py +0 -2
  128. wsba_hockey-1.0.2.dist-info/RECORD +0 -19
  129. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/licenses/LICENSE +0 -0
  130. {wsba_hockey-1.0.2.dist-info → wsba_hockey-1.0.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,2714 @@
1
+ # Copyright (c) 2013 Google Inc. All rights reserved.
2
+ # Use of this source code is governed by a BSD-style license that can be
3
+ # found in the LICENSE file.
4
+
5
+ # Notes:
6
+ #
7
+ # This is all roughly based on the Makefile system used by the Linux
8
+ # kernel, but is a non-recursive make -- we put the entire dependency
9
+ # graph in front of make and let it figure it out.
10
+ #
11
+ # The code below generates a separate .mk file for each target, but
12
+ # all are sourced by the top-level Makefile. This means that all
13
+ # variables in .mk-files clobber one another. Be careful to use :=
14
+ # where appropriate for immediate evaluation, and similarly to watch
15
+ # that you're not relying on a variable value to last between different
16
+ # .mk files.
17
+ #
18
+ # TODOs:
19
+ #
20
+ # Global settings and utility functions are currently stuffed in the
21
+ # toplevel Makefile. It may make sense to generate some .mk files on
22
+ # the side to keep the files readable.
23
+
24
+
25
+ import os
26
+ import re
27
+ import subprocess
28
+ import gyp
29
+ import gyp.common
30
+ import gyp.xcode_emulation
31
+ from gyp.common import GetEnvironFallback
32
+
33
+ import hashlib
34
+
35
+ generator_default_variables = {
36
+ "EXECUTABLE_PREFIX": "",
37
+ "EXECUTABLE_SUFFIX": "",
38
+ "STATIC_LIB_PREFIX": "lib",
39
+ "SHARED_LIB_PREFIX": "lib",
40
+ "STATIC_LIB_SUFFIX": ".a",
41
+ "INTERMEDIATE_DIR": "$(obj).$(TOOLSET)/$(TARGET)/geni",
42
+ "SHARED_INTERMEDIATE_DIR": "$(obj)/gen",
43
+ "PRODUCT_DIR": "$(builddir)",
44
+ "RULE_INPUT_ROOT": "%(INPUT_ROOT)s", # This gets expanded by Python.
45
+ "RULE_INPUT_DIRNAME": "%(INPUT_DIRNAME)s", # This gets expanded by Python.
46
+ "RULE_INPUT_PATH": "$(abspath $<)",
47
+ "RULE_INPUT_EXT": "$(suffix $<)",
48
+ "RULE_INPUT_NAME": "$(notdir $<)",
49
+ "CONFIGURATION_NAME": "$(BUILDTYPE)",
50
+ }
51
+
52
+ # Make supports multiple toolsets
53
+ generator_supports_multiple_toolsets = gyp.common.CrossCompileRequested()
54
+
55
+ # Request sorted dependencies in the order from dependents to dependencies.
56
+ generator_wants_sorted_dependencies = False
57
+
58
+ # Placates pylint.
59
+ generator_additional_non_configuration_keys = []
60
+ generator_additional_path_sections = []
61
+ generator_extra_sources_for_rules = []
62
+ generator_filelist_paths = None
63
+
64
+
65
+ def CalculateVariables(default_variables, params):
66
+ """Calculate additional variables for use in the build (called by gyp)."""
67
+ flavor = gyp.common.GetFlavor(params)
68
+ if flavor == "mac":
69
+ default_variables.setdefault("OS", "mac")
70
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".dylib")
71
+ default_variables.setdefault(
72
+ "SHARED_LIB_DIR", generator_default_variables["PRODUCT_DIR"]
73
+ )
74
+ default_variables.setdefault(
75
+ "LIB_DIR", generator_default_variables["PRODUCT_DIR"]
76
+ )
77
+
78
+ # Copy additional generator configuration data from Xcode, which is shared
79
+ # by the Mac Make generator.
80
+ import gyp.generator.xcode as xcode_generator
81
+
82
+ global generator_additional_non_configuration_keys
83
+ generator_additional_non_configuration_keys = getattr(
84
+ xcode_generator, "generator_additional_non_configuration_keys", []
85
+ )
86
+ global generator_additional_path_sections
87
+ generator_additional_path_sections = getattr(
88
+ xcode_generator, "generator_additional_path_sections", []
89
+ )
90
+ global generator_extra_sources_for_rules
91
+ generator_extra_sources_for_rules = getattr(
92
+ xcode_generator, "generator_extra_sources_for_rules", []
93
+ )
94
+ COMPILABLE_EXTENSIONS.update({".m": "objc", ".mm": "objcxx"})
95
+ else:
96
+ operating_system = flavor
97
+ if flavor == "android":
98
+ operating_system = "linux" # Keep this legacy behavior for now.
99
+ default_variables.setdefault("OS", operating_system)
100
+ if flavor == "aix":
101
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".a")
102
+ elif flavor == "zos":
103
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".x")
104
+ COMPILABLE_EXTENSIONS.update({".pli": "pli"})
105
+ else:
106
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".so")
107
+ default_variables.setdefault("SHARED_LIB_DIR", "$(builddir)/lib.$(TOOLSET)")
108
+ default_variables.setdefault("LIB_DIR", "$(obj).$(TOOLSET)")
109
+
110
+
111
+ def CalculateGeneratorInputInfo(params):
112
+ """Calculate the generator specific info that gets fed to input (called by
113
+ gyp)."""
114
+ generator_flags = params.get("generator_flags", {})
115
+ android_ndk_version = generator_flags.get("android_ndk_version", None)
116
+ # Android NDK requires a strict link order.
117
+ if android_ndk_version:
118
+ global generator_wants_sorted_dependencies
119
+ generator_wants_sorted_dependencies = True
120
+
121
+ output_dir = params["options"].generator_output or params["options"].toplevel_dir
122
+ builddir_name = generator_flags.get("output_dir", "out")
123
+ qualified_out_dir = os.path.normpath(
124
+ os.path.join(output_dir, builddir_name, "gypfiles")
125
+ )
126
+
127
+ global generator_filelist_paths
128
+ generator_filelist_paths = {
129
+ "toplevel": params["options"].toplevel_dir,
130
+ "qualified_out_dir": qualified_out_dir,
131
+ }
132
+
133
+
134
+ # The .d checking code below uses these functions:
135
+ # wildcard, sort, foreach, shell, wordlist
136
+ # wildcard can handle spaces, the rest can't.
137
+ # Since I could find no way to make foreach work with spaces in filenames
138
+ # correctly, the .d files have spaces replaced with another character. The .d
139
+ # file for
140
+ # Chromium\ Framework.framework/foo
141
+ # is for example
142
+ # out/Release/.deps/out/Release/Chromium?Framework.framework/foo
143
+ # This is the replacement character.
144
+ SPACE_REPLACEMENT = "?"
145
+
146
+
147
+ LINK_COMMANDS_LINUX = """\
148
+ quiet_cmd_alink = AR($(TOOLSET)) $@
149
+ cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
150
+
151
+ quiet_cmd_alink_thin = AR($(TOOLSET)) $@
152
+ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
153
+
154
+ # Due to circular dependencies between libraries :(, we wrap the
155
+ # special "figure out circular dependencies" flags around the entire
156
+ # input list during linking.
157
+ quiet_cmd_link = LINK($(TOOLSET)) $@
158
+ cmd_link = $(LINK.$(TOOLSET)) -o $@ $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
159
+
160
+ # Note: this does not handle spaces in paths
161
+ define xargs
162
+ $(1) $(word 1,$(2))
163
+ $(if $(word 2,$(2)),$(call xargs,$(1),$(wordlist 2,$(words $(2)),$(2))))
164
+ endef
165
+
166
+ define write-to-file
167
+ @: >$(1)
168
+ $(call xargs,@printf "%s\\n" >>$(1),$(2))
169
+ endef
170
+
171
+ OBJ_FILE_LIST := ar-file-list
172
+
173
+ define create_archive
174
+ rm -f $(1) $(1).$(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
175
+ $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
176
+ $(AR.$(TOOLSET)) crs $(1) @$(1).$(OBJ_FILE_LIST)
177
+ endef
178
+
179
+ define create_thin_archive
180
+ rm -f $(1) $(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
181
+ $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
182
+ $(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST)
183
+ endef
184
+
185
+ # We support two kinds of shared objects (.so):
186
+ # 1) shared_library, which is just bundling together many dependent libraries
187
+ # into a link line.
188
+ # 2) loadable_module, which is generating a module intended for dlopen().
189
+ #
190
+ # They differ only slightly:
191
+ # In the former case, we want to package all dependent code into the .so.
192
+ # In the latter case, we want to package just the API exposed by the
193
+ # outermost module.
194
+ # This means shared_library uses --whole-archive, while loadable_module doesn't.
195
+ # (Note that --whole-archive is incompatible with the --start-group used in
196
+ # normal linking.)
197
+
198
+ # Other shared-object link notes:
199
+ # - Set SONAME to the library filename so our binaries don't reference
200
+ # the local, absolute paths used on the link command-line.
201
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
202
+ cmd_solink = $(LINK.$(TOOLSET)) -o $@ -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
203
+
204
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
205
+ 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)
206
+ """ # noqa: E501
207
+
208
+ LINK_COMMANDS_MAC = """\
209
+ quiet_cmd_alink = LIBTOOL-STATIC $@
210
+ cmd_alink = rm -f $@ && ./gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^)
211
+
212
+ quiet_cmd_link = LINK($(TOOLSET)) $@
213
+ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
214
+
215
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
216
+ cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
217
+
218
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
219
+ cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
220
+ """ # noqa: E501
221
+
222
+ LINK_COMMANDS_ANDROID = """\
223
+ quiet_cmd_alink = AR($(TOOLSET)) $@
224
+ cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
225
+
226
+ quiet_cmd_alink_thin = AR($(TOOLSET)) $@
227
+ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
228
+
229
+ # Note: this does not handle spaces in paths
230
+ define xargs
231
+ $(1) $(word 1,$(2))
232
+ $(if $(word 2,$(2)),$(call xargs,$(1),$(wordlist 2,$(words $(2)),$(2))))
233
+ endef
234
+
235
+ define write-to-file
236
+ @: >$(1)
237
+ $(call xargs,@printf "%s\\n" >>$(1),$(2))
238
+ endef
239
+
240
+ OBJ_FILE_LIST := ar-file-list
241
+
242
+ define create_archive
243
+ rm -f $(1) $(1).$(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
244
+ $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
245
+ $(AR.$(TOOLSET)) crs $(1) @$(1).$(OBJ_FILE_LIST)
246
+ endef
247
+
248
+ define create_thin_archive
249
+ rm -f $(1) $(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
250
+ $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
251
+ $(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST)
252
+ endef
253
+
254
+ # Due to circular dependencies between libraries :(, we wrap the
255
+ # special "figure out circular dependencies" flags around the entire
256
+ # input list during linking.
257
+ quiet_cmd_link = LINK($(TOOLSET)) $@
258
+ quiet_cmd_link_host = LINK($(TOOLSET)) $@
259
+ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
260
+ cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
261
+
262
+ # Other shared-object link notes:
263
+ # - Set SONAME to the library filename so our binaries don't reference
264
+ # the local, absolute paths used on the link command-line.
265
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
266
+ cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
267
+
268
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
269
+ cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
270
+ quiet_cmd_solink_module_host = SOLINK_MODULE($(TOOLSET)) $@
271
+ cmd_solink_module_host = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
272
+ """ # noqa: E501
273
+
274
+
275
+ LINK_COMMANDS_AIX = """\
276
+ quiet_cmd_alink = AR($(TOOLSET)) $@
277
+ cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) -X32_64 crs $@ $(filter %.o,$^)
278
+
279
+ quiet_cmd_alink_thin = AR($(TOOLSET)) $@
280
+ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) -X32_64 crs $@ $(filter %.o,$^)
281
+
282
+ quiet_cmd_link = LINK($(TOOLSET)) $@
283
+ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
284
+
285
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
286
+ cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
287
+
288
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
289
+ cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
290
+ """ # noqa: E501
291
+
292
+
293
+ LINK_COMMANDS_OS400 = """\
294
+ quiet_cmd_alink = AR($(TOOLSET)) $@
295
+ cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) -X64 crs $@ $(filter %.o,$^)
296
+
297
+ quiet_cmd_alink_thin = AR($(TOOLSET)) $@
298
+ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) -X64 crs $@ $(filter %.o,$^)
299
+
300
+ quiet_cmd_link = LINK($(TOOLSET)) $@
301
+ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
302
+
303
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
304
+ cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
305
+
306
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
307
+ cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
308
+ """ # noqa: E501
309
+
310
+
311
+ LINK_COMMANDS_OS390 = """\
312
+ quiet_cmd_alink = AR($(TOOLSET)) $@
313
+ cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
314
+
315
+ quiet_cmd_alink_thin = AR($(TOOLSET)) $@
316
+ cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
317
+
318
+ quiet_cmd_link = LINK($(TOOLSET)) $@
319
+ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
320
+
321
+ quiet_cmd_solink = SOLINK($(TOOLSET)) $@
322
+ cmd_solink = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
323
+
324
+ quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
325
+ cmd_solink_module = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
326
+ """ # noqa: E501
327
+
328
+
329
+ # Header of toplevel Makefile.
330
+ # This should go into the build tree, but it's easier to keep it here for now.
331
+ SHARED_HEADER = (
332
+ """\
333
+ # We borrow heavily from the kernel build setup, though we are simpler since
334
+ # we don't have Kconfig tweaking settings on us.
335
+
336
+ # The implicit make rules have it looking for RCS files, among other things.
337
+ # We instead explicitly write all the rules we care about.
338
+ # It's even quicker (saves ~200ms) to pass -r on the command line.
339
+ MAKEFLAGS=-r
340
+
341
+ # The source directory tree.
342
+ srcdir := %(srcdir)s
343
+ abs_srcdir := $(abspath $(srcdir))
344
+
345
+ # The name of the builddir.
346
+ builddir_name ?= %(builddir)s
347
+
348
+ # The V=1 flag on command line makes us verbosely print command lines.
349
+ ifdef V
350
+ quiet=
351
+ else
352
+ quiet=quiet_
353
+ endif
354
+
355
+ # Specify BUILDTYPE=Release on the command line for a release build.
356
+ BUILDTYPE ?= %(default_configuration)s
357
+
358
+ # Directory all our build output goes into.
359
+ # Note that this must be two directories beneath src/ for unit tests to pass,
360
+ # as they reach into the src/ directory for data with relative paths.
361
+ builddir ?= $(builddir_name)/$(BUILDTYPE)
362
+ abs_builddir := $(abspath $(builddir))
363
+ depsdir := $(builddir)/.deps
364
+
365
+ # Object output directory.
366
+ obj := $(builddir)/obj
367
+ abs_obj := $(abspath $(obj))
368
+
369
+ # We build up a list of every single one of the targets so we can slurp in the
370
+ # generated dependency rule Makefiles in one pass.
371
+ all_deps :=
372
+
373
+ %(make_global_settings)s
374
+
375
+ CC.target ?= %(CC.target)s
376
+ CFLAGS.target ?= $(CPPFLAGS) $(CFLAGS)
377
+ CXX.target ?= %(CXX.target)s
378
+ CXXFLAGS.target ?= $(CPPFLAGS) $(CXXFLAGS)
379
+ LINK.target ?= %(LINK.target)s
380
+ LDFLAGS.target ?= $(LDFLAGS)
381
+ AR.target ?= $(AR)
382
+ PLI.target ?= %(PLI.target)s
383
+
384
+ # C++ apps need to be linked with g++.
385
+ LINK ?= $(CXX.target)
386
+
387
+ # TODO(evan): move all cross-compilation logic to gyp-time so we don't need
388
+ # to replicate this environment fallback in make as well.
389
+ CC.host ?= %(CC.host)s
390
+ CFLAGS.host ?= $(CPPFLAGS_host) $(CFLAGS_host)
391
+ CXX.host ?= %(CXX.host)s
392
+ CXXFLAGS.host ?= $(CPPFLAGS_host) $(CXXFLAGS_host)
393
+ LINK.host ?= %(LINK.host)s
394
+ LDFLAGS.host ?= $(LDFLAGS_host)
395
+ AR.host ?= %(AR.host)s
396
+ PLI.host ?= %(PLI.host)s
397
+
398
+ # Define a dir function that can handle spaces.
399
+ # http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions
400
+ # "leading spaces cannot appear in the text of the first argument as written.
401
+ # These characters can be put into the argument value by variable substitution."
402
+ empty :=
403
+ space := $(empty) $(empty)
404
+
405
+ # http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces
406
+ replace_spaces = $(subst $(space),"""
407
+ + SPACE_REPLACEMENT
408
+ + """,$1)
409
+ unreplace_spaces = $(subst """
410
+ + SPACE_REPLACEMENT
411
+ + """,$(space),$1)
412
+ dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1)))
413
+
414
+ # Flags to make gcc output dependency info. Note that you need to be
415
+ # careful here to use the flags that ccache and distcc can understand.
416
+ # We write to a dep file on the side first and then rename at the end
417
+ # so we can't end up with a broken dep file.
418
+ depfile = $(depsdir)/$(call replace_spaces,$@).d
419
+ DEPFLAGS = %(makedep_args)s -MF $(depfile).raw
420
+
421
+ # We have to fixup the deps output in a few ways.
422
+ # (1) the file output should mention the proper .o file.
423
+ # ccache or distcc lose the path to the target, so we convert a rule of
424
+ # the form:
425
+ # foobar.o: DEP1 DEP2
426
+ # into
427
+ # path/to/foobar.o: DEP1 DEP2
428
+ # (2) we want missing files not to cause us to fail to build.
429
+ # We want to rewrite
430
+ # foobar.o: DEP1 DEP2 \\
431
+ # DEP3
432
+ # to
433
+ # DEP1:
434
+ # DEP2:
435
+ # DEP3:
436
+ # so if the files are missing, they're just considered phony rules.
437
+ # We have to do some pretty insane escaping to get those backslashes
438
+ # and dollar signs past make, the shell, and sed at the same time.
439
+ # Doesn't work with spaces, but that's fine: .d files have spaces in
440
+ # their names replaced with other characters."""
441
+ r"""
442
+ define fixup_dep
443
+ # The depfile may not exist if the input file didn't have any #includes.
444
+ touch $(depfile).raw
445
+ # Fixup path as in (1).
446
+ sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile)
447
+ # Add extra rules as in (2).
448
+ # We remove slashes and replace spaces with new lines;
449
+ # remove blank lines;
450
+ # delete the first line and append a colon to the remaining lines.
451
+ sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\
452
+ grep -v '^$$' |\
453
+ sed -e 1d -e 's|$$|:|' \
454
+ >> $(depfile)
455
+ rm $(depfile).raw
456
+ endef
457
+ """
458
+ """
459
+ # Command definitions:
460
+ # - cmd_foo is the actual command to run;
461
+ # - quiet_cmd_foo is the brief-output summary of the command.
462
+
463
+ quiet_cmd_cc = CC($(TOOLSET)) $@
464
+ cmd_cc = $(CC.$(TOOLSET)) -o $@ $< $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c
465
+
466
+ quiet_cmd_cxx = CXX($(TOOLSET)) $@
467
+ cmd_cxx = $(CXX.$(TOOLSET)) -o $@ $< $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c
468
+ %(extra_commands)s
469
+ quiet_cmd_touch = TOUCH $@
470
+ cmd_touch = touch $@
471
+
472
+ quiet_cmd_copy = COPY $@
473
+ # send stderr to /dev/null to ignore messages when linking directories.
474
+ cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp %(copy_archive_args)s "$<" "$@")
475
+
476
+ quiet_cmd_symlink = SYMLINK $@
477
+ cmd_symlink = ln -sf "$<" "$@"
478
+
479
+ %(link_commands)s
480
+ """ # noqa: E501
481
+ r"""
482
+ # Define an escape_quotes function to escape single quotes.
483
+ # This allows us to handle quotes properly as long as we always use
484
+ # use single quotes and escape_quotes.
485
+ escape_quotes = $(subst ','\'',$(1))
486
+ # This comment is here just to include a ' to unconfuse syntax highlighting.
487
+ # Define an escape_vars function to escape '$' variable syntax.
488
+ # This allows us to read/write command lines with shell variables (e.g.
489
+ # $LD_LIBRARY_PATH), without triggering make substitution.
490
+ escape_vars = $(subst $$,$$$$,$(1))
491
+ # Helper that expands to a shell command to echo a string exactly as it is in
492
+ # make. This uses printf instead of echo because printf's behaviour with respect
493
+ # to escape sequences is more portable than echo's across different shells
494
+ # (e.g., dash, bash).
495
+ exact_echo = printf '%%s\n' '$(call escape_quotes,$(1))'
496
+ """
497
+ """
498
+ # Helper to compare the command we're about to run against the command
499
+ # we logged the last time we ran the command. Produces an empty
500
+ # string (false) when the commands match.
501
+ # Tricky point: Make has no string-equality test function.
502
+ # The kernel uses the following, but it seems like it would have false
503
+ # positives, where one string reordered its arguments.
504
+ # arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \\
505
+ # $(filter-out $(cmd_$@), $(cmd_$(1))))
506
+ # We instead substitute each for the empty string into the other, and
507
+ # say they're equal if both substitutions produce the empty string.
508
+ # .d files contain """
509
+ + SPACE_REPLACEMENT
510
+ + """ instead of spaces, take that into account.
511
+ command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\\
512
+ $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1))))
513
+
514
+ # Helper that is non-empty when a prerequisite changes.
515
+ # Normally make does this implicitly, but we force rules to always run
516
+ # so we can check their command lines.
517
+ # $? -- new prerequisites
518
+ # $| -- order-only dependencies
519
+ prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?))
520
+
521
+ # Helper that executes all postbuilds until one fails.
522
+ define do_postbuilds
523
+ @E=0;\\
524
+ for p in $(POSTBUILDS); do\\
525
+ eval $$p;\\
526
+ E=$$?;\\
527
+ if [ $$E -ne 0 ]; then\\
528
+ break;\\
529
+ fi;\\
530
+ done;\\
531
+ if [ $$E -ne 0 ]; then\\
532
+ rm -rf "$@";\\
533
+ exit $$E;\\
534
+ fi
535
+ endef
536
+
537
+ # do_cmd: run a command via the above cmd_foo names, if necessary.
538
+ # Should always run for a given target to handle command-line changes.
539
+ # Second argument, if non-zero, makes it do asm/C/C++ dependency munging.
540
+ # Third argument, if non-zero, makes it do POSTBUILDS processing.
541
+ # Note: We intentionally do NOT call dirx for depfile, since it contains """
542
+ + SPACE_REPLACEMENT
543
+ + """ for
544
+ # spaces already and dirx strips the """
545
+ + SPACE_REPLACEMENT
546
+ + """ characters.
547
+ define do_cmd
548
+ $(if $(or $(command_changed),$(prereq_changed)),
549
+ @$(call exact_echo, $($(quiet)cmd_$(1)))
550
+ @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))"
551
+ $(if $(findstring flock,$(word %(flock_index)d,$(cmd_$1))),
552
+ @$(cmd_$(1))
553
+ @echo " $(quiet_cmd_$(1)): Finished",
554
+ @$(cmd_$(1))
555
+ )
556
+ @$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile)
557
+ @$(if $(2),$(fixup_dep))
558
+ $(if $(and $(3), $(POSTBUILDS)),
559
+ $(call do_postbuilds)
560
+ )
561
+ )
562
+ endef
563
+
564
+ # Declare the "%(default_target)s" target first so it is the default,
565
+ # even though we don't have the deps yet.
566
+ .PHONY: %(default_target)s
567
+ %(default_target)s:
568
+
569
+ # make looks for ways to re-generate included makefiles, but in our case, we
570
+ # don't have a direct way. Explicitly telling make that it has nothing to do
571
+ # for them makes it go faster.
572
+ %%.d: ;
573
+
574
+ # Use FORCE_DO_CMD to force a target to run. Should be coupled with
575
+ # do_cmd.
576
+ .PHONY: FORCE_DO_CMD
577
+ FORCE_DO_CMD:
578
+
579
+ """ # noqa: E501
580
+ )
581
+
582
+ SHARED_HEADER_MAC_COMMANDS = """
583
+ quiet_cmd_objc = CXX($(TOOLSET)) $@
584
+ cmd_objc = $(CC.$(TOOLSET)) $(GYP_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
585
+
586
+ quiet_cmd_objcxx = CXX($(TOOLSET)) $@
587
+ cmd_objcxx = $(CXX.$(TOOLSET)) $(GYP_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
588
+
589
+ # Commands for precompiled header files.
590
+ quiet_cmd_pch_c = CXX($(TOOLSET)) $@
591
+ cmd_pch_c = $(CC.$(TOOLSET)) $(GYP_PCH_CFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
592
+ quiet_cmd_pch_cc = CXX($(TOOLSET)) $@
593
+ cmd_pch_cc = $(CC.$(TOOLSET)) $(GYP_PCH_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
594
+ quiet_cmd_pch_m = CXX($(TOOLSET)) $@
595
+ cmd_pch_m = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
596
+ quiet_cmd_pch_mm = CXX($(TOOLSET)) $@
597
+ cmd_pch_mm = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
598
+
599
+ # gyp-mac-tool is written next to the root Makefile by gyp.
600
+ # Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
601
+ # already.
602
+ quiet_cmd_mac_tool = MACTOOL $(4) $<
603
+ cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@"
604
+
605
+ quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@
606
+ cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4)
607
+
608
+ quiet_cmd_infoplist = INFOPLIST $@
609
+ cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
610
+ """ # noqa: E501
611
+
612
+
613
+ def WriteRootHeaderSuffixRules(writer):
614
+ extensions = sorted(COMPILABLE_EXTENSIONS.keys(), key=str.lower)
615
+
616
+ writer.write("# Suffix rules, putting all outputs into $(obj).\n")
617
+ for ext in extensions:
618
+ writer.write("$(obj).$(TOOLSET)/%%.o: $(srcdir)/%%%s FORCE_DO_CMD\n" % ext)
619
+ writer.write("\t@$(call do_cmd,%s,1)\n" % COMPILABLE_EXTENSIONS[ext])
620
+
621
+ writer.write("\n# Try building from generated source, too.\n")
622
+ for ext in extensions:
623
+ writer.write(
624
+ "$(obj).$(TOOLSET)/%%.o: $(obj).$(TOOLSET)/%%%s FORCE_DO_CMD\n" % ext
625
+ )
626
+ writer.write("\t@$(call do_cmd,%s,1)\n" % COMPILABLE_EXTENSIONS[ext])
627
+ writer.write("\n")
628
+ for ext in extensions:
629
+ writer.write("$(obj).$(TOOLSET)/%%.o: $(obj)/%%%s FORCE_DO_CMD\n" % ext)
630
+ writer.write("\t@$(call do_cmd,%s,1)\n" % COMPILABLE_EXTENSIONS[ext])
631
+ writer.write("\n")
632
+
633
+
634
+ SHARED_HEADER_OS390_COMMANDS = """
635
+ PLIFLAGS.target ?= -qlp=64 -qlimits=extname=31 $(PLIFLAGS)
636
+ PLIFLAGS.host ?= -qlp=64 -qlimits=extname=31 $(PLIFLAGS)
637
+
638
+ quiet_cmd_pli = PLI($(TOOLSET)) $@
639
+ cmd_pli = $(PLI.$(TOOLSET)) $(GYP_PLIFLAGS) $(PLIFLAGS.$(TOOLSET)) -c $< && \
640
+ if [ -f $(notdir $@) ]; then /bin/cp $(notdir $@) $@; else true; fi
641
+ """
642
+
643
+ SHARED_HEADER_SUFFIX_RULES_COMMENT1 = """\
644
+ # Suffix rules, putting all outputs into $(obj).
645
+ """
646
+
647
+
648
+ SHARED_HEADER_SUFFIX_RULES_COMMENT2 = """\
649
+ # Try building from generated source, too.
650
+ """
651
+
652
+
653
+ SHARED_FOOTER = """\
654
+ # "all" is a concatenation of the "all" targets from all the included
655
+ # sub-makefiles. This is just here to clarify.
656
+ all:
657
+
658
+ # Add in dependency-tracking rules. $(all_deps) is the list of every single
659
+ # target in our tree. Only consider the ones with .d (dependency) info:
660
+ d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d))
661
+ ifneq ($(d_files),)
662
+ include $(d_files)
663
+ endif
664
+ """
665
+
666
+ header = """\
667
+ # This file is generated by gyp; do not edit.
668
+
669
+ """
670
+
671
+ # Maps every compilable file extension to the do_cmd that compiles it.
672
+ COMPILABLE_EXTENSIONS = {
673
+ ".c": "cc",
674
+ ".cc": "cxx",
675
+ ".cpp": "cxx",
676
+ ".cxx": "cxx",
677
+ ".s": "cc",
678
+ ".S": "cc",
679
+ }
680
+
681
+
682
+ def Compilable(filename):
683
+ """Return true if the file is compilable (should be in OBJS)."""
684
+ for res in (filename.endswith(e) for e in COMPILABLE_EXTENSIONS):
685
+ if res:
686
+ return True
687
+ return False
688
+
689
+
690
+ def Linkable(filename):
691
+ """Return true if the file is linkable (should be on the link line)."""
692
+ return filename.endswith(".o")
693
+
694
+
695
+ def Target(filename):
696
+ """Translate a compilable filename to its .o target."""
697
+ return os.path.splitext(filename)[0] + ".o"
698
+
699
+
700
+ def EscapeShellArgument(s):
701
+ """Quotes an argument so that it will be interpreted literally by a POSIX
702
+ shell. Taken from
703
+ http://stackoverflow.com/questions/35817/whats-the-best-way-to-escape-ossystem-calls-in-python
704
+ """
705
+ return "'" + s.replace("'", "'\\''") + "'"
706
+
707
+
708
+ def EscapeMakeVariableExpansion(s):
709
+ """Make has its own variable expansion syntax using $. We must escape it for
710
+ string to be interpreted literally."""
711
+ return s.replace("$", "$$")
712
+
713
+
714
+ def EscapeCppDefine(s):
715
+ """Escapes a CPP define so that it will reach the compiler unaltered."""
716
+ s = EscapeShellArgument(s)
717
+ s = EscapeMakeVariableExpansion(s)
718
+ # '#' characters must be escaped even embedded in a string, else Make will
719
+ # treat it as the start of a comment.
720
+ return s.replace("#", r"\#")
721
+
722
+
723
+ def QuoteIfNecessary(string):
724
+ """TODO: Should this ideally be replaced with one or more of the above
725
+ functions?"""
726
+ if '"' in string:
727
+ string = '"' + string.replace('"', '\\"') + '"'
728
+ return string
729
+
730
+
731
+ def StringToMakefileVariable(string):
732
+ """Convert a string to a value that is acceptable as a make variable name."""
733
+ return re.sub("[^a-zA-Z0-9_]", "_", string)
734
+
735
+
736
+ srcdir_prefix = ""
737
+
738
+
739
+ def Sourceify(path):
740
+ """Convert a path to its source directory form."""
741
+ if "$(" in path:
742
+ return path
743
+ if os.path.isabs(path):
744
+ return path
745
+ return srcdir_prefix + path
746
+
747
+
748
+ def QuoteSpaces(s, quote=r"\ "):
749
+ return s.replace(" ", quote)
750
+
751
+
752
+ def SourceifyAndQuoteSpaces(path):
753
+ """Convert a path to its source directory form and quote spaces."""
754
+ return QuoteSpaces(Sourceify(path))
755
+
756
+
757
+ # Map from qualified target to path to output.
758
+ target_outputs = {}
759
+ # Map from qualified target to any linkable output. A subset
760
+ # of target_outputs. E.g. when mybinary depends on liba, we want to
761
+ # include liba in the linker line; when otherbinary depends on
762
+ # mybinary, we just want to build mybinary first.
763
+ target_link_deps = {}
764
+
765
+
766
+ class MakefileWriter:
767
+ """MakefileWriter packages up the writing of one target-specific foobar.mk.
768
+
769
+ Its only real entry point is Write(), and is mostly used for namespacing.
770
+ """
771
+
772
+ def __init__(self, generator_flags, flavor):
773
+ self.generator_flags = generator_flags
774
+ self.flavor = flavor
775
+
776
+ self.suffix_rules_srcdir = {}
777
+ self.suffix_rules_objdir1 = {}
778
+ self.suffix_rules_objdir2 = {}
779
+
780
+ # Generate suffix rules for all compilable extensions.
781
+ for ext in COMPILABLE_EXTENSIONS.keys():
782
+ # Suffix rules for source folder.
783
+ self.suffix_rules_srcdir.update(
784
+ {
785
+ ext: (
786
+ """\
787
+ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(srcdir)/%%%s FORCE_DO_CMD
788
+ \t@$(call do_cmd,%s,1)
789
+ """
790
+ % (ext, COMPILABLE_EXTENSIONS[ext])
791
+ )
792
+ }
793
+ )
794
+
795
+ # Suffix rules for generated source files.
796
+ self.suffix_rules_objdir1.update(
797
+ {
798
+ ext: (
799
+ """\
800
+ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj).$(TOOLSET)/%%%s FORCE_DO_CMD
801
+ \t@$(call do_cmd,%s,1)
802
+ """
803
+ % (ext, COMPILABLE_EXTENSIONS[ext])
804
+ )
805
+ }
806
+ )
807
+ self.suffix_rules_objdir2.update(
808
+ {
809
+ ext: (
810
+ """\
811
+ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD
812
+ \t@$(call do_cmd,%s,1)
813
+ """
814
+ % (ext, COMPILABLE_EXTENSIONS[ext])
815
+ )
816
+ }
817
+ )
818
+
819
+ def Write(
820
+ self, qualified_target, base_path, output_filename, spec, configs, part_of_all
821
+ ):
822
+ """The main entry point: writes a .mk file for a single target.
823
+
824
+ Arguments:
825
+ qualified_target: target we're generating
826
+ base_path: path relative to source root we're building in, used to resolve
827
+ target-relative paths
828
+ output_filename: output .mk file name to write
829
+ spec, configs: gyp info
830
+ part_of_all: flag indicating this target is part of 'all'
831
+ """
832
+ gyp.common.EnsureDirExists(output_filename)
833
+
834
+ self.fp = open(output_filename, "w")
835
+
836
+ self.fp.write(header)
837
+
838
+ self.qualified_target = qualified_target
839
+ self.path = base_path
840
+ self.target = spec["target_name"]
841
+ self.type = spec["type"]
842
+ self.toolset = spec["toolset"]
843
+
844
+ self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
845
+ if self.flavor == "mac":
846
+ self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
847
+ else:
848
+ self.xcode_settings = None
849
+
850
+ deps, link_deps = self.ComputeDeps(spec)
851
+
852
+ # Some of the generation below can add extra output, sources, or
853
+ # link dependencies. All of the out params of the functions that
854
+ # follow use names like extra_foo.
855
+ extra_outputs = []
856
+ extra_sources = []
857
+ extra_link_deps = []
858
+ extra_mac_bundle_resources = []
859
+ mac_bundle_deps = []
860
+
861
+ if self.is_mac_bundle:
862
+ self.output = self.ComputeMacBundleOutput(spec)
863
+ self.output_binary = self.ComputeMacBundleBinaryOutput(spec)
864
+ else:
865
+ self.output = self.output_binary = self.ComputeOutput(spec)
866
+
867
+ self.is_standalone_static_library = bool(
868
+ spec.get("standalone_static_library", 0)
869
+ )
870
+ self._INSTALLABLE_TARGETS = ("executable", "loadable_module", "shared_library")
871
+ if self.is_standalone_static_library or self.type in self._INSTALLABLE_TARGETS:
872
+ self.alias = os.path.basename(self.output)
873
+ install_path = self._InstallableTargetInstallPath()
874
+ else:
875
+ self.alias = self.output
876
+ install_path = self.output
877
+
878
+ self.WriteLn("TOOLSET := " + self.toolset)
879
+ self.WriteLn("TARGET := " + self.target)
880
+
881
+ # Actions must come first, since they can generate more OBJs for use below.
882
+ if "actions" in spec:
883
+ self.WriteActions(
884
+ spec["actions"],
885
+ extra_sources,
886
+ extra_outputs,
887
+ extra_mac_bundle_resources,
888
+ part_of_all,
889
+ )
890
+
891
+ # Rules must be early like actions.
892
+ if "rules" in spec:
893
+ self.WriteRules(
894
+ spec["rules"],
895
+ extra_sources,
896
+ extra_outputs,
897
+ extra_mac_bundle_resources,
898
+ part_of_all,
899
+ )
900
+
901
+ if "copies" in spec:
902
+ self.WriteCopies(spec["copies"], extra_outputs, part_of_all)
903
+
904
+ # Bundle resources.
905
+ if self.is_mac_bundle:
906
+ all_mac_bundle_resources = (
907
+ spec.get("mac_bundle_resources", []) + extra_mac_bundle_resources
908
+ )
909
+ self.WriteMacBundleResources(all_mac_bundle_resources, mac_bundle_deps)
910
+ self.WriteMacInfoPlist(mac_bundle_deps)
911
+
912
+ # Sources.
913
+ all_sources = spec.get("sources", []) + extra_sources
914
+ if all_sources:
915
+ self.WriteSources(
916
+ configs,
917
+ deps,
918
+ all_sources,
919
+ extra_outputs,
920
+ extra_link_deps,
921
+ part_of_all,
922
+ gyp.xcode_emulation.MacPrefixHeader(
923
+ self.xcode_settings,
924
+ lambda p: Sourceify(self.Absolutify(p)),
925
+ self.Pchify,
926
+ ),
927
+ )
928
+ sources = [x for x in all_sources if Compilable(x)]
929
+ if sources:
930
+ self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
931
+ extensions = {os.path.splitext(s)[1] for s in sources}
932
+ for ext in extensions:
933
+ if ext in self.suffix_rules_srcdir:
934
+ self.WriteLn(self.suffix_rules_srcdir[ext])
935
+ self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT2)
936
+ for ext in extensions:
937
+ if ext in self.suffix_rules_objdir1:
938
+ self.WriteLn(self.suffix_rules_objdir1[ext])
939
+ for ext in extensions:
940
+ if ext in self.suffix_rules_objdir2:
941
+ self.WriteLn(self.suffix_rules_objdir2[ext])
942
+ self.WriteLn("# End of this set of suffix rules")
943
+
944
+ # Add dependency from bundle to bundle binary.
945
+ if self.is_mac_bundle:
946
+ mac_bundle_deps.append(self.output_binary)
947
+
948
+ self.WriteTarget(
949
+ spec,
950
+ configs,
951
+ deps,
952
+ extra_link_deps + link_deps,
953
+ mac_bundle_deps,
954
+ extra_outputs,
955
+ part_of_all,
956
+ )
957
+
958
+ # Update global list of target outputs, used in dependency tracking.
959
+ target_outputs[qualified_target] = install_path
960
+
961
+ # Update global list of link dependencies.
962
+ if self.type in ("static_library", "shared_library"):
963
+ target_link_deps[qualified_target] = self.output_binary
964
+
965
+ # Currently any versions have the same effect, but in future the behavior
966
+ # could be different.
967
+ if self.generator_flags.get("android_ndk_version", None):
968
+ self.WriteAndroidNdkModuleRule(self.target, all_sources, link_deps)
969
+
970
+ self.fp.close()
971
+
972
+ def WriteSubMake(self, output_filename, makefile_path, targets, build_dir):
973
+ """Write a "sub-project" Makefile.
974
+
975
+ This is a small, wrapper Makefile that calls the top-level Makefile to build
976
+ the targets from a single gyp file (i.e. a sub-project).
977
+
978
+ Arguments:
979
+ output_filename: sub-project Makefile name to write
980
+ makefile_path: path to the top-level Makefile
981
+ targets: list of "all" targets for this sub-project
982
+ build_dir: build output directory, relative to the sub-project
983
+ """
984
+ gyp.common.EnsureDirExists(output_filename)
985
+ self.fp = open(output_filename, "w")
986
+ self.fp.write(header)
987
+ # For consistency with other builders, put sub-project build output in the
988
+ # sub-project dir (see test/subdirectory/gyptest-subdir-all.py).
989
+ self.WriteLn(
990
+ "export builddir_name ?= %s"
991
+ % os.path.join(os.path.dirname(output_filename), build_dir)
992
+ )
993
+ self.WriteLn(".PHONY: all")
994
+ self.WriteLn("all:")
995
+ if makefile_path:
996
+ makefile_path = " -C " + makefile_path
997
+ self.WriteLn("\t$(MAKE){} {}".format(makefile_path, " ".join(targets)))
998
+ self.fp.close()
999
+
1000
+ def WriteActions(
1001
+ self,
1002
+ actions,
1003
+ extra_sources,
1004
+ extra_outputs,
1005
+ extra_mac_bundle_resources,
1006
+ part_of_all,
1007
+ ):
1008
+ """Write Makefile code for any 'actions' from the gyp input.
1009
+
1010
+ extra_sources: a list that will be filled in with newly generated source
1011
+ files, if any
1012
+ extra_outputs: a list that will be filled in with any outputs of these
1013
+ actions (used to make other pieces dependent on these
1014
+ actions)
1015
+ part_of_all: flag indicating this target is part of 'all'
1016
+ """
1017
+ env = self.GetSortedXcodeEnv()
1018
+ for action in actions:
1019
+ name = StringToMakefileVariable(
1020
+ "{}_{}".format(self.qualified_target, action["action_name"])
1021
+ )
1022
+ self.WriteLn('### Rules for action "%s":' % action["action_name"])
1023
+ inputs = action["inputs"]
1024
+ outputs = action["outputs"]
1025
+
1026
+ # Build up a list of outputs.
1027
+ # Collect the output dirs we'll need.
1028
+ dirs = set()
1029
+ for out in outputs:
1030
+ dir = os.path.split(out)[0]
1031
+ if dir:
1032
+ dirs.add(dir)
1033
+ if int(action.get("process_outputs_as_sources", False)):
1034
+ extra_sources += outputs
1035
+ if int(action.get("process_outputs_as_mac_bundle_resources", False)):
1036
+ extra_mac_bundle_resources += outputs
1037
+
1038
+ # Write the actual command.
1039
+ action_commands = action["action"]
1040
+ if self.flavor == "mac":
1041
+ action_commands = [
1042
+ gyp.xcode_emulation.ExpandEnvVars(command, env)
1043
+ for command in action_commands
1044
+ ]
1045
+ command = gyp.common.EncodePOSIXShellList(action_commands)
1046
+ if "message" in action:
1047
+ self.WriteLn(
1048
+ "quiet_cmd_{} = ACTION {} $@".format(name, action["message"])
1049
+ )
1050
+ else:
1051
+ self.WriteLn(f"quiet_cmd_{name} = ACTION {name} $@")
1052
+ if len(dirs) > 0:
1053
+ command = "mkdir -p %s" % " ".join(dirs) + "; " + command
1054
+
1055
+ cd_action = "cd %s; " % Sourceify(self.path or ".")
1056
+
1057
+ # command and cd_action get written to a toplevel variable called
1058
+ # cmd_foo. Toplevel variables can't handle things that change per
1059
+ # makefile like $(TARGET), so hardcode the target.
1060
+ command = command.replace("$(TARGET)", self.target)
1061
+ cd_action = cd_action.replace("$(TARGET)", self.target)
1062
+
1063
+ # Set LD_LIBRARY_PATH in case the action runs an executable from this
1064
+ # build which links to shared libs from this build.
1065
+ # actions run on the host, so they should in theory only use host
1066
+ # libraries, but until everything is made cross-compile safe, also use
1067
+ # target libraries.
1068
+ # TODO(piman): when everything is cross-compile safe, remove lib.target
1069
+ if self.flavor == "zos" or self.flavor == "aix":
1070
+ self.WriteLn(
1071
+ "cmd_%s = LIBPATH=$(builddir)/lib.host:"
1072
+ "$(builddir)/lib.target:$$LIBPATH; "
1073
+ "export LIBPATH; "
1074
+ "%s%s" % (name, cd_action, command)
1075
+ )
1076
+ else:
1077
+ self.WriteLn(
1078
+ "cmd_%s = LD_LIBRARY_PATH=$(builddir)/lib.host:"
1079
+ "$(builddir)/lib.target:$$LD_LIBRARY_PATH; "
1080
+ "export LD_LIBRARY_PATH; "
1081
+ "%s%s" % (name, cd_action, command)
1082
+ )
1083
+ self.WriteLn()
1084
+ outputs = [self.Absolutify(o) for o in outputs]
1085
+ # The makefile rules are all relative to the top dir, but the gyp actions
1086
+ # are defined relative to their containing dir. This replaces the obj
1087
+ # variable for the action rule with an absolute version so that the output
1088
+ # goes in the right place.
1089
+ # Only write the 'obj' and 'builddir' rules for the "primary" output (:1);
1090
+ # it's superfluous for the "extra outputs", and this avoids accidentally
1091
+ # writing duplicate dummy rules for those outputs.
1092
+ # Same for environment.
1093
+ self.WriteLn("%s: obj := $(abs_obj)" % QuoteSpaces(outputs[0]))
1094
+ self.WriteLn("%s: builddir := $(abs_builddir)" % QuoteSpaces(outputs[0]))
1095
+ self.WriteSortedXcodeEnv(outputs[0], self.GetSortedXcodeEnv())
1096
+
1097
+ for input in inputs:
1098
+ assert " " not in input, (
1099
+ "Spaces in action input filenames not supported (%s)" % input
1100
+ )
1101
+ for output in outputs:
1102
+ assert " " not in output, (
1103
+ "Spaces in action output filenames not supported (%s)" % output
1104
+ )
1105
+
1106
+ # See the comment in WriteCopies about expanding env vars.
1107
+ outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs]
1108
+ inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs]
1109
+
1110
+ self.WriteDoCmd(
1111
+ outputs,
1112
+ [Sourceify(self.Absolutify(i)) for i in inputs],
1113
+ part_of_all=part_of_all,
1114
+ command=name,
1115
+ )
1116
+
1117
+ # Stuff the outputs in a variable so we can refer to them later.
1118
+ outputs_variable = "action_%s_outputs" % name
1119
+ self.WriteLn("{} := {}".format(outputs_variable, " ".join(outputs)))
1120
+ extra_outputs.append("$(%s)" % outputs_variable)
1121
+ self.WriteLn()
1122
+
1123
+ self.WriteLn()
1124
+
1125
+ def WriteRules(
1126
+ self,
1127
+ rules,
1128
+ extra_sources,
1129
+ extra_outputs,
1130
+ extra_mac_bundle_resources,
1131
+ part_of_all,
1132
+ ):
1133
+ """Write Makefile code for any 'rules' from the gyp input.
1134
+
1135
+ extra_sources: a list that will be filled in with newly generated source
1136
+ files, if any
1137
+ extra_outputs: a list that will be filled in with any outputs of these
1138
+ rules (used to make other pieces dependent on these rules)
1139
+ part_of_all: flag indicating this target is part of 'all'
1140
+ """
1141
+ env = self.GetSortedXcodeEnv()
1142
+ for rule in rules:
1143
+ name = StringToMakefileVariable(
1144
+ "{}_{}".format(self.qualified_target, rule["rule_name"])
1145
+ )
1146
+ count = 0
1147
+ self.WriteLn("### Generated for rule %s:" % name)
1148
+
1149
+ all_outputs = []
1150
+
1151
+ for rule_source in rule.get("rule_sources", []):
1152
+ dirs = set()
1153
+ (rule_source_dirname, rule_source_basename) = os.path.split(rule_source)
1154
+ (rule_source_root, rule_source_ext) = os.path.splitext(
1155
+ rule_source_basename
1156
+ )
1157
+
1158
+ outputs = [
1159
+ self.ExpandInputRoot(out, rule_source_root, rule_source_dirname)
1160
+ for out in rule["outputs"]
1161
+ ]
1162
+
1163
+ for out in outputs:
1164
+ dir = os.path.dirname(out)
1165
+ if dir:
1166
+ dirs.add(dir)
1167
+ if int(rule.get("process_outputs_as_sources", False)):
1168
+ extra_sources += outputs
1169
+ if int(rule.get("process_outputs_as_mac_bundle_resources", False)):
1170
+ extra_mac_bundle_resources += outputs
1171
+ inputs = [
1172
+ Sourceify(self.Absolutify(i))
1173
+ for i in [rule_source] + rule.get("inputs", [])
1174
+ ]
1175
+ actions = ["$(call do_cmd,%s_%d)" % (name, count)]
1176
+
1177
+ if name == "resources_grit":
1178
+ # HACK: This is ugly. Grit intentionally doesn't touch the
1179
+ # timestamp of its output file when the file doesn't change,
1180
+ # which is fine in hash-based dependency systems like scons
1181
+ # and forge, but not kosher in the make world. After some
1182
+ # discussion, hacking around it here seems like the least
1183
+ # amount of pain.
1184
+ actions += ["@touch --no-create $@"]
1185
+
1186
+ # See the comment in WriteCopies about expanding env vars.
1187
+ outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs]
1188
+ inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs]
1189
+
1190
+ outputs = [self.Absolutify(o) for o in outputs]
1191
+ all_outputs += outputs
1192
+ # Only write the 'obj' and 'builddir' rules for the "primary" output
1193
+ # (:1); it's superfluous for the "extra outputs", and this avoids
1194
+ # accidentally writing duplicate dummy rules for those outputs.
1195
+ self.WriteLn("%s: obj := $(abs_obj)" % outputs[0])
1196
+ self.WriteLn("%s: builddir := $(abs_builddir)" % outputs[0])
1197
+ self.WriteMakeRule(
1198
+ outputs, inputs, actions, command="%s_%d" % (name, count)
1199
+ )
1200
+ # Spaces in rule filenames are not supported, but rule variables have
1201
+ # spaces in them (e.g. RULE_INPUT_PATH expands to '$(abspath $<)').
1202
+ # The spaces within the variables are valid, so remove the variables
1203
+ # before checking.
1204
+ variables_with_spaces = re.compile(r"\$\([^ ]* \$<\)")
1205
+ for output in outputs:
1206
+ output = re.sub(variables_with_spaces, "", output)
1207
+ assert " " not in output, (
1208
+ "Spaces in rule filenames not yet supported (%s)" % output
1209
+ )
1210
+ self.WriteLn("all_deps += %s" % " ".join(outputs))
1211
+
1212
+ action = [
1213
+ self.ExpandInputRoot(ac, rule_source_root, rule_source_dirname)
1214
+ for ac in rule["action"]
1215
+ ]
1216
+ mkdirs = ""
1217
+ if len(dirs) > 0:
1218
+ mkdirs = "mkdir -p %s; " % " ".join(dirs)
1219
+ cd_action = "cd %s; " % Sourceify(self.path or ".")
1220
+
1221
+ # action, cd_action, and mkdirs get written to a toplevel variable
1222
+ # called cmd_foo. Toplevel variables can't handle things that change
1223
+ # per makefile like $(TARGET), so hardcode the target.
1224
+ if self.flavor == "mac":
1225
+ action = [
1226
+ gyp.xcode_emulation.ExpandEnvVars(command, env)
1227
+ for command in action
1228
+ ]
1229
+ action = gyp.common.EncodePOSIXShellList(action)
1230
+ action = action.replace("$(TARGET)", self.target)
1231
+ cd_action = cd_action.replace("$(TARGET)", self.target)
1232
+ mkdirs = mkdirs.replace("$(TARGET)", self.target)
1233
+
1234
+ # Set LD_LIBRARY_PATH in case the rule runs an executable from this
1235
+ # build which links to shared libs from this build.
1236
+ # rules run on the host, so they should in theory only use host
1237
+ # libraries, but until everything is made cross-compile safe, also use
1238
+ # target libraries.
1239
+ # TODO(piman): when everything is cross-compile safe, remove lib.target
1240
+ self.WriteLn(
1241
+ "cmd_%(name)s_%(count)d = LD_LIBRARY_PATH="
1242
+ "$(builddir)/lib.host:$(builddir)/lib.target:$$LD_LIBRARY_PATH; "
1243
+ "export LD_LIBRARY_PATH; "
1244
+ "%(cd_action)s%(mkdirs)s%(action)s"
1245
+ % {
1246
+ "action": action,
1247
+ "cd_action": cd_action,
1248
+ "count": count,
1249
+ "mkdirs": mkdirs,
1250
+ "name": name,
1251
+ }
1252
+ )
1253
+ self.WriteLn(
1254
+ "quiet_cmd_%(name)s_%(count)d = RULE %(name)s_%(count)d $@"
1255
+ % {"count": count, "name": name}
1256
+ )
1257
+ self.WriteLn()
1258
+ count += 1
1259
+
1260
+ outputs_variable = "rule_%s_outputs" % name
1261
+ self.WriteList(all_outputs, outputs_variable)
1262
+ extra_outputs.append("$(%s)" % outputs_variable)
1263
+
1264
+ self.WriteLn("### Finished generating for rule: %s" % name)
1265
+ self.WriteLn()
1266
+ self.WriteLn("### Finished generating for all rules")
1267
+ self.WriteLn("")
1268
+
1269
+ def WriteCopies(self, copies, extra_outputs, part_of_all):
1270
+ """Write Makefile code for any 'copies' from the gyp input.
1271
+
1272
+ extra_outputs: a list that will be filled in with any outputs of this action
1273
+ (used to make other pieces dependent on this action)
1274
+ part_of_all: flag indicating this target is part of 'all'
1275
+ """
1276
+ self.WriteLn("### Generated for copy rule.")
1277
+
1278
+ variable = StringToMakefileVariable(self.qualified_target + "_copies")
1279
+ outputs = []
1280
+ for copy in copies:
1281
+ for path in copy["files"]:
1282
+ # Absolutify() may call normpath, and will strip trailing slashes.
1283
+ path = Sourceify(self.Absolutify(path))
1284
+ filename = os.path.split(path)[1]
1285
+ output = Sourceify(
1286
+ self.Absolutify(os.path.join(copy["destination"], filename))
1287
+ )
1288
+
1289
+ # If the output path has variables in it, which happens in practice for
1290
+ # 'copies', writing the environment as target-local doesn't work,
1291
+ # because the variables are already needed for the target name.
1292
+ # Copying the environment variables into global make variables doesn't
1293
+ # work either, because then the .d files will potentially contain spaces
1294
+ # after variable expansion, and .d file handling cannot handle spaces.
1295
+ # As a workaround, manually expand variables at gyp time. Since 'copies'
1296
+ # can't run scripts, there's no need to write the env then.
1297
+ # WriteDoCmd() will escape spaces for .d files.
1298
+ env = self.GetSortedXcodeEnv()
1299
+ output = gyp.xcode_emulation.ExpandEnvVars(output, env)
1300
+ path = gyp.xcode_emulation.ExpandEnvVars(path, env)
1301
+ self.WriteDoCmd([output], [path], "copy", part_of_all)
1302
+ outputs.append(output)
1303
+ self.WriteLn(
1304
+ "{} = {}".format(variable, " ".join(QuoteSpaces(o) for o in outputs))
1305
+ )
1306
+ extra_outputs.append("$(%s)" % variable)
1307
+ self.WriteLn()
1308
+
1309
+ def WriteMacBundleResources(self, resources, bundle_deps):
1310
+ """Writes Makefile code for 'mac_bundle_resources'."""
1311
+ self.WriteLn("### Generated for mac_bundle_resources")
1312
+
1313
+ for output, res in gyp.xcode_emulation.GetMacBundleResources(
1314
+ generator_default_variables["PRODUCT_DIR"],
1315
+ self.xcode_settings,
1316
+ [Sourceify(self.Absolutify(r)) for r in resources],
1317
+ ):
1318
+ _, ext = os.path.splitext(output)
1319
+ if ext != ".xcassets":
1320
+ # Make does not supports '.xcassets' emulation.
1321
+ self.WriteDoCmd(
1322
+ [output], [res], "mac_tool,,,copy-bundle-resource", part_of_all=True
1323
+ )
1324
+ bundle_deps.append(output)
1325
+
1326
+ def WriteMacInfoPlist(self, bundle_deps):
1327
+ """Write Makefile code for bundle Info.plist files."""
1328
+ info_plist, out, defines, extra_env = gyp.xcode_emulation.GetMacInfoPlist(
1329
+ generator_default_variables["PRODUCT_DIR"],
1330
+ self.xcode_settings,
1331
+ lambda p: Sourceify(self.Absolutify(p)),
1332
+ )
1333
+ if not info_plist:
1334
+ return
1335
+ if defines:
1336
+ # Create an intermediate file to store preprocessed results.
1337
+ intermediate_plist = "$(obj).$(TOOLSET)/$(TARGET)/" + os.path.basename(
1338
+ info_plist
1339
+ )
1340
+ self.WriteList(
1341
+ defines,
1342
+ intermediate_plist + ": INFOPLIST_DEFINES",
1343
+ "-D",
1344
+ quoter=EscapeCppDefine,
1345
+ )
1346
+ self.WriteMakeRule(
1347
+ [intermediate_plist],
1348
+ [info_plist],
1349
+ [
1350
+ "$(call do_cmd,infoplist)",
1351
+ # "Convert" the plist so that any weird whitespace changes from the
1352
+ # preprocessor do not affect the XML parser in mac_tool.
1353
+ "@plutil -convert xml1 $@ $@",
1354
+ ],
1355
+ )
1356
+ info_plist = intermediate_plist
1357
+ # plists can contain envvars and substitute them into the file.
1358
+ self.WriteSortedXcodeEnv(
1359
+ out, self.GetSortedXcodeEnv(additional_settings=extra_env)
1360
+ )
1361
+ self.WriteDoCmd(
1362
+ [out], [info_plist], "mac_tool,,,copy-info-plist", part_of_all=True
1363
+ )
1364
+ bundle_deps.append(out)
1365
+
1366
+ def WriteSources(
1367
+ self,
1368
+ configs,
1369
+ deps,
1370
+ sources,
1371
+ extra_outputs,
1372
+ extra_link_deps,
1373
+ part_of_all,
1374
+ precompiled_header,
1375
+ ):
1376
+ """Write Makefile code for any 'sources' from the gyp input.
1377
+ These are source files necessary to build the current target.
1378
+
1379
+ configs, deps, sources: input from gyp.
1380
+ extra_outputs: a list of extra outputs this action should be dependent on;
1381
+ used to serialize action/rules before compilation
1382
+ extra_link_deps: a list that will be filled in with any outputs of
1383
+ compilation (to be used in link lines)
1384
+ part_of_all: flag indicating this target is part of 'all'
1385
+ """
1386
+
1387
+ # Write configuration-specific variables for CFLAGS, etc.
1388
+ for configname in sorted(configs.keys()):
1389
+ config = configs[configname]
1390
+ self.WriteList(
1391
+ config.get("defines"),
1392
+ "DEFS_%s" % configname,
1393
+ prefix="-D",
1394
+ quoter=EscapeCppDefine,
1395
+ )
1396
+
1397
+ if self.flavor == "mac":
1398
+ cflags = self.xcode_settings.GetCflags(
1399
+ configname, arch=config.get("xcode_configuration_platform")
1400
+ )
1401
+ cflags_c = self.xcode_settings.GetCflagsC(configname)
1402
+ cflags_cc = self.xcode_settings.GetCflagsCC(configname)
1403
+ cflags_objc = self.xcode_settings.GetCflagsObjC(configname)
1404
+ cflags_objcc = self.xcode_settings.GetCflagsObjCC(configname)
1405
+ else:
1406
+ cflags = config.get("cflags")
1407
+ cflags_c = config.get("cflags_c")
1408
+ cflags_cc = config.get("cflags_cc")
1409
+
1410
+ self.WriteLn("# Flags passed to all source files.")
1411
+ self.WriteList(cflags, "CFLAGS_%s" % configname)
1412
+ self.WriteLn("# Flags passed to only C files.")
1413
+ self.WriteList(cflags_c, "CFLAGS_C_%s" % configname)
1414
+ self.WriteLn("# Flags passed to only C++ files.")
1415
+ self.WriteList(cflags_cc, "CFLAGS_CC_%s" % configname)
1416
+ if self.flavor == "mac":
1417
+ self.WriteLn("# Flags passed to only ObjC files.")
1418
+ self.WriteList(cflags_objc, "CFLAGS_OBJC_%s" % configname)
1419
+ self.WriteLn("# Flags passed to only ObjC++ files.")
1420
+ self.WriteList(cflags_objcc, "CFLAGS_OBJCC_%s" % configname)
1421
+ includes = config.get("include_dirs")
1422
+ if includes:
1423
+ includes = [Sourceify(self.Absolutify(i)) for i in includes]
1424
+ self.WriteList(includes, "INCS_%s" % configname, prefix="-I")
1425
+
1426
+ compilable = list(filter(Compilable, sources))
1427
+ objs = [self.Objectify(self.Absolutify(Target(c))) for c in compilable]
1428
+ self.WriteList(objs, "OBJS")
1429
+
1430
+ for obj in objs:
1431
+ assert " " not in obj, "Spaces in object filenames not supported (%s)" % obj
1432
+ self.WriteLn(
1433
+ "# Add to the list of files we specially track " "dependencies for."
1434
+ )
1435
+ self.WriteLn("all_deps += $(OBJS)")
1436
+ self.WriteLn()
1437
+
1438
+ # Make sure our dependencies are built first.
1439
+ if deps:
1440
+ self.WriteMakeRule(
1441
+ ["$(OBJS)"],
1442
+ deps,
1443
+ comment="Make sure our dependencies are built " "before any of us.",
1444
+ order_only=True,
1445
+ )
1446
+
1447
+ # Make sure the actions and rules run first.
1448
+ # If they generate any extra headers etc., the per-.o file dep tracking
1449
+ # will catch the proper rebuilds, so order only is still ok here.
1450
+ if extra_outputs:
1451
+ self.WriteMakeRule(
1452
+ ["$(OBJS)"],
1453
+ extra_outputs,
1454
+ comment="Make sure our actions/rules run " "before any of us.",
1455
+ order_only=True,
1456
+ )
1457
+
1458
+ pchdeps = precompiled_header.GetObjDependencies(compilable, objs)
1459
+ if pchdeps:
1460
+ self.WriteLn("# Dependencies from obj files to their precompiled headers")
1461
+ for source, obj, gch in pchdeps:
1462
+ self.WriteLn(f"{obj}: {gch}")
1463
+ self.WriteLn("# End precompiled header dependencies")
1464
+
1465
+ if objs:
1466
+ extra_link_deps.append("$(OBJS)")
1467
+ self.WriteLn(
1468
+ """\
1469
+ # CFLAGS et al overrides must be target-local.
1470
+ # See "Target-specific Variable Values" in the GNU Make manual."""
1471
+ )
1472
+ self.WriteLn("$(OBJS): TOOLSET := $(TOOLSET)")
1473
+ self.WriteLn(
1474
+ "$(OBJS): GYP_CFLAGS := "
1475
+ "$(DEFS_$(BUILDTYPE)) "
1476
+ "$(INCS_$(BUILDTYPE)) "
1477
+ "%s " % precompiled_header.GetInclude("c") + "$(CFLAGS_$(BUILDTYPE)) "
1478
+ "$(CFLAGS_C_$(BUILDTYPE))"
1479
+ )
1480
+ self.WriteLn(
1481
+ "$(OBJS): GYP_CXXFLAGS := "
1482
+ "$(DEFS_$(BUILDTYPE)) "
1483
+ "$(INCS_$(BUILDTYPE)) "
1484
+ "%s " % precompiled_header.GetInclude("cc") + "$(CFLAGS_$(BUILDTYPE)) "
1485
+ "$(CFLAGS_CC_$(BUILDTYPE))"
1486
+ )
1487
+ if self.flavor == "mac":
1488
+ self.WriteLn(
1489
+ "$(OBJS): GYP_OBJCFLAGS := "
1490
+ "$(DEFS_$(BUILDTYPE)) "
1491
+ "$(INCS_$(BUILDTYPE)) "
1492
+ "%s " % precompiled_header.GetInclude("m")
1493
+ + "$(CFLAGS_$(BUILDTYPE)) "
1494
+ "$(CFLAGS_C_$(BUILDTYPE)) "
1495
+ "$(CFLAGS_OBJC_$(BUILDTYPE))"
1496
+ )
1497
+ self.WriteLn(
1498
+ "$(OBJS): GYP_OBJCXXFLAGS := "
1499
+ "$(DEFS_$(BUILDTYPE)) "
1500
+ "$(INCS_$(BUILDTYPE)) "
1501
+ "%s " % precompiled_header.GetInclude("mm")
1502
+ + "$(CFLAGS_$(BUILDTYPE)) "
1503
+ "$(CFLAGS_CC_$(BUILDTYPE)) "
1504
+ "$(CFLAGS_OBJCC_$(BUILDTYPE))"
1505
+ )
1506
+
1507
+ self.WritePchTargets(precompiled_header.GetPchBuildCommands())
1508
+
1509
+ # If there are any object files in our input file list, link them into our
1510
+ # output.
1511
+ extra_link_deps += [source for source in sources if Linkable(source)]
1512
+
1513
+ self.WriteLn()
1514
+
1515
+ def WritePchTargets(self, pch_commands):
1516
+ """Writes make rules to compile prefix headers."""
1517
+ if not pch_commands:
1518
+ return
1519
+
1520
+ for gch, lang_flag, lang, input in pch_commands:
1521
+ extra_flags = {
1522
+ "c": "$(CFLAGS_C_$(BUILDTYPE))",
1523
+ "cc": "$(CFLAGS_CC_$(BUILDTYPE))",
1524
+ "m": "$(CFLAGS_C_$(BUILDTYPE)) $(CFLAGS_OBJC_$(BUILDTYPE))",
1525
+ "mm": "$(CFLAGS_CC_$(BUILDTYPE)) $(CFLAGS_OBJCC_$(BUILDTYPE))",
1526
+ }[lang]
1527
+ var_name = {
1528
+ "c": "GYP_PCH_CFLAGS",
1529
+ "cc": "GYP_PCH_CXXFLAGS",
1530
+ "m": "GYP_PCH_OBJCFLAGS",
1531
+ "mm": "GYP_PCH_OBJCXXFLAGS",
1532
+ }[lang]
1533
+ self.WriteLn(
1534
+ f"{gch}: {var_name} := {lang_flag} " + "$(DEFS_$(BUILDTYPE)) "
1535
+ "$(INCS_$(BUILDTYPE)) "
1536
+ "$(CFLAGS_$(BUILDTYPE)) " + extra_flags
1537
+ )
1538
+
1539
+ self.WriteLn(f"{gch}: {input} FORCE_DO_CMD")
1540
+ self.WriteLn("\t@$(call do_cmd,pch_%s,1)" % lang)
1541
+ self.WriteLn("")
1542
+ assert " " not in gch, "Spaces in gch filenames not supported (%s)" % gch
1543
+ self.WriteLn("all_deps += %s" % gch)
1544
+ self.WriteLn("")
1545
+
1546
+ def ComputeOutputBasename(self, spec):
1547
+ """Return the 'output basename' of a gyp spec.
1548
+
1549
+ E.g., the loadable module 'foobar' in directory 'baz' will produce
1550
+ 'libfoobar.so'
1551
+ """
1552
+ assert not self.is_mac_bundle
1553
+
1554
+ if self.flavor == "mac" and self.type in (
1555
+ "static_library",
1556
+ "executable",
1557
+ "shared_library",
1558
+ "loadable_module",
1559
+ ):
1560
+ return self.xcode_settings.GetExecutablePath()
1561
+
1562
+ target = spec["target_name"]
1563
+ target_prefix = ""
1564
+ target_ext = ""
1565
+ if self.type == "static_library":
1566
+ if target[:3] == "lib":
1567
+ target = target[3:]
1568
+ target_prefix = "lib"
1569
+ target_ext = ".a"
1570
+ elif self.type in ("loadable_module", "shared_library"):
1571
+ if target[:3] == "lib":
1572
+ target = target[3:]
1573
+ target_prefix = "lib"
1574
+ if self.flavor == "aix":
1575
+ target_ext = ".a"
1576
+ elif self.flavor == "zos":
1577
+ target_ext = ".x"
1578
+ else:
1579
+ target_ext = ".so"
1580
+ elif self.type == "none":
1581
+ target = "%s.stamp" % target
1582
+ elif self.type != "executable":
1583
+ print(
1584
+ "ERROR: What output file should be generated?",
1585
+ "type",
1586
+ self.type,
1587
+ "target",
1588
+ target,
1589
+ )
1590
+
1591
+ target_prefix = spec.get("product_prefix", target_prefix)
1592
+ target = spec.get("product_name", target)
1593
+ product_ext = spec.get("product_extension")
1594
+ if product_ext:
1595
+ target_ext = "." + product_ext
1596
+
1597
+ return target_prefix + target + target_ext
1598
+
1599
+ def _InstallImmediately(self):
1600
+ return (
1601
+ self.toolset == "target"
1602
+ and self.flavor == "mac"
1603
+ and self.type
1604
+ in ("static_library", "executable", "shared_library", "loadable_module")
1605
+ )
1606
+
1607
+ def ComputeOutput(self, spec):
1608
+ """Return the 'output' (full output path) of a gyp spec.
1609
+
1610
+ E.g., the loadable module 'foobar' in directory 'baz' will produce
1611
+ '$(obj)/baz/libfoobar.so'
1612
+ """
1613
+ assert not self.is_mac_bundle
1614
+
1615
+ path = os.path.join("$(obj)." + self.toolset, self.path)
1616
+ if self.type == "executable" or self._InstallImmediately():
1617
+ path = "$(builddir)"
1618
+ path = spec.get("product_dir", path)
1619
+ return os.path.join(path, self.ComputeOutputBasename(spec))
1620
+
1621
+ def ComputeMacBundleOutput(self, spec):
1622
+ """Return the 'output' (full output path) to a bundle output directory."""
1623
+ assert self.is_mac_bundle
1624
+ path = generator_default_variables["PRODUCT_DIR"]
1625
+ return os.path.join(path, self.xcode_settings.GetWrapperName())
1626
+
1627
+ def ComputeMacBundleBinaryOutput(self, spec):
1628
+ """Return the 'output' (full output path) to the binary in a bundle."""
1629
+ path = generator_default_variables["PRODUCT_DIR"]
1630
+ return os.path.join(path, self.xcode_settings.GetExecutablePath())
1631
+
1632
+ def ComputeDeps(self, spec):
1633
+ """Compute the dependencies of a gyp spec.
1634
+
1635
+ Returns a tuple (deps, link_deps), where each is a list of
1636
+ filenames that will need to be put in front of make for either
1637
+ building (deps) or linking (link_deps).
1638
+ """
1639
+ deps = []
1640
+ link_deps = []
1641
+ if "dependencies" in spec:
1642
+ deps.extend(
1643
+ [
1644
+ target_outputs[dep]
1645
+ for dep in spec["dependencies"]
1646
+ if target_outputs[dep]
1647
+ ]
1648
+ )
1649
+ for dep in spec["dependencies"]:
1650
+ if dep in target_link_deps:
1651
+ link_deps.append(target_link_deps[dep])
1652
+ deps.extend(link_deps)
1653
+ # TODO: It seems we need to transitively link in libraries (e.g. -lfoo)?
1654
+ # This hack makes it work:
1655
+ # link_deps.extend(spec.get('libraries', []))
1656
+ return (gyp.common.uniquer(deps), gyp.common.uniquer(link_deps))
1657
+
1658
+ def GetSharedObjectFromSidedeck(self, sidedeck):
1659
+ """Return the shared object files based on sidedeck"""
1660
+ return re.sub(r"\.x$", ".so", sidedeck)
1661
+
1662
+ def GetUnversionedSidedeckFromSidedeck(self, sidedeck):
1663
+ """Return the shared object files based on sidedeck"""
1664
+ return re.sub(r"\.\d+\.x$", ".x", sidedeck)
1665
+
1666
+ def WriteDependencyOnExtraOutputs(self, target, extra_outputs):
1667
+ self.WriteMakeRule(
1668
+ [self.output_binary],
1669
+ extra_outputs,
1670
+ comment="Build our special outputs first.",
1671
+ order_only=True,
1672
+ )
1673
+
1674
+ def WriteTarget(
1675
+ self, spec, configs, deps, link_deps, bundle_deps, extra_outputs, part_of_all
1676
+ ):
1677
+ """Write Makefile code to produce the final target of the gyp spec.
1678
+
1679
+ spec, configs: input from gyp.
1680
+ deps, link_deps: dependency lists; see ComputeDeps()
1681
+ extra_outputs: any extra outputs that our target should depend on
1682
+ part_of_all: flag indicating this target is part of 'all'
1683
+ """
1684
+
1685
+ self.WriteLn("### Rules for final target.")
1686
+
1687
+ if extra_outputs:
1688
+ self.WriteDependencyOnExtraOutputs(self.output_binary, extra_outputs)
1689
+ self.WriteMakeRule(
1690
+ extra_outputs,
1691
+ deps,
1692
+ comment=("Preserve order dependency of " "special output on deps."),
1693
+ order_only=True,
1694
+ )
1695
+
1696
+ target_postbuilds = {}
1697
+ if self.type != "none":
1698
+ for configname in sorted(configs.keys()):
1699
+ config = configs[configname]
1700
+ if self.flavor == "mac":
1701
+ ldflags = self.xcode_settings.GetLdflags(
1702
+ configname,
1703
+ generator_default_variables["PRODUCT_DIR"],
1704
+ lambda p: Sourceify(self.Absolutify(p)),
1705
+ arch=config.get("xcode_configuration_platform"),
1706
+ )
1707
+
1708
+ # TARGET_POSTBUILDS_$(BUILDTYPE) is added to postbuilds later on.
1709
+ gyp_to_build = gyp.common.InvertRelativePath(self.path)
1710
+ target_postbuild = self.xcode_settings.AddImplicitPostbuilds(
1711
+ configname,
1712
+ QuoteSpaces(
1713
+ os.path.normpath(os.path.join(gyp_to_build, self.output))
1714
+ ),
1715
+ QuoteSpaces(
1716
+ os.path.normpath(
1717
+ os.path.join(gyp_to_build, self.output_binary)
1718
+ )
1719
+ ),
1720
+ )
1721
+ if target_postbuild:
1722
+ target_postbuilds[configname] = target_postbuild
1723
+ else:
1724
+ ldflags = config.get("ldflags", [])
1725
+ # Compute an rpath for this output if needed.
1726
+ if any(dep.endswith(".so") or ".so." in dep for dep in deps):
1727
+ # We want to get the literal string "$ORIGIN"
1728
+ # into the link command, so we need lots of escaping.
1729
+ ldflags.append(r"-Wl,-rpath=\$$ORIGIN/")
1730
+ ldflags.append(r"-Wl,-rpath-link=\$(builddir)/")
1731
+ library_dirs = config.get("library_dirs", [])
1732
+ ldflags += [("-L%s" % library_dir) for library_dir in library_dirs]
1733
+ self.WriteList(ldflags, "LDFLAGS_%s" % configname)
1734
+ if self.flavor == "mac":
1735
+ self.WriteList(
1736
+ self.xcode_settings.GetLibtoolflags(configname),
1737
+ "LIBTOOLFLAGS_%s" % configname,
1738
+ )
1739
+ libraries = spec.get("libraries")
1740
+ if libraries:
1741
+ # Remove duplicate entries
1742
+ libraries = gyp.common.uniquer(libraries)
1743
+ if self.flavor == "mac":
1744
+ libraries = self.xcode_settings.AdjustLibraries(libraries)
1745
+ self.WriteList(libraries, "LIBS")
1746
+ self.WriteLn(
1747
+ "%s: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE))"
1748
+ % QuoteSpaces(self.output_binary)
1749
+ )
1750
+ self.WriteLn("%s: LIBS := $(LIBS)" % QuoteSpaces(self.output_binary))
1751
+
1752
+ if self.flavor == "mac":
1753
+ self.WriteLn(
1754
+ "%s: GYP_LIBTOOLFLAGS := $(LIBTOOLFLAGS_$(BUILDTYPE))"
1755
+ % QuoteSpaces(self.output_binary)
1756
+ )
1757
+
1758
+ # Postbuild actions. Like actions, but implicitly depend on the target's
1759
+ # output.
1760
+ postbuilds = []
1761
+ if self.flavor == "mac":
1762
+ if target_postbuilds:
1763
+ postbuilds.append("$(TARGET_POSTBUILDS_$(BUILDTYPE))")
1764
+ postbuilds.extend(gyp.xcode_emulation.GetSpecPostbuildCommands(spec))
1765
+
1766
+ if postbuilds:
1767
+ # Envvars may be referenced by TARGET_POSTBUILDS_$(BUILDTYPE),
1768
+ # so we must output its definition first, since we declare variables
1769
+ # using ":=".
1770
+ self.WriteSortedXcodeEnv(self.output, self.GetSortedXcodePostbuildEnv())
1771
+
1772
+ for configname in target_postbuilds:
1773
+ self.WriteLn(
1774
+ "%s: TARGET_POSTBUILDS_%s := %s"
1775
+ % (
1776
+ QuoteSpaces(self.output),
1777
+ configname,
1778
+ gyp.common.EncodePOSIXShellList(target_postbuilds[configname]),
1779
+ )
1780
+ )
1781
+
1782
+ # Postbuilds expect to be run in the gyp file's directory, so insert an
1783
+ # implicit postbuild to cd to there.
1784
+ postbuilds.insert(0, gyp.common.EncodePOSIXShellList(["cd", self.path]))
1785
+ for i, postbuild in enumerate(postbuilds):
1786
+ if not postbuild.startswith("$"):
1787
+ postbuilds[i] = EscapeShellArgument(postbuild)
1788
+ self.WriteLn("%s: builddir := $(abs_builddir)" % QuoteSpaces(self.output))
1789
+ self.WriteLn(
1790
+ "%s: POSTBUILDS := %s"
1791
+ % (QuoteSpaces(self.output), " ".join(postbuilds))
1792
+ )
1793
+
1794
+ # A bundle directory depends on its dependencies such as bundle resources
1795
+ # and bundle binary. When all dependencies have been built, the bundle
1796
+ # needs to be packaged.
1797
+ if self.is_mac_bundle:
1798
+ # If the framework doesn't contain a binary, then nothing depends
1799
+ # on the actions -- make the framework depend on them directly too.
1800
+ self.WriteDependencyOnExtraOutputs(self.output, extra_outputs)
1801
+
1802
+ # Bundle dependencies. Note that the code below adds actions to this
1803
+ # target, so if you move these two lines, move the lines below as well.
1804
+ self.WriteList([QuoteSpaces(dep) for dep in bundle_deps], "BUNDLE_DEPS")
1805
+ self.WriteLn("%s: $(BUNDLE_DEPS)" % QuoteSpaces(self.output))
1806
+
1807
+ # After the framework is built, package it. Needs to happen before
1808
+ # postbuilds, since postbuilds depend on this.
1809
+ if self.type in ("shared_library", "loadable_module"):
1810
+ self.WriteLn(
1811
+ "\t@$(call do_cmd,mac_package_framework,,,%s)"
1812
+ % self.xcode_settings.GetFrameworkVersion()
1813
+ )
1814
+
1815
+ # Bundle postbuilds can depend on the whole bundle, so run them after
1816
+ # the bundle is packaged, not already after the bundle binary is done.
1817
+ if postbuilds:
1818
+ self.WriteLn("\t@$(call do_postbuilds)")
1819
+ postbuilds = [] # Don't write postbuilds for target's output.
1820
+
1821
+ # Needed by test/mac/gyptest-rebuild.py.
1822
+ self.WriteLn("\t@true # No-op, used by tests")
1823
+
1824
+ # Since this target depends on binary and resources which are in
1825
+ # nested subfolders, the framework directory will be older than
1826
+ # its dependencies usually. To prevent this rule from executing
1827
+ # on every build (expensive, especially with postbuilds), expliclity
1828
+ # update the time on the framework directory.
1829
+ self.WriteLn("\t@touch -c %s" % QuoteSpaces(self.output))
1830
+
1831
+ if postbuilds:
1832
+ assert not self.is_mac_bundle, (
1833
+ "Postbuilds for bundles should be done "
1834
+ "on the bundle, not the binary (target '%s')" % self.target
1835
+ )
1836
+ assert "product_dir" not in spec, (
1837
+ "Postbuilds do not work with " "custom product_dir"
1838
+ )
1839
+
1840
+ if self.type == "executable":
1841
+ self.WriteLn(
1842
+ "%s: LD_INPUTS := %s"
1843
+ % (
1844
+ QuoteSpaces(self.output_binary),
1845
+ " ".join(QuoteSpaces(dep) for dep in link_deps),
1846
+ )
1847
+ )
1848
+ if self.toolset == "host" and self.flavor == "android":
1849
+ self.WriteDoCmd(
1850
+ [self.output_binary],
1851
+ link_deps,
1852
+ "link_host",
1853
+ part_of_all,
1854
+ postbuilds=postbuilds,
1855
+ )
1856
+ else:
1857
+ self.WriteDoCmd(
1858
+ [self.output_binary],
1859
+ link_deps,
1860
+ "link",
1861
+ part_of_all,
1862
+ postbuilds=postbuilds,
1863
+ )
1864
+
1865
+ elif self.type == "static_library":
1866
+ for link_dep in link_deps:
1867
+ assert " " not in link_dep, (
1868
+ "Spaces in alink input filenames not supported (%s)" % link_dep
1869
+ )
1870
+ if (
1871
+ self.flavor not in ("mac", "openbsd", "netbsd", "win")
1872
+ and not self.is_standalone_static_library
1873
+ ):
1874
+ if self.flavor in ("linux", "android"):
1875
+ self.WriteMakeRule(
1876
+ [self.output_binary],
1877
+ link_deps,
1878
+ actions=["$(call create_thin_archive,$@,$^)"],
1879
+ )
1880
+ else:
1881
+ self.WriteDoCmd(
1882
+ [self.output_binary],
1883
+ link_deps,
1884
+ "alink_thin",
1885
+ part_of_all,
1886
+ postbuilds=postbuilds,
1887
+ )
1888
+ else:
1889
+ if self.flavor in ("linux", "android"):
1890
+ self.WriteMakeRule(
1891
+ [self.output_binary],
1892
+ link_deps,
1893
+ actions=["$(call create_archive,$@,$^)"],
1894
+ )
1895
+ else:
1896
+ self.WriteDoCmd(
1897
+ [self.output_binary],
1898
+ link_deps,
1899
+ "alink",
1900
+ part_of_all,
1901
+ postbuilds=postbuilds,
1902
+ )
1903
+ elif self.type == "shared_library":
1904
+ self.WriteLn(
1905
+ "%s: LD_INPUTS := %s"
1906
+ % (
1907
+ QuoteSpaces(self.output_binary),
1908
+ " ".join(QuoteSpaces(dep) for dep in link_deps),
1909
+ )
1910
+ )
1911
+ self.WriteDoCmd(
1912
+ [self.output_binary],
1913
+ link_deps,
1914
+ "solink",
1915
+ part_of_all,
1916
+ postbuilds=postbuilds,
1917
+ )
1918
+ # z/OS has a .so target as well as a sidedeck .x target
1919
+ if self.flavor == "zos":
1920
+ self.WriteLn(
1921
+ "%s: %s"
1922
+ % (
1923
+ QuoteSpaces(
1924
+ self.GetSharedObjectFromSidedeck(self.output_binary)
1925
+ ),
1926
+ QuoteSpaces(self.output_binary),
1927
+ )
1928
+ )
1929
+ elif self.type == "loadable_module":
1930
+ for link_dep in link_deps:
1931
+ assert " " not in link_dep, (
1932
+ "Spaces in module input filenames not supported (%s)" % link_dep
1933
+ )
1934
+ if self.toolset == "host" and self.flavor == "android":
1935
+ self.WriteDoCmd(
1936
+ [self.output_binary],
1937
+ link_deps,
1938
+ "solink_module_host",
1939
+ part_of_all,
1940
+ postbuilds=postbuilds,
1941
+ )
1942
+ else:
1943
+ self.WriteDoCmd(
1944
+ [self.output_binary],
1945
+ link_deps,
1946
+ "solink_module",
1947
+ part_of_all,
1948
+ postbuilds=postbuilds,
1949
+ )
1950
+ elif self.type == "none":
1951
+ # Write a stamp line.
1952
+ self.WriteDoCmd(
1953
+ [self.output_binary], deps, "touch", part_of_all, postbuilds=postbuilds
1954
+ )
1955
+ else:
1956
+ print("WARNING: no output for", self.type, self.target)
1957
+
1958
+ # Add an alias for each target (if there are any outputs).
1959
+ # Installable target aliases are created below.
1960
+ if (self.output and self.output != self.target) and (
1961
+ self.type not in self._INSTALLABLE_TARGETS
1962
+ ):
1963
+ self.WriteMakeRule(
1964
+ [self.target], [self.output], comment="Add target alias", phony=True
1965
+ )
1966
+ if part_of_all:
1967
+ self.WriteMakeRule(
1968
+ ["all"],
1969
+ [self.target],
1970
+ comment='Add target alias to "all" target.',
1971
+ phony=True,
1972
+ )
1973
+
1974
+ # Add special-case rules for our installable targets.
1975
+ # 1) They need to install to the build dir or "product" dir.
1976
+ # 2) They get shortcuts for building (e.g. "make chrome").
1977
+ # 3) They are part of "make all".
1978
+ if self.type in self._INSTALLABLE_TARGETS or self.is_standalone_static_library:
1979
+ if self.type == "shared_library":
1980
+ file_desc = "shared library"
1981
+ elif self.type == "static_library":
1982
+ file_desc = "static library"
1983
+ else:
1984
+ file_desc = "executable"
1985
+ install_path = self._InstallableTargetInstallPath()
1986
+ installable_deps = []
1987
+ if self.flavor != "zos":
1988
+ installable_deps.append(self.output)
1989
+ if (
1990
+ self.flavor == "mac"
1991
+ and "product_dir" not in spec
1992
+ and self.toolset == "target"
1993
+ ):
1994
+ # On macOS, products are created in install_path immediately.
1995
+ assert install_path == self.output, f"{install_path} != {self.output}"
1996
+
1997
+ # Point the target alias to the final binary output.
1998
+ self.WriteMakeRule(
1999
+ [self.target], [install_path], comment="Add target alias", phony=True
2000
+ )
2001
+ if install_path != self.output:
2002
+ assert not self.is_mac_bundle # See comment a few lines above.
2003
+ self.WriteDoCmd(
2004
+ [install_path],
2005
+ [self.output],
2006
+ "copy",
2007
+ comment="Copy this to the %s output path." % file_desc,
2008
+ part_of_all=part_of_all,
2009
+ )
2010
+ if self.flavor != "zos":
2011
+ installable_deps.append(install_path)
2012
+ if self.flavor == "zos" and self.type == "shared_library":
2013
+ # lib.target/libnode.so has a dependency on $(obj).target/libnode.so
2014
+ self.WriteDoCmd(
2015
+ [self.GetSharedObjectFromSidedeck(install_path)],
2016
+ [self.GetSharedObjectFromSidedeck(self.output)],
2017
+ "copy",
2018
+ comment="Copy this to the %s output path." % file_desc,
2019
+ part_of_all=part_of_all,
2020
+ )
2021
+ # Create a symlink of libnode.x to libnode.version.x
2022
+ self.WriteDoCmd(
2023
+ [self.GetUnversionedSidedeckFromSidedeck(install_path)],
2024
+ [install_path],
2025
+ "symlink",
2026
+ comment="Symlnk this to the %s output path." % file_desc,
2027
+ part_of_all=part_of_all,
2028
+ )
2029
+ # Place libnode.version.so and libnode.x symlink in lib.target dir
2030
+ installable_deps.append(self.GetSharedObjectFromSidedeck(install_path))
2031
+ installable_deps.append(
2032
+ self.GetUnversionedSidedeckFromSidedeck(install_path)
2033
+ )
2034
+ if self.output != self.alias and self.alias != self.target:
2035
+ self.WriteMakeRule(
2036
+ [self.alias],
2037
+ installable_deps,
2038
+ comment="Short alias for building this %s." % file_desc,
2039
+ phony=True,
2040
+ )
2041
+ if self.flavor == "zos" and self.type == "shared_library":
2042
+ # Make sure that .x symlink target is run
2043
+ self.WriteMakeRule(
2044
+ ["all"],
2045
+ [
2046
+ self.GetUnversionedSidedeckFromSidedeck(install_path),
2047
+ self.GetSharedObjectFromSidedeck(install_path),
2048
+ ],
2049
+ comment='Add %s to "all" target.' % file_desc,
2050
+ phony=True,
2051
+ )
2052
+ elif part_of_all:
2053
+ self.WriteMakeRule(
2054
+ ["all"],
2055
+ [install_path],
2056
+ comment='Add %s to "all" target.' % file_desc,
2057
+ phony=True,
2058
+ )
2059
+
2060
+ def WriteList(self, value_list, variable=None, prefix="", quoter=QuoteIfNecessary):
2061
+ """Write a variable definition that is a list of values.
2062
+
2063
+ E.g. WriteList(['a','b'], 'foo', prefix='blah') writes out
2064
+ foo = blaha blahb
2065
+ but in a pretty-printed style.
2066
+ """
2067
+ values = ""
2068
+ if value_list:
2069
+ value_list = [quoter(prefix + value) for value in value_list]
2070
+ values = " \\\n\t" + " \\\n\t".join(value_list)
2071
+ self.fp.write(f"{variable} :={values}\n\n")
2072
+
2073
+ def WriteDoCmd(
2074
+ self, outputs, inputs, command, part_of_all, comment=None, postbuilds=False
2075
+ ):
2076
+ """Write a Makefile rule that uses do_cmd.
2077
+
2078
+ This makes the outputs dependent on the command line that was run,
2079
+ as well as support the V= make command line flag.
2080
+ """
2081
+ suffix = ""
2082
+ if postbuilds:
2083
+ assert "," not in command
2084
+ suffix = ",,1" # Tell do_cmd to honor $POSTBUILDS
2085
+ self.WriteMakeRule(
2086
+ outputs,
2087
+ inputs,
2088
+ actions=[f"$(call do_cmd,{command}{suffix})"],
2089
+ comment=comment,
2090
+ command=command,
2091
+ force=True,
2092
+ )
2093
+ # Add our outputs to the list of targets we read depfiles from.
2094
+ # all_deps is only used for deps file reading, and for deps files we replace
2095
+ # spaces with ? because escaping doesn't work with make's $(sort) and
2096
+ # other functions.
2097
+ outputs = [QuoteSpaces(o, SPACE_REPLACEMENT) for o in outputs]
2098
+ self.WriteLn("all_deps += %s" % " ".join(outputs))
2099
+
2100
+ def WriteMakeRule(
2101
+ self,
2102
+ outputs,
2103
+ inputs,
2104
+ actions=None,
2105
+ comment=None,
2106
+ order_only=False,
2107
+ force=False,
2108
+ phony=False,
2109
+ command=None,
2110
+ ):
2111
+ """Write a Makefile rule, with some extra tricks.
2112
+
2113
+ outputs: a list of outputs for the rule (note: this is not directly
2114
+ supported by make; see comments below)
2115
+ inputs: a list of inputs for the rule
2116
+ actions: a list of shell commands to run for the rule
2117
+ comment: a comment to put in the Makefile above the rule (also useful
2118
+ for making this Python script's code self-documenting)
2119
+ order_only: if true, makes the dependency order-only
2120
+ force: if true, include FORCE_DO_CMD as an order-only dep
2121
+ phony: if true, the rule does not actually generate the named output, the
2122
+ output is just a name to run the rule
2123
+ command: (optional) command name to generate unambiguous labels
2124
+ """
2125
+ outputs = [QuoteSpaces(o) for o in outputs]
2126
+ inputs = [QuoteSpaces(i) for i in inputs]
2127
+
2128
+ if comment:
2129
+ self.WriteLn("# " + comment)
2130
+ if phony:
2131
+ self.WriteLn(".PHONY: " + " ".join(outputs))
2132
+ if actions:
2133
+ self.WriteLn("%s: TOOLSET := $(TOOLSET)" % outputs[0])
2134
+ force_append = " FORCE_DO_CMD" if force else ""
2135
+
2136
+ if order_only:
2137
+ # Order only rule: Just write a simple rule.
2138
+ # TODO(evanm): just make order_only a list of deps instead of this hack.
2139
+ self.WriteLn(
2140
+ "{}: | {}{}".format(" ".join(outputs), " ".join(inputs), force_append)
2141
+ )
2142
+ elif len(outputs) == 1:
2143
+ # Regular rule, one output: Just write a simple rule.
2144
+ self.WriteLn("{}: {}{}".format(outputs[0], " ".join(inputs), force_append))
2145
+ else:
2146
+ # Regular rule, more than one output: Multiple outputs are tricky in
2147
+ # make. We will write three rules:
2148
+ # - All outputs depend on an intermediate file.
2149
+ # - Make .INTERMEDIATE depend on the intermediate.
2150
+ # - The intermediate file depends on the inputs and executes the
2151
+ # actual command.
2152
+ # - The intermediate recipe will 'touch' the intermediate file.
2153
+ # - The multi-output rule will have an do-nothing recipe.
2154
+
2155
+ # Hash the target name to avoid generating overlong filenames.
2156
+ cmddigest = hashlib.sha1(
2157
+ (command or self.target).encode("utf-8")
2158
+ ).hexdigest()
2159
+ intermediate = "%s.intermediate" % cmddigest
2160
+ self.WriteLn("{}: {}".format(" ".join(outputs), intermediate))
2161
+ self.WriteLn("\t%s" % "@:")
2162
+ self.WriteLn("{}: {}".format(".INTERMEDIATE", intermediate))
2163
+ self.WriteLn(
2164
+ "{}: {}{}".format(intermediate, " ".join(inputs), force_append)
2165
+ )
2166
+ actions.insert(0, "$(call do_cmd,touch)")
2167
+
2168
+ if actions:
2169
+ for action in actions:
2170
+ self.WriteLn("\t%s" % action)
2171
+ self.WriteLn()
2172
+
2173
+ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
2174
+ """Write a set of LOCAL_XXX definitions for Android NDK.
2175
+
2176
+ These variable definitions will be used by Android NDK but do nothing for
2177
+ non-Android applications.
2178
+
2179
+ Arguments:
2180
+ module_name: Android NDK module name, which must be unique among all
2181
+ module names.
2182
+ all_sources: A list of source files (will be filtered by Compilable).
2183
+ link_deps: A list of link dependencies, which must be sorted in
2184
+ the order from dependencies to dependents.
2185
+ """
2186
+ if self.type not in ("executable", "shared_library", "static_library"):
2187
+ return
2188
+
2189
+ self.WriteLn("# Variable definitions for Android applications")
2190
+ self.WriteLn("include $(CLEAR_VARS)")
2191
+ self.WriteLn("LOCAL_MODULE := " + module_name)
2192
+ self.WriteLn(
2193
+ "LOCAL_CFLAGS := $(CFLAGS_$(BUILDTYPE)) "
2194
+ "$(DEFS_$(BUILDTYPE)) "
2195
+ # LOCAL_CFLAGS is applied to both of C and C++. There is
2196
+ # no way to specify $(CFLAGS_C_$(BUILDTYPE)) only for C
2197
+ # sources.
2198
+ "$(CFLAGS_C_$(BUILDTYPE)) "
2199
+ # $(INCS_$(BUILDTYPE)) includes the prefix '-I' while
2200
+ # LOCAL_C_INCLUDES does not expect it. So put it in
2201
+ # LOCAL_CFLAGS.
2202
+ "$(INCS_$(BUILDTYPE))"
2203
+ )
2204
+ # LOCAL_CXXFLAGS is obsolete and LOCAL_CPPFLAGS is preferred.
2205
+ self.WriteLn("LOCAL_CPPFLAGS := $(CFLAGS_CC_$(BUILDTYPE))")
2206
+ self.WriteLn("LOCAL_C_INCLUDES :=")
2207
+ self.WriteLn("LOCAL_LDLIBS := $(LDFLAGS_$(BUILDTYPE)) $(LIBS)")
2208
+
2209
+ # Detect the C++ extension.
2210
+ cpp_ext = {".cc": 0, ".cpp": 0, ".cxx": 0}
2211
+ default_cpp_ext = ".cpp"
2212
+ for filename in all_sources:
2213
+ ext = os.path.splitext(filename)[1]
2214
+ if ext in cpp_ext:
2215
+ cpp_ext[ext] += 1
2216
+ if cpp_ext[ext] > cpp_ext[default_cpp_ext]:
2217
+ default_cpp_ext = ext
2218
+ self.WriteLn("LOCAL_CPP_EXTENSION := " + default_cpp_ext)
2219
+
2220
+ self.WriteList(
2221
+ list(map(self.Absolutify, filter(Compilable, all_sources))),
2222
+ "LOCAL_SRC_FILES",
2223
+ )
2224
+
2225
+ # Filter out those which do not match prefix and suffix and produce
2226
+ # the resulting list without prefix and suffix.
2227
+ def DepsToModules(deps, prefix, suffix):
2228
+ modules = []
2229
+ for filepath in deps:
2230
+ filename = os.path.basename(filepath)
2231
+ if filename.startswith(prefix) and filename.endswith(suffix):
2232
+ modules.append(filename[len(prefix) : -len(suffix)])
2233
+ return modules
2234
+
2235
+ # Retrieve the default value of 'SHARED_LIB_SUFFIX'
2236
+ params = {"flavor": "linux"}
2237
+ default_variables = {}
2238
+ CalculateVariables(default_variables, params)
2239
+
2240
+ self.WriteList(
2241
+ DepsToModules(
2242
+ link_deps,
2243
+ generator_default_variables["SHARED_LIB_PREFIX"],
2244
+ default_variables["SHARED_LIB_SUFFIX"],
2245
+ ),
2246
+ "LOCAL_SHARED_LIBRARIES",
2247
+ )
2248
+ self.WriteList(
2249
+ DepsToModules(
2250
+ link_deps,
2251
+ generator_default_variables["STATIC_LIB_PREFIX"],
2252
+ generator_default_variables["STATIC_LIB_SUFFIX"],
2253
+ ),
2254
+ "LOCAL_STATIC_LIBRARIES",
2255
+ )
2256
+
2257
+ if self.type == "executable":
2258
+ self.WriteLn("include $(BUILD_EXECUTABLE)")
2259
+ elif self.type == "shared_library":
2260
+ self.WriteLn("include $(BUILD_SHARED_LIBRARY)")
2261
+ elif self.type == "static_library":
2262
+ self.WriteLn("include $(BUILD_STATIC_LIBRARY)")
2263
+ self.WriteLn()
2264
+
2265
+ def WriteLn(self, text=""):
2266
+ self.fp.write(text + "\n")
2267
+
2268
+ def GetSortedXcodeEnv(self, additional_settings=None):
2269
+ return gyp.xcode_emulation.GetSortedXcodeEnv(
2270
+ self.xcode_settings,
2271
+ "$(abs_builddir)",
2272
+ os.path.join("$(abs_srcdir)", self.path),
2273
+ "$(BUILDTYPE)",
2274
+ additional_settings,
2275
+ )
2276
+
2277
+ def GetSortedXcodePostbuildEnv(self):
2278
+ # CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack.
2279
+ # TODO(thakis): It would be nice to have some general mechanism instead.
2280
+ strip_save_file = self.xcode_settings.GetPerTargetSetting(
2281
+ "CHROMIUM_STRIP_SAVE_FILE", ""
2282
+ )
2283
+ # Even if strip_save_file is empty, explicitly write it. Else a postbuild
2284
+ # might pick up an export from an earlier target.
2285
+ return self.GetSortedXcodeEnv(
2286
+ additional_settings={"CHROMIUM_STRIP_SAVE_FILE": strip_save_file}
2287
+ )
2288
+
2289
+ def WriteSortedXcodeEnv(self, target, env):
2290
+ for k, v in env:
2291
+ # For
2292
+ # foo := a\ b
2293
+ # the escaped space does the right thing. For
2294
+ # export foo := a\ b
2295
+ # it does not -- the backslash is written to the env as literal character.
2296
+ # So don't escape spaces in |env[k]|.
2297
+ self.WriteLn(f"{QuoteSpaces(target)}: export {k} := {v}")
2298
+
2299
+ def Objectify(self, path):
2300
+ """Convert a path to its output directory form."""
2301
+ if "$(" in path:
2302
+ path = path.replace("$(obj)/", "$(obj).%s/$(TARGET)/" % self.toolset)
2303
+ if "$(obj)" not in path:
2304
+ path = f"$(obj).{self.toolset}/$(TARGET)/{path}"
2305
+ return path
2306
+
2307
+ def Pchify(self, path, lang):
2308
+ """Convert a prefix header path to its output directory form."""
2309
+ path = self.Absolutify(path)
2310
+ if "$(" in path:
2311
+ path = path.replace(
2312
+ "$(obj)/", f"$(obj).{self.toolset}/$(TARGET)/pch-{lang}"
2313
+ )
2314
+ return path
2315
+ return f"$(obj).{self.toolset}/$(TARGET)/pch-{lang}/{path}"
2316
+
2317
+ def Absolutify(self, path):
2318
+ """Convert a subdirectory-relative path into a base-relative path.
2319
+ Skips over paths that contain variables."""
2320
+ if "$(" in path:
2321
+ # Don't call normpath in this case, as it might collapse the
2322
+ # path too aggressively if it features '..'. However it's still
2323
+ # important to strip trailing slashes.
2324
+ return path.rstrip("/")
2325
+ return os.path.normpath(os.path.join(self.path, path))
2326
+
2327
+ def ExpandInputRoot(self, template, expansion, dirname):
2328
+ if "%(INPUT_ROOT)s" not in template and "%(INPUT_DIRNAME)s" not in template:
2329
+ return template
2330
+ path = template % {
2331
+ "INPUT_ROOT": expansion,
2332
+ "INPUT_DIRNAME": dirname,
2333
+ }
2334
+ return path
2335
+
2336
+ def _InstallableTargetInstallPath(self):
2337
+ """Returns the location of the final output for an installable target."""
2338
+ # Functionality removed for all platforms to match Xcode and hoist
2339
+ # shared libraries into PRODUCT_DIR for users:
2340
+ # Xcode puts shared_library results into PRODUCT_DIR, and some gyp files
2341
+ # rely on this. Emulate this behavior for mac.
2342
+ # if self.type == "shared_library" and (
2343
+ # self.flavor != "mac" or self.toolset != "target"
2344
+ # ):
2345
+ # # Install all shared libs into a common directory (per toolset) for
2346
+ # # convenient access with LD_LIBRARY_PATH.
2347
+ # return "$(builddir)/lib.%s/%s" % (self.toolset, self.alias)
2348
+ if self.flavor == "zos" and self.type == "shared_library":
2349
+ return "$(builddir)/lib.%s/%s" % (self.toolset, self.alias)
2350
+
2351
+ return "$(builddir)/" + self.alias
2352
+
2353
+
2354
+ def WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files):
2355
+ """Write the target to regenerate the Makefile."""
2356
+ options = params["options"]
2357
+ build_files_args = [
2358
+ gyp.common.RelativePath(filename, options.toplevel_dir)
2359
+ for filename in params["build_files_arg"]
2360
+ ]
2361
+
2362
+ gyp_binary = gyp.common.FixIfRelativePath(
2363
+ params["gyp_binary"], options.toplevel_dir
2364
+ )
2365
+ if not gyp_binary.startswith(os.sep):
2366
+ gyp_binary = os.path.join(".", gyp_binary)
2367
+
2368
+ root_makefile.write(
2369
+ "quiet_cmd_regen_makefile = ACTION Regenerating $@\n"
2370
+ "cmd_regen_makefile = cd $(srcdir); %(cmd)s\n"
2371
+ "%(makefile_name)s: %(deps)s\n"
2372
+ "\t$(call do_cmd,regen_makefile)\n\n"
2373
+ % {
2374
+ "makefile_name": makefile_name,
2375
+ "deps": " ".join(SourceifyAndQuoteSpaces(bf) for bf in build_files),
2376
+ "cmd": gyp.common.EncodePOSIXShellList(
2377
+ [gyp_binary, "-fmake"] + gyp.RegenerateFlags(options) + build_files_args
2378
+ ),
2379
+ }
2380
+ )
2381
+
2382
+
2383
+ def PerformBuild(data, configurations, params):
2384
+ options = params["options"]
2385
+ for config in configurations:
2386
+ arguments = ["make"]
2387
+ if options.toplevel_dir and options.toplevel_dir != ".":
2388
+ arguments += "-C", options.toplevel_dir
2389
+ arguments.append("BUILDTYPE=" + config)
2390
+ print(f"Building [{config}]: {arguments}")
2391
+ subprocess.check_call(arguments)
2392
+
2393
+
2394
+ def GenerateOutput(target_list, target_dicts, data, params):
2395
+ options = params["options"]
2396
+ flavor = gyp.common.GetFlavor(params)
2397
+ generator_flags = params.get("generator_flags", {})
2398
+ builddir_name = generator_flags.get("output_dir", "out")
2399
+ android_ndk_version = generator_flags.get("android_ndk_version", None)
2400
+ default_target = generator_flags.get("default_target", "all")
2401
+
2402
+ def CalculateMakefilePath(build_file, base_name):
2403
+ """Determine where to write a Makefile for a given gyp file."""
2404
+ # Paths in gyp files are relative to the .gyp file, but we want
2405
+ # paths relative to the source root for the master makefile. Grab
2406
+ # the path of the .gyp file as the base to relativize against.
2407
+ # E.g. "foo/bar" when we're constructing targets for "foo/bar/baz.gyp".
2408
+ base_path = gyp.common.RelativePath(os.path.dirname(build_file), options.depth)
2409
+ # We write the file in the base_path directory.
2410
+ output_file = os.path.join(options.depth, base_path, base_name)
2411
+ if options.generator_output:
2412
+ output_file = os.path.join(
2413
+ options.depth, options.generator_output, base_path, base_name
2414
+ )
2415
+ base_path = gyp.common.RelativePath(
2416
+ os.path.dirname(build_file), options.toplevel_dir
2417
+ )
2418
+ return base_path, output_file
2419
+
2420
+ # TODO: search for the first non-'Default' target. This can go
2421
+ # away when we add verification that all targets have the
2422
+ # necessary configurations.
2423
+ default_configuration = None
2424
+ toolsets = {target_dicts[target]["toolset"] for target in target_list}
2425
+ for target in target_list:
2426
+ spec = target_dicts[target]
2427
+ if spec["default_configuration"] != "Default":
2428
+ default_configuration = spec["default_configuration"]
2429
+ break
2430
+ if not default_configuration:
2431
+ default_configuration = "Default"
2432
+
2433
+ srcdir = "."
2434
+ makefile_name = "Makefile" + options.suffix
2435
+ makefile_path = os.path.join(options.toplevel_dir, makefile_name)
2436
+ if options.generator_output:
2437
+ global srcdir_prefix
2438
+ makefile_path = os.path.join(
2439
+ options.toplevel_dir, options.generator_output, makefile_name
2440
+ )
2441
+ srcdir = gyp.common.RelativePath(srcdir, options.generator_output)
2442
+ srcdir_prefix = "$(srcdir)/"
2443
+
2444
+ flock_command = "flock"
2445
+ copy_archive_arguments = "-af"
2446
+ makedep_arguments = "-MMD"
2447
+ header_params = {
2448
+ "default_target": default_target,
2449
+ "builddir": builddir_name,
2450
+ "default_configuration": default_configuration,
2451
+ "flock": flock_command,
2452
+ "flock_index": 1,
2453
+ "link_commands": LINK_COMMANDS_LINUX,
2454
+ "extra_commands": "",
2455
+ "srcdir": srcdir,
2456
+ "copy_archive_args": copy_archive_arguments,
2457
+ "makedep_args": makedep_arguments,
2458
+ "CC.target": GetEnvironFallback(("CC_target", "CC"), "$(CC)"),
2459
+ "AR.target": GetEnvironFallback(("AR_target", "AR"), "$(AR)"),
2460
+ "CXX.target": GetEnvironFallback(("CXX_target", "CXX"), "$(CXX)"),
2461
+ "LINK.target": GetEnvironFallback(("LINK_target", "LINK"), "$(LINK)"),
2462
+ "PLI.target": GetEnvironFallback(("PLI_target", "PLI"), "pli"),
2463
+ "CC.host": GetEnvironFallback(("CC_host", "CC"), "gcc"),
2464
+ "AR.host": GetEnvironFallback(("AR_host", "AR"), "ar"),
2465
+ "CXX.host": GetEnvironFallback(("CXX_host", "CXX"), "g++"),
2466
+ "LINK.host": GetEnvironFallback(("LINK_host", "LINK"), "$(CXX.host)"),
2467
+ "PLI.host": GetEnvironFallback(("PLI_host", "PLI"), "pli"),
2468
+ }
2469
+ if flavor == "mac":
2470
+ flock_command = "./gyp-mac-tool flock"
2471
+ header_params.update(
2472
+ {
2473
+ "flock": flock_command,
2474
+ "flock_index": 2,
2475
+ "link_commands": LINK_COMMANDS_MAC,
2476
+ "extra_commands": SHARED_HEADER_MAC_COMMANDS,
2477
+ }
2478
+ )
2479
+ elif flavor == "android":
2480
+ header_params.update({"link_commands": LINK_COMMANDS_ANDROID})
2481
+ elif flavor == "zos":
2482
+ copy_archive_arguments = "-fPR"
2483
+ CC_target = GetEnvironFallback(("CC_target", "CC"), "njsc")
2484
+ makedep_arguments = "-MMD"
2485
+ if CC_target == "clang":
2486
+ CC_host = GetEnvironFallback(("CC_host", "CC"), "clang")
2487
+ CXX_target = GetEnvironFallback(("CXX_target", "CXX"), "clang++")
2488
+ CXX_host = GetEnvironFallback(("CXX_host", "CXX"), "clang++")
2489
+ elif CC_target == "ibm-clang64":
2490
+ CC_host = GetEnvironFallback(("CC_host", "CC"), "ibm-clang64")
2491
+ CXX_target = GetEnvironFallback(("CXX_target", "CXX"), "ibm-clang++64")
2492
+ CXX_host = GetEnvironFallback(("CXX_host", "CXX"), "ibm-clang++64")
2493
+ elif CC_target == "ibm-clang":
2494
+ CC_host = GetEnvironFallback(("CC_host", "CC"), "ibm-clang")
2495
+ CXX_target = GetEnvironFallback(("CXX_target", "CXX"), "ibm-clang++")
2496
+ CXX_host = GetEnvironFallback(("CXX_host", "CXX"), "ibm-clang++")
2497
+ else:
2498
+ # Node.js versions prior to v18:
2499
+ makedep_arguments = "-qmakedep=gcc"
2500
+ CC_host = GetEnvironFallback(("CC_host", "CC"), "njsc")
2501
+ CXX_target = GetEnvironFallback(("CXX_target", "CXX"), "njsc++")
2502
+ CXX_host = GetEnvironFallback(("CXX_host", "CXX"), "njsc++")
2503
+ header_params.update(
2504
+ {
2505
+ "copy_archive_args": copy_archive_arguments,
2506
+ "makedep_args": makedep_arguments,
2507
+ "link_commands": LINK_COMMANDS_OS390,
2508
+ "extra_commands": SHARED_HEADER_OS390_COMMANDS,
2509
+ "CC.target": CC_target,
2510
+ "CXX.target": CXX_target,
2511
+ "CC.host": CC_host,
2512
+ "CXX.host": CXX_host,
2513
+ }
2514
+ )
2515
+ elif flavor == "solaris":
2516
+ copy_archive_arguments = "-pPRf@"
2517
+ header_params.update(
2518
+ {
2519
+ "copy_archive_args": copy_archive_arguments,
2520
+ "flock": "./gyp-flock-tool flock",
2521
+ "flock_index": 2,
2522
+ }
2523
+ )
2524
+ elif flavor == "freebsd":
2525
+ # Note: OpenBSD has sysutils/flock. lockf seems to be FreeBSD specific.
2526
+ header_params.update({"flock": "lockf"})
2527
+ elif flavor == "openbsd":
2528
+ copy_archive_arguments = "-pPRf"
2529
+ header_params.update({"copy_archive_args": copy_archive_arguments})
2530
+ elif flavor == "aix":
2531
+ copy_archive_arguments = "-pPRf"
2532
+ header_params.update(
2533
+ {
2534
+ "copy_archive_args": copy_archive_arguments,
2535
+ "link_commands": LINK_COMMANDS_AIX,
2536
+ "flock": "./gyp-flock-tool flock",
2537
+ "flock_index": 2,
2538
+ }
2539
+ )
2540
+ elif flavor == "os400":
2541
+ copy_archive_arguments = "-pPRf"
2542
+ header_params.update(
2543
+ {
2544
+ "copy_archive_args": copy_archive_arguments,
2545
+ "link_commands": LINK_COMMANDS_OS400,
2546
+ "flock": "./gyp-flock-tool flock",
2547
+ "flock_index": 2,
2548
+ }
2549
+ )
2550
+
2551
+ build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
2552
+ make_global_settings_array = data[build_file].get("make_global_settings", [])
2553
+ wrappers = {}
2554
+ for key, value in make_global_settings_array:
2555
+ if key.endswith("_wrapper"):
2556
+ wrappers[key[: -len("_wrapper")]] = "$(abspath %s)" % value
2557
+ make_global_settings = ""
2558
+ for key, value in make_global_settings_array:
2559
+ if re.match(".*_wrapper", key):
2560
+ continue
2561
+ if value[0] != "$":
2562
+ value = "$(abspath %s)" % value
2563
+ wrapper = wrappers.get(key)
2564
+ if wrapper:
2565
+ value = f"{wrapper} {value}"
2566
+ del wrappers[key]
2567
+ if key in ("CC", "CC.host", "CXX", "CXX.host"):
2568
+ make_global_settings += (
2569
+ "ifneq (,$(filter $(origin %s), undefined default))\n" % key
2570
+ )
2571
+ # Let gyp-time envvars win over global settings.
2572
+ env_key = key.replace(".", "_") # CC.host -> CC_host
2573
+ if env_key in os.environ:
2574
+ value = os.environ[env_key]
2575
+ make_global_settings += f" {key} = {value}\n"
2576
+ make_global_settings += "endif\n"
2577
+ else:
2578
+ make_global_settings += f"{key} ?= {value}\n"
2579
+ # TODO(ukai): define cmd when only wrapper is specified in
2580
+ # make_global_settings.
2581
+
2582
+ header_params["make_global_settings"] = make_global_settings
2583
+
2584
+ gyp.common.EnsureDirExists(makefile_path)
2585
+ root_makefile = open(makefile_path, "w")
2586
+ root_makefile.write(SHARED_HEADER % header_params)
2587
+ # Currently any versions have the same effect, but in future the behavior
2588
+ # could be different.
2589
+ if android_ndk_version:
2590
+ root_makefile.write(
2591
+ "# Define LOCAL_PATH for build of Android applications.\n"
2592
+ "LOCAL_PATH := $(call my-dir)\n"
2593
+ "\n"
2594
+ )
2595
+ for toolset in toolsets:
2596
+ root_makefile.write("TOOLSET := %s\n" % toolset)
2597
+ WriteRootHeaderSuffixRules(root_makefile)
2598
+
2599
+ # Put build-time support tools next to the root Makefile.
2600
+ dest_path = os.path.dirname(makefile_path)
2601
+ gyp.common.CopyTool(flavor, dest_path)
2602
+
2603
+ # Find the list of targets that derive from the gyp file(s) being built.
2604
+ needed_targets = set()
2605
+ for build_file in params["build_files"]:
2606
+ for target in gyp.common.AllTargets(target_list, target_dicts, build_file):
2607
+ needed_targets.add(target)
2608
+
2609
+ build_files = set()
2610
+ include_list = set()
2611
+ for qualified_target in target_list:
2612
+ build_file, target, toolset = gyp.common.ParseQualifiedTarget(qualified_target)
2613
+
2614
+ this_make_global_settings = data[build_file].get("make_global_settings", [])
2615
+ assert make_global_settings_array == this_make_global_settings, (
2616
+ "make_global_settings needs to be the same for all targets "
2617
+ f"{this_make_global_settings} vs. {make_global_settings}"
2618
+ )
2619
+
2620
+ build_files.add(gyp.common.RelativePath(build_file, options.toplevel_dir))
2621
+ included_files = data[build_file]["included_files"]
2622
+ for included_file in included_files:
2623
+ # The included_files entries are relative to the dir of the build file
2624
+ # that included them, so we have to undo that and then make them relative
2625
+ # to the root dir.
2626
+ relative_include_file = gyp.common.RelativePath(
2627
+ gyp.common.UnrelativePath(included_file, build_file),
2628
+ options.toplevel_dir,
2629
+ )
2630
+ abs_include_file = os.path.abspath(relative_include_file)
2631
+ # If the include file is from the ~/.gyp dir, we should use absolute path
2632
+ # so that relocating the src dir doesn't break the path.
2633
+ if params["home_dot_gyp"] and abs_include_file.startswith(
2634
+ params["home_dot_gyp"]
2635
+ ):
2636
+ build_files.add(abs_include_file)
2637
+ else:
2638
+ build_files.add(relative_include_file)
2639
+
2640
+ base_path, output_file = CalculateMakefilePath(
2641
+ build_file, target + "." + toolset + options.suffix + ".mk"
2642
+ )
2643
+
2644
+ spec = target_dicts[qualified_target]
2645
+ configs = spec["configurations"]
2646
+
2647
+ if flavor == "mac":
2648
+ gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[build_file], spec)
2649
+
2650
+ writer = MakefileWriter(generator_flags, flavor)
2651
+ writer.Write(
2652
+ qualified_target,
2653
+ base_path,
2654
+ output_file,
2655
+ spec,
2656
+ configs,
2657
+ part_of_all=qualified_target in needed_targets,
2658
+ )
2659
+
2660
+ # Our root_makefile lives at the source root. Compute the relative path
2661
+ # from there to the output_file for including.
2662
+ mkfile_rel_path = gyp.common.RelativePath(
2663
+ output_file, os.path.dirname(makefile_path)
2664
+ )
2665
+ include_list.add(mkfile_rel_path)
2666
+
2667
+ # Write out per-gyp (sub-project) Makefiles.
2668
+ depth_rel_path = gyp.common.RelativePath(options.depth, os.getcwd())
2669
+ for build_file in build_files:
2670
+ # The paths in build_files were relativized above, so undo that before
2671
+ # testing against the non-relativized items in target_list and before
2672
+ # calculating the Makefile path.
2673
+ build_file = os.path.join(depth_rel_path, build_file)
2674
+ gyp_targets = [
2675
+ target_dicts[qualified_target]["target_name"]
2676
+ for qualified_target in target_list
2677
+ if qualified_target.startswith(build_file)
2678
+ and qualified_target in needed_targets
2679
+ ]
2680
+ # Only generate Makefiles for gyp files with targets.
2681
+ if not gyp_targets:
2682
+ continue
2683
+ base_path, output_file = CalculateMakefilePath(
2684
+ build_file, os.path.splitext(os.path.basename(build_file))[0] + ".Makefile"
2685
+ )
2686
+ makefile_rel_path = gyp.common.RelativePath(
2687
+ os.path.dirname(makefile_path), os.path.dirname(output_file)
2688
+ )
2689
+ writer.WriteSubMake(output_file, makefile_rel_path, gyp_targets, builddir_name)
2690
+
2691
+ # Write out the sorted list of includes.
2692
+ root_makefile.write("\n")
2693
+ for include_file in sorted(include_list):
2694
+ # We wrap each .mk include in an if statement so users can tell make to
2695
+ # not load a file by setting NO_LOAD. The below make code says, only
2696
+ # load the .mk file if the .mk filename doesn't start with a token in
2697
+ # NO_LOAD.
2698
+ root_makefile.write(
2699
+ "ifeq ($(strip $(foreach prefix,$(NO_LOAD),\\\n"
2700
+ " $(findstring $(join ^,$(prefix)),\\\n"
2701
+ " $(join ^," + include_file + ")))),)\n"
2702
+ )
2703
+ root_makefile.write(" include " + include_file + "\n")
2704
+ root_makefile.write("endif\n")
2705
+ root_makefile.write("\n")
2706
+
2707
+ if not generator_flags.get("standalone") and generator_flags.get(
2708
+ "auto_regeneration", True
2709
+ ):
2710
+ WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files)
2711
+
2712
+ root_makefile.write(SHARED_FOOTER)
2713
+
2714
+ root_makefile.close()