@@ -156,6 +156,31 @@ def CalculateGeneratorInputInfo(params):
156156quiet_cmd_link = LINK($(TOOLSET)) $@
157157cmd_link = $(LINK.$(TOOLSET)) -o $@ $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,--start-group $(LD_INPUTS) $(LIBS) -Wl,--end-group
158158
159+ # Note: this does not handle spaces in paths
160+ define xargs
161+ $(1) $(word 1,$(2))
162+ $(if $(word 2,$(2)),$(call xargs,$(1),$(wordlist 2,$(words $(2)),$(2))))
163+ endef
164+
165+ define write-to-file
166+ @: >$(1)
167+ $(call xargs,@printf "%s\\ n" >>$(1),$(2))
168+ endef
169+
170+ OBJ_FILE_LIST := ar-file-list
171+
172+ define create_archive
173+ rm -f $(1) $(1).$(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
174+ $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
175+ $(AR.$(TOOLSET)) crs $(1) @$(1).$(OBJ_FILE_LIST)
176+ endef
177+
178+ define create_thin_archive
179+ rm -f $(1) $(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
180+ $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
181+ $(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST)
182+ endef
183+
159184# We support two kinds of shared objects (.so):
160185# 1) shared_library, which is just bundling together many dependent libraries
161186# into a link line.
@@ -200,6 +225,31 @@ def CalculateGeneratorInputInfo(params):
200225quiet_cmd_alink_thin = AR($(TOOLSET)) $@
201226cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crsT $@ $(filter %.o,$^)
202227
228+ # Note: this does not handle spaces in paths
229+ define xargs
230+ $(1) $(word 1,$(2))
231+ $(if $(word 2,$(2)),$(call xargs,$(1),$(wordlist 2,$(words $(2)),$(2))))
232+ endef
233+
234+ define write-to-file
235+ @: >$(1)
236+ $(call xargs,@printf "%s\\ n" >>$(1),$(2))
237+ endef
238+
239+ OBJ_FILE_LIST := ar-file-list
240+
241+ define create_archive
242+ rm -f $(1) $(1).$(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
243+ $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
244+ $(AR.$(TOOLSET)) crs $(1) @$(1).$(OBJ_FILE_LIST)
245+ endef
246+
247+ define create_thin_archive
248+ rm -f $(1) $(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
249+ $(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
250+ $(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST)
251+ endef
252+
203253# Due to circular dependencies between libraries :(, we wrap the
204254# special "figure out circular dependencies" flags around the entire
205255# input list during linking.
@@ -1809,21 +1859,35 @@ def WriteTarget(
18091859 self .flavor not in ("mac" , "openbsd" , "netbsd" , "win" )
18101860 and not self .is_standalone_static_library
18111861 ):
1812- self .WriteDoCmd (
1813- [self .output_binary ],
1814- link_deps ,
1815- "alink_thin" ,
1816- part_of_all ,
1817- postbuilds = postbuilds ,
1818- )
1862+ if self .flavor in ("linux" , "android" ):
1863+ self .WriteMakeRule (
1864+ [self .output_binary ],
1865+ link_deps ,
1866+ actions = ["$(call create_thin_archive,$@,$^)" ],
1867+ )
1868+ else :
1869+ self .WriteDoCmd (
1870+ [self .output_binary ],
1871+ link_deps ,
1872+ "alink_thin" ,
1873+ part_of_all ,
1874+ postbuilds = postbuilds ,
1875+ )
18191876 else :
1820- self .WriteDoCmd (
1821- [self .output_binary ],
1822- link_deps ,
1823- "alink" ,
1824- part_of_all ,
1825- postbuilds = postbuilds ,
1826- )
1877+ if self .flavor in ("linux" , "android" ):
1878+ self .WriteMakeRule (
1879+ [self .output_binary ],
1880+ link_deps ,
1881+ actions = ["$(call create_archive,$@,$^)" ],
1882+ )
1883+ else :
1884+ self .WriteDoCmd (
1885+ [self .output_binary ],
1886+ link_deps ,
1887+ "alink" ,
1888+ part_of_all ,
1889+ postbuilds = postbuilds ,
1890+ )
18271891 elif self .type == "shared_library" :
18281892 self .WriteLn (
18291893 "%s: LD_INPUTS := %s"
@@ -1841,9 +1905,15 @@ def WriteTarget(
18411905 )
18421906 # z/OS has a .so target as well as a sidedeck .x target
18431907 if self .flavor == "zos" :
1844- self .WriteLn ('%s: %s' % (
1845- QuoteSpaces (self .GetSharedObjectFromSidedeck (self .output_binary )),
1846- QuoteSpaces (self .output_binary )))
1908+ self .WriteLn (
1909+ "%s: %s"
1910+ % (
1911+ QuoteSpaces (
1912+ self .GetSharedObjectFromSidedeck (self .output_binary )
1913+ ),
1914+ QuoteSpaces (self .output_binary ),
1915+ )
1916+ )
18471917 elif self .type == "loadable_module" :
18481918 for link_dep in link_deps :
18491919 assert " " not in link_dep , (
@@ -1930,35 +2000,42 @@ def WriteTarget(
19302000 )
19312001 if self .flavor != "zos" :
19322002 installable_deps .append (install_path )
1933- if self .flavor == ' zos' and self .type == ' shared_library' :
2003+ if self .flavor == " zos" and self .type == " shared_library" :
19342004 # lib.target/libnode.so has a dependency on $(obj).target/libnode.so
1935- self .WriteDoCmd ([self .GetSharedObjectFromSidedeck (install_path )],
1936- [self .GetSharedObjectFromSidedeck (self .output )], 'copy' ,
1937- comment = 'Copy this to the %s output path.' %
1938- file_desc , part_of_all = part_of_all )
2005+ self .WriteDoCmd (
2006+ [self .GetSharedObjectFromSidedeck (install_path )],
2007+ [self .GetSharedObjectFromSidedeck (self .output )],
2008+ "copy" ,
2009+ comment = "Copy this to the %s output path." % file_desc ,
2010+ part_of_all = part_of_all ,
2011+ )
19392012 # Create a symlink of libnode.x to libnode.version.x
1940- self .WriteDoCmd ([self .GetUnversionedSidedeckFromSidedeck (install_path )],
1941- [install_path ], 'symlink' ,
1942- comment = 'Symlnk this to the %s output path.' %
1943- file_desc , part_of_all = part_of_all )
2013+ self .WriteDoCmd (
2014+ [self .GetUnversionedSidedeckFromSidedeck (install_path )],
2015+ [install_path ],
2016+ "symlink" ,
2017+ comment = "Symlnk this to the %s output path." % file_desc ,
2018+ part_of_all = part_of_all ,
2019+ )
19442020 # Place libnode.version.so and libnode.x symlink in lib.target dir
19452021 installable_deps .append (self .GetSharedObjectFromSidedeck (install_path ))
19462022 installable_deps .append (
1947- self .GetUnversionedSidedeckFromSidedeck (install_path ))
2023+ self .GetUnversionedSidedeckFromSidedeck (install_path )
2024+ )
19482025 if self .output != self .alias and self .alias != self .target :
19492026 self .WriteMakeRule (
19502027 [self .alias ],
19512028 installable_deps ,
19522029 comment = "Short alias for building this %s." % file_desc ,
19532030 phony = True ,
19542031 )
1955- if self .flavor == ' zos' and self .type == ' shared_library' :
2032+ if self .flavor == " zos" and self .type == " shared_library" :
19562033 # Make sure that .x symlink target is run
19572034 self .WriteMakeRule (
1958- [' all' ],
2035+ [" all" ],
19592036 [
19602037 self .GetUnversionedSidedeckFromSidedeck (install_path ),
1961- self .GetSharedObjectFromSidedeck (install_path )
2038+ self .GetSharedObjectFromSidedeck (install_path ),
19622039 ],
19632040 comment = 'Add %s to "all" target.' % file_desc ,
19642041 phony = True ,
0 commit comments