From 831823773e16aff2a237335145effd426d5ebf87 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sat, 23 Nov 2013 07:13:40 +0000 Subject: Fixed #1713: Enable building the libraries as shared libraries/DLLs for GNU targets git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4656 74dad513-b988-da41-8d7b-12977e46ad98 --- build/rules.mak | 79 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 22 deletions(-) (limited to 'build') diff --git a/build/rules.mak b/build/rules.mak index 49798a37..a939db47 100644 --- a/build/rules.mak +++ b/build/rules.mak @@ -6,17 +6,22 @@ BINDIR = ../bin endif # -# The full path of output lib file (e.g. ../lib/libapp.a). -# -LIB = $($(APP)_LIB) - -# -# The full path of output lib file (e.g. ../lib/libapp.a). +# The name(s) of output lib file(s) (e.g. libapp.a). # +LIB := $($(APP)_LIB) SHLIB = $($(APP)_SHLIB) +SONAME = $($(APP)_SONAME) + +ifeq ($(SHLIB_SUFFIX),so) +SHLIB_OPT := -shared -Wl,-soname,$(SHLIB) +else ifeq ($(SHLIB_SUFFIX),dylib) +SHLIB_OPT := -dynamiclib -undefined dynamic_lookup -flat_namespace +else +SHLIB_OPT := +endif # -# The full path of output executable file (e.g. ../bin/app.exe). +# The name of output executable file (e.g. app.exe). # EXE = $($(APP)_EXE) @@ -76,27 +81,46 @@ print_common: @echo RANLIB=$(RANLIB) print_bin: print_common - @echo EXE=$(EXE) + @echo EXE=$(subst /,$(HOST_PSEP),$(BINDIR)/$(EXE)) @echo BINDIR=$(BINDIR) - + print_lib: print_common - @echo LIB=$(LIB) +ifneq ($(LIB),) + @echo LIB=$(subst /,$(HOST_PSEP),$(LIBDIR)/$(LIB)) +endif +ifneq ($(SHLIB),) + @echo SHLIB=$(subst /,$(HOST_PSEP),$(LIBDIR)/$(SHLIB)) +endif +ifneq ($(SONAME),) + @echo SONAME=$(subst /,$(HOST_PSEP),$(LIBDIR)/$(SONAME)) +endif @echo LIBDIR=$(LIBDIR) -$(LIB): $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP) +ifneq ($(LIB),) +$(subst /,$(HOST_PSEP),$(LIBDIR)/$(LIB)): $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP) if test ! -d $(LIBDIR); then $(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)),$(HOST_MKDIR)); fi - $(AR) $(AR_FLAGS) $(LIB) $(OBJS) - $(RANLIB) $(LIB) + $(AR) $(AR_FLAGS) $@ $(OBJS) + $(RANLIB) $@ +endif -$(SHLIB): $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP) +ifneq ($(SHLIB),) +$(subst /,$(HOST_PSEP),$(LIBDIR)/$(SHLIB)): $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP) if test ! -d $(LIBDIR); then $(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)),$(HOST_MKDIR)); fi - $(LD) $(LDOUT)$(subst /,$(HOST_PSEP),$(SHLIB)) \ - $(subst /,$(HOST_PSEP),$(OBJS)) $($(APP)_LDFLAGS) + $(LD) $(LDOUT)$(subst /,$(HOST_PSEP),$@) \ + $(subst /,$(HOST_PSEP),$(OBJS)) $($(APP)_LDFLAGS) $(SHLIB_OPT) +endif + +ifneq ($(SONAME),) +$(subst /,$(HOST_PSEP),$(LIBDIR)/$(SONAME)): $(subst /,$(HOST_PSEP),$(LIBDIR)/$(SHLIB)) + ln -sf $(SHLIB) $@ +endif -$(EXE): $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP) +ifneq ($(EXE),) +$(subst /,$(HOST_PSEP),$(BINDIR)/$(EXE)): $(OBJDIRS) $(OBJS) $($(APP)_EXTRA_DEP) if test ! -d $(BINDIR); then $(subst @@,$(subst /,$(HOST_PSEP),$(BINDIR)),$(HOST_MKDIR)); fi - $(LD) $(LDOUT)$(subst /,$(HOST_PSEP),$(EXE)) \ + $(LD) $(LDOUT)$(subst /,$(HOST_PSEP),$(BINDIR)/$(EXE)) \ $(subst /,$(HOST_PSEP),$(OBJS)) $($(APP)_LDFLAGS) +endif $(OBJDIR)/$(app).o: $(OBJDIRS) $(OBJS) $(CROSS_COMPILE)ld -r -o $@ $(OBJS) @@ -147,13 +171,13 @@ $(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.cpp $(subst /,$(HOST_PSEP),$<) $(OBJDIRS): - $(subst @@,$(subst /,$(HOST_PSEP),$@),$(HOST_MKDIR)) + $(subst @@,$(subst /,$(HOST_PSEP),$@),$(HOST_MKDIR)) $(LIBDIR): - $(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)),$(HOST_MKDIR)) + $(subst @@,$(subst /,$(HOST_PSEP),$@),$(HOST_MKDIR)) $(BINDIR): - $(subst @@,$(subst /,$(HOST_PSEP),$(BINDIR)),$(HOST_MKDIR)) + $(subst @@,$(subst /,$(HOST_PSEP),$@),$(HOST_MKDIR)) clean: $(subst @@,$(subst /,$(HOST_PSEP),$(OBJDIR)/*),$(HOST_RMR)) @@ -168,7 +192,18 @@ gcov-report: done realclean: clean - $(subst @@,$(subst /,$(HOST_PSEP),$(LIB)) $(subst /,$(HOST_PSEP),$(EXE)),$(HOST_RM)) +ifneq ($(LIB),) + $(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)/$(LIB)),$(HOST_RM)) +endif +ifneq ($(SHLIB),) + $(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)/$(SHLIB)),$(HOST_RM)) +endif +ifneq ($(SONAME),) + $(subst @@,$(subst /,$(HOST_PSEP),$(LIBDIR)/$(SONAME)),$(HOST_RM)) +endif +ifneq ($(EXE),) + $(subst @@,$(subst /,$(HOST_PSEP),$(BINDIR)/$(EXE)),$(HOST_RM)) +endif $(subst @@,$(DEP_FILE),$(HOST_RM)) ifeq ($(OS_NAME),linux-kernel) rm -f ../lib/$(app).ko -- cgit v1.2.3