Makefile.shared 22.2 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 69 70 71 72 73 74 75 76
# 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.

#DEBUG=:
DEBUG=set -x

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 90
LINK_APP=	\
  ( $(DEBUG);   \
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 95
    $$LDCMD $(LDFLAGS) $$LDFLAGS -o $$APPNAME $(OBJECTS) $$LIBDEPS )

96
LINK_SO=	\
97
  ( $(DEBUG);   \
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 $(SHARED_LDFLAGS) $$SHAREDFLAGS -o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \
103 104 105
	$$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS ) && \
  $(SYMLINK_SO); ( $(DEBUG); rm -f lib$(LIBNAME).exp )
SYMLINK_SO=	\
106 107 108 109 110 111 112 113 114 115 116 117 118
	if [ -n "$$INHIBIT_SYMLINKS" ]; then :; else \
		prev=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
		if [ -n "$$SHLIB_COMPAT" ]; then \
			for x in $$SHLIB_COMPAT; do \
				( $(DEBUG); rm -f $$SHLIB$$x$$SHLIB_SUFFIX; \
				  ln -s $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \
				prev=$$SHLIB$$x$$SHLIB_SUFFIX; \
			done; \
		fi; \
		if [ -n "$$SHLIB_SOVER" ]; then \
			( $(DEBUG); rm -f $$SHLIB$$SHLIB_SUFFIX; \
			  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 127 128 129 130
  ( $(DEBUG); \
    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 141 142 143
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
144
	SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-rpath,$(LIBRPATH)"; \
145
	SHAREDCMD='$(CC)'
146 147 148 149
DO_GNU_APP=LDCMD=$(CC);\
	LDFLAGS="-Wl,-rpath,$(LIBRPATH)"; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	APPNAME=$(APPNAME)
150

151 152 153 154 155 156 157 158 159 160 161 162
#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); \
	LDFLAGS=""; \
	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

# For Darwin AKA Mac OS/X (dyld)
link_o.darwin:
	@ $(CALC_VERSIONS); \
173 174 175 176 177 178
	SHLIB=lib$(LIBNAME); \
	SHLIB_SUFFIX=.dylib; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	ALLSYMSFLAGS='-all_load'; \
	NOALLSYMSFLAGS=''; \
	SHAREDFLAGS="-dynamiclib"; \
179
	SHAREDCMD='$(CC)'; \
180
	if [ -n "$(LIBVERSION)" ]; then \
181
		SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
182 183
	fi; \
	if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
184
		SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
185
	fi; \
186 187 188
	$(LINK_SO_O)
link_a.darwin:
	@ $(CALC_VERSIONS); \
189 190 191 192 193 194
	SHLIB=lib$(LIBNAME); \
	SHLIB_SUFFIX=.dylib; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	ALLSYMSFLAGS='-all_load'; \
	NOALLSYMSFLAGS=''; \
	SHAREDFLAGS="-dynamiclib"; \
195
	SHAREDCMD='$(CC)'; \
196
	if [ -n "$(LIBVERSION)" ]; then \
197
		SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
198 199
	fi; \
	if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
200
		SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
201
	fi; \
202
	$(LINK_SO_A)
203 204 205 206 207 208
link_app.darwin:
	LDCMD=$(CC);\
	LDFLAGS=""; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	APPNAME="$(APPNAME)"; \
	$(LINK_APP)
209 210

link_o.cygwin:
211 212
	@ $(CALC_VERSIONS); \
	INHIBIT_SYMLINKS=yes; \
213
	SHLIB=cyg$(LIBNAME); \
214
	expr $(PLATFORM) : 'mingw' > /dev/null && SHLIB=$(LIBNAME)eay32; \
215
	SHLIB_SUFFIX=.dll; \
216
	LIBDEPS="$(LIBDEPS)"; \
217 218 219
	SHLIB_SOVER=-$(LIBVERSION); \
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
220
	SHAREDFLAGS="-Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
221 222 223
	SHAREDCMD='${CC}'; \
	$(LINK_SO_O)
link_a.cygwin:
224 225
	@ $(CALC_VERSIONS); \
	INHIBIT_SYMLINKS=yes; \
226
	SHLIB=cyg$(LIBNAME); \
227
	expr $(PLATFORM) : 'mingw' > /dev/null && SHLIB=$(LIBNAME)eay32; \
228
	SHLIB_SUFFIX=.dll; \
229
	LIBDEPS="$(LIBDEPS)"; \
230 231 232
	SHLIB_SOVER=; \
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
233
	SHAREDFLAGS="-Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
234 235
	SHAREDCMD='${CC}'; \
	$(LINK_SO_A)
236 237 238
link_app.cygwin:
	LDCMD=$(CC);\
	LDFLAGS=""; \
239 240
	LIBDEPS="$(LIBDEPS)"; \
	APPNAME="$(APPNAME)"; \
241
	$(LINK_APP)
242 243 244

link_o.alpha-osf1:
	@ if ${DETECT_GNU_LD}; then \
245
		$(DO_GNU_SO); \
246
	else \
247 248 249
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
250 251 252 253 254
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
255
		fi; \
256 257 258 259
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
		SHAREDFLAGS="-shared"; \
260
		SHAREDCMD='$(CC)'; \
261
		if [ -n "$$SHLIB_HIST" ]; then \
262
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
263
		fi; \
264 265
	fi; \
	$(LINK_SO_O)
266 267
link_a.alpha-osf1:
	@ if ${DETECT_GNU_LD}; then \
268
		$(DO_GNU_SO); \
269
	else \
270 271 272
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
273 274 275 276 277
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
278
		fi; \
279 280 281 282
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
		SHAREDFLAGS="-shared"; \
283
		SHAREDCMD='$(CC)'; \
284
		if [ -n "$$SHLIB_HIST" ]; then \
285
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
286
		fi; \
287 288
	fi; \
	$(LINK_SO_A)
289 290 291 292 293 294 295 296 297 298
link_app.alpha-osf1:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
		LDFLAGS=""; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		APPNAME="$(APPNAME)"
	fi; \
	$(LINK_APP)
299 300 301 302 303

# 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 \
304
		$(DO_GNU_SO); \
305
	else \
306 307 308
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
309 310 311 312 313
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
314
		fi; \
315 316 317
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
318
		SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)"; \
319
		SHAREDCMD='$(CC)'; \
320
		if [ -n "$$SHLIB_HIST" ]; then \
321
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
322
		fi; \
323 324
	fi; \
	$(LINK_SO_O)
325 326
link_a.tru64:
	@ if ${DETECT_GNU_LD}; then \
327
		$(DO_GNU_SO); \
328
	else \
329 330 331
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
332 333 334 335 336
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
337
		fi; \
338 339 340
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
341
		SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)"; \
342
		SHAREDCMD='$(CC)'; \
343
		if [ -n "$$SHLIB_HIST" ]; then \
344
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
345
		fi; \
346 347
	fi; \
	$(LINK_SO_A)
348 349 350 351 352 353 354 355 356 357
link_app.tru64:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
		LDFLAGS="-rpath $(LIBRPATH)"; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
358 359 360 361 362

# 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 \
363
		$(DO_GNU_SO); \
364
	else \
365 366 367
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
368 369 370 371 372
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
373
		fi; \
374 375 376 377
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
		SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)"; \
378
		SHAREDCMD='$(CC)'; \
379
		if [ -n "$$SHLIB_HIST" ]; then \
380
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
381
		fi; \
382 383
	fi; \
	$(LINK_SO_O)
384 385
link_a.tru64-rpath:
	@ if ${DETECT_GNU_LD}; then \
386
		$(DO_GNU_SO); \
387
	else \
388 389 390
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
391 392 393 394 395
		SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
		if [ -n "$$SHLIB_HIST" ]; then \
			SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
		else \
			SHLIB_HIST="$(LIBVERSION)"; \
396
		fi; \
397 398 399 400
		SHLIB_SOVER=; \
		ALLSYMSFLAGS='-all'; \
		NOALLSYMSFLAGS='-none'; \
		SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)"; \
401
		SHAREDCMD='$(CC)'; \
402
		if [ -n "$$SHLIB_HIST" ]; then \
403
			SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
404
		fi; \
405 406
	fi; \
	$(LINK_SO_A)
407 408 409 410 411 412 413 414 415 416
link_app.tru64-rpath:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
		LDFLAGS="-rpath $(LIBRPATH)"; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
417 418

link_o.solaris:
R
Richard Levitte 已提交
419
	@ if ${DETECT_GNU_LD}; then \
420
		$(DO_GNU_SO); \
421 422
	else \
		$(CALC_VERSIONS); \
423 424
		MINUSZ='-z '; \
		(${CC} -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
425 426 427 428 429
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		ALLSYMSFLAGS="$${MINUSZ}allextract"; \
		NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
430
		SHAREDFLAGS="-G -dy -z text -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -R $(LIBRPATH)"; \
431
		SHAREDCMD='$(CC)'; \
432 433
	fi; \
	$(LINK_SO_O)
434
link_a.solaris:
R
Richard Levitte 已提交
435
	@ if ${DETECT_GNU_LD}; then \
436
		$(DO_GNU_SO); \
437 438
	else \
		$(CALC_VERSIONS); \
439 440
		MINUSZ='-z '; \
		(${CC} -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
441 442 443 444 445
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=;\
		LIBDEPS="$(LIBDEPS) -lc"; \
		ALLSYMSFLAGS="$${MINUSZ}allextract"; \
		NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
446
		SHAREDFLAGS="-G -dy -z text -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -R $(LIBRPATH)"; \
447
		SHAREDCMD='$(CC)'; \
448 449
	fi; \
	$(LINK_SO_A)
450 451 452 453 454 455 456 457 458 459
link_app.solaris:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
		LDFLAGS="-R $(LIBRPATH)"; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
460 461 462

# OpenServer 5 native compilers used
link_o.svr3:
R
Richard Levitte 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_SO); \
	else \
		$(CALC_VERSIONS); \
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		ALLSYMSFLAGS=''; \
		NOALLSYMSFLAGS=''; \
		SHAREDFLAGS="-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
		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=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		ALLSYMSFLAGS=''; \
		NOALLSYMSFLAGS=''; \
		SHAREDFLAGS="-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
		SHAREDCMD='$(CC)'; \
	fi; \
	$(LINK_SO_A_UNPACKED)
link_app.svr3:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
		LDFLAGS=""; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)

# UnixWare 7 and OpenUNIX 8 native compilers used
link_o.svr5:
503
	@ if ${DETECT_GNU_LD}; then \
504
		$(DO_GNU_SO); \
505 506
	else \
		$(CALC_VERSIONS); \
507
		SHARE_FLAG='-G'; \
508
		(${CC} -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
509 510 511
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
512
		ALLSYMSFLAGS=''; \
513
		NOALLSYMSFLAGS=''; \
514
		SHAREDFLAGS="$${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
515
		SHAREDCMD='$(CC)'; \
516 517
	fi; \
	$(LINK_SO_O)
R
Richard Levitte 已提交
518
link_a.svr5:
519
	@ if ${DETECT_GNU_LD}; then \
520
		$(DO_GNU_SO); \
521 522
	else \
		$(CALC_VERSIONS); \
523
		SHARE_FLAG='-G'; \
524
		(${CC} -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
525 526 527
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
528
		ALLSYMSFLAGS=''; \
529
		NOALLSYMSFLAGS=''; \
530
		SHAREDFLAGS="$${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
531
		SHAREDCMD='$(CC)'; \
532 533
	fi; \
	$(LINK_SO_A_UNPACKED)
R
Richard Levitte 已提交
534
link_app.svr5:
535 536 537 538 539 540 541 542 543
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
		LDFLAGS=""; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
544 545 546

link_o.irix:
	@ if ${DETECT_GNU_LD}; then \
547
		$(DO_GNU_SO); \
548 549
	else \
		$(CALC_VERSIONS); \
550 551 552
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
A
Andy Polyakov 已提交
553 554 555 556
		MINUSWL=""; \
		($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
		ALLSYMSFLAGS="$${MINUSWL}-all"; \
		NOALLSYMSFLAGS="$${MINUSWL}-notall"; \
557
		SHAREDFLAGS="-shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-rpath,$(LIBRPATH)"; \
558
		SHAREDCMD='$(CC)'; \
559 560
	fi; \
	$(LINK_SO_O)
561 562
link_a.irix:
	@ if ${DETECT_GNU_LD}; then \
563
		$(DO_GNU_SO); \
564 565
	else \
		$(CALC_VERSIONS); \
566 567 568
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		LIBDEPS="$(LIBDEPS) -lc"; \
A
Andy Polyakov 已提交
569 570 571 572
		MINUSWL=""; \
		($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
		ALLSYMSFLAGS="$${MINUSWL}-all"; \
		NOALLSYMSFLAGS="$${MINUSWL}-notall"; \
573
		SHAREDFLAGS="-shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-rpath,$(LIBRPATH)"; \
574
		SHAREDCMD='$(CC)'; \
575 576
	fi; \
	$(LINK_SO_A)
577 578 579 580 581 582 583 584 585 586
link_app.irix:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
		LDCMD=$(CC);\
		LDFLAGS="-Wl,-rpath,$(LIBRPATH)"; \
		LIBDEPS="$(LIBDEPS) -lc"; \
		APPNAME="$(APPNAME)"; \
	fi; \
	$(LINK_APP)
587

588 589 590 591 592 593 594
# 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].
595
#
596
link_o.hpux:
597 598
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
599
	SHLIB=lib$(LIBNAME).sl; \
600
	expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
601
	SHLIB_SUFFIX=; \
602 603
	LIBDEPS="$(LIBDEPS)"; \
	ALLSYMSFLAGS='-Wl,-Fl'; \
604
	NOALLSYMSFLAGS=''; \
605
	expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
606
	SHAREDFLAGS="-Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+cdp,../:,+cdp,./:,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+b,$(LIBRPATH)"; \
607
	SHAREDCMD=$(CC); \
608
	fi; \
609
	$(LINK_SO_O) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
610
link_a.hpux:
611 612
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
613
	SHLIB=lib$(LIBNAME).sl; \
614
	expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
615
	SHLIB_SUFFIX=; \
616 617
	LIBDEPS="$(LIBDEPS)"; \
	ALLSYMSFLAGS='-Wl,-Fl'; \
618
	NOALLSYMSFLAGS=''; \
619
	expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
620
	SHAREDFLAGS="-Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+cdp,../:,+cdp,./:,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+b,$(LIBRPATH)"; \
621
	SHAREDCMD='$(CC)'; \
622
	fi; \
623
	$(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
624
link_app.hpux:
625
	@if ${DETECT_GNU_LD}; then $(DO_GNU_APP); else \
626
	LDCMD=$(CC);\
627
	LDFLAGS="-Wl,+s,+cdp,../:,+cdp,./:,+b,$(LIBRPATH)"; \
628 629
	LIBDEPS="$(LIBDEPS)"; \
	APPNAME="$(APPNAME)"; \
630
	fi; \
631
	$(LINK_APP)
632 633 634

link_o.aix:
	@ $(CALC_VERSIONS); \
635 636 637 638 639
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	ALLSYMSFLAGS='-bnogc'; \
	NOALLSYMSFLAGS=''; \
640
	SHAREDFLAGS='-G -bE:lib$(LIBNAME).exp -bM:SRE -blibpath:$(LIBRPATH)'; \
641 642 643 644
	SHAREDCMD='$(CC)'; \
	$(LINK_SO_O)
link_a.aix:
	@ $(CALC_VERSIONS); \
645 646 647 648 649
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	ALLSYMSFLAGS='-bnogc'; \
	NOALLSYMSFLAGS=''; \
650
	SHAREDFLAGS='-G -bE:lib$(LIBNAME).exp -bM:SRE -blibpath:$(LIBRPATH)'; \
651 652
	SHAREDCMD='$(CC)'; \
	$(LINK_SO_A_VIA_O)
653 654 655 656 657 658
link_app.aix:
	LDCMD=$(CC);\
	LDFLAGS="-blibpath:$(LIBRPATH)"; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	APPNAME="$(APPNAME)"
	$(LINK_APP)
659 660 661

link_o.reliantunix:
	@ $(CALC_VERSIONS); \
662 663 664 665 666 667
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	ALLSYMSFLAGS=; \
	NOALLSYMSFLAGS=''; \
	SHAREDFLAGS='-G'; \
668 669 670 671
	SHAREDCMD='$(CC)'; \
	$(LINK_SO_O)
link_a.reliantunix:
	@ $(CALC_VERSIONS); \
672 673 674 675 676 677
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	ALLSYMSFLAGS=; \
	NOALLSYMSFLAGS=''; \
	SHAREDFLAGS='-G'; \
678 679
	SHAREDCMD='$(CC)'; \
	$(LINK_SO_A_UNPACKED)
680 681 682 683 684 685
link_app.reliantunix:
	LDCMD=$(CC);\
	LDFLAGS=""; \
	LIBDEPS="$(LIBDEPS) -lc"; \
	APPNAME="$(APPNAME)"
	$(LINK_APP)
686 687

# Targets to build symbolic links when needed
R
Richard Levitte 已提交
688
symlink.gnu symlink.solaris symlink.svr3 symlink.svr5 symlink.irix \
689 690
symlink.aix symlink.reliantunix:
	@ $(CALC_VERSIONS); \
691
	SHLIB=lib$(LIBNAME).so; \
692
	$(SYMLINK_SO)
693 694
symlink.darwin:
	@ $(CALC_VERSIONS); \
695
	SHLIB=lib$(LIBNAME); \
696
	SHLIB_SUFFIX=.dylib; \
697
	$(SYMLINK_SO)
698
symlink.hpux:
699
	@ $(CALC_VERSIONS); \
700
	SHLIB=lib$(LIBNAME).sl; \
701
	expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
702
	$(SYMLINK_SO)
703 704
# The following lines means those specific architectures do no symlinks
symlink.cygwin symlib.alpha-osf1 symlink.tru64 symlink.tru64-rpath:
705 706 707 708

# 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
709
link_app.bsd-gcc-shared link_app.linux-shared link_app.gnu-shared: link_app.gnu
710 711 712
symlink.bsd-gcc-shared symlink.linux-shared symlink.gnu-shared: symlink.gnu
link_o.darwin-shared: link_o.darwin
link_a.darwin-shared: link_a.darwin
713
link_app.darwin-shared: link_app.darwin
714 715 716
symlink.darwin-shared: symlink.darwin
link_o.cygwin-shared: link_o.cygwin
link_a.cygwin-shared: link_a.cygwin
717
link_app.cygwin-shared: link_app.cygwin
718 719 720
symlink.cygwin-shared: symlink.cygwin
link_o.alpha-osf1-shared: link_o.alpha-osf1
link_a.alpha-osf1-shared: link_a.alpha-osf1
721
link_app.alpha-osf1-shared: link_app.alpha-osf1
722 723 724
symlink.alpha-osf1-shared: symlink.alpha-osf1
link_o.tru64-shared: link_o.tru64
link_a.tru64-shared: link_a.tru64
725
link_app.tru64-shared: link_app.tru64
726 727 728
symlink.tru64-shared: symlink.tru64
link_o.tru64-shared-rpath: link_o.tru64-rpath
link_a.tru64-shared-rpath: link_a.tru64-rpath
729
link_app.tru64-shared-rpath: link_app.tru64-rpath
730 731 732
symlink.tru64-shared-rpath: symlink.tru64-rpath
link_o.solaris-shared: link_o.solaris
link_a.solaris-shared: link_a.solaris
733
link_app.solaris-shared: link_app.solaris
734 735 736
symlink.solaris-shared: symlink.solaris
link_o.svr3-shared: link_o.svr3
link_a.svr3-shared: link_a.svr3
737
link_app.svr3-shared: link_app.svr3
738
symlink.svr3-shared: symlink.svr3
R
Richard Levitte 已提交
739 740 741 742
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
743 744
link_o.irix-shared: link_o.irix
link_a.irix-shared: link_a.irix
745
link_app.irix-shared: link_app.irix
746
symlink.irix-shared: symlink.irix
747 748 749 750
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
751 752
link_o.aix-shared: link_o.aix
link_a.aix-shared: link_a.aix
753
link_app.aix-shared: link_app.aix
754 755 756
symlink.aix-shared: symlink.aix
link_o.reliantunix-shared: link_o.reliantunix
link_a.reliantunix-shared: link_a.reliantunix
757
link_app.reliantunix-shared: link_app.reliantunix
758
symlink.reliantunix-shared: symlink.reliantunix