From f0594a6f357ec2fe2ebef775a7bf1569f1414749 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 29 Oct 2008 09:17:00 +0000 Subject: [PATCH] Added experimental support for shared library dependencies In fact, I'm not sure, whether dependency of shared libraries is the real problem. Currently, the problem appears if a shared library depends on a static library. Then this static library must be created before the shared one. This change adds a new link-pseudo-pass, which is called after library-pass and before binary-pass. This "pseudo" pass doesn't traverse directories recursively, but instead it processes *.omkvar files prepared during library-pass. Since the shared libraries are linked after the static ones, we have no problems with dependencies described in the previous paragraph. In future, we will extend this approach to linking of libraries, binaries and maybe even kernel modules. This allows to save at least binary-pass and the compilation will be faster. darcs-hash:20081029091745-f2ef6-daa7a8825364b2bbc40f1f00bfd51dd6676ea4d3.gz --- snippets/linux | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/snippets/linux b/snippets/linux index 57f43b8..c3b552b 100644 --- a/snippets/linux +++ b/snippets/linux @@ -136,6 +136,7 @@ endif USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR) KERN_OBJS_DIR = $(KERN_BUILD_DIR)/$(RELATIVE_DIR) +OMK_WORK_DIR = $(USER_OBJS_DIR) .PHONY: dep subdirs clean clean-custom cleandepend check-dir @@ -143,7 +144,7 @@ KERN_OBJS_DIR = $(KERN_BUILD_DIR)/$(RELATIVE_DIR) ifneq ($(OMK_SERIALIZE_INCLUDED),y) include-pass: check-dir library-pass: include-pass -binary-pass: library-pass +binary-pass: library-pass link-pseudo-pass kernel-lib-pass: include-pass kernel-mod-pass: kernel-lib-pass kernel-modpost-pass: kernel-mod-pass @@ -311,6 +312,7 @@ $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS) $(Q) $(AR) rcs $$@ $$^ endef +.PHONY: FORCE # Syntax: $(call SOLIB_template,) define SOLIB_template @@ -332,15 +334,15 @@ $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO:%/=%)) SOLIB_OBJS += $$($(1)_OBJSLO) SOLIB_SOURCES += $$($(1)_SOURCES) -$(USER_LIB_DIR)/lib$(1).$(SOLIB_EXT): $$($(1)_OBJSLO) - @$(QUIET_CMD_ECHO) " LINK $$@" - $(Q) $(CC) --shared -Xlinker -soname=lib$(1).$(SOLIB_EXT) -o $$@ $$^ $$(LOADLIBES) $$($(1)_LIBS:%=-l%) +$(OMK_WORK_DIR)/lib$(1).$(SOLIB_EXT).omkvar: $$($(1)_OBJSLO) FORCE + $(Q)echo '$(1)_objslo += $$$$(addprefix $(USER_OBJS_DIR)/,$$($(1)_OBJSLO))' > $$@.tmp; \ + echo '$(1)_libs += $$($(1)_LIBS) $$(lib_LOADLIBES)' >> $$@.tmp; \ + echo 'shared_libs := $$$$(sort $(1) $$$$(shared_libs))' >> $$@.tmp; \ + if cmp -s $$@.tmp $$@; then rm $$@.tmp; else mv $$@.tmp $$@; fi endef - - library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \ - $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.$(SOLIB_EXT)) + $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(OMK_WORK_DIR)/lib%.$(SOLIB_EXT).omkvar) binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%$(EXE_SUFFIX)) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%$(EXE_SUFFIX)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%$(EXE_SUFFIX)) @@ -371,7 +373,30 @@ $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib)))) -include $(USER_OBJS_DIR)/*.d -endif +endif # USER_RULE_TEMPLATES + +.PHONY: link-pseudo-pass +link-pseudo-pass: + $(Q)$(MAKE) $(NO_PRINT_DIRECTORY) -C $(USER_BUILD_DIR) -f $(SOURCESDIR_MAKEFILE) link-shared-libs + +ifeq ($(MAKECMDGOALS),link-shared-libs) + +# Syntax: $(call solib_link_template,) +define solib_link_template +$(1)_shared_libs = $$(patsubst %,$(USER_LIB_DIR)/lib%.$(SOLIB_EXT),$$(filter $$(shared_libs),$$($(1)_libs))) +#$$(warning $(1)_shared_libs = $$($(1)_shared_libs)) +$(USER_LIB_DIR)/lib$(1).$(SOLIB_EXT): $$($(1)_shared_libs) $$($(1)_objslo) + @$(QUIET_CMD_ECHO) " LINK $$@" + $(Q) $(CC) --shared -Xlinker -soname=lib$(1).$(SOLIB_EXT) -o $$@ $$($(1)_objslo) $$(LOADLIBES) $$($(1)_libs:%=-l%) +endef + +-include $(shell find $(USER_BUILD_DIR) -name 'lib*.omkvar') +#$(warning $(shared_libs)) +$(foreach lib,$(shared_libs),$(eval $(call solib_link_template,$(lib)))) + +.PHONY: link-shared-libs +link-shared-libs: $(shared_libs:%=$(USER_LIB_DIR)/lib%.$(SOLIB_EXT)) +endif # link-shared-libs #===================================================================== # Kernel-space rules and templates to compile modules, libraries etc. -- 2.39.2