diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-22T20·56+0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-22T20·56+0000 |
commit | 6dd74b48f8d587fcc215e9f4721eacace7f8f462 (patch) | |
tree | 77f7f80e43f4f1de5d38d1351638c2eb0bf5e1b2 /Makefile.lib | |
parent | 9b11a8bfbcfd9e6f40ae8b573d4de492a23b91b9 (diff) |
Support building dynamic libraries
Diffstat (limited to 'Makefile.lib')
-rw-r--r-- | Makefile.lib | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/Makefile.lib b/Makefile.lib index b045534dcca8..3ebb8df7c98b 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -25,15 +25,15 @@ QUIET = @ # Pass -fPIC if we're building dynamic libraries. ifeq ($(BUILD_SHARED_LIBS), 1) -GLOBAL_CFLAGS += -fPIC -GLOBAL_CXXFLAGS += -fPIC + GLOBAL_CFLAGS += -fPIC + GLOBAL_CXXFLAGS += -fPIC endif # Pass -g if we want debug info. ifeq ($(BUILD_DEBUG), 1) -GLOBAL_CFLAGS += -g -GLOBAL_CXXFLAGS += -g + GLOBAL_CFLAGS += -g + GLOBAL_CXXFLAGS += -g endif @@ -53,11 +53,19 @@ define LIBS_template = _d := $$($(1)_DIR) _srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src)) _objs := $$(addsuffix .o, $$(basename $$(_srcs))) - _libs := $$(foreach lib, $$($(1)_LIBS), $$(lib).a) - _lib := $$(_d)/$(1).a - $$(_lib): $$(_objs) + ifeq ($(BUILD_SHARED_LIBS), 1) + _lib := $$(_d)/$(1).so + $$(_lib): $$(_objs) + $(QUIET) $(CC) -o $$@ -shared $$^ $$($(1)_LDFLAGS) + else + _lib := $$(_d)/$(1).a + $$(_lib): $$(_objs) $(QUIET) ar crs $$@ $$? + $(1)_LDFLAGS_PROPAGATED += $$($(1)_LDFLAGS) + endif + + $(1)_NAME := $$(_lib) # Propagate CXXFLAGS to the individual object files. $$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) @@ -65,7 +73,7 @@ define LIBS_template = include $$(wildcard $$(_d)/*.dep) libs_list += $$(_lib) - clean_list += $$(_d)/*.a $$(_d)/*.o $$(_d)/*.dep + clean_list += $$(_d)/*.a $$(_d)/*.so $$(_d)/*.o $$(_d)/*.dep dist_files += $$(_srcs) endef @@ -79,11 +87,11 @@ define PROGRAMS_template = _d := $$($(1)_DIR) _srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src)) _objs := $$(addsuffix .o, $$(basename $$(_srcs))) - _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_DIR)/$$(lib).a) + _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_NAME)) _prog := $$(_d)/$(1) $$(_prog): $$(_objs) $$(_libs) - $(QUIET) g++ -o $$@ $$^ $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS)) + $(QUIET) $(CXX) -o $$@ -Wl,--no-copy-dt-needed-entries $$^ $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_PROPAGATED)) # Propagate CXXFLAGS to the individual object files. $$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) |