Browse code

- 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 authored on 16/03/2007 21:53:54
Showing 4 changed files
... ...
@@ -41,6 +41,7 @@
41 41
 #               logic when using group_include (greger)
42 42
 #  2007-03-01  fail if a module or a required utility make fail unless 
43 43
 #              err_fail=0; don't try to make modules with no Makefiles (andrei)
44
+#  2007-03-16  moved the exports to Makefile.defs
44 45
 
45 46
 auto_gen=lex.yy.c cfg.tab.c #lexx, yacc etc
46 47
 auto_gen_others=cfg.tab.h  # auto generated, non-c
... ...
@@ -134,7 +135,7 @@ else
134 134
 							auth_radius group_radius uri_radius avp_radius \
135 135
 							acc_radius dialog pa rls presence_b2b xcap xmlrpc\
136 136
 							osp tls oracle \
137
-							unixsock eval dbg
137
+							unixsock eval dbg print_lib
138 138
 endif
139 139
 
140 140
 # always exclude the CVS dir
... ...
@@ -226,23 +227,6 @@ include Makefile.defs
226 226
 
227 227
 NAME=$(MAIN_NAME)
228 228
 
229
-#export relevant variables to the sub-makes
230
-export DEFS PROFILE CC LD MKDEP MKTAGS CFLAGS LDFLAGS INCLUDES MOD_CFLAGS \
231
-		MOD_LDFLAGS 
232
-export LIBS
233
-export LEX YACC YACC_FLAGS
234
-export PREFIX LOCALBASE
235
-# export relevant variables for recursive calls of this makefile 
236
-# (e.g. make deb)
237
-#export LIBS
238
-#export TAR 
239
-#export NAME RELEASE OS ARCH 
240
-#export cfg-prefix cfg-dir bin-prefix bin-dir modules-prefix modules-dir
241
-#export doc-prefix doc-dir man-prefix man-dir ut-prefix ut-dir
242
-#export cfg-target modules-target
243
-#export INSTALL INSTALL-CFG INSTALL-BIN INSTALL-MODULES INSTALL-DOC INSTALL-MAN 
244
-#export INSTALL-TOUCH
245
-
246 229
 tar_name=$(NAME)-$(RELEASE)_src
247 230
 
248 231
 tar_extra_args+=$(addprefix --exclude=$(notdir $(CURDIR))/, \
... ...
@@ -550,11 +534,6 @@ install-man: $(man-prefix)/$(man-dir)/man8 $(man-prefix)/$(man-dir)/man5
550 550
 
551 551
 lib_dependent_modules = dialog pa rls presence_b2b xcap
552 552
 
553
-# exports for libs
554
-export cfg-prefix cfg-dir bin-prefix bin-dir modules-prefix modules-dir
555
-export doc-prefix doc-dir man-prefix man-dir ut-prefix ut-dir
556
-export INSTALL INSTALL-CFG INSTALL-BIN INSTALL-MODULES INSTALL-DOC INSTALL-MAN 
557
-export INSTALL-TOUCH
558 553
 
559 554
 dep_mods = $(filter $(addprefix modules/, $(lib_dependent_modules)), $(modules))
560 555
 dep_mods += $(filter $(lib_dependent_modules), $(static_modules))
... ...
@@ -53,6 +53,8 @@
53 53
 #  2006-07-10  added -DPROFILING (hscholz)
54 54
 #  2007-02-09  added TLS_HOOKS and CORE_TLS support, obsoleted TLS=1
55 55
 #              added TLS_EXTRA_LIBS (andrei)
56
+#  2007-03-16  added LIB building options: LIB_LDFLAGS, LIB_SONAME, LIB_RPATH,
57
+#                INSTALL-LIB, libraries install paths (andrei)
56 58
 
57 59
 
58 60
 # check if already included/exported
... ...
@@ -123,6 +125,7 @@ CC_EXTRA_OPTS ?=
123 123
 cfg-dir = etc/ser/
124 124
 bin-dir = sbin/
125 125
 modules-dir = lib/ser/modules/
126
+lib-dir = lib/ser/
126 127
 ifeq ($(OS), linux)
127 128
 	doc-dir = share/doc/ser/
128 129
 	man-dir = share/man/
... ...
@@ -173,6 +176,7 @@ basedir = $(BASEDIR)
173 173
 cfg-prefix = $(basedir)$(prefix)
174 174
 bin-prefix = $(basedir)$(prefix)
175 175
 modules-prefix = $(basedir)$(prefix)
176
+lib-prefix = $(basedir)$(prefix)
176 177
 doc-prefix = $(basedir)$(prefix)
177 178
 man-prefix = $(basedir)$(prefix)
178 179
 ut-prefix = $(basedir)$(prefix)
... ...
@@ -182,6 +186,7 @@ ut-prefix = $(basedir)$(prefix)
182 182
 cfg-target = $(prefix)/$(cfg-dir)
183 183
 bin-target = $(prefix)/$(bin-dir)
184 184
 modules-target = $(prefix)/$(modules-dir)
185
+lib-target = $(prefix)/$(lib-dir)
185 186
 doc-target = $(prefix)/$(doc-dir)
186 187
 
187 188
 
... ...
@@ -199,6 +204,7 @@ INSTALL-TOUCH = touch          # used to create the file first (good to
199 199
 INSTALL-CFG = $(INSTALL) -m 644
200 200
 INSTALL-BIN = $(INSTALL) -m 755
201 201
 INSTALL-MODULES = $(INSTALL) -m 755
202
+INSTALL-LIB = $(INSTALL) -m 755
202 203
 INSTALL-DOC = $(INSTALL) -m 644
203 204
 INSTALL-MAN = $(INSTALL) -m 644
204 205
 
... ...
@@ -1144,21 +1150,34 @@ ifeq	($(CC_NAME), gcc)
1144 1144
 ifeq		($(LDTYPE), solaris)
1145 1145
 		# solaris ld
1146 1146
 		LDFLAGS+=-O2 $(PROFILE)
1147
-		MOD_LDFLAGS=-G $(LDFLAGS)
1147
+		MOD_LDFLAGS:=-G $(LDFLAGS)
1148
+		LIB_LDFLAGS:=-G $(LDFLAGS)
1149
+		LIB_SONAME=-Wl,-h,
1150
+		LD_RPATH=-Wl,-R,
1148 1151
 else		
1149 1152
 		#gcc and maybe others, => gnu ld
1150 1153
 		LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1151
-		MOD_LDFLAGS=-shared $(LDFLAGS)
1154
+		MOD_LDFLAGS:=-shared $(LDFLAGS)
1155
+		LIB_LDFLAGS:=-shared $(LDFLAGS)
1156
+		LIB_SONAME=-Wl,-soname,
1157
+		LD_RPATH=-Wl,-rpath,
1152 1158
 endif
1153 1159
 endif
1154 1160
 ifeq	($(CC_NAME), icc)
1155 1161
 	#gcc and maybe others
1156 1162
 	LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1157
-	MOD_LDFLAGS=-shared $(LDFLAGS)
1163
+	MOD_LDFLAGS:=-shared $(LDFLAGS)
1164
+	LIB_LDFLAGS:=-shared $(LDFLAGS)
1165
+	LIB_SONAME=-Wl,-soname,
1166
+	LD_RPATH=-Wl,-rpath,
1158 1167
 endif
1159 1168
 ifeq	($(CC_NAME), suncc)
1169
+	# -dy?
1160 1170
 	LDFLAGS+=-xO5 $(PROFILE)
1161
-	MOD_LDFLAGS=-G $(LDFLAGS)
1171
+	MOD_LDFLAGS:=-G $(LDFLAGS)
1172
+	LIB_LDFLAGS:=-G $(LDFLAGS)
1173
+	LIB_SONAME="-h "
1174
+	LD_RPATH=-"-R "
1162 1175
 endif
1163 1176
 	# we need -fPIC -DPIC only for shared objects, we don't need them for
1164 1177
 	# the executable file, because it's always loaded at a fixed address
... ...
@@ -1175,23 +1194,35 @@ endif
1175 1175
 ifeq		($(LDTYPE), solaris)
1176 1176
 			#solaris ld
1177 1177
 			LDFLAGS+=-g $(PROFILE)
1178
-			MOD_LDFLAGS=-G $(LDFLAGS)
1178
+			MOD_LDFLAGS:=-G $(LDFLAGS)
1179
+			LIB_LDFLAGS:=-G $(LDFLAGS)
1180
+			LIB_SONAME=-Wl,-h,
1181
+			LD_RPATH=-Wl,-R,
1179 1182
 else
1180 1183
 			#gnu or other ld type
1181 1184
 			LDFLAGS+=-g -Wl,-E $(PROFILE)
1182
-			MOD_LDFLAGS=-shared $(LDFLAGS)
1185
+			MOD_LDFLAGS:=-shared $(LDFLAGS)
1186
+			LIB_LDFLAGS:=-shared $(LDFLAGS)
1187
+			LIB_SONAME=-Wl,-soname,
1188
+			LD_RPATH=-Wl,-rpath,
1183 1189
 endif
1184 1190
 endif
1185 1191
 ifeq	($(CC_NAME), icc)
1186 1192
 		DEFS+=-DCC_GCC_LIKE_ASM
1187 1193
 		CFLAGS=-g  $(PROFILE)
1188 1194
 		LDFLAGS+=-g -Wl,-E $(PROFILE)
1189
-		MOD_LDFLAGS=-shared $(LDFLAGS)
1195
+		MOD_LDFLAGS:=-shared $(LDFLAGS)
1196
+		LIB_LDFLAGS:=-shared $(LDFLAGS)
1197
+		LIB_SONAME=-Wl,-soname,
1198
+		LD_RPATH=-Wl,-rpath,
1190 1199
 endif
1191 1200
 ifeq	($(CC_NAME), suncc)
1192 1201
 		CFLAGS= -g $(PROFILE)
1193 1202
 		LDFLAGS+=-g $(PROFILE)
1194
-		MOD_LDFLAGS=-G $(LDFLAGS)
1203
+		MOD_LDFLAGS:=-G $(LDFLAGS)
1204
+		LIB_LDFLAGS:=-G $(LDFLAGS)
1205
+		LIB_SONAME="-h "
1206
+		LD_RPATH=-"-R "
1195 1207
 endif
1196 1208
 
1197 1209
 endif #mode=release
... ...
@@ -1213,13 +1244,17 @@ endif # CC_NAME=gcc
1213 1213
 
1214 1214
 #*FLAGS used for compiling the modules
1215 1215
 ifeq	($(CC_NAME), gcc)
1216
-MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
1216
+MOD_CFLAGS:=-fPIC -DPIC $(CFLAGS)
1217
+LIB_CFLAGS:=-fPIC -DPIC $(CFLAGS)
1217 1218
 endif
1218 1219
 ifeq	($(CC_NAME), icc)
1219
-MOD_CFLAGS=-Kpic $(CFLAGS)
1220
+MOD_CFLAGS:=-Kpic $(CFLAGS)
1221
+LIB_CFLAGS:=-Kpic $(CFLAGS)
1220 1222
 endif
1221 1223
 ifeq	($(CC_NAME), suncc)
1222
-MOD_CFLAGS=-xcode=pic32  $(CFLAGS)
1224
+# FIMXE: use -KPIC instead -xcode ?
1225
+MOD_CFLAGS:=-xcode=pic32  $(CFLAGS)
1226
+LIB_CFLAGS:=-xcode=pic32  $(CFLAGS)
1223 1227
 endif
1224 1228
 
1225 1229
 ifeq ($(LEX),)
... ...
@@ -1418,7 +1453,13 @@ ifeq ($(OS), darwin)
1418 1418
 		DEFS+=-DHAVE_SELECT
1419 1419
 	endif
1420 1420
 	LDFLAGS=        # darwin doesn't like -O2 or -E
1421
-	MOD_LDFLAGS= -bundle -bundle_loader ../../$(MAIN_NAME)
1421
+	MOD_LDFLAGS:= -bundle -bundle_loader ../../$(MAIN_NAME)
1422
+	LIB_LDFLAGS:= -dynamiclib
1423
+	# on darwin soname should include the full path
1424
+	# (it kind of combines rpath & soname)
1425
+	LIB_SONAME=
1426
+	# no equiv. for rpath on darwin
1427
+	LD_RPATH=
1422 1428
 	YACC=yacc
1423 1429
 endif
1424 1430
 
... ...
@@ -1453,6 +1494,18 @@ endif
1453 1453
 
1454 1454
 
1455 1455
 
1456
-
1456
+#export relevant variables to the sub-makes
1457
+export RELEASE OS ARCH
1458
+export DEFS PROFILE CC LD MKDEP MKTAGS CFLAGS LDFLAGS INCLUDES MOD_CFLAGS \
1459
+		MOD_LDFLAGS LIB_CFLAGS LIB_LDFLAGS LIB_SONAME LD_RPATH
1460
+export LIBS
1461
+export LEX YACC YACC_FLAGS
1462
+export PREFIX LOCALBASE
1463
+export TAR
1464
+export cfg-prefix cfg-dir bin-prefix bin-dir modules-prefix modules-dir
1465
+export doc-prefix doc-dir man-prefix man-dir ut-prefix ut-dir
1466
+export lib-prefix lib-dir cfg-target lib-target modules-target
1467
+export INSTALL INSTALL-CFG INSTALL-BIN INSTALL-MODULES INSTALL-DOC INSTALL-MAN 
1468
+export INSTALL-LIB INSTALL-TOUCH
1457 1469
 
1458 1470
 endif  # ifeq ($(makefile_defs, 1)
1459 1471
new file mode 100644
... ...
@@ -0,0 +1,101 @@
0
+#
1
+# $Id$
2
+#
3
+# module Makefile
4
+#(to be included from each library makefile)
5
+#
6
+# History:
7
+# --------
8
+#  2007-03-16  created by andrei
9
+
10
+# NAME, MAJOR_VER and MINOR_VER should be pre-defined in the library 
11
+# makefile
12
+#
13
+
14
+ifeq ($(NAME),)
15
+$(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
16
+endif
17
+ifeq ($(MAJOR_VER),)
18
+$(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
19
+endif
20
+ifeq ($(MINOR_VER),)
21
+$(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
22
+endif
23
+ifeq ($(BUGFIX_VER),)
24
+	BUGFIX_VER:=0
25
+endif
26
+
27
+ifeq ($(OS), darwin)
28
+	LIB_NAME:=lib$(NAME).$(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER).dylib
29
+	LIB_RUNTIME_NAME:=lib$(NAME).$(MAJOR_VER).dylib
30
+	LIB_LINK_NAME:=lib$(NAME).dylib
31
+	NAME_LD_FLAGS:= -compatibility_version $(MAJOR_VER).$(MINOR_VER) \
32
+					-current_version $(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER) \
33
+					-install_name $(lib_target)/$(LIB_RUNTIME_NAME)
34
+
35
+else
36
+	LIB_NAME:=lib$(NAME).so.$(MAJOR_VER).$(MINOR_VER)
37
+	LIB_RUNTIME_NAME:=lib$(NAME).so.$(MAJOR_VER)
38
+	LIB_LINK_NAME:=lib$(NAME).so
39
+	NAME_LD_FLAGS:= $(LIB_SONAME)$(LIB_RUNTIME_NAME)
40
+endif
41
+
42
+
43
+COREPATH ?=../..
44
+
45
+ALLDEP=Makefile $(COREPATH)/Makefile.sources $(COREPATH)/Makefile.rules \
46
+ $(COREPATH)/Makefile.libs
47
+
48
+
49
+ifeq ($(MAKELEVEL), 0)
50
+# make called directly in the library dir!
51
+ifneq ($(makefile_defs), 1)
52
+$(error "the local makefile does not include Makefile.defs!")
53
+endif
54
+
55
+else
56
+# called by the main Makefile
57
+
58
+ALLDEP+=$(COREPATH)/Makefile $(COREPATH)/Makefile.defs
59
+
60
+endif
61
+
62
+include $(COREPATH)/Makefile.sources
63
+
64
+
65
+CFLAGS:=$(LIB_CFLAGS)
66
+LDFLAGS:=$(LIB_LDFLAGS) $(NAME_LD_FLAGS)
67
+NAME:=$(LIB_NAME)
68
+
69
+
70
+include $(COREPATH)/Makefile.rules
71
+
72
+$(NAME): $(LIB_RUNTIME_NAME) $(LIB_LINK_NAME)
73
+
74
+$(LIB_RUNTIME_NAME): 
75
+	-@ln -s $(LIB_NAME) $(LIB_RUNTIME_NAME)
76
+
77
+$(LIB_LINK_NAME):
78
+	-@ln -s $(LIB_NAME) $(LIB_LINK_NAME)
79
+
80
+.PHONY: link_clean
81
+link_clean:
82
+	-@rm -f $(LIB_RUNTIME_NAME)
83
+	-@rm -f $(LIB_LINK_NAME)
84
+
85
+clean: link_clean
86
+
87
+$(lib-prefix)/$(lib-dir):
88
+	mkdir -p $(lib-prefix)/$(lib-dir)
89
+
90
+.PHONY: install
91
+install: $(LIB_NAME) $(lib-prefix)/$(lib-dir)
92
+	$(INSTALL-TOUCH) $(lib-prefix)/$(lib-dir)/$(LIB_NAME)
93
+	$(INSTALL-LIB) $(LIB_NAME) $(lib-prefix)/$(lib-dir)
94
+	rm -f $(lib-prefix)/$(lib-dir)/$(LIB_RUNTIME_NAME) \
95
+			$(lib-prefix)/$(lib-dir)/$(LIB_LINK_NAME) 
96
+	ln -s $(lib-prefix)/$(lib-dir)/$(LIB_NAME) \
97
+			$(lib-prefix)/$(lib-dir)/$(LIB_RUNTIME_NAME) 
98
+	ln -s $(lib-prefix)/$(lib-dir)/$(LIB_NAME) \
99
+			$(lib-prefix)/$(lib-dir)/$(LIB_LINK_NAME) 
100
+
... ...
@@ -22,10 +22,18 @@
22 22
 	|  sed 's#\(\($*D)\)\?$(*F)\)\.o[ :]*#$*.o $@ : #g' > $@; \
23 23
 	[ -s $@ ] || rm -f $@
24 24
 
25
+# use RPATH and SER_LIBS if needed
26
+ifneq	($(SER_LIBS),)
27
+ifneq	($(LD_RPATH),)
28
+SER_RPATH:=$(LD_RPATH)$(lib-target)
29
+endif
30
+endif
31
+
32
+ALL_LIBS=$(LIBS) $(SER_LIBS)
25 33
 
26 34
 # normal rules
27 35
 $(NAME): $(objs) $(ALLDEP)
28
-	$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(LIBS) -o $(NAME) 
36
+	$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) -o $(NAME)
29 37
 
30 38
 
31 39
 .PHONY: all