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