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