Makefile.shared 20.0 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
CFLAGS=$(CFLAG)
11 12 13
# 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.
14 15 16
LDFLAGS=
SHARED_LDFLAGS=

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

25 26 27 28 29 30 31 32 33 34 35 36
# 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=

37
# LIBEXTRAS contains extra modules to link together with the library.
38
# For example, if a second library, say libbar.a needs to be linked into
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
# 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.

70 71
SET_X=:
#SET_X=set -x
72 73 74 75 76 77

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

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

90
LINK_APP=	\
91
  ( $(SET_X);   \
92 93
    LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \
    LDCMD="$${LDCMD:-$(CC)}"; LDFLAGS="$${LDFLAGS:-$(CFLAGS)}"; \
R
Richard Levitte 已提交
94
    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 已提交
95
    LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
96
    LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
97
    $${LDCMD} $${LDFLAGS} -o $${APPNAME:=$(APPNAME)} $(OBJECTS) $${LIBDEPS} )
98

99
LINK_SO=	\
100
  ( $(SET_X);   \
101 102 103
    LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \
    SHAREDCMD="$${SHAREDCMD:-$(CC)}"; \
    SHAREDFLAGS="$${SHAREDFLAGS:-$(CFLAGS) $(SHARED_LDFLAGS)}"; \
104
    nm -Pg $$SHOBJECTS | grep ' [BDT] ' | cut -f1 -d' ' > lib$(LIBNAME).exp; \
R
Richard Levitte 已提交
105
    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 已提交
106
    LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
107
    LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
108
    $${SHAREDCMD} $${SHAREDFLAGS} \
109 110 111 112 113
	-o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \
	$$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS \
  ) && $(SYMLINK_SO); \
  ( $(SET_X); rm -f lib$(LIBNAME).exp )

114
SYMLINK_SO=	\
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 \
119
				( $(SET_X); rm -f $$SHLIB$$x$$SHLIB_SUFFIX; \
120 121 122 123 124
				  ln -s $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \
				prev=$$SHLIB$$x$$SHLIB_SUFFIX; \
			done; \
		fi; \
		if [ -n "$$SHLIB_SOVER" ]; then \
125
			( $(SET_X); rm -f $$SHLIB$$SHLIB_SUFFIX; \
126 127
			  ln -s $$prev $$SHLIB$$SHLIB_SUFFIX ); \
		fi; \
128
	fi
129

130 131
LINK_SO_A=	SHOBJECTS="lib$(LIBNAME).a $(LIBEXTRAS)"; $(LINK_SO)
LINK_SO_O=	SHOBJECTS="$(LIBEXTRAS)"; $(LINK_SO)
132

133
LINK_SO_A_VIA_O=	\
134 135
  SHOBJECTS=lib$(LIBNAME).o; \
  ALL=$$ALLSYMSFLAGS; ALLSYMSFLAGS=; NOALLSYMSFLAGS=; \
136
  ( $(SET_X); \
137 138
    ld $(LDFLAGS) -r -o lib$(LIBNAME).o $$ALL lib$(LIBNAME).a $(LIBEXTRAS) ); \
  $(LINK_SO) && rm -f $(LIBNAME).o
139

140 141
LINK_SO_A_UNPACKED=	\
  UNPACKDIR=link_tmp.$$$$; rm -rf $$UNPACKDIR; mkdir $$UNPACKDIR; \
142 143
  (cd $$UNPACKDIR; ar x ../lib$(LIBNAME).a) && \
  ([ -z "$(LIBEXTRAS)" ] || cp $(LIBEXTRAS) $$UNPACKDIR) && \
144 145 146
  SHOBJECTS=$$UNPACKDIR/*.o; \
  $(LINK_SO) && rm -rf $$UNPACKDIR

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

149
DO_GNU_SO=$(CALC_VERSIONS); \
150 151 152 153
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
154 155 156
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"

DO_GNU_APP=LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)"
157

158 159 160 161 162 163 164 165
#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.:
	$(LINK_APP)

166
link_o.gnu:
167
	@ $(DO_GNU_SO); $(LINK_SO_O)
168
link_a.gnu:
169 170 171
	@ $(DO_GNU_SO); $(LINK_SO_A)
link_app.gnu:
	@ $(DO_GNU_APP); $(LINK_APP)
172

U
Ulf Möller 已提交
173 174 175 176 177 178 179 180 181 182 183
DO_BEOS_SO=	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SUFFIX"

link_o.beos:
	@ $(DO_BEOS_SO); $(LINK_SO_O)
link_a.beos:
	@ $(DO_BEOS_SO); $(LINK_SO_A)

184 185 186 187 188
link_o.bsd:
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
189
	LIBDEPS=" "; \
190 191
	ALLSYMSFLAGS="-Wl,-Bforcearchive"; \
	NOALLSYMSFLAGS=; \
192
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \
193 194 195 196 197 198
	fi; $(LINK_SO_O)
link_a.bsd:
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
199
	LIBDEPS=" "; \
200 201
	ALLSYMSFLAGS="-Wl,-Bforcearchive"; \
	NOALLSYMSFLAGS=; \
202
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \
203 204 205
	fi; $(LINK_SO_A)
link_app.bsd:
	@if ${DETECT_GNU_LD}; then $(DO_GNU_APP); else \
206
	LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBPATH)"; \
207 208
	fi; $(LINK_APP)

209
# For Darwin AKA Mac OS/X (dyld)
210 211 212 213
# link_o.darwin produces .so, because we let it use dso_dlfcn module,
# which has .so extension hard-coded. One can argue that one should
# develop special dso module for MacOS X. At least manual encourages
# to use native NSModule(3) API and refers to dlfcn as termporary hack.
214 215
link_o.darwin:
	@ $(CALC_VERSIONS); \
216
	SHLIB=lib$(LIBNAME); \
217
	SHLIB_SUFFIX=.so; \
218 219
	ALLSYMSFLAGS='-all_load'; \
	NOALLSYMSFLAGS=''; \
220
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS)"; \
221
	if [ -n "$(LIBVERSION)" ]; then \
222
		SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
223 224
	fi; \
	if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
225
		SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
226
	fi; \
227 228 229
	$(LINK_SO_O)
link_a.darwin:
	@ $(CALC_VERSIONS); \
230 231 232 233
	SHLIB=lib$(LIBNAME); \
	SHLIB_SUFFIX=.dylib; \
	ALLSYMSFLAGS='-all_load'; \
	NOALLSYMSFLAGS=''; \
234
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS)"; \
235
	if [ -n "$(LIBVERSION)" ]; then \
236
		SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
237 238
	fi; \
	if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
239
		SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
240
	fi; \
241
	SHAREDFLAGS="$$SHAREDFLAGS -install_name ${INSTALLTOP}/lib/$$SHLIB${SHLIB_EXT}"; \
242
	$(LINK_SO_A)
243
link_app.darwin:	# is there run-path on darwin?
244
	$(LINK_APP)
245 246

link_o.cygwin:
247 248
	@ $(CALC_VERSIONS); \
	INHIBIT_SYMLINKS=yes; \
249
	SHLIB=cyg$(LIBNAME); \
250
	expr $(PLATFORM) : 'mingw' > /dev/null && SHLIB=$(LIBNAME)eay32; \
251
	SHLIB_SUFFIX=.dll; \
252 253
	LIBVERSION="$(LIBVERSION)"; \
	SHLIB_SOVER=${LIBVERSION:+"-$(LIBVERSION)"}; \
254 255
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
256
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
257 258
	$(LINK_SO_O)
link_a.cygwin:
259 260
	@ $(CALC_VERSIONS); \
	INHIBIT_SYMLINKS=yes; \
261
	SHLIB=cyg$(LIBNAME); \
262
	expr $(PLATFORM) : 'mingw' > /dev/null && SHLIB=$(LIBNAME)eay32; \
263
	SHLIB_SUFFIX=.dll; \
264
	SHLIB_SOVER=-$(LIBVERSION); \
265 266
	ALLSYMSFLAGS='-Wl,--whole-archive'; \
	NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
267
	base=;  [ $(LIBNAME) = "crypto" ] && base=-Wl,--image-base,0x63000000; \
268
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
A
Andy Polyakov 已提交
269 270 271
	[ -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; \
272 273
	cp -p $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX apps/; \
	cp -p $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX test/
274 275
link_app.cygwin:
	$(LINK_APP)
276 277 278

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

link_o.solaris:
R
Richard Levitte 已提交
328
	@ if ${DETECT_GNU_LD}; then \
329
		$(DO_GNU_SO); \
330 331
	else \
		$(CALC_VERSIONS); \
332
		MINUSZ='-z '; \
333
		($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
334 335 336 337
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		ALLSYMSFLAGS="$${MINUSZ}allextract"; \
		NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
338
		SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-Bsymbolic"; \
339 340
	fi; \
	$(LINK_SO_O)
341
link_a.solaris:
R
Richard Levitte 已提交
342
	@ if ${DETECT_GNU_LD}; then \
343
		$(DO_GNU_SO); \
344 345
	else \
		$(CALC_VERSIONS); \
346 347
		MINUSZ='-z '; \
		(${CC} -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
348 349 350 351
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=;\
		ALLSYMSFLAGS="$${MINUSZ}allextract"; \
		NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
352
		SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-Bsymbolic"; \
353 354
	fi; \
	$(LINK_SO_A)
355 356 357 358
link_app.solaris:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_APP); \
	else \
359
		LDFLAGS="$(CFLAGS) -R $(LIBRPATH)"; \
360 361
	fi; \
	$(LINK_APP)
362 363 364

# OpenServer 5 native compilers used
link_o.svr3:
R
Richard Levitte 已提交
365 366 367 368 369 370 371 372
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_SO); \
	else \
		$(CALC_VERSIONS); \
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		ALLSYMSFLAGS=''; \
		NOALLSYMSFLAGS=''; \
373
		SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
R
Richard Levitte 已提交
374 375 376 377 378 379 380 381 382 383 384
	fi; \
	$(LINK_SO_O)
link_a.svr3:
	@ if ${DETECT_GNU_LD}; then \
		$(DO_GNU_SO); \
	else \
		$(CALC_VERSIONS); \
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
		ALLSYMSFLAGS=''; \
		NOALLSYMSFLAGS=''; \
385
		SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
R
Richard Levitte 已提交
386 387 388
	fi; \
	$(LINK_SO_A_UNPACKED)
link_app.svr3:
389
	@${DETECT_GNU_LD} && $(DO_GNU_APP); \
R
Richard Levitte 已提交
390 391 392 393
	$(LINK_APP)

# UnixWare 7 and OpenUNIX 8 native compilers used
link_o.svr5:
394
	@ if ${DETECT_GNU_LD}; then \
395
		$(DO_GNU_SO); \
396 397
	else \
		$(CALC_VERSIONS); \
398
		SHARE_FLAG='-G'; \
399
		($(CC) -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
400 401
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
402
		ALLSYMSFLAGS=''; \
403
		NOALLSYMSFLAGS=''; \
404
		SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
405 406
	fi; \
	$(LINK_SO_O)
R
Richard Levitte 已提交
407
link_a.svr5:
408
	@ if ${DETECT_GNU_LD}; then \
409
		$(DO_GNU_SO); \
410 411
	else \
		$(CALC_VERSIONS); \
412
		SHARE_FLAG='-G'; \
413
		(${CC} -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
414 415
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
416
		ALLSYMSFLAGS=''; \
417
		NOALLSYMSFLAGS=''; \
418
		SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
419 420
	fi; \
	$(LINK_SO_A_UNPACKED)
R
Richard Levitte 已提交
421
link_app.svr5:
422
	@${DETECT_GNU_LD} && $(DO_GNU_APP); \
423
	$(LINK_APP)
424 425 426

link_o.irix:
	@ if ${DETECT_GNU_LD}; then \
427
		$(DO_GNU_SO); \
428 429
	else \
		$(CALC_VERSIONS); \
430 431
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
A
Andy Polyakov 已提交
432 433 434
		MINUSWL=""; \
		($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
		ALLSYMSFLAGS="$${MINUSWL}-all"; \
435
		NOALLSYMSFLAGS="$${MINUSWL}-none"; \
436
		SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
437 438
	fi; \
	$(LINK_SO_O)
439 440
link_a.irix:
	@ if ${DETECT_GNU_LD}; then \
441
		$(DO_GNU_SO); \
442 443
	else \
		$(CALC_VERSIONS); \
444 445
		SHLIB=lib$(LIBNAME).so; \
		SHLIB_SUFFIX=; \
A
Andy Polyakov 已提交
446 447 448
		MINUSWL=""; \
		($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
		ALLSYMSFLAGS="$${MINUSWL}-all"; \
449
		NOALLSYMSFLAGS="$${MINUSWL}-none"; \
450
		SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
451 452
	fi; \
	$(LINK_SO_A)
453
link_app.irix:
454
	@LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)"; \
455
	$(LINK_APP)
456

457 458 459 460 461 462 463
# 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].
464
#
465
link_o.hpux:
466 467
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
468
	SHLIB=lib$(LIBNAME).sl; \
469
	expr "$(CFLAGS)" : 'DSO_DLFCN' > /dev/null && SHLIB=lib$(LIBNAME).so; \
470
	SHLIB_SUFFIX=; \
471
	ALLSYMSFLAGS='-Wl,-Fl'; \
472
	NOALLSYMSFLAGS=''; \
473
	expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
474
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
475
	fi; \
476
	rm -f $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX || :; \
477
	$(LINK_SO_O) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
478
link_a.hpux:
479 480
	@if ${DETECT_GNU_LD}; then $(DO_GNU_SO); else \
	$(CALC_VERSIONS); \
481
	SHLIB=lib$(LIBNAME).sl; \
482
	expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
483
	SHLIB_SUFFIX=; \
484
	ALLSYMSFLAGS='-Wl,-Fl'; \
485
	NOALLSYMSFLAGS=''; \
486
	expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
487
	SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
488
	fi; \
489
	rm -f $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX || :; \
490
	$(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
491
link_app.hpux:
492
	@if ${DETECT_GNU_LD}; then $(DO_GNU_APP); else \
493
	LDFLAGS="$(CFLAGS) -Wl,+s,+cdp,../:,+cdp,./:,+b,$(LIBRPATH)"; \
494
	fi; \
495
	$(LINK_APP)
496 497 498

link_o.aix:
	@ $(CALC_VERSIONS); \
499 500
	OBJECT_MODE=`expr x$(SHARED_LDFLAGS) : 'x\-[a-z]\([0-9]*\)'`; \
	OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \
501 502 503 504
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	ALLSYMSFLAGS='-bnogc'; \
	NOALLSYMSFLAGS=''; \
505
	SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -G -bE:lib$(LIBNAME).exp -bM:SRE'; \
506
	$(LINK_SO_O); rm -rf lib$(LIBNAME).exp
507 508
link_a.aix:
	@ $(CALC_VERSIONS); \
509 510
	OBJECT_MODE=`expr x$(SHARED_LDFLAGS) : 'x\-[a-z]\([0-9]*\)'`; \
	OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \
511 512 513 514
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	ALLSYMSFLAGS='-bnogc'; \
	NOALLSYMSFLAGS=''; \
515
	SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -G -bE:lib$(LIBNAME).exp -bM:SRE'; \
516
	$(LINK_SO_A_VIA_O)
517
link_app.aix:
518
	LDFLAGS="$(CFLAGS) -blibpath:$(LIBRPATH):$${LIBPATH:-/usr/lib:/lib}"; \
519
	$(LINK_APP)
520 521 522

link_o.reliantunix:
	@ $(CALC_VERSIONS); \
523 524 525 526
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	ALLSYMSFLAGS=; \
	NOALLSYMSFLAGS=''; \
527
	SHAREDFLAGS='$(CFLAGS) -G'; \
528 529 530
	$(LINK_SO_O)
link_a.reliantunix:
	@ $(CALC_VERSIONS); \
531 532 533 534
	SHLIB=lib$(LIBNAME).so; \
	SHLIB_SUFFIX=; \
	ALLSYMSFLAGS=; \
	NOALLSYMSFLAGS=''; \
535
	SHAREDFLAGS='$(CFLAGS) -G'; \
536
	$(LINK_SO_A_UNPACKED)
537 538
link_app.reliantunix:
	$(LINK_APP)
539 540

# Targets to build symbolic links when needed
R
Richard Levitte 已提交
541
symlink.gnu symlink.solaris symlink.svr3 symlink.svr5 symlink.irix \
542 543
symlink.aix symlink.reliantunix:
	@ $(CALC_VERSIONS); \
544
	SHLIB=lib$(LIBNAME).so; \
545
	$(SYMLINK_SO)
546 547
symlink.darwin:
	@ $(CALC_VERSIONS); \
548
	SHLIB=lib$(LIBNAME); \
549
	SHLIB_SUFFIX=.dylib; \
550
	$(SYMLINK_SO)
551
symlink.hpux:
552
	@ $(CALC_VERSIONS); \
553
	SHLIB=lib$(LIBNAME).sl; \
554
	expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
555
	$(SYMLINK_SO)
556
# The following lines means those specific architectures do no symlinks
U
Ulf Möller 已提交
557
symlink.cygwin symlink.alpha-osf1 symlink.tru64 symlink.tru64-rpath symlink.beos:
558 559 560 561

# 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
562
link_app.bsd-gcc-shared link_app.linux-shared link_app.gnu-shared: link_app.gnu
563 564 565 566
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
567 568
link_o.darwin-shared: link_o.darwin
link_a.darwin-shared: link_a.darwin
569
link_app.darwin-shared: link_app.darwin
570 571 572
symlink.darwin-shared: symlink.darwin
link_o.cygwin-shared: link_o.cygwin
link_a.cygwin-shared: link_a.cygwin
573
link_app.cygwin-shared: link_app.cygwin
574 575 576
symlink.cygwin-shared: symlink.cygwin
link_o.alpha-osf1-shared: link_o.alpha-osf1
link_a.alpha-osf1-shared: link_a.alpha-osf1
577
link_app.alpha-osf1-shared: link_app.alpha-osf1
578 579 580
symlink.alpha-osf1-shared: symlink.alpha-osf1
link_o.tru64-shared: link_o.tru64
link_a.tru64-shared: link_a.tru64
581
link_app.tru64-shared: link_app.tru64
582 583 584
symlink.tru64-shared: symlink.tru64
link_o.tru64-shared-rpath: link_o.tru64-rpath
link_a.tru64-shared-rpath: link_a.tru64-rpath
585
link_app.tru64-shared-rpath: link_app.tru64-rpath
586 587 588
symlink.tru64-shared-rpath: symlink.tru64-rpath
link_o.solaris-shared: link_o.solaris
link_a.solaris-shared: link_a.solaris
589
link_app.solaris-shared: link_app.solaris
590 591 592
symlink.solaris-shared: symlink.solaris
link_o.svr3-shared: link_o.svr3
link_a.svr3-shared: link_a.svr3
593
link_app.svr3-shared: link_app.svr3
594
symlink.svr3-shared: symlink.svr3
R
Richard Levitte 已提交
595 596 597 598
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
599 600
link_o.irix-shared: link_o.irix
link_a.irix-shared: link_a.irix
601
link_app.irix-shared: link_app.irix
602
symlink.irix-shared: symlink.irix
603 604 605 606
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
607 608
link_o.aix-shared: link_o.aix
link_a.aix-shared: link_a.aix
609
link_app.aix-shared: link_app.aix
610 611 612
symlink.aix-shared: symlink.aix
link_o.reliantunix-shared: link_o.reliantunix
link_a.reliantunix-shared: link_a.reliantunix
613
link_app.reliantunix-shared: link_app.reliantunix
614
symlink.reliantunix-shared: symlink.reliantunix
U
Ulf Möller 已提交
615 616 617 618
link_o.beos-shared: link_o.beos
link_a.beos-shared: link_a.beos
link_app.beos-shared: link_app.gnu
symlink.beos-shared: symlink.beos