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