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