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