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