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