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