a8d5cff3a83c3f05e96e4a1a77e3ba63db90c25d
[openssl.git] / Configurations / unix-Makefile.tmpl
1 ##
2 ## Makefile for OpenSSL
3 ##
4 ## {- join("\n## ", @autowarntext) -}
5 {-
6      sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }
7
8      # shlib and shlib_simple both take a static library name and figure
9      # out what the shlib name should be.
10      #
11      # When OpenSSL is configured "no-shared", these functions will just
12      # return empty lists, making them suitable to join().
13      #
14      # With Windows DLL producers, shlib($libname) will return the shared
15      # library name (which usually is different from the static library
16      # name) with the default shared extension appended to it, while
17      # shlib_simple($libname) will return the static library name with
18      # the shared extension followed by ".a" appended to it.  The former
19      # result is used as the runtime shared library while the latter is
20      # used as the DLL import library.
21      #
22      # On all Unix systems, shlib($libname) will return the library name
23      # with the default shared extension, while shlib_simple($libname)
24      # will return the name from shlib($libname) with any SO version number
25      # removed.  On some systems, they may therefore return the exact same
26      # string.
27      sub shlib {
28          return () if $config{no_shared};
29          my $lib = shift;
30          return $unified_info{sharednames}->{$lib} . '$(SHLIB_EXT)';
31      }
32      sub shlib_simple {
33          return () if $config{no_shared};
34
35          my $lib = shift;
36          if (windowsdll()) {
37              return $lib . '$(SHLIB_EXT_IMPORT)';
38          }
39          return $lib . '$(SHLIB_EXT_SIMPLE)';
40      }
41
42      # dso is a complement to shlib / shlib_simple that returns the
43      # given libname with the simple shared extension (possible SO version
44      # removed).  This differs from shlib_simple() by being unconditional.
45      sub dso {
46          return () if $config{no_shared};
47          my $engine = shift;
48
49          return $engine . '$(DSO_EXT)';
50      }
51 -}
52 PLATFORM={- $config{target} -}
53 OPTIONS={- $config{options} -}
54 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
55 SRCDIR={- $config{sourcedir} -}
56 BLDDIR={- $config{builddir} -}
57
58 VERSION={- $config{version} -}
59 MAJOR={- $config{major} -}
60 MINOR={- $config{minor} -}
61 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
62 SHLIB_VERSION_HISTORY={- $config{shlib_version_history} -}
63 SHLIB_MAJOR={- $config{shlib_major} -}
64 SHLIB_MINOR={- $config{shlib_minor} -}
65 SHLIB_TARGET={- $target{shared_target} -}
66
67 EXE_EXT={- $target{exe_extension} || "" -}
68 LIB_EXT={- $target{lib_extension} || ".a" -}
69 SHLIB_EXT={- $target{shared_extension} || ".so" -}
70 SHLIB_EXT_SIMPLE={- $target{shared_extension_simple} || ".so" -}
71 SHLIB_EXT_IMPORT={- $target{shared_import_extension} || "" -}
72 DSO_EXT={- $target{dso_extension} || ".so" -}
73 OBJ_EXT={- $target{obj_extension} || ".o" -}
74 DEP_EXT={- $target{dep_extension} || ".d" -}
75
76 LIBS={- join(" ", map { $_."\$(LIB_EXT)" } @{$unified_info{libraries}}) -}
77 SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
78 ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
79 PROGRAMS={- join(" ", map { $_."\$(EXE_EXT)" } grep { !m|^test/| } @{$unified_info{programs}}) -}
80 TESTPROGS={- join(" ", map { $_."\$(EXE_EXT)" } grep { m|^test/| } @{$unified_info{programs}}) -}
81 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
82 DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|\$(DEP_EXT)|; $x; }
83                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
84                   keys %{$unified_info{sources}}); -}
85
86 BIN_SCRIPTS=$(BLDDIR)/tools/c_rehash
87 MISC_SCRIPTS=$(SRCDIR)/tools/c_hash $(SRCDIR)/tools/c_info \
88              $(SRCDIR)/tools/c_issuer $(SRCDIR)/tools/c_name \
89              $(BLDDIR)/apps/CA.pl $(SRCDIR)/apps/tsget
90
91 SHLIB_INFO={- join(" ", map { "\"".shlib($_).";".shlib_simple($_)."\"" } @{$unified_info{libraries}}) -}
92
93 # DESTDIR is for package builders so that they can configure for, say,
94 # /usr/ and yet have everything installed to /tmp/somedir/usr/.
95 # Normally it is left empty.
96 DESTDIR=
97
98 # Do not edit these manually. Use Configure with --prefix or --openssldir
99 # to change this!  Short explanation in the top comment in Configure
100 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
101               #
102               our $prefix = $config{prefix} || "/usr/local";
103               $prefix -}
104 OPENSSLDIR={- #
105               # The logic here is that if no --openssldir was given,
106               # OPENSSLDIR will get the value from $prefix plus "/ssl".
107               # If --openssldir was given and the value is an absolute
108               # path, OPENSSLDIR will get its value without change.
109               # If the value from --openssldir is a relative path,
110               # OPENSSLDIR will get $prefix with the --openssldir
111               # value appended as a subdirectory.
112               #
113               use File::Spec::Functions;
114               our $openssldir =
115                   $config{openssldir} ?
116                       (file_name_is_absolute($config{openssldir}) ?
117                            $config{openssldir}
118                            : catdir($prefix, $config{openssldir}))
119                       : catdir($prefix, "ssl");
120               $openssldir -}
121 LIBDIR={- #
122           # if $prefix/lib$target{multilib} is not an existing
123           # directory, then assume that it's not searched by linker
124           # automatically, in which case adding $target{multilib} suffix
125           # causes more grief than we're ready to tolerate, so don't...
126           our $multilib =
127               -d "$prefix/lib$target{multilib}" ? $target{multilib} : "";
128           our $libdir = $config{libdir} || "lib$multilib";
129           $libdir -}
130 ENGINESDIR={- use File::Spec::Functions;
131               catdir($prefix,$libdir,"engines") -}
132
133 MANDIR=$(INSTALLTOP)/share/man
134 DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)
135 HTMLDIR=$(DOCDIR)/html
136
137 # MANSUFFIX is for the benefit of anyone who may want to have a suffix
138 # appended after the manpage file section number.  "ssl" is popular,
139 # resulting in files such as config.5ssl rather than config.5.
140 MANSUFFIX=
141 HTMLSUFFIX=html
142
143
144
145 CROSS_COMPILE= {- $config{cross_compile_prefix} -}
146 CC= $(CROSS_COMPILE){- $target{cc} -}
147 CFLAGS={- our $cflags2 = join(" ",(map { "-D".$_} @{$config{defines}}),"-DOPENSSLDIR=\"\\\"\$(OPENSSLDIR)\\\"\"","-DENGINESDIR=\"\\\"\$(ENGINESDIR)\\\"\"") -} {- $config{cflags} -}
148 CFLAGS_Q={- $cflags2 =~ s|([\\"])|\\$1|g; $cflags2 -} {- $config{cflags} -}
149 LDFLAGS= {- $config{lflags} -}
150 PLIB_LDFLAGS= {- $config{plib_lflags} -}
151 EX_LIBS= {- $config{ex_libs} -}
152 SHARED_LDFLAGS={- $target{shared_ldflag}
153                   # Unlike other OSes (like Solaris, Linux, Tru64,
154                   # IRIX) BSD run-time linkers (tested OpenBSD, NetBSD
155                   # and FreeBSD) "demand" RPATH set on .so objects.
156                   # Apparently application RPATH is not global and
157                   # does not apply to .so linked with other .so.
158                   # Problem manifests itself when libssl.so fails to
159                   # load libcrypto.so. One can argue that we should
160                   # engrave this into Makefile.shared rules or into
161                   # BSD-* config lines above. Meanwhile let's try to
162                   # be cautious and pass -rpath to linker only when
163                   # $prefix is not /usr.
164                   . ($config{target} =~ m|^BSD-| && $prefix !~ m|^/usr/.*$|
165                      ? " -Wl,-rpath,\$\$(LIBRPATH)" : "") -}
166 SHARED_RCFLAGS={- $target{shared_rcflag} -}
167
168 PERL={- $config{perl} -}
169
170 ARFLAGS= {- $target{arflags} -}
171 AR=$(CROSS_COMPILE){- $target{ar} || "ar" -} $(ARFLAGS) r
172 RANLIB= {- $target{ranlib} -}
173 NM= $(CROSS_COMPILE){- $target{nm} || "nm" -}
174 RM= rm -f
175 RMDIR= rmdir
176 TAR= {- $target{tar} || "tar" -}
177 TARFLAGS= {- $target{tarflags} -}
178 MAKEDEPEND=$(CROSS_COMPILE){- $config{makedepprog} -}
179
180 BASENAME=       openssl
181 NAME=           $(BASENAME)-$(VERSION)
182 TARFILE=        ../$(NAME).tar
183
184 # We let the C compiler driver to take care of .s files. This is done in
185 # order to be excused from maintaining a separate set of architecture
186 # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
187 # gcc, then the driver will automatically translate it to -xarch=v8plus
188 # and pass it down to assembler.
189 AS=$(CC) -c
190 ASFLAG=$(CFLAGS)
191 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
192
193 # For x86 assembler: Set PROCESSOR to 386 if you want to support
194 # the 80386.
195 PROCESSOR= {- $config{processor} -}
196
197 # The main targets ###################################################
198
199 all: configdata.pm build_libs_nodep build_engines_nodep build_apps_nodep \
200      depend link-utils
201
202 build_libs: configdata.pm build_libs_nodep depend
203 build_libs_nodep: libcrypto.pc libssl.pc openssl.pc
204 build_engines: configdata.pm build_engines_nodep depend
205 build_engines_nodep: $(ENGINES)
206 build_apps: configdata.pm build_apps_nodep depend
207 build_apps_nodep: $(PROGRAMS) $(SCRIPTS)
208 build_tests: configdata.pm build_tests_nodep depend
209 build_tests_nodep: $(TESTPROGS)
210
211 test tests: build_tests_nodep build_apps_nodep build_engines_nodep depend rehash
212         ( cd test; \
213           SRCTOP=../$(SRCDIR) \
214           BLDTOP=../$(BLDDIR) \
215           EXE_EXT=$(EXE_EXT) \
216             $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
217
218 list-tests:
219         @TOP=$(SRCDIR) PERL=$(PERL) $(PERL) $(SRCDIR)/test/run_tests.pl list
220
221 libclean:
222         -rm -f `find $(BLDDIR) -name '*$(LIB_EXT)' -o -name '*$(SHLIB_EXT)'`
223
224 install: install_sw install_ssldirs install_docs
225
226 uninstall: uninstall_docs uninstall_sw
227
228 clean: libclean
229         rm -f $(PROGRAMS) $(TESTPROGS)
230         rm -f `find $(BLDDIR) -name '*$(DEP_EXT)'`
231         rm -f `find $(BLDDIR) -name '*$(OBJ_EXT)'`
232         rm -f $(BLDDIR)/core $(BLDDIR)/rehash.time
233         rm -f $(BLDDIR)/tags $(BLDDIR)/TAGS
234         rm -f $(BLDDIR)/openssl.pc $(BLDDIR)/libcrypto.pc $(BLDDIR)/libssl.pc
235         -rm -f `find $(BLDDIR) -type l`
236         rm -f $(TARFILE)
237
238 # This exists solely for those who still type 'make depend'
239 depend: Makefile
240 Makefile: FORCE
241         @( sed -e '/^# DO NOT DELETE THIS LINE.*/,$$d' < Makefile; \
242           echo '# DO NOT DELETE THIS LINE -- make depend depends on it.'; \
243           echo; \
244           for d in $(DEPS); do \
245             if [ -f $$d ]; then cat $$d; fi; \
246           done ) > Makefile.new
247         @if ! cmp Makefile.new Makefile >/dev/null 2>&1; then \
248                 mv -f Makefile.new Makefile; \
249         fi
250
251 # Install helper targets #############################################
252
253 install_sw: all install_dev install_engines install_runtime
254
255 uninstall_sw: uninstall_dev uninstall_engines uninstall_runtime
256
257 install_docs: install_man_docs install_html_docs
258
259 uninstall_docs: uninstall_man_docs uninstall_html_docs
260         $(RM) -r -v $(DESTDIR)$(DOCDIR)
261
262 install_ssldirs:
263         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/certs
264         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/private
265
266 install_dev:
267         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
268         @echo "*** Installing development files"
269         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/include/openssl
270         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
271                           $(BLDDIR)/include/openssl/*.h; do \
272                 fn=`basename $$i`; \
273                 echo "install $$i -> $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
274                 cp $$i $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
275                 chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
276         done
277         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
278         @set -e; for l in $(LIBS); do \
279                 fn=`basename $$l`; \
280                 echo "install $$l -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
281                 cp $$l $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
282                 $(RANLIB) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
283                 chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new; \
284                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn.new \
285                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
286         done
287         @ : {- output_off() if $config{no_shared}; "" -}
288         @set -e; for s in $(SHLIB_INFO); do \
289                 s1=`echo "$$s" | cut -f1 -d";"`; \
290                 s2=`echo "$$s" | cut -f2 -d";"`; \
291                 fn1=`basename $$s1`; \
292                 fn2=`basename $$s2`; \
293                 : {- output_off() if windowsdll(); "" -}; \
294                 echo "install $$s1 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
295                 cp $$s1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
296                 chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new; \
297                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1.new \
298                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
299                 if [ "$$fn1" != "$$fn2" ]; then \
300                         echo "link $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
301                         ln -sf $$fn1 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
302                 fi; \
303                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
304                 echo "install $$s2 -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
305                 cp $$s2 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
306                 chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new; \
307                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2.new \
308                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
309                 : {- output_off() unless windowsdll(); "" -}; \
310         done
311         @ : {- output_on() if $config{no_shared}; "" -}
312         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
313         @echo "install libcrypto.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
314         @cp libcrypto.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
315         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
316         @echo "install libssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
317         @cp libssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
318         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
319         @echo "install openssl.pc -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
320         @cp openssl.pc $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
321         @chmod 644 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
322
323 uninstall_dev:
324         @echo "*** Uninstalling development files"
325         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
326                           $(BLDDIR)/include/openssl/*.h; do \
327                 fn=`basename $$i`; \
328                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
329                 $(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
330         done
331         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include/openssl
332         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include
333         @set -e; for l in $(LIBS); do \
334                 fn=`basename $$l`; \
335                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn"; \
336                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn; \
337         done
338         @ : {- output_off() if $config{no_shared}; "" -}
339         @set -e; for s in $(SHLIB_INFO); do \
340                 s1=`echo "$$s" | cut -f1 -d";"`; \
341                 s2=`echo "$$s" | cut -f2 -d";"`; \
342                 fn1=`basename $$s1`; \
343                 fn2=`basename $$s2`; \
344                 : {- output_off() if windowsdll(); "" -}; \
345                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1"; \
346                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn1; \
347                 if [ "$$fn1" != "$$fn2" ]; then \
348                         echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
349                         $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
350                 fi; \
351                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
352                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2"; \
353                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/$$fn2; \
354                 : {- output_off() unless windowsdll(); "" -}; \
355         done
356         @ : {- output_on() if $config{no_shared}; "" -}
357         @echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc"
358         @$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
359         @echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc"
360         @$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
361         @echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc"
362         @$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
363         @echo $(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
364         -@$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
365         @echo $(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
366         -@$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)
367
368 install_engines:
369         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
370         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines/
371         @echo "*** Installing engines"
372         @set -e; for e in $(ENGINES); do \
373                 fn=`basename $$e`; \
374                 if [ "$$fn" = '{- dso("ossltest") -}' ]; then \
375                         continue; \
376                 fi; \
377                 echo "install $$e -> $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn"; \
378                 cp $$e $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn.new; \
379                 chmod 755 $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn.new; \
380                 mv -f $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn.new \
381                       $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn; \
382         done
383
384 uninstall_engines:
385         @echo "*** Uninstalling engines"
386         @set -e; for e in $(ENGINES); do \
387                 fn=`basename $$e`; \
388                 if [ "$$fn" = '{- dso("ossltest") -}' ]; then \
389                         continue; \
390                 fi; \
391                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn"; \
392                 $(RM) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines/$$fn; \
393         done
394         @echo "$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines"
395         -@$(RMDIR) $(DESTDIR)$(INSTALLTOP)/$(LIBDIR)/engines
396
397 install_runtime:
398         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
399         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
400         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/misc
401         @echo "*** Installing runtime files"
402         : {- output_off() unless windowsdll(); "" -};
403         @set -e; for s in $(SHLIBS); do \
404                 fn=`basename $$i`; \
405                 echo "install $$s -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
406                 cp $$s $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
407                 chmod 644 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
408                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
409                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
410         done
411         : {- output_on() unless windowsdll(); "" -};
412         @set -e; for x in $(PROGRAMS); do \
413                 fn=`basename $$x`; \
414                 echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
415                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
416                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
417                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
418                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
419         done
420         @set -e; for x in $(BIN_SCRIPTS); do \
421                 fn=`basename $$x`; \
422                 echo "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
423                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
424                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
425                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
426                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
427         done
428         @set -e; for x in $(MISC_SCRIPTS); do \
429                 fn=`basename $$x`; \
430                 echo "install $$x -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
431                 cp $$x $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
432                 chmod 755 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
433                 mv -f $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new \
434                       $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
435         done
436         @echo "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"
437         @cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
438         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
439         @mv -f  $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new $(DESTDIR)$(OPENSSLDIR)/openssl.cnf
440
441 uninstall_runtime:
442         @echo "*** Uninstalling runtime files"
443         @set -e; for x in $(PROGRAMS); \
444         do  \
445                 fn=`basename $$x`; \
446                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
447                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
448         done;
449         @set -e; for x in $(BIN_SCRIPTS); \
450         do  \
451                 fn=`basename $$x`; \
452                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
453                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
454         done
455         @set -e; for x in $(MISC_SCRIPTS); \
456         do  \
457                 fn=`basename $$x`; \
458                 echo "$(RM) $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
459                 $(RM) $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
460         done
461         : {- output_off() unless windowsdll(); "" -};
462         @set -e; for s in $(SHLIBS); do \
463                 fn=`basename $$i`; \
464                 echo "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
465                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
466         done
467         : {- output_on() unless windowsdll(); "" -};
468         $(RM) $(DESTDIR)$(OPENSSLDIR)/openssl.cnf
469         @echo "$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin"
470         -@$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin
471         @echo "$(RMDIR) $(DESTDIR)$(OPENSSLDIR)/misc"
472         -@$(RMDIR) $(DESTDIR)$(OPENSSLDIR)/misc
473
474 # A method to extract all names from a .pod file
475 # The first sed extracts everything between "=head1 NAME" and the next =head1
476 # The second sed joins all the lines into one
477 # The third sed removes the description and turns all commas into spaces
478 # Voilà, you have a space separated list of names!
479 EXTRACT_NAMES=sed -e '1,/^=head1  *NAME *$$/d;/^=head1/,$$d' | \
480               sed -e ':a;{N;s/\n/ /;ba}' | \
481               sed -e 's/ - .*$$//;s/,/ /g'
482 PROCESS_PODS=\
483         set -e; \
484         here=`cd $(SRCDIR); pwd`; \
485         point=$$here/util/point.sh; \
486         for ds in apps:1 crypto:3 ssl:3; do \
487             defdir=`echo $$ds | cut -f1 -d:`; \
488             defsec=`echo $$ds | cut -f2 -d:`; \
489             for p in $(SRCDIR)/doc/$$defdir/*.pod; do \
490                 SEC=`sed -ne 's/^=for  *comment  *openssl_manual_section: *\([0-9]\) *$$/\1/p' $$p`; \
491                 [ -z "$$SEC" ] && SEC=$$defsec; \
492                 fn=`basename $$p .pod`; \
493                 NAME=`echo $$fn | tr [a-z] [A-Z]`; \
494                 suf=`eval "echo $$OUTSUFFIX"`; \
495                 top=`eval "echo $$OUTTOP"`; \
496                 $(PERL) $(SRCDIR)/util/mkdir-p.pl $$top/man$$SEC; \
497                 echo "install $$p -> $$top/man$$SEC/$$fn$$suf"; \
498                 cat $$p | eval "$$GENERATE" \
499                         >  $$top/man$$SEC/$$fn$$suf; \
500                 names=`cat $$p | $(EXTRACT_NAMES)`; \
501                 ( cd $$top/man$$SEC; \
502                   for n in $$names; do \
503                       comp_n="$$n"; \
504                       comp_fn="$$fn"; \
505                       case "$(PLATFORM)" in DJGPP|Cygwin*|mingw*|darwin*-*-cc) \
506                           comp_n=`echo "$$n" | tr [A-Z] [a-z]`; \
507                           comp_fn=`echo "$$fn" | tr [A-Z] [a-z]`; \
508                           ;; \
509                       esac; \
510                       if [ "$$comp_n" != "$$comp_fn" ]; then \
511                           echo "link $$top/man$$SEC/$$n$$suf -> $$top/man$$SEC/$$fn$$suf"; \
512                           PLATFORM=$(PLATFORM) $$point $$fn$$suf $$n$$suf; \
513                       fi; \
514                   done ); \
515             done; \
516         done
517 UNINSTALL_DOCS=\
518         set -e; \
519         here=`cd $(SRCDIR); pwd`; \
520         for ds in apps:1 crypto:3 ssl:3; do \
521             defdir=`echo $$ds | cut -f1 -d:`; \
522             defsec=`echo $$ds | cut -f2 -d:`; \
523             for p in $(SRCDIR)/doc/$$defdir/*.pod; do \
524                 SEC=`sed -ne 's/^=for  *comment  *openssl_manual_section: *\([0-9]\) *$$/\1/p' $$p`; \
525                 [ -z "$$SEC" ] && SEC=$$defsec; \
526                 fn=`basename $$p .pod`; \
527                 suf=`eval "echo $$OUTSUFFIX"`; \
528                 top=`eval "echo $$OUTTOP"`; \
529                 echo "$(RM) $$top/man$$SEC/$$fn$$suf"; \
530                 $(RM) $$top/man$$SEC/$$fn$$suf; \
531                 names=`cat $$p | $(EXTRACT_NAMES)`; \
532                 for n in $$names; do \
533                     comp_n="$$n"; \
534                     comp_fn="$$fn"; \
535                     case "$(PLATFORM)" in DJGPP|Cygwin*|mingw*|darwin*-*-cc) \
536                         comp_n=`echo "$$n" | tr [A-Z] [a-z]`; \
537                         comp_fn=`echo "$$fn" | tr [A-Z] [a-z]`; \
538                         ;; \
539                     esac; \
540                     if [ "$$comp_n" != "$$comp_fn" ]; then \
541                         echo "$(RM) $$top/man$$SEC/$$n$$suf"; \
542                         $(RM) $$top/man$$SEC/$$n$$suf; \
543                     fi; \
544                 done; \
545                 ( $(RMDIR) $$top/man$$SEC 2>/dev/null || exit 0 ); \
546             done; \
547         done
548
549 install_man_docs:
550         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
551         @echo "*** Installing manpages"
552         @\
553         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
554         OUTTOP="$(DESTDIR)$(MANDIR)"; \
555         GENERATE='pod2man --name=$$NAME --section=$$SEC --center=OpenSSL --release=$(VERSION)'; \
556         $(PROCESS_PODS)
557
558 uninstall_man_docs:
559         @echo "*** Uninstalling manpages"
560         @\
561         OUTSUFFIX='.$${SEC}$(MANSUFFIX)'; \
562         OUTTOP="$(DESTDIR)$(MANDIR)"; \
563         $(UNINSTALL_DOCS)
564
565 install_html_docs:
566         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
567         @echo "*** Installing HTML manpages"
568         @\
569         OUTSUFFIX='.$(HTMLSUFFIX)'; \
570         OUTTOP="$(DESTDIR)$(HTMLDIR)"; \
571         GENERATE="pod2html --podroot=$(SRCDIR)/doc --htmldir=.. \
572                            --podpath=apps:crypto:ssl \
573                   | sed -e 's|href=\"http://man.he.net/man|href=\"../man|g'"; \
574         $(PROCESS_PODS)
575
576 uninstall_html_docs:
577         @echo "*** Uninstalling manpages"
578         @\
579         OUTSUFFIX='.$(HTMLSUFFIX)'; \
580         OUTTOP="$(DESTDIR)$(HTMLDIR)"; \
581         $(UNINSTALL_DOCS)
582
583
584 # Developer targets (note: these are only available on Unix) #########
585
586 update: generate errors ordinals
587
588 generate: generate_apps generate_crypto_bn generate_crypto_objects
589
590 # Test coverage is a good idea for the future
591 #coverage: $(PROGRAMS) $(TESTPROGRAMS)
592 #       ...
593
594 # Currently disabled, util/selftest.pl needs a rewrite
595 #report:
596 #       SRCDIR=$(SRCDIR) @$(PERL) util/selftest.pl
597
598 lint:
599         lint -DLINT $(INCLUDES) $(SRCS)
600
601 generate_apps: $(SRCDIR)/apps/openssl-vms.cnf $(SRCDIR)/apps/progs.h
602
603 generate_crypto_bn: $(SRCDIR)/crypto/bn/bn_prime.h
604
605 generate_crypto_objects: $(SRCDIR)/crypto/objects/obj_dat.h \
606                          $(SRCDIR)/include/openssl/obj_mac.h \
607                          $(SRCDIR)/crypto/objects/obj_xref.h
608
609 errors:
610         ( cd $(SRCDIR); $(PERL) util/ck_errf.pl -strict */*.c */*/*.c )
611         ( cd $(SRCDIR); $(PERL) util/mkerr.pl -recurse -write )
612         ( cd $(SRCDIR)/engines; \
613           for e in *.ec; do \
614               $(PERL) ../util/mkerr.pl -conf $$e \
615                       -nostatic -staticloader -write *.c; \
616           done )
617         ( cd $(SRCDIR)/crypto/ct; \
618           $(PERL) ../../util/mkerr.pl -conf ct.ec -hprefix internal/ -write *.c )
619
620 ordinals:
621         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl crypto update )
622         ( b=`pwd`; cd $(SRCDIR); $(PERL) -I$$b util/mkdef.pl ssl update )
623
624 test_ordinals:
625         ( cd test; \
626           SRCTOP=../$(SRCDIR) \
627           BLDTOP=../$(BLDDIR) \
628             $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
629
630 tags TAGS: FORCE
631         rm -f TAGS tags
632         -ctags -R .
633         -etags `find . -name '*.[ch]' -o -name '*.pm'`
634
635 # Release targets (note: only available on Unix) #####################
636
637 tar:
638         TMPDIR=/var/tmp/openssl-copy.$$$$; \
639         DISTDIR=openssl-$(VERSION); \
640         mkdir -p $$TMPDIR/$$DISTDIR; \
641         (cd $(SRCDIR); \
642          git ls-tree -r --name-only --full-tree HEAD \
643          | while read F; do \
644                mkdir -p $$TMPDIR/$$DISTDIR/`dirname $$F`; \
645                cp $$F $$TMPDIR/$$DISTDIR/$$F; \
646            done); \
647         (cd $$TMPDIR; \
648          [ -n "$(PREPARE_CMD)" ] && $(PREPARE_CMD); \
649          find $$TMPDIR/$$DISTDIR -type d -print | xargs chmod 755; \
650          find $$TMPDIR/$$DISTDIR -type f -print | xargs chmod a+r; \
651          find $$TMPDIR/$$DISTDIR -type f -perm -0100 -print | xargs chmod a+x; \
652          $(TAR) $(TARFLAGS) --owner 0 --group 0 -cvf - $$DISTDIR) \
653         | (cd $(SRCDIR); gzip --best > $(TARFILE).gz); \
654         rm -rf $$TMPDIR
655         cd $(SRCDIR); ls -l $(TARFILE).gz
656
657 dist:
658         @$(MAKE) PREPARE_CMD='./Configure dist' tar
659
660 # Helper targets #####################################################
661
662 rehash: link-utils copy-certs build_apps_nodep
663         @if [ -z "$(CROSS_COMPILE)" ]; then \
664                 (OPENSSL="$(BLDDIR)/util/shlib_wrap.sh apps/openssl"; \
665                 [ -x "$(BLDDIR)/openssl.exe" ] && OPENSSL="$(BLDDIR)/openssl.exe" || :; \
666                 OPENSSL_DEBUG_MEMORY=on; OPENSSL_CONF=/dev/null ; \
667                 export OPENSSL OPENSSL_DEBUG_MEMORY OPENSSL_CONF; \
668                 $$OPENSSL rehash certs/demo \
669                 || $(PERL) tools/c_rehash certs/demo) && \
670                 touch rehash.time; \
671         else :; fi
672
673 link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/util/shlib_wrap.sh
674
675 $(BLDDIR)/util/opensslwrap.sh: configdata.pm
676         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
677             mkdir -p "$(BLDDIR)/util"; \
678             ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
679         fi
680 $(BLDDIR)/util/shlib_wrap.sh: configdata.pm
681         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
682             mkdir -p "$(BLDDIR)/util"; \
683             ln -sf "../$(SRCDIR)/util/shlib_wrap.sh" "$(BLDDIR)/util"; \
684         fi
685
686 copy-certs: FORCE
687         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
688             cp -R "$(SRCDIR)/certs" "$(BLDDIR)/"; \
689         fi
690
691 $(SRCDIR)/apps/openssl-vms.cnf: $(SRCDIR)/apps/openssl.cnf
692         $(PERL) $(SRCDIR)/VMS/VMSify-conf.pl \
693                 < $(SRCDIR)/apps/openssl.cnf > $(SRCDIR)/apps/openssl-vms.cnf
694
695 {- # because the program apps/openssl has object files as sources, and
696    # they then have the corresponding C files as source, we need to chain
697    # the lookups in %unified_info
698    my $apps_openssl = catfile("apps","openssl");
699    our @openssl_source = map { @{$unified_info{sources}->{$_}} }
700                          @{$unified_info{sources}->{$apps_openssl}};
701    ""; -}
702 $(SRCDIR)/apps/progs.h:
703         $(RM) $@
704         $(PERL) $(SRCDIR)/apps/progs.pl {- join(" ", @openssl_source) -} > $@
705
706 $(SRCDIR)/crypto/bn/bn_prime.h: $(SRCDIR)/crypto/bn/bn_prime.pl
707         $(PERL) $(SRCDIR)/crypto/bn/bn_prime.pl > $(SRCDIR)/crypto/bn/bn_prime.h
708
709 $(SRCDIR)/crypto/objects/obj_dat.h: $(SRCDIR)/crypto/objects/obj_dat.pl \
710                                     $(SRCDIR)/include/openssl/obj_mac.h
711         $(PERL) $(SRCDIR)/crypto/objects/obj_dat.pl \
712                 $(SRCDIR)/include/openssl/obj_mac.h \
713                 $(SRCDIR)/crypto/objects/obj_dat.h
714
715 # objects.pl both reads and writes obj_mac.num
716 $(SRCDIR)/include/openssl/obj_mac.h: $(SRCDIR)/crypto/objects/objects.pl \
717                                      $(SRCDIR)/crypto/objects/objects.txt \
718                                      $(SRCDIR)/crypto/objects/obj_mac.num
719         $(PERL) $(SRCDIR)/crypto/objects/objects.pl \
720                 $(SRCDIR)/crypto/objects/objects.txt \
721                 $(SRCDIR)/crypto/objects/obj_mac.num \
722                 $(SRCDIR)/include/openssl/obj_mac.h
723         @sleep 1; touch $(SRCDIR)/include/openssl/obj_mac.h; sleep 1
724
725 $(SRCDIR)/crypto/objects/obj_xref.h: $(SRCDIR)/crypto/objects/objxref.pl \
726                                      $(SRCDIR)/crypto/objects/obj_xref.txt \
727                                      $(SRCDIR)/crypto/objects/obj_mac.num
728         $(PERL) $(SRCDIR)/crypto/objects/objxref.pl \
729                 $(SRCDIR)/crypto/objects/obj_mac.num \
730                 $(SRCDIR)/crypto/objects/obj_xref.txt \
731                 > $(SRCDIR)/crypto/objects/obj_xref.h
732         @sleep 1; touch $(SRCDIR)/crypto/objects/obj_xref.h; sleep 1
733
734 FORCE:
735
736 # Building targets ###################################################
737
738 libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS)
739 libcrypto.pc:
740         @ ( echo 'prefix=$(INSTALLTOP)'; \
741             echo 'exec_prefix=$${prefix}'; \
742             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
743             echo 'includedir=$${prefix}/include'; \
744             echo ''; \
745             echo 'Name: OpenSSL-libcrypto'; \
746             echo 'Description: OpenSSL cryptography library'; \
747             echo 'Version: '$(VERSION); \
748             echo 'Libs: -L$${libdir} -lcrypto'; \
749             echo 'Libs.private: $(EX_LIBS)'; \
750             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
751
752 libssl.pc:
753         @ ( echo 'prefix=$(INSTALLTOP)'; \
754             echo 'exec_prefix=$${prefix}'; \
755             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
756             echo 'includedir=$${prefix}/include'; \
757             echo ''; \
758             echo 'Name: OpenSSL-libssl'; \
759             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
760             echo 'Version: '$(VERSION); \
761             echo 'Requires.private: libcrypto'; \
762             echo 'Libs: -L$${libdir} -lssl'; \
763             echo 'Libs.private: $(EX_LIBS)'; \
764             echo 'Cflags: -I$${includedir}' ) > libssl.pc
765
766 openssl.pc:
767         @ ( echo 'prefix=$(INSTALLTOP)'; \
768             echo 'exec_prefix=$${prefix}'; \
769             echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
770             echo 'includedir=$${prefix}/include'; \
771             echo ''; \
772             echo 'Name: OpenSSL'; \
773             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
774             echo 'Version: '$(VERSION); \
775             echo 'Requires: libssl libcrypto' ) > openssl.pc
776
777 # Note on the use of $(MFLAGS): this was an older variant of MAKEFLAGS which
778 # wasn't passed down automatically.  It's quite safe to use it like we do
779 # below; if it doesn't exist, the result will be empty and 'make' will pick
780 # up $(MAKEFLAGS) which is passed down as an environment variable.
781 configdata.pm: {- $config{build_file_template} -} $(SRCDIR)/Configure $(SRCDIR)/config
782         @echo "Detected changed: $?"
783         @echo "Reconfiguring..."
784         $(SRCDIR)/Configure reconf
785         @echo "**************************************************"
786         @echo "***                                            ***"
787         @echo "***   Please run the same make command again   ***"
788         @echo "***                                            ***"
789         @echo "**************************************************"
790         @false
791
792 {-
793   use File::Basename;
794   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
795
796   # Helper function to figure out dependencies on libraries
797   # It takes a list of library names and outputs a list of dependencies
798   sub compute_lib_depends {
799       if ($config{no_shared}) {
800           return map { $_."\$(LIB_EXT)" } @_;
801       }
802
803       # Depending on shared libraries:
804       # On Windows POSIX layers, we depend on {libname}.dll.a
805       # On Unix platforms, we depend on {shlibname}.so
806       return map { shlib_simple($_) } @_;
807   }
808
809   sub src2obj {
810       my %args = @_;
811       my $obj = $args{obj};
812       my $srcs = join(" ", @{$args{srcs}});
813       my $deps = join(" ", @{$args{srcs}}, @{$args{deps}});
814       my $incs = join(" ", map { " -I".$_ } @{$args{incs}});
815       my $makedepprog = $config{makedepprog};
816       if ($makedepprog eq "makedepend") {
817           return <<"EOF";
818 $obj\$(DEP_EXT): $deps
819         rm -f \$\@.tmp; touch \$\@.tmp
820         \$(MAKEDEPEND) -f\$\@.tmp -o"|$obj" -- \$(CFLAGS)$incs -- $srcs \\
821             2>/dev/null
822         sed -e 's/^.*|//' -e 's/ \\/\\(\\\\.\\|[^ ]\\)*//g' -e '/: *\$\$/d' -e '/^\\(#.*\\| *\\)\$\$/d' \$\@.tmp > \$\@
823         rm \$\@.tmp
824 $obj\$(OBJ_EXT): $obj\$(DEP_EXT)
825         \$(CC) \$(CFLAGS)$incs -c -o \$\@ $srcs
826 EOF
827       }
828       return <<"EOF";
829 $obj\$(DEP_EXT): $deps
830         \$(CC) \$(CFLAGS)$incs -MM -MF \$\@ -MQ $obj $srcs
831 $obj\$(OBJ_EXT): $obj\$(DEP_EXT)
832         \$(CC) \$(CFLAGS)$incs -c -o \$\@ $srcs
833 EOF
834   }
835   # On Unix, we build shlibs from static libs, so we're ignoring the
836   # object file array.  We *know* this routine is only called when we've
837   # configure 'shared'.
838   sub libobj2shlib {
839       my %args = @_;
840       my $lib = $args{lib};
841       my $shlib = $args{shlib};
842       my $libd = dirname($lib);
843       my $libn = basename($lib);
844       (my $libname = $libn) =~ s/^lib//;
845       my $linklibs = join("", map { my $d = dirname($_);
846                                     my $f = basename($_);
847                                     (my $l = $f) =~ s/^lib//;
848                                     " -L$d -l$l" } @{$args{deps}});
849       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
850       my $shlib_target = $target{shared_target};
851       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
852       my $target = shlib_simple($lib);
853       return <<"EOF"
854 # With a build on a Windows POSIX layer (Cygwin or Mingw), we know for a fact
855 # that two files get produced, {shlibname}.dll and {libname}.dll.a.
856 # With all other Unix platforms, we often build a shared library with the
857 # SO version built into the file name and a symlink without the SO version
858 # It's not necessary to have both as targets.  The choice falls on the
859 # simplest, {libname}\$(SHLIB_EXT_IMPORT) for Windows POSIX layers and
860 # {libname}\$(SHLIB_EXT_SIMPLE) for the Unix platforms.
861 $target : $lib\$(LIB_EXT) $deps $ordinalsfile
862         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
863                 PLATFORM=\$(PLATFORM) \\
864                 PERL=\$(PERL) SRCDIR="\$(SRCDIR)" DSTDIR="$libd" \\
865                 INSTALLTOP="\$(INSTALLTOP)" LIBDIR="\$(LIBDIR)" \\
866                 LIBDEPS="\$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)" \\
867                 LIBNAME=$libname LIBVERSION=\$(SHLIB_MAJOR).\$(SHLIB_MINOR) \\
868                 LIBCOMPATVERSIONS=";\$(SHLIB_VERSION_HISTORY)" \\
869                 CC="\$(CC)" CFLAGS="\$(CFLAGS)" LDFLAGS="\$(LDFLAGS)" \\
870                 CROSS_COMPILE="\$(CROSS_COMPILE)" \\
871                 SHARED_LDFLAGS="\$(SHARED_LDFLAGS)" SHLIB_EXT=\$(SHLIB_EXT) \\
872                 SHARED_RCFLAGS="\$(SHARED_RCFLAGS)" \\
873                 link_shlib.$shlib_target
874 EOF
875           . (windowsdll() ? <<"EOF" : "");
876         rm -f apps/$shlib\$(SHLIB_EXT)
877         rm -f test/$shlib\$(SHLIB_EXT)
878         cp -p $shlib\$(SHLIB_EXT) apps/
879         cp -p $shlib\$(SHLIB_EXT) test/
880 EOF
881   }
882   sub obj2dso {
883       my %args = @_;
884       my $lib = $args{lib};
885       my $libd = dirname($lib);
886       my $libn = basename($lib);
887       (my $libname = $libn) =~ s/^lib//;
888       my $shlibdeps = join("", map { my $d = dirname($_);
889                                      my $f = basename($_);
890                                      (my $l = $f) =~ s/^lib//;
891                                      " -L$d -l$l" } @{$args{deps}});
892       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
893       my $shlib_target = $target{shared_target};
894       my $objs = join(" ", map { $_."\$(OBJ_EXT)" } @{$args{objs}});
895       my $target = dso($lib);
896       return <<"EOF";
897 $target: $objs $deps
898         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
899                 PLATFORM=\$(PLATFORM) \\
900                 PERL=\$(PERL) SRCDIR="\$(SRCDIR)" DSTDIR="$libd" \\
901                 LIBDEPS="\$(PLIB_LDFLAGS) $shlibdeps \$(EX_LIBS)" \\
902                 LIBNAME=$libname LDFLAGS="\$(LDFLAGS)" \\
903                 CC="\$(CC)" CFLAGS="\$(CFLAGS)" \\
904                 SHARED_LDFLAGS="\$(SHARED_LDFLAGS)" \\
905                 SHLIB_EXT=\$(DSO_EXT) \\
906                 LIBEXTRAS="$objs" \\
907                 link_dso.$shlib_target
908 EOF
909   }
910   sub obj2lib {
911       my %args = @_;
912       my $lib = $args{lib};
913       my $objs = join(" ", map { $_."\$(OBJ_EXT)" } @{$args{objs}});
914       return <<"EOF";
915 $lib\$(LIB_EXT): $objs
916         \$(AR) \$\@ $objs
917         \$(RANLIB) \$\@ || echo Never mind.
918 EOF
919   }
920   sub obj2bin {
921       my %args = @_;
922       my $bin = $args{bin};
923       my $bind = dirname($bin);
924       my $binn = basename($bin);
925       my $objs = join(" ", map { $_."\$(OBJ_EXT)" } @{$args{objs}});
926       my $deps = join(" ",compute_lib_depends(@{$args{deps}}));
927       my $linklibs = join("", map { my $d = dirname($_);
928                                     my $f = basename($_);
929                                     $d = "." if $d eq $f;
930                                     (my $l = $f) =~ s/^lib//;
931                                     " -L$d -l$l" } @{$args{deps}});
932       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
933       return <<"EOF";
934 $bin\$(EXE_EXT): $objs $deps
935         \$(RM) $bin\$(EXE_EXT)
936         \$(MAKE) -f \$(SRCDIR)/Makefile.shared -e \\
937                 PERL=\$(PERL) SRCDIR=\$(SRCDIR) \\
938                 APPNAME=$bin OBJECTS="$objs" \\
939                 LIBDEPS="\$(PLIB_LDFLAGS) $linklibs \$(EX_LIBS)" \\
940                 CC="\$(CC)" CFLAGS="\$(CFLAGS)" LDFLAGS="\$(LDFLAGS)" \\
941                 LIBRPATH="\$(INSTALLTOP)/\$(LIBDIR)" \\
942                 link_app.$shlib_target
943 EOF
944   }
945   sub in2script {
946       my %args = @_;
947       my $script = $args{script};
948       my $sources = join(" ", @{$args{sources}});
949       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
950                                            "util", "dofile.pl")),
951                            rel2abs($config{builddir}));
952       return <<"EOF";
953 $script: $sources
954         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
955             "-o$target{build_file}" $sources > "$script"
956         chmod a+x $script
957 EOF
958   }
959   ""    # Important!  This becomes part of the template result.
960 -}