Improve building dynamic libraries

They now get a correct RPATH.
This commit is contained in:
Eelco Dolstra 2013-11-23 17:20:15 +01:00
parent 6dd74b48f8
commit d1b3ca0b4a
2 changed files with 11 additions and 7 deletions

View file

@ -50,21 +50,25 @@ endif
libs_list := libs_list :=
define LIBS_template = define LIBS_template =
_d := $$($(1)_DIR) _d := $$(strip $$($(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)))
$(1)_LDFLAGS_USE :=
ifeq ($(BUILD_SHARED_LIBS), 1) ifeq ($(BUILD_SHARED_LIBS), 1)
_lib := $$(_d)/$(1).so _lib := $$(_d)/$(1).so
$$(_lib): $$(_objs) $$(_lib): $$(_objs)
$(QUIET) $(CC) -o $$@ -shared $$^ $$($(1)_LDFLAGS) $(QUIET) $(CC) -o $$@ -shared $$^ $$($(1)_LDFLAGS)
$(1)_LDFLAGS_USE += -L$$(_d) -Wl,-rpath,$$(abspath $$(_d)) -l$$(patsubst lib%,%,$$(strip $(1)))
else else
_lib := $$(_d)/$(1).a _lib := $$(_d)/$(1).a
$$(_lib): $$(_objs) $$(_lib): $$(_objs)
$(QUIET) ar crs $$@ $$? $(QUIET) ar crs $$@ $$?
$(1)_LDFLAGS_PROPAGATED += $$($(1)_LDFLAGS) $(1)_LDFLAGS_USE += $$(_lib) $$($(1)_LDFLAGS)
endif endif
$(1)_LDFLAGS_USE += $$($(1)_LDFLAGS_PROPAGATED)
$(1)_NAME := $$(_lib) $(1)_NAME := $$(_lib)
# Propagate CXXFLAGS to the individual object files. # Propagate CXXFLAGS to the individual object files.
@ -86,15 +90,15 @@ programs_list :=
define PROGRAMS_template = 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))) $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs)))
_libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_NAME)) _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_NAME))
_prog := $$(_d)/$(1) _prog := $$(_d)/$(1)
$$(_prog): $$(_objs) $$(_libs) $$(_prog): $$($(1)_OBJS) $$(_libs)
$(QUIET) $(CXX) -o $$@ -Wl,--no-copy-dt-needed-entries $$^ $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_PROPAGATED)) $(QUIET) $(CXX) -o $$@ -Wl,--no-copy-dt-needed-entries $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
# Propagate CXXFLAGS to the individual object files. # Propagate CXXFLAGS to the individual object files.
$$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
include $$(wildcard $$(_d)/*.dep) include $$(wildcard $$(_d)/*.dep)

View file

@ -2,6 +2,6 @@ PROGRAMS += nix-env
nix-env_DIR := $(d) nix-env_DIR := $(d)
nix-env_SOURCES = nix-env.cc profiles.cc profiles.hh user-env.cc user-env.hh nix-env_SOURCES = nix-env.cc profiles.cc user-env.cc
nix-env_LIBS = libexpr libmain libstore libutil libformat nix-env_LIBS = libexpr libmain libstore libutil libformat