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