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