Makefile.shared 23.9 KB
Newer Older
1 2 3 4 5 6 7 8 9
#
# Helper makefile to link shared libraries in a portable way.
# This is much simpler than libtool, and hopefully not too error-prone.
#
# The following variables need to be set on the command line to build
# properly

# CC contains the current compiler.  This one MUST be defined
CC=cc
10 11 12
# LDFLAGS contains flags to be used when temporary object files (when building
# shared libraries) are created, or when an application is linked.
# SHARED_LDFLAGS contains flags to be used when the shared library is created.
13 14 15
LDFLAGS=
SHARED_LDFLAGS=

16
# LIBNAME contains just the name of the library, without prefix ("lib"
17
# on Unix, "cyg" for certain forms under Cygwin...) or suffix (.a, .so,
18 19
# .dll, ...).  This one MUST have a value when using this makefile to
# build shared libraries.
20 21 22 23
# For example, to build libfoo.so, you need to do the following:
#LIBNAME=foo
LIBNAME=

24 25 26 27 28 29 30 31 32 33 34 35
# APPNAME contains just the name of the application, without suffix (""
# on Unix, ".exe" on Windows, ...).  This one MUST have a value when using
# this makefile to build applications.
# For example, to build foo, you need to do the following:
#APPNAME=foo
APPNAME=

# OBJECTS contains all the object files to link together into the application.
# This must contain at least one object file.
#OBJECTS=foo.o
OBJECTS=

36
# LIBEXTRAS contains extra modules to link together with the library.
37
# For example, if a second library, say libbar.a needs to be linked into
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
# libfoo.so, you need to do the following:
#LIBEXTRAS=libbar.a
# Note that this MUST be used when using the link_o targets, to hold the
# names of all object files that go into the target library.
LIBEXTRAS=

# LIBVERSION contains the current version of the library.
# For example, to build libfoo.so.1.2, you need to do the following:
#LIBVERSION=1.2
LIBVERSION=

# LIBCOMPATVERSIONS contains the compatibility versions (a list) of
# the library.  They MUST be in decreasing order.
# For example, if libfoo.so.1.2.1 is backward compatible with libfoo.so.1.2
# and libfoo.so.1, you need to do the following:
#LIBCOMPATVERSIONS=1.2 1
# Note that on systems that use sonames, the last number will appear as
# part of it.
# It's also possible, for systems that support it (Tru64, for example),
# to add extra compatibility info with more precision, by adding a second
# list of versions, separated from the first with a semicolon, like this:
#LIBCOMPATVERSIONS=1.2 1;1.2.0 1.1.2 1.1.1 1.1.0 1.0.0
LIBCOMPATVERSIONS=

# LIBDEPS contains all the flags necessary to cover all necessary
# dependencies to other libraries.
LIBDEPS=

#------------------------------------------------------------------------------
# The rest is private to this makefile.

B
Ben Laurie 已提交
69 70
SET_X=:
#SET_X=set -x
71 72 73 74 75 76

top:
	echo "Trying to use this makefile interactively?  Don't."

CALC_VERSIONS=	\
	SHLIB_COMPAT=; SHLIB_SOVER=; \
77
	if [ -n "$(LIBVERSION)$(LIBCOMPATVERSIONS)" ]; then \
78 79
		prev=""; \
		for v in `echo "$(LIBVERSION) $(LIBCOMPATVERSIONS)" | cut -d';' -f1`; do \
80
			SHLIB_SOVER_NODOT=$$v; \
81 82
			SHLIB_SOVER=.$$v; \
			if [ -n "$$prev" ]; then \
R
Richard Levitte 已提交
83
				SHLIB_COMPAT="$$SHLIB_COMPAT .$$prev"; \
84 85 86 87 88
			fi; \
			prev=$$v; \
		done; \
	fi

89
LINK_APP=	\
90
  ( $(SET_X);   \
R
Richard Levitte 已提交
91
    LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \
R
Richard Levitte 已提交
92
    LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
93
    LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
94
    $$LDCMD $$LDFLAGS -o $$APPNAME $(OBJECTS) $$LIBDEPS )
95

96
LINK_SO=	\
97
  ( $(SET_X);   \
98
    nm -Pg $$SHOBJECTS | grep ' [BDT] ' | cut -f1 -d' ' > lib$(LIBNAME).exp; \
R
Richard Levitte 已提交
99
    LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \
R
Richard Levitte 已提交
100
    LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
101
    LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
102
    $$SHAREDCMD $$SHAREDFLAGS -o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \
103
	$$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS ) && \
104
  $(SYMLINK_SO); ( $(SET_X); rm -f lib$(LIBNAME).exp )
105
SYMLINK_SO=	\
106 107 108 109
	if [ -n "$$INHIBIT_SYMLINKS" ]; then :; else \
		prev=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
		if [ -n "$$SHLIB_COMPAT" ]; then \
			for x in $$SHLIB_COMPAT; do \
110
				( $(SET_X); rm -f $$SHLIB$$x$$SHLIB_SUFFIX; \
111 112 113 114 115
				  ln -s $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \
				prev=$$SHLIB$$x$$SHLIB_SUFFIX; \
			done; \
		fi; \
		if [ -n "$$SHLIB_SOVER" ]; then \
116
			( $(SET_X); rm -f $$SHLIB$$SHLIB_SUFFIX; \
117 118
			  ln -s $$prev $$SHLIB$$SHLIB_SUFFIX ); \
		fi; \
119
	fi
120

121 122 123
LINK_SO_A=	SHOBJECTS="lib$(LIBNAME).a $(LIBEXTRAS)"; $(LINK_SO)
LINK_SO_O=	SHOBJECTS="$(LIBEXTRAS)"; $(LINK_SO)
LINK_SO_A_VIA_O=	\
124 125
  SHOBJECTS=lib$(LIBNAME).o; \
  ALL=$$ALLSYMSFLAGS; ALLSYMSFLAGS=; NOALLSYMSFLAGS=; \
126
  ( $(SET_X); \
127 128 129 130
    ld $(LDFLAGS) -r -o lib$(LIBNAME).o $$ALL lib$(LIBNAME).a $(LIBEXTRAS) ); \
  $(LINK_SO) && rm -f $(LIBNAME).o
LINK_SO_A_UNPACKED=	\
  UNPACKDIR=link_tmp.$$$$; rm -rf $$UNPACKDIR; mkdir $$UNPACKDIR; \
131 132
  (cd $$UNPACKDIR; ar x ../lib$(LIBNAME).a) && \
  ([ -z "$(LIBEXTRAS)" ] || cp $(LIBEXTRAS) $$UNPACKDIR) && \
133 134 135
  SHOBJECTS=$$UNPACKDIR/*.o; \
  $(LINK_SO) && rm -rf $$UNPACKDIR

A
Andy Polyakov 已提交
136 137
DETECT_GNU_LD=(${CC} -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/null

138
DO_GNU_SO=$(CALC_VERSIONS); \
139 140
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
141
	LIBDEPS="$(LIBDEPS)"; \
142 143
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
144
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-rpath,$(LIBRPATH)"; \
145
	SHAREDCMD='$(CC)'
146
DO_GNU_APP=LDCMD=$(CC);\
147
	LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)"; \
148
	LIBDEPS="$(LIBDEPS)"; \
149
	APPNAME=$(APPNAME)
150

151 152 153 154 155 156 157
#This is rather special.  It's a special target with which one can link
#applications without bothering with any features that have anything to
#do with shared libraries, for example when linking against static
#libraries.  It's mostly here to avoid a lot of conditionals everywhere
#else...
link_app.:
	LDCMD=$(CC); \
158
	LDFLAGS="$(CFLAGS)"; \
159 160 161 162
	LIBDEPS="$(LIBDEPS)"; \
	APPNAME="$(APPNAME)"; \
	$(LINK_APP)

163
link_o.gnu:
164
	@ $(DO_GNU_SO); $(LINK_SO_O)
165
link_a.gnu:
166 167 168
	@ $(DO_GNU_SO); $(LINK_SO_A)
link_app.gnu:
	@ $(DO_GNU_APP); $(LINK_APP)
169

170 171 172 173 174 175 176 177
link_o.bsd:
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	LIBDEPS=; \
	ALLSYMSFLAGS="-Wl,-Bforcearchive"; \
	NOALLSYMSFLAGS=; \
178
	SHAREDFLAGS="$(CFLAGS) -shared -nostdlib"; \
179 180 181 182 183 184 185 186 187 188
	SHAREDCMD=$(CC); \
	fi; $(LINK_SO_O)
link_a.bsd:
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	LIBDEPS=; \
	ALLSYMSFLAGS="-Wl,-Bforcearchive"; \
	NOALLSYMSFLAGS=; \
189
	SHAREDFLAGS="$(CFLAGS) -shared -nostdlib"; \
190 191 192 193 194
	SHAREDCMD=$(CC); \
	fi; $(LINK_SO_A)
link_app.bsd:
	@if ${DETECT_GNU_LD}; then $(DO_GNU_APP); else \
	LDCMD=$(CC); \
195
	LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBPATH)"; \
196 197 198 199
	LIBDEPS="$(LIBDEPS)"; \
	APPNAME="$(APPNAME)"; \
	fi; $(LINK_APP)

200 201 202
# For Darwin AKA Mac OS/X (dyld)
link_o.darwin:
	@ $(CALC_VERSIONS); \
203 204
	SHLIB=lib$(LIBNAME); \
	SHLIB_SUFFIX=.dylib; \
205
	LIBDEPS="$(LIBDEPS)"; \
206 207
	ALLSYMSFLAGS='-all_load'; \
	NOALLSYMSFLAGS=''; \
208
	SHAREDFLAGS="$(CFLAGS) -dynamiclib"; \
209
	SHAREDCMD='$(CC)'; \
210
	if [ -n "$(LIBVERSION)" ]; then \
211
		SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
212 213
	fi; \
	if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
214
		SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
215
	fi; \
216 217 218
	$(LINK_SO_O)
link_a.darwin:
	@ $(CALC_VERSIONS); \
219 220
	SHLIB=lib$(LIBNAME); \
	SHLIB_SUFFIX=.dylib; \
221
	LIBDEPS="$(LIBDEPS)"; \
222 223
	ALLSYMSFLAGS='-all_load'; \
	NOALLSYMSFLAGS=''; \
224
	SHAREDFLAGS="$(CFLAGS) -dynamiclib"; \
225
	SHAREDCMD='$(CC)'; \
226
	if [ -n "$(LIBVERSION)" ]; then \
227
		SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
228 229
	fi; \
	if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
230
		SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
231
	fi; \
232
	$(LINK_SO_A)
233 234
link_app.darwin:
	LDCMD=$(CC);\
235
	LDFLAGS="$(CFLAGS)"; \
236
	LIBDEPS="$(LIBDEPS)"; \
237 238
	APPNAME="$(APPNAME)"; \
	$(LINK_APP)
239 240

link_o.cygwin:
241 242
	@ $(CALC_VERSIONS); \
	INHIBIT_SYMLINKS=yes; \
243
	SHLIB=cyg$(LIBNAME); \
244
	expr $(PLATFORM) : 'mingw' > /dev/null && SHLIB=$(LIBNAME)eay32; \
245
	SHLIB_SUFFIX=.dll; \
246
	LIBDEPS="$(LIBDEPS)"; \
247 248 249
	SHLIB_SOVER=-$(LIBVERSION); \
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
250
	SHAREDFLAGS="$(CFLAGS) -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
251 252 253
	SHAREDCMD='${CC}'; \
	$(LINK_SO_O)
link_a.cygwin:
254 255
	@ $(CALC_VERSIONS); \
	INHIBIT_SYMLINKS=yes; \
256
	SHLIB=cyg$(LIBNAME); \
257
	expr $(PLATFORM) : 'mingw' > /dev/null && SHLIB=$(LIBNAME)eay32; \
258
	SHLIB_SUFFIX=.dll; \
259
	LIBDEPS="$(LIBDEPS)"; \
260 261 262
	SHLIB_SOVER=; \
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
A
Andy Polyakov 已提交
263 264
	base=;  [ $(LIBNAME) = "crypto" ] && base=-Wl,--image-base,0x61200000; \
	SHAREDFLAGS="$(CFLAGS) $$base -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
265
	SHAREDCMD='${CC}'; \
A
Andy Polyakov 已提交
266 267 268 269 270
	[ -f apps/$$SHLIB$$SHLIB_SUFFIX ] && rm apps/$$SHLIB$$SHLIB_SUFFIX; \
	[ -f test/$$SHLIB$$SHLIB_SUFFIX ] && rm test/$$SHLIB$$SHLIB_SUFFIX; \
	$(LINK_SO_A) || exit 1; \
	cp -p $$SHLIB$$SHLIB_SUFFIX apps/; \
	cp -p $$SHLIB$$SHLIB_SUFFIX test/
271 272
link_app.cygwin:
	LDCMD=$(CC);\
273
	LDFLAGS="$(CFLAGS)"; \
274 275
	LIBDEPS="$(LIBDEPS)"; \
	APPNAME="$(APPNAME)"; \
276
	$(LINK_APP)
277 278 279

link_o.alpha-osf1:
	@ if ${DETECT_GNU_LD}; then \
280
		$(DO_GNU_SO); \
281
	else \
282 283
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
284
		LIBDEPS="$(LIBDEPS)"; \
285 286 287 288 289
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
290
		fi; \
291 292 293
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
294
		SHAREDFLAGS="$(CFLAGS) -shared"; \
295
		SHAREDCMD='$(CC)'; \
296
		if [ -n "$$SHLIB_HIST" ]; then \
297
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
298
		fi; \
299 300
	fi; \
	$(LINK_SO_O)
301 302
link_a.alpha-osf1:
	@ if ${DETECT_GNU_LD}; then \
303
		$(DO_GNU_SO); \
304
	else \
305 306
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
307
		LIBDEPS="$(LIBDEPS)"; \
308 309 310 311 312
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
313
		fi; \
314 315 316
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
317
		SHAREDFLAGS="$(CFLAGS) -shared"; \
318
		SHAREDCMD='$(CC)'; \
319
		if [ -n "$$SHLIB_HIST" ]; then \
320
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
321
		fi; \
322 323
	fi; \
	$(LINK_SO_A)
324 325 326 327 328
link_app.alpha-osf1:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
329
		LDFLAGS="$(CFLAGS)"; \
330
		LIBDEPS="$(LIBDEPS)"; \
331 332 333
		APPNAME="$(APPNAME)"
	fi; \
	$(LINK_APP)
334 335 336 337 338

# The difference between alpha-osf1-shared and tru64-shared is the `-msym'
# option passed to the linker.
link_o.tru64:
	@ if ${DETECT_GNU_LD}; then \
339
		$(DO_GNU_SO); \
340
	else \
341 342
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
343
		LIBDEPS="$(LIBDEPS)"; \
344 345 346 347 348
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
349
		fi; \
350 351 352
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
353
		SHAREDFLAGS="$(CFLAGS) -shared -msym -rpath $(LIBRPATH)"; \
354
		SHAREDCMD='$(CC)'; \
355
		if [ -n "$$SHLIB_HIST" ]; then \
356
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
357
		fi; \
358 359
	fi; \
	$(LINK_SO_O)
360 361
link_a.tru64:
	@ if ${DETECT_GNU_LD}; then \
362
		$(DO_GNU_SO); \
363
	else \
364 365
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
366
		LIBDEPS="$(LIBDEPS)"; \
367 368 369 370 371
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
372
		fi; \
373 374 375
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
376
		SHAREDFLAGS="$(CFLAGS) -shared -msym -rpath $(LIBRPATH)"; \
377
		SHAREDCMD='$(CC)'; \
378
		if [ -n "$$SHLIB_HIST" ]; then \
379
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
380
		fi; \
381 382
	fi; \
	$(LINK_SO_A)
383 384 385 386 387
link_app.tru64:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
388
		LDFLAGS="$(CFLAGS) -rpath $(LIBRPATH)"; \
389
		LIBDEPS="$(LIBDEPS)"; \
390 391 392
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
393 394 395 396 397

# The difference between tru64-shared and tru64-shared-rpath is the
# -rpath ${LIBRPATH} passed to the linker.
link_o.tru64-rpath:
	@ if ${DETECT_GNU_LD}; then \
398
		$(DO_GNU_SO); \
399
	else \
400 401
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
402
		LIBDEPS="$(LIBDEPS)"; \
403 404 405 406 407
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
408
		fi; \
409 410 411
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
412
		SHAREDFLAGS="$(CFLAGS) -shared -msym -rpath $(LIBRPATH)"; \
413
		SHAREDCMD='$(CC)'; \
414
		if [ -n "$$SHLIB_HIST" ]; then \
415
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
416
		fi; \
417 418
	fi; \
	$(LINK_SO_O)
419 420
link_a.tru64-rpath:
	@ if ${DETECT_GNU_LD}; then \
421
		$(DO_GNU_SO); \
422
	else \
423 424
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
425
		LIBDEPS="$(LIBDEPS)"; \
426 427 428 429 430
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
431
		fi; \
432 433 434
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
435
		SHAREDFLAGS="$(CFLAGS) -shared -msym -rpath $(LIBRPATH)"; \
436
		SHAREDCMD='$(CC)'; \
437
		if [ -n "$$SHLIB_HIST" ]; then \
438
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
439
		fi; \
440 441
	fi; \
	$(LINK_SO_A)
442 443 444 445 446
link_app.tru64-rpath:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
447
		LDFLAGS="$(CFLAGS) -rpath $(LIBRPATH)"; \
448
		LIBDEPS="$(LIBDEPS)"; \
449 450 451
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
452 453

link_o.solaris:
R
Richard Levitte 已提交
454
	@ if ${DETECT_GNU_LD}; then \
455
		$(DO_GNU_SO); \
456 457
	else \
		$(CALC_VERSIONS); \
458 459
		MINUSZ='-z '; \
		(${CC} -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
460 461
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
462
		LIBDEPS="$(LIBDEPS)"; \
463 464
		ALLSYMSFLAGS="$${MINUSZ}allextract"; \
		NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
465
		SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -R $(LIBRPATH) -Wl,-Bsymbolic"; \
466
		SHAREDCMD='$(CC)'; \
467 468
	fi; \
	$(LINK_SO_O)
469
link_a.solaris:
R
Richard Levitte 已提交
470
	@ if ${DETECT_GNU_LD}; then \
471
		$(DO_GNU_SO); \
472 473
	else \
		$(CALC_VERSIONS); \
474 475
		MINUSZ='-z '; \
		(${CC} -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
476 477
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=;\
478
		LIBDEPS="$(LIBDEPS)"; \
479 480
		ALLSYMSFLAGS="$${MINUSZ}allextract"; \
		NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
481
		SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -R $(LIBRPATH) -Wl,-Bsymbolic"; \
482
		SHAREDCMD='$(CC)'; \
483 484
	fi; \
	$(LINK_SO_A)
485 486 487 488 489
link_app.solaris:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
490
		LDFLAGS="$(CFLAGS) -R $(LIBRPATH)"; \
491
		LIBDEPS="$(LIBDEPS)"; \
492 493 494
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
495 496 497

# OpenServer 5 native compilers used
link_o.svr3:
R
Richard Levitte 已提交
498 499 500 501 502 503
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_SO); \
	else \
		$(CALC_VERSIONS); \
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
504
		LIBDEPS="$(LIBDEPS)"; \
R
Richard Levitte 已提交
505 506
		ALLSYMSFLAGS=''; \
		NOALLSYMSFLAGS=''; \
507
		SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
R
Richard Levitte 已提交
508 509 510 511 512 513 514 515 516 517
		SHAREDCMD='$(CC)'; \
	fi; \
	$(LINK_SO_O)
link_a.svr3:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_SO); \
	else \
		$(CALC_VERSIONS); \
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
518
		LIBDEPS="$(LIBDEPS)"; \
R
Richard Levitte 已提交
519 520
		ALLSYMSFLAGS=''; \
		NOALLSYMSFLAGS=''; \
521
		SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
R
Richard Levitte 已提交
522 523 524 525 526 527 528 529
		SHAREDCMD='$(CC)'; \
	fi; \
	$(LINK_SO_A_UNPACKED)
link_app.svr3:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
530
		LDFLAGS="$(CFLAGS)"; \
531
		LIBDEPS="$(LIBDEPS)"; \
R
Richard Levitte 已提交
532 533 534 535 536 537
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)

# UnixWare 7 and OpenUNIX 8 native compilers used
link_o.svr5:
538
	@ if ${DETECT_GNU_LD}; then \
539
		$(DO_GNU_SO); \
540 541
	else \
		$(CALC_VERSIONS); \
542
		SHARE_FLAG='-G'; \
543
		(${CC} -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
544 545
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
546
		LIBDEPS="$(LIBDEPS)"; \
547
		ALLSYMSFLAGS=''; \
548
		NOALLSYMSFLAGS=''; \
549
		SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
550
		SHAREDCMD='$(CC)'; \
551 552
	fi; \
	$(LINK_SO_O)
R
Richard Levitte 已提交
553
link_a.svr5:
554
	@ if ${DETECT_GNU_LD}; then \
555
		$(DO_GNU_SO); \
556 557
	else \
		$(CALC_VERSIONS); \
558
		SHARE_FLAG='-G'; \
559
		(${CC} -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
560 561
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
562
		LIBDEPS="$(LIBDEPS)"; \
563
		ALLSYMSFLAGS=''; \
564
		NOALLSYMSFLAGS=''; \
565
		SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
566
		SHAREDCMD='$(CC)'; \
567 568
	fi; \
	$(LINK_SO_A_UNPACKED)
R
Richard Levitte 已提交
569
link_app.svr5:
570 571 572 573
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
574
		LDFLAGS="$(CFLAGS)"; \
575
		LIBDEPS="$(LIBDEPS)"; \
576 577 578
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
579 580 581

link_o.irix:
	@ if ${DETECT_GNU_LD}; then \
582
		$(DO_GNU_SO); \
583 584
	else \
		$(CALC_VERSIONS); \
585 586
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
587
		LIBDEPS="$(LIBDEPS)"; \
A
Andy Polyakov 已提交
588 589 590
		MINUSWL=""; \
		($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
		ALLSYMSFLAGS="$${MINUSWL}-all"; \
591
		NOALLSYMSFLAGS="$${MINUSWL}-none"; \
592
		SHAREDFLAGS="$(CFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-rpath,$(LIBRPATH)"; \
593
		SHAREDCMD='$(CC)'; \
594 595
	fi; \
	$(LINK_SO_O)
596 597
link_a.irix:
	@ if ${DETECT_GNU_LD}; then \
598
		$(DO_GNU_SO); \
599 600
	else \
		$(CALC_VERSIONS); \
601 602
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
603
		LIBDEPS="$(LIBDEPS)"; \
A
Andy Polyakov 已提交
604 605 606
		MINUSWL=""; \
		($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
		ALLSYMSFLAGS="$${MINUSWL}-all"; \
607
		NOALLSYMSFLAGS="$${MINUSWL}-none"; \
608
		SHAREDFLAGS="$(CFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-rpath,$(LIBRPATH)"; \
609
		SHAREDCMD='$(CC)'; \
610 611
	fi; \
	$(LINK_SO_A)
612 613 614 615 616
link_app.irix:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
617
		LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)"; \
618
		LIBDEPS="$(LIBDEPS)"; \
619 620 621
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
622

623 624 625 626 627 628 629
# 32-bit PA-RISC HP-UX embeds the -L pathname of libs we link with, so
# we compensate for it with +cdp ../: and +cdp ./:. Yes, these rewrite
# rules imply that we can only link one level down in catalog structure,
# but that's what takes place for the moment of this writing. +cdp option
# was introduced in HP-UX 11.x and applies in 32-bit PA-RISC link
# editor context only [it's simply ignored in other cases, which are all
# ELFs by the way].
630
#
631
link_o.hpux:
632 633
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
634
	SHLIB=lib$(LIBNAME).sl; \
635
	expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
636
	SHLIB_SUFFIX=; \
637 638
	LIBDEPS="$(LIBDEPS)"; \
	ALLSYMSFLAGS='-Wl,-Fl'; \
639
	NOALLSYMSFLAGS=''; \
640
	expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
641
	SHAREDFLAGS="$(CFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+cdp,../:,+cdp,./:,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+b,$(LIBRPATH)"; \
642
	SHAREDCMD=$(CC); \
643
	fi; \
644
	$(LINK_SO_O) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
645
link_a.hpux:
646 647
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
648
	SHLIB=lib$(LIBNAME).sl; \
649
	expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
650
	SHLIB_SUFFIX=; \
651 652
	LIBDEPS="$(LIBDEPS)"; \
	ALLSYMSFLAGS='-Wl,-Fl'; \
653
	NOALLSYMSFLAGS=''; \
654
	expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
655
	SHAREDFLAGS="$(CFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+cdp,../:,+cdp,./:,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+b,$(LIBRPATH)"; \
656
	SHAREDCMD='$(CC)'; \
657
	fi; \
658
	$(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
659
link_app.hpux:
660
	@if ${DETECT_GNU_LD}; then $(DO_GNU_APP); else \
661
	LDCMD=$(CC);\
662
	LDFLAGS="$(CFLAGS) -Wl,+s,+cdp,../:,+cdp,./:,+b,$(LIBRPATH)"; \
663 664
	LIBDEPS="$(LIBDEPS)"; \
	APPNAME="$(APPNAME)"; \
665
	fi; \
666
	$(LINK_APP)
667 668 669

link_o.aix:
	@ $(CALC_VERSIONS); \
670 671
	OBJECT_MODE=`expr x$(SHARED_LDFLAGS) : 'x\-[a-z]\([0-9]*\)'`; \
	OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \
672 673
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
674
	LIBDEPS="$(LIBDEPS)"; \
675 676
	ALLSYMSFLAGS='-bnogc'; \
	NOALLSYMSFLAGS=''; \
677
	SHAREDFLAGS='$(CFLAGS) -G -bE:lib$(LIBNAME).exp -bM:SRE -blibpath:$(LIBRPATH)'; \
678
	SHAREDCMD='$(CC)'; \
679
	$(LINK_SO_O); rm -rf lib$(LIBNAME).exp
680 681
link_a.aix:
	@ $(CALC_VERSIONS); \
682 683
	OBJECT_MODE=`expr x$(SHARED_LDFLAGS) : 'x\-[a-z]\([0-9]*\)'`; \
	OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \
684 685
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
686
	LIBDEPS="$(LIBDEPS)"; \
687 688
	ALLSYMSFLAGS='-bnogc'; \
	NOALLSYMSFLAGS=''; \
689
	SHAREDFLAGS='$(CFLAGS) -G -bE:lib$(LIBNAME).exp -bM:SRE -blibpath:$(LIBRPATH)'; \
690 691
	SHAREDCMD='$(CC)'; \
	$(LINK_SO_A_VIA_O)
692 693
link_app.aix:
	LDCMD=$(CC);\
694
	LDFLAGS="$(CFLAGS) -blibpath:$(LIBRPATH)"; \
695
	LIBDEPS="$(LIBDEPS)"; \
696 697
	APPNAME="$(APPNAME)"
	$(LINK_APP)
698 699 700

link_o.reliantunix:
	@ $(CALC_VERSIONS); \
701 702
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
703
	LIBDEPS="$(LIBDEPS)"; \
704 705
	ALLSYMSFLAGS=; \
	NOALLSYMSFLAGS=''; \
706
	SHAREDFLAGS='$(CFLAGS) -G'; \
707 708 709 710
	SHAREDCMD='$(CC)'; \
	$(LINK_SO_O)
link_a.reliantunix:
	@ $(CALC_VERSIONS); \
711 712
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
713
	LIBDEPS="$(LIBDEPS)"; \
714 715
	ALLSYMSFLAGS=; \
	NOALLSYMSFLAGS=''; \
716
	SHAREDFLAGS='$(CFLAGS) -G'; \
717 718
	SHAREDCMD='$(CC)'; \
	$(LINK_SO_A_UNPACKED)
719 720
link_app.reliantunix:
	LDCMD=$(CC);\
721
	LDFLAGS="$(CFLAGS)"; \
722
	LIBDEPS="$(LIBDEPS)"; \
723 724
	APPNAME="$(APPNAME)"
	$(LINK_APP)
725 726

# Targets to build symbolic links when needed
R
Richard Levitte 已提交
727
symlink.gnu symlink.solaris symlink.svr3 symlink.svr5 symlink.irix \
728 729
symlink.aix symlink.reliantunix:
	@ $(CALC_VERSIONS); \
730
	SHLIB=lib$(LIBNAME).so; \
731
	$(SYMLINK_SO)
732 733
symlink.darwin:
	@ $(CALC_VERSIONS); \
734
	SHLIB=lib$(LIBNAME); \
735
	SHLIB_SUFFIX=.dylib; \
736
	$(SYMLINK_SO)
737
symlink.hpux:
738
	@ $(CALC_VERSIONS); \
739
	SHLIB=lib$(LIBNAME).sl; \
740
	expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
741
	$(SYMLINK_SO)
742 743
# The following lines means those specific architectures do no symlinks
symlink.cygwin symlib.alpha-osf1 symlink.tru64 symlink.tru64-rpath:
744 745 746 747

# Compatibility targets
link_o.bsd-gcc-shared link_o.linux-shared link_o.gnu-shared: link_o.gnu
link_a.bsd-gcc-shared link_a.linux-shared link_a.gnu-shared: link_a.gnu
748
link_app.bsd-gcc-shared link_app.linux-shared link_app.gnu-shared: link_app.gnu
749 750 751 752
symlink.bsd-gcc-shared symlink.bsd-shared symlink.linux-shared symlink.gnu-shared: symlink.gnu
link_o.bsd-shared: link_o.bsd
link_a.bsd-shared: link_a.bsd
link_app.bsd-shared: link_app.bsd
753 754
link_o.darwin-shared: link_o.darwin
link_a.darwin-shared: link_a.darwin
755
link_app.darwin-shared: link_app.darwin
756 757 758
symlink.darwin-shared: symlink.darwin
link_o.cygwin-shared: link_o.cygwin
link_a.cygwin-shared: link_a.cygwin
759
link_app.cygwin-shared: link_app.cygwin
760 761 762
symlink.cygwin-shared: symlink.cygwin
link_o.alpha-osf1-shared: link_o.alpha-osf1
link_a.alpha-osf1-shared: link_a.alpha-osf1
763
link_app.alpha-osf1-shared: link_app.alpha-osf1
764 765 766
symlink.alpha-osf1-shared: symlink.alpha-osf1
link_o.tru64-shared: link_o.tru64
link_a.tru64-shared: link_a.tru64
767
link_app.tru64-shared: link_app.tru64
768 769 770
symlink.tru64-shared: symlink.tru64
link_o.tru64-shared-rpath: link_o.tru64-rpath
link_a.tru64-shared-rpath: link_a.tru64-rpath
771
link_app.tru64-shared-rpath: link_app.tru64-rpath
772 773 774
symlink.tru64-shared-rpath: symlink.tru64-rpath
link_o.solaris-shared: link_o.solaris
link_a.solaris-shared: link_a.solaris
775
link_app.solaris-shared: link_app.solaris
776 777 778
symlink.solaris-shared: symlink.solaris
link_o.svr3-shared: link_o.svr3
link_a.svr3-shared: link_a.svr3
779
link_app.svr3-shared: link_app.svr3
780
symlink.svr3-shared: symlink.svr3
R
Richard Levitte 已提交
781 782 783 784
link_o.svr5-shared: link_o.svr5
link_a.svr5-shared: link_a.svr5
link_app.svr5-shared: link_app.svr5
symlink.svr5-shared: symlink.svr5
785 786
link_o.irix-shared: link_o.irix
link_a.irix-shared: link_a.irix
787
link_app.irix-shared: link_app.irix
788
symlink.irix-shared: symlink.irix
789 790 791 792
link_o.hpux-shared: link_o.hpux
link_a.hpux-shared: link_a.hpux
link_app.hpux-shared: link_app.hpux
symlink.hpux-shared: symlink.hpux
793 794
link_o.aix-shared: link_o.aix
link_a.aix-shared: link_a.aix
795
link_app.aix-shared: link_app.aix
796 797 798
symlink.aix-shared: symlink.aix
link_o.reliantunix-shared: link_o.reliantunix
link_a.reliantunix-shared: link_a.reliantunix
799
link_app.reliantunix-shared: link_app.reliantunix
800
symlink.reliantunix-shared: symlink.reliantunix