Support building dynamic libraries

This commit is contained in:
Eelco Dolstra 2013-11-22 20:56:58 +00:00
parent 9b11a8bfbc
commit 6dd74b48f8
4 changed files with 23 additions and 13 deletions

View file

@ -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
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)))

View file

@ -4,4 +4,4 @@ libmain_DIR := $(d)
libmain_SOURCES = shared.cc stack.cc
libmain_LDFLAGS = $(BDW_GC_LIBS)
libmain_LDFLAGS_PROPAGATED = $(BDW_GC_LIBS)

View file

@ -5,3 +5,5 @@ nix-store_DIR := $(d)
nix-store_SOURCES = nix-store.cc dotgraph.cc xmlgraph.cc
nix-store_LIBS = libmain libstore libutil libformat
nix-store_LDFLAGS = -lbz2