Browse Source

- better support for building libraries added (should work on all archs,
sets soname, rpath a.s.o). static libs are not yet supported.

Andrei Pelinescu-Onciul 18 years ago
parent
commit
c853f68a3f
4 changed files with 178 additions and 37 deletions
  1. 2 23
      Makefile
  2. 66 13
      Makefile.defs
  3. 101 0
      Makefile.libs
  4. 9 1
      Makefile.rules

+ 2 - 23
Makefile

@@ -41,6 +41,7 @@
 #               logic when using group_include (greger)
 #  2007-03-01  fail if a module or a required utility make fail unless 
 #              err_fail=0; don't try to make modules with no Makefiles (andrei)
+#  2007-03-16  moved the exports to Makefile.defs
 
 auto_gen=lex.yy.c cfg.tab.c #lexx, yacc etc
 auto_gen_others=cfg.tab.h  # auto generated, non-c
@@ -134,7 +135,7 @@ else
 							auth_radius group_radius uri_radius avp_radius \
 							acc_radius dialog pa rls presence_b2b xcap xmlrpc\
 							osp tls oracle \
-							unixsock eval dbg
+							unixsock eval dbg print_lib
 endif
 
 # always exclude the CVS dir
@@ -226,23 +227,6 @@ include Makefile.defs
 
 NAME=$(MAIN_NAME)
 
-#export relevant variables to the sub-makes
-export DEFS PROFILE CC LD MKDEP MKTAGS CFLAGS LDFLAGS INCLUDES MOD_CFLAGS \
-		MOD_LDFLAGS 
-export LIBS
-export LEX YACC YACC_FLAGS
-export PREFIX LOCALBASE
-# export relevant variables for recursive calls of this makefile 
-# (e.g. make deb)
-#export LIBS
-#export TAR 
-#export NAME RELEASE OS ARCH 
-#export cfg-prefix cfg-dir bin-prefix bin-dir modules-prefix modules-dir
-#export doc-prefix doc-dir man-prefix man-dir ut-prefix ut-dir
-#export cfg-target modules-target
-#export INSTALL INSTALL-CFG INSTALL-BIN INSTALL-MODULES INSTALL-DOC INSTALL-MAN 
-#export INSTALL-TOUCH
-
 tar_name=$(NAME)-$(RELEASE)_src
 
 tar_extra_args+=$(addprefix --exclude=$(notdir $(CURDIR))/, \
@@ -550,11 +534,6 @@ install-man: $(man-prefix)/$(man-dir)/man8 $(man-prefix)/$(man-dir)/man5
 
 lib_dependent_modules = dialog pa rls presence_b2b xcap
 
-# exports for libs
-export cfg-prefix cfg-dir bin-prefix bin-dir modules-prefix modules-dir
-export doc-prefix doc-dir man-prefix man-dir ut-prefix ut-dir
-export INSTALL INSTALL-CFG INSTALL-BIN INSTALL-MODULES INSTALL-DOC INSTALL-MAN 
-export INSTALL-TOUCH
 
 dep_mods = $(filter $(addprefix modules/, $(lib_dependent_modules)), $(modules))
 dep_mods += $(filter $(lib_dependent_modules), $(static_modules))

+ 66 - 13
Makefile.defs

@@ -53,6 +53,8 @@
 #  2006-07-10  added -DPROFILING (hscholz)
 #  2007-02-09  added TLS_HOOKS and CORE_TLS support, obsoleted TLS=1
 #              added TLS_EXTRA_LIBS (andrei)
+#  2007-03-16  added LIB building options: LIB_LDFLAGS, LIB_SONAME, LIB_RPATH,
+#                INSTALL-LIB, libraries install paths (andrei)
 
 
 # check if already included/exported
@@ -123,6 +125,7 @@ CC_EXTRA_OPTS ?=
 cfg-dir = etc/ser/
 bin-dir = sbin/
 modules-dir = lib/ser/modules/
+lib-dir = lib/ser/
 ifeq ($(OS), linux)
 	doc-dir = share/doc/ser/
 	man-dir = share/man/
@@ -173,6 +176,7 @@ basedir = $(BASEDIR)
 cfg-prefix = $(basedir)$(prefix)
 bin-prefix = $(basedir)$(prefix)
 modules-prefix = $(basedir)$(prefix)
+lib-prefix = $(basedir)$(prefix)
 doc-prefix = $(basedir)$(prefix)
 man-prefix = $(basedir)$(prefix)
 ut-prefix = $(basedir)$(prefix)
@@ -182,6 +186,7 @@ ut-prefix = $(basedir)$(prefix)
 cfg-target = $(prefix)/$(cfg-dir)
 bin-target = $(prefix)/$(bin-dir)
 modules-target = $(prefix)/$(modules-dir)
+lib-target = $(prefix)/$(lib-dir)
 doc-target = $(prefix)/$(doc-dir)
 
 
@@ -199,6 +204,7 @@ INSTALL-TOUCH = touch          # used to create the file first (good to
 INSTALL-CFG = $(INSTALL) -m 644
 INSTALL-BIN = $(INSTALL) -m 755
 INSTALL-MODULES = $(INSTALL) -m 755
+INSTALL-LIB = $(INSTALL) -m 755
 INSTALL-DOC = $(INSTALL) -m 644
 INSTALL-MAN = $(INSTALL) -m 644
 
@@ -1144,21 +1150,34 @@ ifeq	($(CC_NAME), gcc)
 ifeq		($(LDTYPE), solaris)
 		# solaris ld
 		LDFLAGS+=-O2 $(PROFILE)
-		MOD_LDFLAGS=-G $(LDFLAGS)
+		MOD_LDFLAGS:=-G $(LDFLAGS)
+		LIB_LDFLAGS:=-G $(LDFLAGS)
+		LIB_SONAME=-Wl,-h,
+		LD_RPATH=-Wl,-R,
 else		
 		#gcc and maybe others, => gnu ld
 		LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
-		MOD_LDFLAGS=-shared $(LDFLAGS)
+		MOD_LDFLAGS:=-shared $(LDFLAGS)
+		LIB_LDFLAGS:=-shared $(LDFLAGS)
+		LIB_SONAME=-Wl,-soname,
+		LD_RPATH=-Wl,-rpath,
 endif
 endif
 ifeq	($(CC_NAME), icc)
 	#gcc and maybe others
 	LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
-	MOD_LDFLAGS=-shared $(LDFLAGS)
+	MOD_LDFLAGS:=-shared $(LDFLAGS)
+	LIB_LDFLAGS:=-shared $(LDFLAGS)
+	LIB_SONAME=-Wl,-soname,
+	LD_RPATH=-Wl,-rpath,
 endif
 ifeq	($(CC_NAME), suncc)
+	# -dy?
 	LDFLAGS+=-xO5 $(PROFILE)
-	MOD_LDFLAGS=-G $(LDFLAGS)
+	MOD_LDFLAGS:=-G $(LDFLAGS)
+	LIB_LDFLAGS:=-G $(LDFLAGS)
+	LIB_SONAME="-h "
+	LD_RPATH=-"-R "
 endif
 	# we need -fPIC -DPIC only for shared objects, we don't need them for
 	# the executable file, because it's always loaded at a fixed address
@@ -1175,23 +1194,35 @@ endif
 ifeq		($(LDTYPE), solaris)
 			#solaris ld
 			LDFLAGS+=-g $(PROFILE)
-			MOD_LDFLAGS=-G $(LDFLAGS)
+			MOD_LDFLAGS:=-G $(LDFLAGS)
+			LIB_LDFLAGS:=-G $(LDFLAGS)
+			LIB_SONAME=-Wl,-h,
+			LD_RPATH=-Wl,-R,
 else
 			#gnu or other ld type
 			LDFLAGS+=-g -Wl,-E $(PROFILE)
-			MOD_LDFLAGS=-shared $(LDFLAGS)
+			MOD_LDFLAGS:=-shared $(LDFLAGS)
+			LIB_LDFLAGS:=-shared $(LDFLAGS)
+			LIB_SONAME=-Wl,-soname,
+			LD_RPATH=-Wl,-rpath,
 endif
 endif
 ifeq	($(CC_NAME), icc)
 		DEFS+=-DCC_GCC_LIKE_ASM
 		CFLAGS=-g  $(PROFILE)
 		LDFLAGS+=-g -Wl,-E $(PROFILE)
-		MOD_LDFLAGS=-shared $(LDFLAGS)
+		MOD_LDFLAGS:=-shared $(LDFLAGS)
+		LIB_LDFLAGS:=-shared $(LDFLAGS)
+		LIB_SONAME=-Wl,-soname,
+		LD_RPATH=-Wl,-rpath,
 endif
 ifeq	($(CC_NAME), suncc)
 		CFLAGS= -g $(PROFILE)
 		LDFLAGS+=-g $(PROFILE)
-		MOD_LDFLAGS=-G $(LDFLAGS)
+		MOD_LDFLAGS:=-G $(LDFLAGS)
+		LIB_LDFLAGS:=-G $(LDFLAGS)
+		LIB_SONAME="-h "
+		LD_RPATH=-"-R "
 endif
 
 endif #mode=release
@@ -1213,13 +1244,17 @@ endif # CC_NAME=gcc
 
 #*FLAGS used for compiling the modules
 ifeq	($(CC_NAME), gcc)
-MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
+MOD_CFLAGS:=-fPIC -DPIC $(CFLAGS)
+LIB_CFLAGS:=-fPIC -DPIC $(CFLAGS)
 endif
 ifeq	($(CC_NAME), icc)
-MOD_CFLAGS=-Kpic $(CFLAGS)
+MOD_CFLAGS:=-Kpic $(CFLAGS)
+LIB_CFLAGS:=-Kpic $(CFLAGS)
 endif
 ifeq	($(CC_NAME), suncc)
-MOD_CFLAGS=-xcode=pic32  $(CFLAGS)
+# FIMXE: use -KPIC instead -xcode ?
+MOD_CFLAGS:=-xcode=pic32  $(CFLAGS)
+LIB_CFLAGS:=-xcode=pic32  $(CFLAGS)
 endif
 
 ifeq ($(LEX),)
@@ -1418,7 +1453,13 @@ ifeq ($(OS), darwin)
 		DEFS+=-DHAVE_SELECT
 	endif
 	LDFLAGS=        # darwin doesn't like -O2 or -E
-	MOD_LDFLAGS= -bundle -bundle_loader ../../$(MAIN_NAME)
+	MOD_LDFLAGS:= -bundle -bundle_loader ../../$(MAIN_NAME)
+	LIB_LDFLAGS:= -dynamiclib
+	# on darwin soname should include the full path
+	# (it kind of combines rpath & soname)
+	LIB_SONAME=
+	# no equiv. for rpath on darwin
+	LD_RPATH=
 	YACC=yacc
 endif
 
@@ -1453,6 +1494,18 @@ endif
 
 
 
-
+#export relevant variables to the sub-makes
+export RELEASE OS ARCH
+export DEFS PROFILE CC LD MKDEP MKTAGS CFLAGS LDFLAGS INCLUDES MOD_CFLAGS \
+		MOD_LDFLAGS LIB_CFLAGS LIB_LDFLAGS LIB_SONAME LD_RPATH
+export LIBS
+export LEX YACC YACC_FLAGS
+export PREFIX LOCALBASE
+export TAR
+export cfg-prefix cfg-dir bin-prefix bin-dir modules-prefix modules-dir
+export doc-prefix doc-dir man-prefix man-dir ut-prefix ut-dir
+export lib-prefix lib-dir cfg-target lib-target modules-target
+export INSTALL INSTALL-CFG INSTALL-BIN INSTALL-MODULES INSTALL-DOC INSTALL-MAN 
+export INSTALL-LIB INSTALL-TOUCH
 
 endif  # ifeq ($(makefile_defs, 1)

+ 101 - 0
Makefile.libs

@@ -0,0 +1,101 @@
+#
+# $Id$
+#
+# module Makefile
+#(to be included from each library makefile)
+#
+# History:
+# --------
+#  2007-03-16  created by andrei
+
+# NAME, MAJOR_VER and MINOR_VER should be pre-defined in the library 
+# makefile
+#
+
+ifeq ($(NAME),)
+$(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
+endif
+ifeq ($(MAJOR_VER),)
+$(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
+endif
+ifeq ($(MINOR_VER),)
+$(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
+endif
+ifeq ($(BUGFIX_VER),)
+	BUGFIX_VER:=0
+endif
+
+ifeq ($(OS), darwin)
+	LIB_NAME:=lib$(NAME).$(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER).dylib
+	LIB_RUNTIME_NAME:=lib$(NAME).$(MAJOR_VER).dylib
+	LIB_LINK_NAME:=lib$(NAME).dylib
+	NAME_LD_FLAGS:= -compatibility_version $(MAJOR_VER).$(MINOR_VER) \
+					-current_version $(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER) \
+					-install_name $(lib_target)/$(LIB_RUNTIME_NAME)
+
+else
+	LIB_NAME:=lib$(NAME).so.$(MAJOR_VER).$(MINOR_VER)
+	LIB_RUNTIME_NAME:=lib$(NAME).so.$(MAJOR_VER)
+	LIB_LINK_NAME:=lib$(NAME).so
+	NAME_LD_FLAGS:= $(LIB_SONAME)$(LIB_RUNTIME_NAME)
+endif
+
+
+COREPATH ?=../..
+
+ALLDEP=Makefile $(COREPATH)/Makefile.sources $(COREPATH)/Makefile.rules \
+ $(COREPATH)/Makefile.libs
+
+
+ifeq ($(MAKELEVEL), 0)
+# make called directly in the library dir!
+ifneq ($(makefile_defs), 1)
+$(error "the local makefile does not include Makefile.defs!")
+endif
+
+else
+# called by the main Makefile
+
+ALLDEP+=$(COREPATH)/Makefile $(COREPATH)/Makefile.defs
+
+endif
+
+include $(COREPATH)/Makefile.sources
+
+
+CFLAGS:=$(LIB_CFLAGS)
+LDFLAGS:=$(LIB_LDFLAGS) $(NAME_LD_FLAGS)
+NAME:=$(LIB_NAME)
+
+
+include $(COREPATH)/Makefile.rules
+
+$(NAME): $(LIB_RUNTIME_NAME) $(LIB_LINK_NAME)
+
+$(LIB_RUNTIME_NAME): 
+	-@ln -s $(LIB_NAME) $(LIB_RUNTIME_NAME)
+
+$(LIB_LINK_NAME):
+	-@ln -s $(LIB_NAME) $(LIB_LINK_NAME)
+
+.PHONY: link_clean
+link_clean:
+	-@rm -f $(LIB_RUNTIME_NAME)
+	-@rm -f $(LIB_LINK_NAME)
+
+clean: link_clean
+
+$(lib-prefix)/$(lib-dir):
+	mkdir -p $(lib-prefix)/$(lib-dir)
+
+.PHONY: install
+install: $(LIB_NAME) $(lib-prefix)/$(lib-dir)
+	$(INSTALL-TOUCH) $(lib-prefix)/$(lib-dir)/$(LIB_NAME)
+	$(INSTALL-LIB) $(LIB_NAME) $(lib-prefix)/$(lib-dir)
+	rm -f $(lib-prefix)/$(lib-dir)/$(LIB_RUNTIME_NAME) \
+			$(lib-prefix)/$(lib-dir)/$(LIB_LINK_NAME) 
+	ln -s $(lib-prefix)/$(lib-dir)/$(LIB_NAME) \
+			$(lib-prefix)/$(lib-dir)/$(LIB_RUNTIME_NAME) 
+	ln -s $(lib-prefix)/$(lib-dir)/$(LIB_NAME) \
+			$(lib-prefix)/$(lib-dir)/$(LIB_LINK_NAME) 
+

+ 9 - 1
Makefile.rules

@@ -22,10 +22,18 @@
 	|  sed 's#\(\($*D)\)\?$(*F)\)\.o[ :]*#$*.o $@ : #g' > $@; \
 	[ -s $@ ] || rm -f $@
 
+# use RPATH and SER_LIBS if needed
+ifneq	($(SER_LIBS),)
+ifneq	($(LD_RPATH),)
+SER_RPATH:=$(LD_RPATH)$(lib-target)
+endif
+endif
+
+ALL_LIBS=$(LIBS) $(SER_LIBS)
 
 # normal rules
 $(NAME): $(objs) $(ALLDEP)
-	$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(LIBS) -o $(NAME) 
+	$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) -o $(NAME)
 
 
 .PHONY: all