Makefile.shared: update link_o.dawrin rule.
[openssl.git] / Makefile.shared
1 #
2 # Helper makefile to link shared libraries in a portable way.
3 # This is much simpler than libtool, and hopefully not too error-prone.
4 #
5 # The following variables need to be set on the command line to build
6 # properly
7
8 # CC contains the current compiler.  This one MUST be defined
9 CC=cc
10 CFLAGS=$(CFLAG)
11 # LDFLAGS contains flags to be used when temporary object files (when building
12 # shared libraries) are created, or when an application is linked.
13 # SHARED_LDFLAGS contains flags to be used when the shared library is created.
14 LDFLAGS=
15 SHARED_LDFLAGS=
16
17 NM=nm
18
19 # LIBNAME contains just the name of the library, without prefix ("lib"
20 # on Unix, "cyg" for certain forms under Cygwin...) or suffix (.a, .so,
21 # .dll, ...).  This one MUST have a value when using this makefile to
22 # build shared libraries.
23 # For example, to build libfoo.so, you need to do the following:
24 #LIBNAME=foo
25 LIBNAME=
26
27 # APPNAME contains just the name of the application, without suffix (""
28 # on Unix, ".exe" on Windows, ...).  This one MUST have a value when using
29 # this makefile to build applications.
30 # For example, to build foo, you need to do the following:
31 #APPNAME=foo
32 APPNAME=
33
34 # OBJECTS contains all the object files to link together into the application.
35 # This must contain at least one object file.
36 #OBJECTS=foo.o
37 OBJECTS=
38
39 # LIBEXTRAS contains extra modules to link together with the library.
40 # For example, if a second library, say libbar.a needs to be linked into
41 # libfoo.so, you need to do the following:
42 #LIBEXTRAS=libbar.a
43 # Note that this MUST be used when using the link_o targets, to hold the
44 # names of all object files that go into the target library.
45 LIBEXTRAS=
46
47 # LIBVERSION contains the current version of the library.
48 # For example, to build libfoo.so.1.2, you need to do the following:
49 #LIBVERSION=1.2
50 LIBVERSION=
51
52 # LIBCOMPATVERSIONS contains the compatibility versions (a list) of
53 # the library.  They MUST be in decreasing order.
54 # For example, if libfoo.so.1.2.1 is backward compatible with libfoo.so.1.2
55 # and libfoo.so.1, you need to do the following:
56 #LIBCOMPATVERSIONS=1.2 1
57 # Note that on systems that use sonames, the last number will appear as
58 # part of it.
59 # It's also possible, for systems that support it (Tru64, for example),
60 # to add extra compatibility info with more precision, by adding a second
61 # list of versions, separated from the first with a semicolon, like this:
62 #LIBCOMPATVERSIONS=1.2 1;1.2.0 1.1.2 1.1.1 1.1.0 1.0.0
63 LIBCOMPATVERSIONS=
64
65 # LIBDEPS contains all the flags necessary to cover all necessary
66 # dependencies to other libraries.
67 LIBDEPS=
68
69 #------------------------------------------------------------------------------
70 # The rest is private to this makefile.
71
72 SET_X=:
73 SET_X=set -x
74
75 top:
76         echo "Trying to use this makefile interactively?  Don't."
77
78 CALC_VERSIONS=  \
79         SHLIB_COMPAT=; SHLIB_SOVER=; \
80         if [ -n "$(LIBVERSION)$(LIBCOMPATVERSIONS)" ]; then \
81                 prev=""; \
82                 for v in `echo "$(LIBVERSION) $(LIBCOMPATVERSIONS)" | cut -d';' -f1`; do \
83                         SHLIB_SOVER_NODOT=$$v; \
84                         SHLIB_SOVER=.$$v; \
85                         if [ -n "$$prev" ]; then \
86                                 SHLIB_COMPAT="$$SHLIB_COMPAT .$$prev"; \
87                         fi; \
88                         prev=$$v; \
89                 done; \
90         fi
91
92 LINK_APP=       \
93   ( $(SET_X);   \
94     LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \
95     LDCMD="$${LDCMD:-$(CC)}"; LDFLAGS="$${LDFLAGS:-$(CFLAGS)}"; \
96     LIBPATH=`for x in $$LIBDEPS; do echo $$x; done | sed -e 's/^ *-L//;t' -e d | uniq`; \
97     LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
98     LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
99     $${LDCMD} $${LDFLAGS} -o $${APPNAME:=$(APPNAME)} $(OBJECTS) $${LIBDEPS} )
100
101 LINK_SO=        \
102   ( $(SET_X);   \
103     LIBDEPS="$${LIBDEPS:-$(LIBDEPS)}"; \
104     SHAREDCMD="$${SHAREDCMD:-$(CC)}"; \
105     SHAREDFLAGS="$${SHAREDFLAGS:-$(CFLAGS) $(SHARED_LDFLAGS)}"; \
106     LIBPATH=`for x in $$LIBDEPS; do echo $$x; done | sed -e 's/^ *-L//;t' -e d | uniq`; \
107     LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
108     LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
109     $${SHAREDCMD} $${SHAREDFLAGS} \
110         -o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \
111         $$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS \
112   ) && $(SYMLINK_SO)
113
114 SYMLINK_SO=     \
115         if [ -n "$$INHIBIT_SYMLINKS" ]; then :; else \
116                 prev=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
117                 if [ -n "$$SHLIB_COMPAT" ]; then \
118                         for x in $$SHLIB_COMPAT; do \
119                                 ( $(SET_X); rm -f $$SHLIB$$x$$SHLIB_SUFFIX; \
120                                   ln -s $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \
121                                 prev=$$SHLIB$$x$$SHLIB_SUFFIX; \
122                         done; \
123                 fi; \
124                 if [ -n "$$SHLIB_SOVER" ]; then \
125                         ( $(SET_X); rm -f $$SHLIB$$SHLIB_SUFFIX; \
126                           ln -s $$prev $$SHLIB$$SHLIB_SUFFIX ); \
127                 fi; \
128         fi
129
130 LINK_SO_A=      SHOBJECTS="lib$(LIBNAME).a $(LIBEXTRAS)"; $(LINK_SO)
131 LINK_SO_O=      SHOBJECTS="$(LIBEXTRAS)"; $(LINK_SO)
132
133 LINK_SO_A_VIA_O=        \
134   SHOBJECTS=lib$(LIBNAME).o; \
135   ALL=$$ALLSYMSFLAGS; ALLSYMSFLAGS=; NOALLSYMSFLAGS=; \
136   ( $(SET_X); \
137     ld $(LDFLAGS) -r -o lib$(LIBNAME).o $$ALL lib$(LIBNAME).a $(LIBEXTRAS) ); \
138   $(LINK_SO) && rm -f lib$(LIBNAME).o
139
140 LINK_SO_A_UNPACKED=     \
141   UNPACKDIR=link_tmp.$$$$; rm -rf $$UNPACKDIR; mkdir $$UNPACKDIR; \
142   (cd $$UNPACKDIR; ar x ../lib$(LIBNAME).a) && \
143   ([ -z "$(LIBEXTRAS)" ] || cp $(LIBEXTRAS) $$UNPACKDIR) && \
144   SHOBJECTS=$$UNPACKDIR/*.o; \
145   $(LINK_SO) && rm -rf $$UNPACKDIR
146
147 DETECT_GNU_LD=($(CC) -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/null
148
149 DO_GNU_SO=$(CALC_VERSIONS); \
150         SHLIB=lib$(LIBNAME).so; \
151         SHLIB_SUFFIX=; \
152         ALLSYMSFLAGS='-Wl,--whole-archive'; \
153         NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
154         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"
155
156 DO_GNU_APP=LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)"
157
158 #This is rather special.  It's a special target with which one can link
159 #applications without bothering with any features that have anything to
160 #do with shared libraries, for example when linking against static
161 #libraries.  It's mostly here to avoid a lot of conditionals everywhere
162 #else...
163 link_app.:
164         $(LINK_APP)
165
166 link_o.gnu:
167         @ $(DO_GNU_SO); $(LINK_SO_O)
168 link_a.gnu:
169         @ $(DO_GNU_SO); $(LINK_SO_A)
170 link_app.gnu:
171         @ $(DO_GNU_APP); $(LINK_APP)
172
173 DO_BEOS_SO=     SHLIB=lib$(LIBNAME).so; \
174         SHLIB_SUFFIX=; \
175         ALLSYMSFLAGS='-Wl,--whole-archive'; \
176         NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
177         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SUFFIX"
178
179 link_o.beos:
180         @ $(DO_BEOS_SO); $(LINK_SO_O)
181 link_a.beos:
182         @ $(DO_BEOS_SO); $(LINK_SO_A)
183
184 link_o.bsd:
185         @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
186         $(CALC_VERSIONS); \
187         SHLIB=lib$(LIBNAME).so; \
188         SHLIB_SUFFIX=; \
189         LIBDEPS=" "; \
190         ALLSYMSFLAGS="-Wl,-Bforcearchive"; \
191         NOALLSYMSFLAGS=; \
192         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \
193         fi; $(LINK_SO_O)
194 link_a.bsd:
195         @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
196         $(CALC_VERSIONS); \
197         SHLIB=lib$(LIBNAME).so; \
198         SHLIB_SUFFIX=; \
199         LIBDEPS=" "; \
200         ALLSYMSFLAGS="-Wl,-Bforcearchive"; \
201         NOALLSYMSFLAGS=; \
202         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \
203         fi; $(LINK_SO_A)
204 link_app.bsd:
205         @if $(DETECT_GNU_LD); then $(DO_GNU_APP); else \
206         LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBPATH)"; \
207         fi; $(LINK_APP)
208
209 # For Darwin AKA Mac OS/X (dyld)
210 # Originally link_o.darwin produced .so, because it was hard-coded
211 # in dso_dlfcn module. At later point dso_dlfcn switched to .dylib
212 # extension in order to allow for run-time linking with vendor-
213 # supplied shared libraries such as libz, so that link_o.darwin had
214 # to be harmonized with it. This caused minor controversy, because
215 # it was believed that dlopen can't be used to dynamically load
216 # .dylib-s, only so called bundle modules (ones linked with -bundle
217 # flag). The belief seems to be originating from pre-10.4 release,
218 # where dlfcn functionality was emulated by dlcompat add-on. In
219 # 10.4 dlopen was rewritten as native part of dyld and is documented
220 # to be capable of loading both dynamic libraries and bundles. In
221 # order to provide compatibility with pre-10.4 dlopen, modules are
222 # linked with -bundle flag, which makes .dylib extension misleading.
223 # It works, because dlopen is [and always was] extension-agnostic.
224 link_o.darwin:
225         @ $(CALC_VERSIONS); \
226         SHLIB=lib$(LIBNAME); \
227         SHLIB_SUFFIX=.dylib; \
228         ALLSYMSFLAGS='-all_load'; \
229         NOALLSYMSFLAGS=''; \
230         SHAREDFLAGS="$(CFLAGS) `echo $(SHARED_LDFLAGS) | sed s/dynamiclib/bundle/"; \
231         if [ -n "$(LIBVERSION)" ]; then \
232                 SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
233         fi; \
234         if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
235                 SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
236         fi; \
237         $(LINK_SO_O)
238 link_a.darwin:
239         @ $(CALC_VERSIONS); \
240         SHLIB=lib$(LIBNAME); \
241         SHLIB_SUFFIX=.dylib; \
242         ALLSYMSFLAGS='-all_load'; \
243         NOALLSYMSFLAGS=''; \
244         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS)"; \
245         if [ -n "$(LIBVERSION)" ]; then \
246                 SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
247         fi; \
248         if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
249                 SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
250         fi; \
251         SHAREDFLAGS="$$SHAREDFLAGS -install_name $(INSTALLTOP)/$(LIBDIR)/$$SHLIB$(SHLIB_EXT)"; \
252         $(LINK_SO_A)
253 link_app.darwin:        # is there run-path on darwin?
254         $(LINK_APP)
255
256 link_o.cygwin:
257         @ $(CALC_VERSIONS); \
258         INHIBIT_SYMLINKS=yes; \
259         SHLIB=cyg$(LIBNAME); \
260         base=-Wl,--enable-auto-image-base; \
261         deffile=; \
262         if expr $(PLATFORM) : 'mingw' > /dev/null; then \
263                 SHLIB=$(LIBNAME)eay32; base=; \
264                 if test -f $(LIBNAME)eay32.def; then \
265                         deffile=$(LIBNAME)eay32.def; \
266                 fi; \
267         fi; \
268         SHLIB_SUFFIX=.dll; \
269         LIBVERSION="$(LIBVERSION)"; \
270         SHLIB_SOVER=${LIBVERSION:+"-$(LIBVERSION)"}; \
271         ALLSYMSFLAGS='-Wl,--whole-archive'; \
272         NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
273         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base $$deffile -Wl,-s,-Bsymbolic"; \
274         $(LINK_SO_O)
275 #for mingw target if def-file is in use dll-name should match library-name
276 link_a.cygwin:
277         @ $(CALC_VERSIONS); \
278         INHIBIT_SYMLINKS=yes; \
279         SHLIB=cyg$(LIBNAME); SHLIB_SOVER=-$(LIBVERSION); SHLIB_SUFFIX=.dll; \
280         dll_name=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; extras=; \
281         base=-Wl,--enable-auto-image-base; \
282         if expr $(PLATFORM) : 'mingw' > /dev/null; then \
283                 case $(LIBNAME) in \
284                         crypto) SHLIB=libeay;; \
285                         ssl) SHLIB=ssleay;; \
286                 esac; \
287                 SHLIB_SOVER=32; \
288                 extras="$(LIBNAME).def"; \
289                 $(PERL) util/mkdef.pl 32 $$SHLIB > $$extras; \
290                 base=; [ $(LIBNAME) = "crypto" ] && base=-Wl,--image-base,0x63000000; \
291         fi; \
292         dll_name=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
293         $(PERL) util/mkrc.pl $$dll_name | \
294                 $(CROSS_COMPILE)windres -o rc.o; \
295         extras="$$extras rc.o"; \
296         ALLSYMSFLAGS='-Wl,--whole-archive'; \
297         NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
298         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-s,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a $$extras"; \
299         [ -f apps/$$dll_name ] && rm apps/$$dll_name; \
300         [ -f test/$$dll_name ] && rm test/$$dll_name; \
301         $(LINK_SO_A) || exit 1; \
302         rm $$extras; \
303         cp -p $$dll_name apps/; \
304         cp -p $$dll_name test/
305 link_app.cygwin:
306         @if expr "$(CFLAGS)" : '.*OPENSSL_USE_APPLINK' > /dev/null; then \
307                 LIBDEPS="$(TOP)/crypto/applink.o $${LIBDEPS:-$(LIBDEPS)}"; \
308                 export LIBDEPS; \
309         fi; \
310         $(LINK_APP)
311
312 link_o.alpha-osf1:
313         @ if $(DETECT_GNU_LD); then \
314                 $(DO_GNU_SO); \
315         else \
316                 SHLIB=lib$(LIBNAME).so; \
317                 SHLIB_SUFFIX=; \
318                 SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
319                 if [ -n "$$SHLIB_HIST" ]; then \
320                         SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
321                 else \
322                         SHLIB_HIST="$(LIBVERSION)"; \
323                 fi; \
324                 SHLIB_SOVER=; \
325                 ALLSYMSFLAGS='-all'; \
326                 NOALLSYMSFLAGS='-none'; \
327                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-B,symbolic"; \
328                 if [ -n "$$SHLIB_HIST" ]; then \
329                         SHAREDFLAGS="$$SHAREDFLAGS -set_version $$SHLIB_HIST"; \
330                 fi; \
331         fi; \
332         $(LINK_SO_O)
333 link_a.alpha-osf1:
334         @ if $(DETECT_GNU_LD); then \
335                 $(DO_GNU_SO); \
336         else \
337                 SHLIB=lib$(LIBNAME).so; \
338                 SHLIB_SUFFIX=; \
339                 SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
340                 if [ -n "$$SHLIB_HIST" ]; then \
341                         SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
342                 else \
343                         SHLIB_HIST="$(LIBVERSION)"; \
344                 fi; \
345                 SHLIB_SOVER=; \
346                 ALLSYMSFLAGS='-all'; \
347                 NOALLSYMSFLAGS='-none'; \
348                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-B,symbolic"; \
349                 if [ -n "$$SHLIB_HIST" ]; then \
350                         SHAREDFLAGS="$$SHAREDFLAGS -set_version $$SHLIB_HIST"; \
351                 fi; \
352         fi; \
353         $(LINK_SO_A)
354 link_app.alpha-osf1:
355         @if $(DETECT_GNU_LD); then \
356                 $(DO_GNU_APP); \
357         else \
358                 LDFLAGS="$(CFLAGS) -rpath $(LIBRPATH)"; \
359         fi; \
360         $(LINK_APP)
361
362 link_o.solaris:
363         @ if $(DETECT_GNU_LD); then \
364                 $(DO_GNU_SO); \
365         else \
366                 $(CALC_VERSIONS); \
367                 MINUSZ='-z '; \
368                 ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
369                 SHLIB=lib$(LIBNAME).so; \
370                 SHLIB_SUFFIX=; \
371                 ALLSYMSFLAGS="$${MINUSZ}allextract"; \
372                 NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
373                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-Bsymbolic"; \
374         fi; \
375         $(LINK_SO_O)
376 link_a.solaris:
377         @ if $(DETECT_GNU_LD); then \
378                 $(DO_GNU_SO); \
379         else \
380                 $(CALC_VERSIONS); \
381                 MINUSZ='-z '; \
382                 ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
383                 SHLIB=lib$(LIBNAME).so; \
384                 SHLIB_SUFFIX=;\
385                 ALLSYMSFLAGS="$${MINUSZ}allextract"; \
386                 NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
387                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-Bsymbolic"; \
388         fi; \
389         $(LINK_SO_A)
390 link_app.solaris:
391         @ if $(DETECT_GNU_LD); then \
392                 $(DO_GNU_APP); \
393         else \
394                 LDFLAGS="$(CFLAGS) -R $(LIBRPATH)"; \
395         fi; \
396         $(LINK_APP)
397
398 # OpenServer 5 native compilers used
399 link_o.svr3:
400         @ if $(DETECT_GNU_LD); then \
401                 $(DO_GNU_SO); \
402         else \
403                 $(CALC_VERSIONS); \
404                 SHLIB=lib$(LIBNAME).so; \
405                 SHLIB_SUFFIX=; \
406                 ALLSYMSFLAGS=''; \
407                 NOALLSYMSFLAGS=''; \
408                 SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
409         fi; \
410         $(LINK_SO_O)
411 link_a.svr3:
412         @ if $(DETECT_GNU_LD); then \
413                 $(DO_GNU_SO); \
414         else \
415                 $(CALC_VERSIONS); \
416                 SHLIB=lib$(LIBNAME).so; \
417                 SHLIB_SUFFIX=; \
418                 ALLSYMSFLAGS=''; \
419                 NOALLSYMSFLAGS=''; \
420                 SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
421         fi; \
422         $(LINK_SO_A_UNPACKED)
423 link_app.svr3:
424         @$(DETECT_GNU_LD) && $(DO_GNU_APP); \
425         $(LINK_APP)
426
427 # UnixWare 7 and OpenUNIX 8 native compilers used
428 link_o.svr5:
429         @ if $(DETECT_GNU_LD); then \
430                 $(DO_GNU_SO); \
431         else \
432                 $(CALC_VERSIONS); \
433                 SHARE_FLAG='-G'; \
434                 ($(CC) -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
435                 SHLIB=lib$(LIBNAME).so; \
436                 SHLIB_SUFFIX=; \
437                 ALLSYMSFLAGS=''; \
438                 NOALLSYMSFLAGS=''; \
439                 SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
440         fi; \
441         $(LINK_SO_O)
442 link_a.svr5:
443         @ if $(DETECT_GNU_LD); then \
444                 $(DO_GNU_SO); \
445         else \
446                 $(CALC_VERSIONS); \
447                 SHARE_FLAG='-G'; \
448                 ($(CC) -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
449                 SHLIB=lib$(LIBNAME).so; \
450                 SHLIB_SUFFIX=; \
451                 ALLSYMSFLAGS=''; \
452                 NOALLSYMSFLAGS=''; \
453                 SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
454         fi; \
455         $(LINK_SO_A_UNPACKED)
456 link_app.svr5:
457         @$(DETECT_GNU_LD) && $(DO_GNU_APP); \
458         $(LINK_APP)
459
460 link_o.irix:
461         @ if $(DETECT_GNU_LD); then \
462                 $(DO_GNU_SO); \
463         else \
464                 $(CALC_VERSIONS); \
465                 SHLIB=lib$(LIBNAME).so; \
466                 SHLIB_SUFFIX=; \
467                 MINUSWL=""; \
468                 ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
469                 ALLSYMSFLAGS="$${MINUSWL}-all"; \
470                 NOALLSYMSFLAGS="$${MINUSWL}-none"; \
471                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,-B,symbolic"; \
472         fi; \
473         $(LINK_SO_O)
474 link_a.irix:
475         @ if $(DETECT_GNU_LD); then \
476                 $(DO_GNU_SO); \
477         else \
478                 $(CALC_VERSIONS); \
479                 SHLIB=lib$(LIBNAME).so; \
480                 SHLIB_SUFFIX=; \
481                 MINUSWL=""; \
482                 ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
483                 ALLSYMSFLAGS="$${MINUSWL}-all"; \
484                 NOALLSYMSFLAGS="$${MINUSWL}-none"; \
485                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,-B,symbolic"; \
486         fi; \
487         $(LINK_SO_A)
488 link_app.irix:
489         @LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)"; \
490         $(LINK_APP)
491
492 # 32-bit PA-RISC HP-UX embeds the -L pathname of libs we link with, so
493 # we compensate for it with +cdp ../: and +cdp ./:. Yes, these rewrite
494 # rules imply that we can only link one level down in catalog structure,
495 # but that's what takes place for the moment of this writing. +cdp option
496 # was introduced in HP-UX 11.x and applies in 32-bit PA-RISC link
497 # editor context only [it's simply ignored in other cases, which are all
498 # ELFs by the way].
499 #
500 link_o.hpux:
501         @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
502         $(CALC_VERSIONS); \
503         SHLIB=lib$(LIBNAME).sl; \
504         expr "$(CFLAGS)" : '.*DSO_DLFCN' > /dev/null && SHLIB=lib$(LIBNAME).so; \
505         SHLIB_SUFFIX=; \
506         ALLSYMSFLAGS='-Wl,-Fl'; \
507         NOALLSYMSFLAGS=''; \
508         expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
509         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+cdp,../:,+cdp,./:"; \
510         fi; \
511         rm -f $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX || :; \
512         $(LINK_SO_O) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
513 link_a.hpux:
514         @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
515         $(CALC_VERSIONS); \
516         SHLIB=lib$(LIBNAME).sl; \
517         expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
518         SHLIB_SUFFIX=; \
519         ALLSYMSFLAGS='-Wl,-Fl'; \
520         NOALLSYMSFLAGS=''; \
521         expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
522         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+cdp,../:,+cdp,./:"; \
523         fi; \
524         rm -f $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX || :; \
525         $(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
526 link_app.hpux:
527         @if $(DETECT_GNU_LD); then $(DO_GNU_APP); else \
528         LDFLAGS="$(CFLAGS) -Wl,+s,+cdp,../:,+cdp,./:,+b,$(LIBRPATH)"; \
529         fi; \
530         $(LINK_APP)
531
532 link_o.aix:
533         @ $(CALC_VERSIONS); \
534         OBJECT_MODE=`expr "x$(SHARED_LDFLAGS)" : 'x\-[a-z]*\(64\)'` || :; \
535         OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \
536         SHLIB=lib$(LIBNAME).so; \
537         SHLIB_SUFFIX=; \
538         ALLSYMSFLAGS=''; \
539         NOALLSYMSFLAGS=''; \
540         SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-bexpall,-bnolibpath,-bM:SRE'; \
541         $(LINK_SO_O);
542 link_a.aix:
543         @ $(CALC_VERSIONS); \
544         OBJECT_MODE=`expr "x$(SHARED_LDFLAGS)" : 'x\-[a-z]*\(64\)'` || : ; \
545         OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \
546         SHLIB=lib$(LIBNAME).so; \
547         SHLIB_SUFFIX=; \
548         ALLSYMSFLAGS='-bnogc'; \
549         NOALLSYMSFLAGS=''; \
550         SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-bexpall,-bnolibpath,-bM:SRE'; \
551         $(LINK_SO_A_VIA_O)
552 link_app.aix:
553         LDFLAGS="$(CFLAGS) -Wl,-brtl,-blibpath:$(LIBRPATH):$${LIBPATH:-/usr/lib:/lib}"; \
554         $(LINK_APP)
555
556 link_o.reliantunix:
557         @ $(CALC_VERSIONS); \
558         SHLIB=lib$(LIBNAME).so; \
559         SHLIB_SUFFIX=; \
560         ALLSYMSFLAGS=; \
561         NOALLSYMSFLAGS=''; \
562         SHAREDFLAGS='$(CFLAGS) -G'; \
563         $(LINK_SO_O)
564 link_a.reliantunix:
565         @ $(CALC_VERSIONS); \
566         SHLIB=lib$(LIBNAME).so; \
567         SHLIB_SUFFIX=; \
568         ALLSYMSFLAGS=; \
569         NOALLSYMSFLAGS=''; \
570         SHAREDFLAGS='$(CFLAGS) -G'; \
571         $(LINK_SO_A_UNPACKED)
572 link_app.reliantunix:
573         $(LINK_APP)
574
575 # Targets to build symbolic links when needed
576 symlink.gnu symlink.solaris symlink.svr3 symlink.svr5 symlink.irix \
577 symlink.aix symlink.reliantunix:
578         @ $(CALC_VERSIONS); \
579         SHLIB=lib$(LIBNAME).so; \
580         $(SYMLINK_SO)
581 symlink.darwin:
582         @ $(CALC_VERSIONS); \
583         SHLIB=lib$(LIBNAME); \
584         SHLIB_SUFFIX=.dylib; \
585         $(SYMLINK_SO)
586 symlink.hpux:
587         @ $(CALC_VERSIONS); \
588         SHLIB=lib$(LIBNAME).sl; \
589         expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
590         $(SYMLINK_SO)
591 # The following lines means those specific architectures do no symlinks
592 symlink.cygwin symlink.alpha-osf1 symlink.tru64 symlink.tru64-rpath symlink.beos:
593
594 # Compatibility targets
595 link_o.bsd-gcc-shared link_o.linux-shared link_o.gnu-shared: link_o.gnu
596 link_a.bsd-gcc-shared link_a.linux-shared link_a.gnu-shared: link_a.gnu
597 link_app.bsd-gcc-shared link_app.linux-shared link_app.gnu-shared: link_app.gnu
598 symlink.bsd-gcc-shared symlink.bsd-shared symlink.linux-shared symlink.gnu-shared: symlink.gnu
599 link_o.bsd-shared: link_o.bsd
600 link_a.bsd-shared: link_a.bsd
601 link_app.bsd-shared: link_app.bsd
602 link_o.darwin-shared: link_o.darwin
603 link_a.darwin-shared: link_a.darwin
604 link_app.darwin-shared: link_app.darwin
605 symlink.darwin-shared: symlink.darwin
606 link_o.cygwin-shared: link_o.cygwin
607 link_a.cygwin-shared: link_a.cygwin
608 link_app.cygwin-shared: link_app.cygwin
609 symlink.cygwin-shared: symlink.cygwin
610 link_o.alpha-osf1-shared: link_o.alpha-osf1
611 link_a.alpha-osf1-shared: link_a.alpha-osf1
612 link_app.alpha-osf1-shared: link_app.alpha-osf1
613 symlink.alpha-osf1-shared: symlink.alpha-osf1
614 link_o.tru64-shared: link_o.tru64
615 link_a.tru64-shared: link_a.tru64
616 link_app.tru64-shared: link_app.tru64
617 symlink.tru64-shared: symlink.tru64
618 link_o.tru64-shared-rpath: link_o.tru64-rpath
619 link_a.tru64-shared-rpath: link_a.tru64-rpath
620 link_app.tru64-shared-rpath: link_app.tru64-rpath
621 symlink.tru64-shared-rpath: symlink.tru64-rpath
622 link_o.solaris-shared: link_o.solaris
623 link_a.solaris-shared: link_a.solaris
624 link_app.solaris-shared: link_app.solaris
625 symlink.solaris-shared: symlink.solaris
626 link_o.svr3-shared: link_o.svr3
627 link_a.svr3-shared: link_a.svr3
628 link_app.svr3-shared: link_app.svr3
629 symlink.svr3-shared: symlink.svr3
630 link_o.svr5-shared: link_o.svr5
631 link_a.svr5-shared: link_a.svr5
632 link_app.svr5-shared: link_app.svr5
633 symlink.svr5-shared: symlink.svr5
634 link_o.irix-shared: link_o.irix
635 link_a.irix-shared: link_a.irix
636 link_app.irix-shared: link_app.irix
637 symlink.irix-shared: symlink.irix
638 link_o.hpux-shared: link_o.hpux
639 link_a.hpux-shared: link_a.hpux
640 link_app.hpux-shared: link_app.hpux
641 symlink.hpux-shared: symlink.hpux
642 link_o.aix-shared: link_o.aix
643 link_a.aix-shared: link_a.aix
644 link_app.aix-shared: link_app.aix
645 symlink.aix-shared: symlink.aix
646 link_o.reliantunix-shared: link_o.reliantunix
647 link_a.reliantunix-shared: link_a.reliantunix
648 link_app.reliantunix-shared: link_app.reliantunix
649 symlink.reliantunix-shared: symlink.reliantunix
650 link_o.beos-shared: link_o.beos
651 link_a.beos-shared: link_a.beos
652 link_app.beos-shared: link_app.gnu
653 symlink.beos-shared: symlink.beos