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 135
 							auth_radius group_radius uri_radius avp_radius \
135 136
 							acc_radius dialog pa rls presence_b2b xcap xmlrpc\
136 137
 							osp tls oracle \
137
-							unixsock eval dbg
138
+							unixsock eval dbg print_lib
138 139
 endif
139 140
 
140 141
 # always exclude the CVS dir
... ...
@@ -226,23 +227,6 @@ include Makefile.defs
226 227
 
227 228
 NAME=$(MAIN_NAME)
228 229
 
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 230
 tar_name=$(NAME)-$(RELEASE)_src
247 231
 
248 232
 tar_extra_args+=$(addprefix --exclude=$(notdir $(CURDIR))/, \
... ...
@@ -550,11 +534,6 @@ install-man: $(man-prefix)/$(man-dir)/man8 $(man-prefix)/$(man-dir)/man5
550 534
 
551 535
 lib_dependent_modules = dialog pa rls presence_b2b xcap
552 536
 
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 537
 
559 538
 dep_mods = $(filter $(addprefix modules/, $(lib_dependent_modules)), $(modules))
560 539
 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 125
 cfg-dir = etc/ser/
124 126
 bin-dir = sbin/
125 127
 modules-dir = lib/ser/modules/
128
+lib-dir = lib/ser/
126 129
 ifeq ($(OS), linux)
127 130
 	doc-dir = share/doc/ser/
128 131
 	man-dir = share/man/
... ...
@@ -173,6 +176,7 @@ basedir = $(BASEDIR)
173 176
 cfg-prefix = $(basedir)$(prefix)
174 177
 bin-prefix = $(basedir)$(prefix)
175 178
 modules-prefix = $(basedir)$(prefix)
179
+lib-prefix = $(basedir)$(prefix)
176 180
 doc-prefix = $(basedir)$(prefix)
177 181
 man-prefix = $(basedir)$(prefix)
178 182
 ut-prefix = $(basedir)$(prefix)
... ...
@@ -182,6 +186,7 @@ ut-prefix = $(basedir)$(prefix)
182 186
 cfg-target = $(prefix)/$(cfg-dir)
183 187
 bin-target = $(prefix)/$(bin-dir)
184 188
 modules-target = $(prefix)/$(modules-dir)
189
+lib-target = $(prefix)/$(lib-dir)
185 190
 doc-target = $(prefix)/$(doc-dir)
186 191
 
187 192
 
... ...
@@ -199,6 +204,7 @@ INSTALL-TOUCH = touch          # used to create the file first (good to
199 204
 INSTALL-CFG = $(INSTALL) -m 644
200 205
 INSTALL-BIN = $(INSTALL) -m 755
201 206
 INSTALL-MODULES = $(INSTALL) -m 755
207
+INSTALL-LIB = $(INSTALL) -m 755
202 208
 INSTALL-DOC = $(INSTALL) -m 644
203 209
 INSTALL-MAN = $(INSTALL) -m 644
204 210
 
... ...
@@ -1144,21 +1150,34 @@ ifeq	($(CC_NAME), gcc)
1144 1150
 ifeq		($(LDTYPE), solaris)
1145 1151
 		# solaris ld
1146 1152
 		LDFLAGS+=-O2 $(PROFILE)
1147
-		MOD_LDFLAGS=-G $(LDFLAGS)
1153
+		MOD_LDFLAGS:=-G $(LDFLAGS)
1154
+		LIB_LDFLAGS:=-G $(LDFLAGS)
1155
+		LIB_SONAME=-Wl,-h,
1156
+		LD_RPATH=-Wl,-R,
1148 1157
 else		
1149 1158
 		#gcc and maybe others, => gnu ld
1150 1159
 		LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1151
-		MOD_LDFLAGS=-shared $(LDFLAGS)
1160
+		MOD_LDFLAGS:=-shared $(LDFLAGS)
1161
+		LIB_LDFLAGS:=-shared $(LDFLAGS)
1162
+		LIB_SONAME=-Wl,-soname,
1163
+		LD_RPATH=-Wl,-rpath,
1152 1164
 endif
1153 1165
 endif
1154 1166
 ifeq	($(CC_NAME), icc)
1155 1167
 	#gcc and maybe others
1156 1168
 	LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1157
-	MOD_LDFLAGS=-shared $(LDFLAGS)
1169
+	MOD_LDFLAGS:=-shared $(LDFLAGS)
1170
+	LIB_LDFLAGS:=-shared $(LDFLAGS)
1171
+	LIB_SONAME=-Wl,-soname,
1172
+	LD_RPATH=-Wl,-rpath,
1158 1173
 endif
1159 1174
 ifeq	($(CC_NAME), suncc)
1175
+	# -dy?
1160 1176
 	LDFLAGS+=-xO5 $(PROFILE)
1161
-	MOD_LDFLAGS=-G $(LDFLAGS)
1177
+	MOD_LDFLAGS:=-G $(LDFLAGS)
1178
+	LIB_LDFLAGS:=-G $(LDFLAGS)
1179
+	LIB_SONAME="-h "
1180
+	LD_RPATH=-"-R "
1162 1181
 endif
1163 1182
 	# we need -fPIC -DPIC only for shared objects, we don't need them for
1164 1183
 	# the executable file, because it's always loaded at a fixed address
... ...
@@ -1175,23 +1194,35 @@ endif
1175 1194
 ifeq		($(LDTYPE), solaris)
1176 1195
 			#solaris ld
1177 1196
 			LDFLAGS+=-g $(PROFILE)
1178
-			MOD_LDFLAGS=-G $(LDFLAGS)
1197
+			MOD_LDFLAGS:=-G $(LDFLAGS)
1198
+			LIB_LDFLAGS:=-G $(LDFLAGS)
1199
+			LIB_SONAME=-Wl,-h,
1200
+			LD_RPATH=-Wl,-R,
1179 1201
 else
1180 1202
 			#gnu or other ld type
1181 1203
 			LDFLAGS+=-g -Wl,-E $(PROFILE)
1182
-			MOD_LDFLAGS=-shared $(LDFLAGS)
1204
+			MOD_LDFLAGS:=-shared $(LDFLAGS)
1205
+			LIB_LDFLAGS:=-shared $(LDFLAGS)
1206
+			LIB_SONAME=-Wl,-soname,
1207
+			LD_RPATH=-Wl,-rpath,
1183 1208
 endif
1184 1209
 endif
1185 1210
 ifeq	($(CC_NAME), icc)
1186 1211
 		DEFS+=-DCC_GCC_LIKE_ASM
1187 1212
 		CFLAGS=-g  $(PROFILE)
1188 1213
 		LDFLAGS+=-g -Wl,-E $(PROFILE)
1189
-		MOD_LDFLAGS=-shared $(LDFLAGS)
1214
+		MOD_LDFLAGS:=-shared $(LDFLAGS)
1215
+		LIB_LDFLAGS:=-shared $(LDFLAGS)
1216
+		LIB_SONAME=-Wl,-soname,
1217
+		LD_RPATH=-Wl,-rpath,
1190 1218
 endif
1191 1219
 ifeq	($(CC_NAME), suncc)
1192 1220
 		CFLAGS= -g $(PROFILE)
1193 1221
 		LDFLAGS+=-g $(PROFILE)
1194
-		MOD_LDFLAGS=-G $(LDFLAGS)
1222
+		MOD_LDFLAGS:=-G $(LDFLAGS)
1223
+		LIB_LDFLAGS:=-G $(LDFLAGS)
1224
+		LIB_SONAME="-h "
1225
+		LD_RPATH=-"-R "
1195 1226
 endif
1196 1227
 
1197 1228
 endif #mode=release
... ...
@@ -1213,13 +1244,17 @@ endif # CC_NAME=gcc
1213 1244
 
1214 1245
 #*FLAGS used for compiling the modules
1215 1246
 ifeq	($(CC_NAME), gcc)
1216
-MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
1247
+MOD_CFLAGS:=-fPIC -DPIC $(CFLAGS)
1248
+LIB_CFLAGS:=-fPIC -DPIC $(CFLAGS)
1217 1249
 endif
1218 1250
 ifeq	($(CC_NAME), icc)
1219
-MOD_CFLAGS=-Kpic $(CFLAGS)
1251
+MOD_CFLAGS:=-Kpic $(CFLAGS)
1252
+LIB_CFLAGS:=-Kpic $(CFLAGS)
1220 1253
 endif
1221 1254
 ifeq	($(CC_NAME), suncc)
1222
-MOD_CFLAGS=-xcode=pic32  $(CFLAGS)
1255
+# FIMXE: use -KPIC instead -xcode ?
1256
+MOD_CFLAGS:=-xcode=pic32  $(CFLAGS)
1257
+LIB_CFLAGS:=-xcode=pic32  $(CFLAGS)
1223 1258
 endif
1224 1259
 
1225 1260
 ifeq ($(LEX),)
... ...
@@ -1418,7 +1453,13 @@ ifeq ($(OS), darwin)
1418 1453
 		DEFS+=-DHAVE_SELECT
1419 1454
 	endif
1420 1455
 	LDFLAGS=        # darwin doesn't like -O2 or -E
1421
-	MOD_LDFLAGS= -bundle -bundle_loader ../../$(MAIN_NAME)
1456
+	MOD_LDFLAGS:= -bundle -bundle_loader ../../$(MAIN_NAME)
1457
+	LIB_LDFLAGS:= -dynamiclib
1458
+	# on darwin soname should include the full path
1459
+	# (it kind of combines rpath & soname)
1460
+	LIB_SONAME=
1461
+	# no equiv. for rpath on darwin
1462
+	LD_RPATH=
1422 1463
 	YACC=yacc
1423 1464
 endif
1424 1465
 
... ...
@@ -1453,6 +1494,18 @@ endif
1453 1494
 
1454 1495
 
1455 1496
 
1456
-
1497
+#export relevant variables to the sub-makes
1498
+export RELEASE OS ARCH
1499
+export DEFS PROFILE CC LD MKDEP MKTAGS CFLAGS LDFLAGS INCLUDES MOD_CFLAGS \
1500
+		MOD_LDFLAGS LIB_CFLAGS LIB_LDFLAGS LIB_SONAME LD_RPATH
1501
+export LIBS
1502
+export LEX YACC YACC_FLAGS
1503
+export PREFIX LOCALBASE
1504
+export TAR
1505
+export cfg-prefix cfg-dir bin-prefix bin-dir modules-prefix modules-dir
1506
+export doc-prefix doc-dir man-prefix man-dir ut-prefix ut-dir
1507
+export lib-prefix lib-dir cfg-target lib-target modules-target
1508
+export INSTALL INSTALL-CFG INSTALL-BIN INSTALL-MODULES INSTALL-DOC INSTALL-MAN 
1509
+export INSTALL-LIB INSTALL-TOUCH
1457 1510
 
1458 1511
 endif  # ifeq ($(makefile_defs, 1)
1459 1512
new file mode 100644
... ...
@@ -0,0 +1,101 @@
1
+#
2
+# $Id$
3
+#
4
+# module Makefile
5
+#(to be included from each library makefile)
6
+#
7
+# History:
8
+# --------
9
+#  2007-03-16  created by andrei
10
+
11
+# NAME, MAJOR_VER and MINOR_VER should be pre-defined in the library 
12
+# makefile
13
+#
14
+
15
+ifeq ($(NAME),)
16
+$(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
17
+endif
18
+ifeq ($(MAJOR_VER),)
19
+$(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
20
+endif
21
+ifeq ($(MINOR_VER),)
22
+$(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
23
+endif
24
+ifeq ($(BUGFIX_VER),)
25
+	BUGFIX_VER:=0
26
+endif
27
+
28
+ifeq ($(OS), darwin)
29
+	LIB_NAME:=lib$(NAME).$(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER).dylib
30
+	LIB_RUNTIME_NAME:=lib$(NAME).$(MAJOR_VER).dylib
31
+	LIB_LINK_NAME:=lib$(NAME).dylib
32
+	NAME_LD_FLAGS:= -compatibility_version $(MAJOR_VER).$(MINOR_VER) \
33
+					-current_version $(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER) \
34
+					-install_name $(lib_target)/$(LIB_RUNTIME_NAME)
35
+
36
+else
37
+	LIB_NAME:=lib$(NAME).so.$(MAJOR_VER).$(MINOR_VER)
38
+	LIB_RUNTIME_NAME:=lib$(NAME).so.$(MAJOR_VER)
39
+	LIB_LINK_NAME:=lib$(NAME).so
40
+	NAME_LD_FLAGS:= $(LIB_SONAME)$(LIB_RUNTIME_NAME)
41
+endif
42
+
43
+
44
+COREPATH ?=../..
45
+
46
+ALLDEP=Makefile $(COREPATH)/Makefile.sources $(COREPATH)/Makefile.rules \
47
+ $(COREPATH)/Makefile.libs
48
+
49
+
50
+ifeq ($(MAKELEVEL), 0)
51
+# make called directly in the library dir!
52
+ifneq ($(makefile_defs), 1)
53
+$(error "the local makefile does not include Makefile.defs!")
54
+endif
55
+
56
+else
57
+# called by the main Makefile
58
+
59
+ALLDEP+=$(COREPATH)/Makefile $(COREPATH)/Makefile.defs
60
+
61
+endif
62
+
63
+include $(COREPATH)/Makefile.sources
64
+
65
+
66
+CFLAGS:=$(LIB_CFLAGS)
67
+LDFLAGS:=$(LIB_LDFLAGS) $(NAME_LD_FLAGS)
68
+NAME:=$(LIB_NAME)
69
+
70
+
71
+include $(COREPATH)/Makefile.rules
72
+
73
+$(NAME): $(LIB_RUNTIME_NAME) $(LIB_LINK_NAME)
74
+
75
+$(LIB_RUNTIME_NAME): 
76
+	-@ln -s $(LIB_NAME) $(LIB_RUNTIME_NAME)
77
+
78
+$(LIB_LINK_NAME):
79
+	-@ln -s $(LIB_NAME) $(LIB_LINK_NAME)
80
+
81
+.PHONY: link_clean
82
+link_clean:
83
+	-@rm -f $(LIB_RUNTIME_NAME)
84
+	-@rm -f $(LIB_LINK_NAME)
85
+
86
+clean: link_clean
87
+
88
+$(lib-prefix)/$(lib-dir):
89
+	mkdir -p $(lib-prefix)/$(lib-dir)
90
+
91
+.PHONY: install
92
+install: $(LIB_NAME) $(lib-prefix)/$(lib-dir)
93
+	$(INSTALL-TOUCH) $(lib-prefix)/$(lib-dir)/$(LIB_NAME)
94
+	$(INSTALL-LIB) $(LIB_NAME) $(lib-prefix)/$(lib-dir)
95
+	rm -f $(lib-prefix)/$(lib-dir)/$(LIB_RUNTIME_NAME) \
96
+			$(lib-prefix)/$(lib-dir)/$(LIB_LINK_NAME) 
97
+	ln -s $(lib-prefix)/$(lib-dir)/$(LIB_NAME) \
98
+			$(lib-prefix)/$(lib-dir)/$(LIB_RUNTIME_NAME) 
99
+	ln -s $(lib-prefix)/$(lib-dir)/$(LIB_NAME) \
100
+			$(lib-prefix)/$(lib-dir)/$(LIB_LINK_NAME) 
101
+
... ...
@@ -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