57e1936b9e219f73fec5ef8bf1e7a6be0a49eccf
[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=$(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         @$(PERL) $(SRCDIR)/util/mkdef.pl $(LIBNAME) linux >$(LIBNAME).map; \
191         $(DO_GNU_SO); \
192         ALLSYMSFLAGS='-Wl,--whole-archive,--version-script=$(LIBNAME).map'; \
193         $(LINK_SO_SHLIB)
194
195 link_dso.bsd:
196         @if $(DETECT_GNU_LD); then $(DO_GNU_SO_NOCALC); else \
197         SHLIB=$(LIBNAME).so; \
198         SHLIB_SUFFIX=; \
199         LIBDEPS=" "; \
200         ALLSYMSFLAGS="-Wl,-Bforcearchive"; \
201         NOALLSYMSFLAGS=; \
202         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \
203         fi; $(LINK_SO_DSO)
204 link_shlib.bsd:
205         @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
206         $(CALC_VERSIONS); \
207         SHLIB=lib$(LIBNAME).so; \
208         SHLIB_SUFFIX=; \
209         LIBDEPS=" "; \
210         ALLSYMSFLAGS="-Wl,-Bforcearchive"; \
211         NOALLSYMSFLAGS=; \
212         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -nostdlib"; \
213         fi; $(LINK_SO_SHLIB)
214 link_app.bsd:
215         @if $(DETECT_GNU_LD); then $(DO_GNU_APP); else \
216         LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,-rpath,$(LIBPATH)"; \
217         fi; $(LINK_APP)
218
219 # For Darwin AKA Mac OS/X (dyld)
220 # Originally link_dso.darwin produced .so, because it was hard-coded
221 # in dso_dlfcn module. At later point dso_dlfcn switched to .dylib
222 # extension in order to allow for run-time linking with vendor-
223 # supplied shared libraries such as libz, so that link_dso.darwin had
224 # to be harmonized with it. This caused minor controversy, because
225 # it was believed that dlopen can't be used to dynamically load
226 # .dylib-s, only so called bundle modules (ones linked with -bundle
227 # flag). The belief seems to be originating from pre-10.4 release,
228 # where dlfcn functionality was emulated by dlcompat add-on. In
229 # 10.4 dlopen was rewritten as native part of dyld and is documented
230 # to be capable of loading both dynamic libraries and bundles. In
231 # order to provide compatibility with pre-10.4 dlopen, modules are
232 # linked with -bundle flag, which makes .dylib extension misleading.
233 # It works, because dlopen is [and always was] extension-agnostic.
234 # Alternative to this heuristic approach is to develop specific
235 # MacOS X dso module relying on whichever "native" dyld interface.
236 link_dso.darwin:
237         @ SHLIB=$(LIBNAME); \
238         SHLIB_SUFFIX=.dylib; \
239         ALLSYMSFLAGS='-all_load'; \
240         NOALLSYMSFLAGS=''; \
241         SHAREDFLAGS="$(CFLAGS) `echo $(SHARED_LDFLAGS) | sed s/dynamiclib/bundle/`"; \
242         $(LINK_SO_DSO)
243 link_shlib.darwin:
244         @ $(CALC_VERSIONS); \
245         SHLIB=lib$(LIBNAME); \
246         SHLIB_SUFFIX=.dylib; \
247         ALLSYMSFLAGS='-all_load'; \
248         NOALLSYMSFLAGS=''; \
249         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS)"; \
250         if [ -n "$(LIBVERSION)" ]; then \
251                 SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
252         fi; \
253         if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
254                 SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
255         fi; \
256         SHAREDFLAGS="$$SHAREDFLAGS -install_name $(INSTALLTOP)/$(LIBDIR)/$$SHLIB$(SHLIB_EXT)"; \
257         $(LINK_SO_SHLIB)
258 link_app.darwin:        # is there run-path on darwin?
259         $(LINK_APP)
260
261 link_dso.cygwin:
262         @SHLIB=$(LIBNAME); \
263         SHLIB_SUFFIX=.dll; \
264         ALLSYMSFLAGS='-Wl,--whole-archive'; \
265         NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
266         base=-Wl,--enable-auto-image-base; \
267         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic"; \
268         $(LINK_SO_DSO)
269 link_shlib.cygwin:
270         @ $(CALC_VERSIONS); \
271         INHIBIT_SYMLINKS=yes; \
272         SHLIB=cyg$(LIBNAME); SHLIB_SOVER=-$(LIBVERSION); SHLIB_SUFFIX=.dll; \
273         dll_name=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
274         echo "$(PERL) $(SRCDIR)/util/mkrc.pl $$dll_name |" \
275                      "$(CROSS_COMPILE)windres $(SHARED_RCFLAGS) -o rc.o"; \
276         $(PERL) $(SRCDIR)/util/mkrc.pl $$dll_name | \
277                 $(CROSS_COMPILE)windres $(SHARED_RCFLAGS) -o rc.o; \
278         ALLSYMSFLAGS='-Wl,--whole-archive'; \
279         NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
280         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,--enable-auto-image-base -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a rc.o"; \
281         $(LINK_SO_SHLIB) || exit 1; \
282         rm rc.o
283 link_app.cygwin:
284         $(LINK_APP)
285
286 # link_dso.mingw-shared and link_app.mingw-shared are mapped to the
287 # corresponding cygwin targets, as they do the exact same thing.
288 link_shlib.mingw:
289         @ $(CALC_VERSIONS); \
290         INHIBIT_SYMLINKS=yes; \
291         arch=; \
292         if expr $(PLATFORM) : mingw64 > /dev/null; then arch=-x64; fi; \
293         sover=`echo $(LIBVERSION) | sed -e 's/\./_/g'` ; \
294         SHLIB=lib$(LIBNAME); \
295         SHLIB_SOVER=-$$sover$$arch; \
296         SHLIB_SUFFIX=.dll; \
297         dll_name=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
298         base=; [ $(LIBNAME) = "crypto" ] && base=-Wl,--image-base,0x63000000; \
299         $(PERL) $(SRCDIR)/util/mkdef.pl 32 $(LIBNAME) \
300                 | sed -e 's|^\(LIBRARY  *\)$(LIBNAME)32|\1'"$$dll_name"'|' \
301                 > $(LIBNAME).def; \
302         echo "$(PERL) $(SRCDIR)/util/mkrc.pl $$dll_name |" \
303                 "$(CROSS_COMPILE)windres $(SHARED_RCFLAGS) -o rc.o"; \
304         $(PERL) $(SRCDIR)/util/mkrc.pl $$dll_name | \
305                 $(CROSS_COMPILE)windres $(SHARED_RCFLAGS) -o rc.o; \
306         ALLSYMSFLAGS='-Wl,--whole-archive'; \
307         NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
308         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared $$base -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a $(LIBNAME).def rc.o"; \
309         $(LINK_SO_SHLIB) || exit 1; \
310         rm $(LIBNAME).def rc.o
311
312 link_dso.alpha-osf1:
313         @ if $(DETECT_GNU_LD); then \
314                 $(DO_GNU_SO_NOCALC); \
315         else \
316                 SHLIB=$(LIBNAME).so; \
317                 SHLIB_SUFFIX=; \
318                 ALLSYMSFLAGS='-all'; \
319                 NOALLSYMSFLAGS='-none'; \
320                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-B,symbolic"; \
321         fi; \
322         $(LINK_SO_DSO)
323 link_shlib.alpha-osf1:
324         @ if $(DETECT_GNU_LD); then \
325                 $(DO_GNU_SO); \
326         else \
327                 SHLIB=lib$(LIBNAME).so; \
328                 SHLIB_SUFFIX=; \
329                 SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
330                 if [ -n "$$SHLIB_HIST" ]; then \
331                         SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
332                 else \
333                         SHLIB_HIST="$(LIBVERSION)"; \
334                 fi; \
335                 SHLIB_SOVER=; \
336                 ALLSYMSFLAGS='-all'; \
337                 NOALLSYMSFLAGS='-none'; \
338                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-B,symbolic"; \
339                 if [ -n "$$SHLIB_HIST" ]; then \
340                         SHAREDFLAGS="$$SHAREDFLAGS -set_version $$SHLIB_HIST"; \
341                 fi; \
342         fi; \
343         $(LINK_SO_SHLIB)
344 link_app.alpha-osf1:
345         @if $(DETECT_GNU_LD); then \
346                 $(DO_GNU_APP); \
347         else \
348                 LDFLAGS="$(CFLAGS) $(LDFLAGS) -rpath $(LIBRPATH)"; \
349         fi; \
350         $(LINK_APP)
351
352 link_dso.solaris:
353         @ if $(DETECT_GNU_LD); then \
354                 $(DO_GNU_SO_NOCALC); \
355         else \
356                 $(CALC_VERSIONS); \
357                 SHLIB=lib$(LIBNAME).so; \
358                 SHLIB_SUFFIX=; \
359                 ALLSYMSFLAGS="-Wl,-z,allextract"; \
360                 NOALLSYMSFLAGS="-Wl,-z,defaultextract"; \
361                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-Bsymbolic"; \
362         fi; \
363         $(LINK_SO_DSO)
364 link_shlib.solaris:
365         @ if $(DETECT_GNU_LD); then \
366                 $(DO_GNU_SO); \
367         else \
368                 $(CALC_VERSIONS); \
369                 SHLIB=lib$(LIBNAME).so; \
370                 SHLIB_SUFFIX=;\
371                 $(PERL) $(SRCDIR)/util/mkdef.pl $(LIBNAME) linux >$(LIBNAME).map; \
372                 ALLSYMSFLAGS="-Wl,-z,allextract,-M,$(LIBNAME).map"; \
373                 NOALLSYMSFLAGS="-Wl,-z,defaultextract"; \
374                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-Bsymbolic"; \
375         fi; \
376         $(LINK_SO_SHLIB)
377 link_app.solaris:
378         @ if $(DETECT_GNU_LD); then \
379                 $(DO_GNU_APP); \
380         else \
381                 LDFLAGS="$(CFLAGS) $(LDFLAGS) -R $(LIBRPATH)"; \
382         fi; \
383         $(LINK_APP)
384
385 # OpenServer 5 native compilers used
386 link_dso.svr3:
387         @ if $(DETECT_GNU_LD); then \
388                 $(DO_GNU_SO_NOCALC); \
389         else \
390                 $(CALC_VERSIONS); \
391                 SHLIB=$(LIBNAME).so; \
392                 SHLIB_SUFFIX=; \
393                 ALLSYMSFLAGS=''; \
394                 NOALLSYMSFLAGS=''; \
395                 SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SUFFIX"; \
396         fi; \
397         $(LINK_SO_DSO)
398 link_shlib.svr3:
399         @ if $(DETECT_GNU_LD); then \
400                 $(DO_GNU_SO); \
401         else \
402                 $(CALC_VERSIONS); \
403                 SHLIB=lib$(LIBNAME).so; \
404                 SHLIB_SUFFIX=; \
405                 ALLSYMSFLAGS=''; \
406                 NOALLSYMSFLAGS=''; \
407                 SHAREDFLAGS="$(CFLAGS) -G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
408         fi; \
409         $(LINK_SO_SHLIB_UNPACKED)
410 link_app.svr3:
411         @$(DETECT_GNU_LD) && $(DO_GNU_APP); \
412         $(LINK_APP)
413
414 # UnixWare 7 and OpenUNIX 8 native compilers used
415 link_dso.svr5:
416         @ if $(DETECT_GNU_LD); then \
417                 $(DO_GNU_SO_NOCALC); \
418         else \
419                 SHARE_FLAG='-G'; \
420                 ($(CC) -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
421                 SHLIB=$(LIBNAME).so; \
422                 SHLIB_SUFFIX=; \
423                 ALLSYMSFLAGS=''; \
424                 NOALLSYMSFLAGS=''; \
425                 SHAREDFLAGS="$(CFLAGS) $${SHARE_FLAG} -h $$SHLIB$$SHLIB_SUFFIX"; \
426         fi; \
427         $(LINK_SO_DSO)
428 link_shlib.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_SHLIB_UNPACKED)
442 link_app.svr5:
443         @$(DETECT_GNU_LD) && $(DO_GNU_APP); \
444         $(LINK_APP)
445
446 link_dso.irix:
447         @ if $(DETECT_GNU_LD); then \
448                 $(DO_GNU_SO_NOCALC); \
449         else \
450                 SHLIB=$(LIBNAME).so; \
451                 SHLIB_SUFFIX=; \
452                 MINUSWL=""; \
453                 ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
454                 ALLSYMSFLAGS="$${MINUSWL}-all"; \
455                 NOALLSYMSFLAGS="$${MINUSWL}-none"; \
456                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SUFFIX,-B,symbolic"; \
457         fi; \
458         $(LINK_SO_DSO)
459 link_shlib.irix:
460         @ if $(DETECT_GNU_LD); then \
461                 $(DO_GNU_SO); \
462         else \
463                 $(CALC_VERSIONS); \
464                 SHLIB=lib$(LIBNAME).so; \
465                 SHLIB_SUFFIX=; \
466                 MINUSWL=""; \
467                 ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
468                 ALLSYMSFLAGS="$${MINUSWL}-all"; \
469                 NOALLSYMSFLAGS="$${MINUSWL}-none"; \
470                 SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,-B,symbolic"; \
471         fi; \
472         $(LINK_SO_SHLIB)
473 link_app.irix:
474         @LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,-rpath,$(LIBRPATH)"; \
475         $(LINK_APP)
476
477 # 32-bit PA-RISC HP-UX embeds the -L pathname of libs we link with, so
478 # we compensate for it with +cdp ../: and +cdp ./:. Yes, these rewrite
479 # rules imply that we can only link one level down in catalog structure,
480 # but that's what takes place for the moment of this writing. +cdp option
481 # was introduced in HP-UX 11.x and applies in 32-bit PA-RISC link
482 # editor context only [it's simply ignored in other cases, which are all
483 # ELFs by the way].
484 #
485 link_dso.hpux:
486         @if $(DETECT_GNU_LD); then $(DO_GNU_SO_NOCALC); else \
487         SHLIB=$(LIBNAME).sl; \
488         expr "$(CFLAGS)" : '.*DSO_DLFCN' > /dev/null && SHLIB=lib$(LIBNAME).so; \
489         SHLIB_SUFFIX=; \
490         ALLSYMSFLAGS='-Wl,-Fl'; \
491         NOALLSYMSFLAGS=''; \
492         expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
493         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SUFFIX,+cdp,../:,+cdp,./:"; \
494         fi; \
495         rm -f $$SHLIB$$SHLIB_SUFFIX || :; \
496         $(LINK_SO_DSO) && chmod a=rx $$SHLIB$$SHLIB_SUFFIX
497 link_shlib.hpux:
498         @if $(DETECT_GNU_LD); then $(DO_GNU_SO); else \
499         $(CALC_VERSIONS); \
500         SHLIB=lib$(LIBNAME).sl; \
501         expr $(PLATFORM) : '.*ia64' > /dev/null && SHLIB=lib$(LIBNAME).so; \
502         SHLIB_SUFFIX=; \
503         ALLSYMSFLAGS='-Wl,-Fl'; \
504         NOALLSYMSFLAGS=''; \
505         expr $(PLATFORM) : 'hpux64' > /dev/null && ALLSYMSFLAGS='-Wl,+forceload'; \
506         SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-B,symbolic,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+cdp,../:,+cdp,./:"; \
507         fi; \
508         rm -f $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX || :; \
509         $(LINK_SO_SHLIB) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
510 link_app.hpux:
511         @if $(DETECT_GNU_LD); then $(DO_GNU_APP); else \
512         LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,+s,+cdp,../:,+cdp,./:,+b,$(LIBRPATH)"; \
513         fi; \
514         $(LINK_APP)
515
516 link_dso.aix:
517         @OBJECT_MODE=`expr "x$(SHARED_LDFLAGS)" : 'x\-[a-z]*\(64\)'` || :; \
518         OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \
519         SHLIB=$(LIBNAME).so; \
520         SHLIB_SUFFIX=; \
521         ALLSYMSFLAGS=''; \
522         NOALLSYMSFLAGS=''; \
523         SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-bexpall,-bnolibpath,-bM:SRE'; \
524         $(LINK_SO_DSO);
525 link_shlib.aix:
526         @ $(CALC_VERSIONS); \
527         OBJECT_MODE=`expr "x$(SHARED_LDFLAGS)" : 'x\-[a-z]*\(64\)'` || : ; \
528         OBJECT_MODE=$${OBJECT_MODE:-32}; export OBJECT_MODE; \
529         SHLIB=lib$(LIBNAME).so; \
530         SHLIB_SUFFIX=; \
531         ALLSYMSFLAGS='-bnogc'; \
532         NOALLSYMSFLAGS=''; \
533         SHAREDFLAGS='$(CFLAGS) $(SHARED_LDFLAGS) -Wl,-bexpall,-bnolibpath,-bM:SRE'; \
534         $(LINK_SO_SHLIB_VIA_O)
535 link_app.aix:
536         LDFLAGS="$(CFLAGS) $(LDFLAGS) -Wl,-brtl,-blibpath:$(LIBRPATH):$${LIBPATH:-/usr/lib:/lib}"; \
537         $(LINK_APP)
538
539
540 # Targets to build symbolic links when needed
541 symlink.gnu symlink.solaris symlink.svr3 symlink.svr5 symlink.irix \
542 symlink.aix:
543         @ $(CALC_VERSIONS); \
544         SHLIB=lib$(LIBNAME).so; \
545         $(SYMLINK_SO)
546 symlink.darwin:
547         @ $(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
557 symlink.cygwin symlink.alpha-osf1 symlink.tru64 symlink.tru64-rpath:
558
559 # Compatibility targets
560 link_dso.bsd-gcc-shared link_dso.linux-shared link_dso.gnu-shared: link_dso.gnu
561 link_shlib.bsd-gcc-shared link_shlib.gnu-shared: link_shlib.gnu
562 link_app.bsd-gcc-shared link_app.linux-shared link_app.gnu-shared: link_app.gnu
563 symlink.bsd-gcc-shared symlink.bsd-shared symlink.linux-shared symlink.gnu-shared: symlink.gnu
564 link_dso.bsd-shared: link_dso.bsd
565 link_shlib.bsd-shared: link_shlib.bsd
566 link_app.bsd-shared: link_app.bsd
567 link_dso.darwin-shared: link_dso.darwin
568 link_shlib.darwin-shared: link_shlib.darwin
569 link_app.darwin-shared: link_app.darwin
570 symlink.darwin-shared: symlink.darwin
571 link_dso.cygwin-shared: link_dso.cygwin
572 link_shlib.cygwin-shared: link_shlib.cygwin
573 link_app.cygwin-shared: link_app.cygwin
574 symlink.cygwin-shared: symlink.cygwin
575 link_dso.mingw-shared: link_dso.cygwin
576 link_shlib.mingw-shared: link_shlib.mingw
577 link_app.mingw-shared: link_app.cygwin
578 symlink.mingw-shared: symlink.cygwin
579 link_dso.alpha-osf1-shared: link_dso.alpha-osf1
580 link_shlib.alpha-osf1-shared: link_shlib.alpha-osf1
581 link_app.alpha-osf1-shared: link_app.alpha-osf1
582 symlink.alpha-osf1-shared: symlink.alpha-osf1
583 link_dso.tru64-shared: link_dso.tru64
584 link_shlib.tru64-shared: link_shlib.tru64
585 link_app.tru64-shared: link_app.tru64
586 symlink.tru64-shared: symlink.tru64
587 link_dso.tru64-shared-rpath: link_dso.tru64-rpath
588 link_shlib.tru64-shared-rpath: link_shlib.tru64-rpath
589 link_app.tru64-shared-rpath: link_app.tru64-rpath
590 symlink.tru64-shared-rpath: symlink.tru64-rpath
591 link_dso.solaris-shared: link_dso.solaris
592 link_shlib.solaris-shared: link_shlib.solaris
593 link_app.solaris-shared: link_app.solaris
594 symlink.solaris-shared: symlink.solaris
595 link_dso.svr3-shared: link_dso.svr3
596 link_shlib.svr3-shared: link_shlib.svr3
597 link_app.svr3-shared: link_app.svr3
598 symlink.svr3-shared: symlink.svr3
599 link_dso.svr5-shared: link_dso.svr5
600 link_shlib.svr5-shared: link_shlib.svr5
601 link_app.svr5-shared: link_app.svr5
602 symlink.svr5-shared: symlink.svr5
603 link_dso.irix-shared: link_dso.irix
604 link_shlib.irix-shared: link_shlib.irix
605 link_app.irix-shared: link_app.irix
606 symlink.irix-shared: symlink.irix
607 link_dso.hpux-shared: link_dso.hpux
608 link_shlib.hpux-shared: link_shlib.hpux
609 link_app.hpux-shared: link_app.hpux
610 symlink.hpux-shared: symlink.hpux
611 link_dso.aix-shared: link_dso.aix
612 link_shlib.aix-shared: link_shlib.aix
613 link_app.aix-shared: link_app.aix
614 symlink.aix-shared: symlink.aix