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