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

@ -25,15 +25,15 @@ QUIET = @
# Pass -fPIC if we're building dynamic libraries. # Pass -fPIC if we're building dynamic libraries.
ifeq ($(BUILD_SHARED_LIBS), 1) ifeq ($(BUILD_SHARED_LIBS), 1)
GLOBAL_CFLAGS += -fPIC GLOBAL_CFLAGS += -fPIC
GLOBAL_CXXFLAGS += -fPIC GLOBAL_CXXFLAGS += -fPIC
endif endif
# Pass -g if we want debug info. # Pass -g if we want debug info.
ifeq ($(BUILD_DEBUG), 1) ifeq ($(BUILD_DEBUG), 1)
GLOBAL_CFLAGS += -g GLOBAL_CFLAGS += -g
GLOBAL_CXXFLAGS += -g GLOBAL_CXXFLAGS += -g
endif endif
@ -53,11 +53,19 @@ define LIBS_template =
_d := $$($(1)_DIR) _d := $$($(1)_DIR)
_srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src)) _srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src))
_objs := $$(addsuffix .o, $$(basename $$(_srcs))) _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 $$@ $$? $(QUIET) ar crs $$@ $$?
$(1)_LDFLAGS_PROPAGATED += $$($(1)_LDFLAGS)
endif
$(1)_NAME := $$(_lib)
# Propagate CXXFLAGS to the individual object files. # Propagate CXXFLAGS to the individual object files.
$$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) $$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
@ -65,7 +73,7 @@ define LIBS_template =
include $$(wildcard $$(_d)/*.dep) include $$(wildcard $$(_d)/*.dep)
libs_list += $$(_lib) libs_list += $$(_lib)
clean_list += $$(_d)/*.a $$(_d)/*.o $$(_d)/*.dep clean_list += $$(_d)/*.a $$(_d)/*.so $$(_d)/*.o $$(_d)/*.dep
dist_files += $$(_srcs) dist_files += $$(_srcs)
endef endef
@ -79,11 +87,11 @@ define PROGRAMS_template =
_d := $$($(1)_DIR) _d := $$($(1)_DIR)
_srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src)) _srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src))
_objs := $$(addsuffix .o, $$(basename $$(_srcs))) _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 := $$(_d)/$(1)
$$(_prog): $$(_objs) $$(_libs) $$(_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. # Propagate CXXFLAGS to the individual object files.
$$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) $$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))

View file

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

View file

@ -5,9 +5,9 @@ libutil_DIR := $(d)
libutil_SOURCES = util.cc hash.cc serialise.cc archive.cc xml-writer.cc affinity.cc libutil_SOURCES = util.cc hash.cc serialise.cc archive.cc xml-writer.cc affinity.cc
ifeq ($(HAVE_OPENSSL), 1) ifeq ($(HAVE_OPENSSL), 1)
libutil_LDFLAGS = $(OPENSSL_LIBS) libutil_LDFLAGS = $(OPENSSL_LIBS)
else else
libutil_SOURCES += md5.c sha1.c sha256.c libutil_SOURCES += md5.c sha1.c sha256.c
endif endif
libutil_LIBS = src/boost/format/libformat libutil_LIBS = src/boost/format/libformat

View file

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