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