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