apps: remove NULL check imn release_engine since ENGINE_free also does it.
[openssl.git] / Configurations / unix-Makefile.tmpl
1 ##
2 ## Makefile for OpenSSL
3 ##
4 ## {- join("\n## ", @autowarntext) -}
5 {-
6      our $makedepprog = platform->makedepprog();
7
8      sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }
9
10      # Shared AIX support is special. We put libcrypto[64].so.ver into
11      # libcrypto.a and use libcrypto_a.a as static one.
12      sub sharedaix  { !$disabled{shared} && $config{target} =~ /^aix/ }
13
14      our $sover_dirname = platform->shlib_version_as_filename();
15
16      # This makes sure things get built in the order they need
17      # to. You're welcome.
18      sub dependmagic {
19          my $target = shift;
20
21          return "$target: build_generated\n\t\$(MAKE) depend && \$(MAKE) _$target\n_$target";
22      }
23
24      our $COLUMNS = $ENV{COLUMNS};
25      if ($COLUMNS =~ /^\d+$/) {
26          $COLUMNS = int($COLUMNS) - 2; # 2 to leave space for ending ' \'
27      } else {
28          $COLUMNS = 76;
29      }
30
31      sub fill_lines {
32          my $item_sep = shift;                  # string
33          my $line_length = shift;               # number of chars
34
35          my @result = ();
36          my $resultpos = 0;
37
38          foreach (@_) {
39              my $fill_line = $result[$resultpos] // '';
40              my $newline =
41                  ($fill_line eq '' ? '' : $fill_line . $item_sep) . $_;
42
43              if (length($newline) > $line_length) {
44                  # If this is a single item and the intended result line
45                  # is empty, we put it there anyway
46                  if ($fill_line eq '') {
47                      $result[$resultpos++] = $newline;
48                  } else {
49                      $result[++$resultpos] = $_;
50                  }
51              } else {
52                  $result[$resultpos] = $newline;
53              }
54          }
55          return @result;
56      }
57      '';
58 -}
59 PLATFORM={- $config{target} -}
60 OPTIONS={- $config{options} -}
61 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
62 SRCDIR={- $config{sourcedir} -}
63 BLDDIR={- $config{builddir} -}
64 FIPSKEY={- $config{FIPSKEY} -}
65
66 VERSION={- "$config{full_version}" -}
67 MAJOR={- $config{major} -}
68 MINOR={- $config{minor} -}
69 SHLIB_VERSION_NUMBER={- $config{shlib_version} -}
70 SHLIB_TARGET={- $target{shared_target} -}
71
72 LIBS={- join(" \\\n" . ' ' x 5,
73              fill_lines(" ", $COLUMNS - 5,
74                         map { platform->staticlib($_) // () }
75                         @{$unified_info{libraries}})) -}
76 SHLIBS={- join(" \\\n" . ' ' x 7,
77                fill_lines(" ", $COLUMNS - 7,
78                           map { platform->sharedlib($_) // () }
79                           @{$unified_info{libraries}})) -}
80 SHLIB_INFO={- join(" \\\n" . ' ' x 11,
81                    fill_lines(" ", $COLUMNS - 11,
82                           map { my $x = platform->sharedlib($_);
83                                 my $y = platform->sharedlib_simple($_);
84                                 $x ? "\"$x;$y\"" : () }
85                           @{$unified_info{libraries}})) -}
86 MODULES={- join(" \\\n" . ' ' x 8,
87                 fill_lines(" ", $COLUMNS - 8,
88                            map { platform->dso($_) }
89                            @{$unified_info{modules}})) -}
90 PROGRAMS={- join(" \\\n" . ' ' x 9,
91                  fill_lines(" ", $COLUMNS - 9,
92                             map { platform->bin($_) }
93                             @{$unified_info{programs}})) -}
94 SCRIPTS={- join(" \\\n" . ' ' x 8,
95                 fill_lines(" ", $COLUMNS - 8, @{$unified_info{scripts}})) -}
96 {- output_off() if $disabled{makedepend}; "" -}
97 DEPS={- join(" \\\n" . ' ' x 5,
98              fill_lines(" ", $COLUMNS - 5,
99                         map { platform->isobj($_) ? platform->dep($_) : () }
100                         grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
101                         keys %{$unified_info{sources}})); -}
102 {- output_on() if $disabled{makedepend}; "" -}
103 GENERATED_MANDATORY={- join(" \\\n" . ' ' x 20,
104                             fill_lines(" ", $COLUMNS - 20,
105                                        @{$unified_info{depends}->{""}})) -}
106 GENERATED={- # common0.tmpl provides @generated
107              join(" \\\n" . ' ' x 5,
108                   fill_lines(" ", $COLUMNS - 5,
109                              map { platform->convertext($_) } @generated )) -}
110
111 INSTALL_LIBS={-
112         join(" \\\n" . ' ' x 13,
113              fill_lines(" ", $COLUMNS - 13,
114                         map { platform->staticlib($_) // () }
115                         grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
116                         @{$unified_info{libraries}}))
117 -}
118 INSTALL_SHLIBS={-
119         join(" \\\n" . ' ' x 15,
120              fill_lines(" ", $COLUMNS - 15,
121                         map { platform->sharedlib($_) // () }
122                         grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
123                         @{$unified_info{libraries}}))
124 -}
125 INSTALL_SHLIB_INFO={-
126         join(" \\\n" . ' ' x 19,
127              fill_lines(" ", $COLUMNS - 19,
128                         map { my $x = platform->sharedlib($_);
129                               my $y = platform->sharedlib_simple($_);
130                               $x ? "\"$x;$y\"" : () }
131                         grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
132                         @{$unified_info{libraries}}))
133 -}
134 INSTALL_ENGINES={-
135         join(" \\\n" . ' ' x 16,
136              fill_lines(" ", $COLUMNS - 16,
137                         map { platform->dso($_) }
138                         grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
139                                && $unified_info{attributes}->{modules}->{$_}->{engine} }
140                         @{$unified_info{modules}}))
141 -}
142 INSTALL_MODULES={-
143         join(" \\\n" . ' ' x 16,
144              fill_lines(" ", $COLUMNS - 16,
145                         map { platform->dso($_) }
146                         grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
147                                && !$unified_info{attributes}->{modules}->{$_}->{engine} }
148                         @{$unified_info{modules}}))
149 -}
150 INSTALL_PROGRAMS={-
151         join(" \\\n" . ' ' x 16,
152              fill_lines(" ", $COLUMNS - 16, map { platform->bin($_) }
153                         grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
154                         @{$unified_info{programs}}))
155 -}
156 BIN_SCRIPTS={-
157         join(" \\\n" . ' ' x 12,
158              fill_lines(" ", $COLUMNS - 12,
159                         map { my $x = $unified_info{attributes}->{scripts}->{$_}->{linkname};
160                               $x ? "$_:$x" : $_ }
161                         grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
162                                && !$unified_info{attributes}->{scripts}->{$_}->{misc} }
163                         @{$unified_info{scripts}}))
164 -}
165 MISC_SCRIPTS={-
166         join(" \\\n" . ' ' x 13,
167              fill_lines(" ", $COLUMNS - 13,
168                         map { my $x = $unified_info{attributes}->{scripts}->{$_}->{linkname};
169                               $x ? "$_:$x" : $_ }
170                         grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
171                                && $unified_info{attributes}->{scripts}->{$_}->{misc} }
172                         @{$unified_info{scripts}}))
173 -}
174 HTMLDOCS1={-
175         join(" \\\n" . ' ' x 10,
176              fill_lines(" ", $COLUMNS - 10, map { platform->bin($_) }
177                         @{$unified_info{htmldocs}->{man1}})) -}
178 HTMLDOCS3={-
179         join(" \\\n" . ' ' x 10,
180              fill_lines(" ", $COLUMNS - 10, map { platform->bin($_) }
181                         @{$unified_info{htmldocs}->{man3}})) -}
182 HTMLDOCS5={-
183         join(" \\\n" . ' ' x 10,
184              fill_lines(" ", $COLUMNS - 10, map { platform->bin($_) }
185                         @{$unified_info{htmldocs}->{man5}})) -}
186 HTMLDOCS7={-
187         join(" \\\n" . ' ' x 10,
188              fill_lines(" ", $COLUMNS - 10, map { platform->bin($_) }
189                         @{$unified_info{htmldocs}->{man7}})) -}
190 MANDOCS1={-
191         join(" \\\n" . ' ' x 9,
192              fill_lines(" ", $COLUMNS - 9, map { platform->bin($_) }
193                         @{$unified_info{mandocs}->{man1}})) -}
194 MANDOCS3={-
195         join(" \\\n" . ' ' x 9,
196              fill_lines(" ", $COLUMNS - 9, map { platform->bin($_) }
197                         @{$unified_info{mandocs}->{man3}})) -}
198 MANDOCS5={-
199         join(" \\\n" . ' ' x 9,
200              fill_lines(" ", $COLUMNS - 9, map { platform->bin($_) }
201                         @{$unified_info{mandocs}->{man5}})) -}
202 MANDOCS7={-
203         join(" \\\n" . ' ' x 9,
204              fill_lines(" ", $COLUMNS - 9, map { platform->bin($_) }
205                         @{$unified_info{mandocs}->{man7}})) -}
206
207 APPS_OPENSSL="{- use File::Spec::Functions;
208                  catfile("apps","openssl") -}"
209
210 # DESTDIR is for package builders so that they can configure for, say,
211 # /usr/ and yet have everything installed to /tmp/somedir/usr/.
212 # Normally it is left empty.
213 DESTDIR=
214
215 # Do not edit these manually. Use Configure with --prefix or --openssldir
216 # to change this!  Short explanation in the top comment in Configure
217 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
218               #
219               our $prefix = $config{prefix} || "/usr/local";
220               $prefix -}
221 OPENSSLDIR={- #
222               # The logic here is that if no --openssldir was given,
223               # OPENSSLDIR will get the value from $prefix plus "/ssl".
224               # If --openssldir was given and the value is an absolute
225               # path, OPENSSLDIR will get its value without change.
226               # If the value from --openssldir is a relative path,
227               # OPENSSLDIR will get $prefix with the --openssldir
228               # value appended as a subdirectory.
229               #
230               use File::Spec::Functions;
231               our $openssldir =
232                   $config{openssldir} ?
233                       (file_name_is_absolute($config{openssldir}) ?
234                            $config{openssldir}
235                            : catdir($prefix, $config{openssldir}))
236                       : catdir($prefix, "ssl");
237               $openssldir -}
238 LIBDIR={- our $libdir = $config{libdir};
239           unless ($libdir) {
240               #
241               # if $prefix/lib$target{multilib} is not an existing
242               # directory, then assume that it's not searched by linker
243               # automatically, in which case adding $target{multilib} suffix
244               # causes more grief than we're ready to tolerate, so don't...
245               our $multilib =
246                   -d "$prefix/lib$target{multilib}" ? $target{multilib} : "";
247               $libdir = "lib$multilib";
248           }
249           file_name_is_absolute($libdir) ? "" : $libdir -}
250 # $(libdir) is chosen to be compatible with the GNU coding standards
251 libdir={- file_name_is_absolute($libdir)
252           ? $libdir : '$(INSTALLTOP)/$(LIBDIR)' -}
253 ENGINESDIR=$(libdir)/engines-{- $sover_dirname -}
254 MODULESDIR=$(libdir)/ossl-modules
255
256 # Convenience variable for those who want to set the rpath in shared
257 # libraries and applications
258 LIBRPATH=$(libdir)
259
260 MANDIR=$(INSTALLTOP)/share/man
261 DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)
262 HTMLDIR=$(DOCDIR)/html
263
264 # MANSUFFIX is for the benefit of anyone who may want to have a suffix
265 # appended after the manpage file section number.  "ssl" is popular,
266 # resulting in files such as config.5ssl rather than config.5.
267 MANSUFFIX=
268 HTMLSUFFIX=html
269
270 # For "optional" echo messages, to get "real" silence
271 ECHO = echo
272
273 ##### User defined commands and flags ################################
274
275 # We let the C compiler driver to take care of .s files. This is done in
276 # order to be excused from maintaining a separate set of architecture
277 # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
278 # gcc, then the driver will automatically translate it to -xarch=v8plus
279 # and pass it down to assembler.  In any case, we do not define AS or
280 # ASFLAGS for this reason.
281
282 CROSS_COMPILE={- $config{CROSS_COMPILE} -}
283 CC=$(CROSS_COMPILE){- $config{CC} -}
284 CXX={- $config{CXX} ? "\$(CROSS_COMPILE)$config{CXX}" : '' -}
285 CPPFLAGS={- our $cppflags1 = join(" ",
286                                   (map { "-D".$_} @{$config{CPPDEFINES}}),
287                                   (map { "-I".$_} @{$config{CPPINCLUDES}}),
288                                   @{$config{CPPFLAGS}}) -}
289 CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
290 CXXFLAGS={- join(' ', @{$config{CXXFLAGS}}) -}
291 LDFLAGS= {- join(' ', @{$config{LDFLAGS}}) -}
292 EX_LIBS= {- join(' ', @{$config{LDLIBS}}) -}
293
294 MAKEDEPEND={- $config{makedepprog} -}
295
296 PERL={- $config{PERL} -}
297
298 AR=$(CROSS_COMPILE){- $config{AR} -}
299 ARFLAGS= {- join(' ', @{$config{ARFLAGS}}) -}
300 RANLIB={- $config{RANLIB} ? "\$(CROSS_COMPILE)$config{RANLIB}" : "true"; -}
301 RC= $(CROSS_COMPILE){- $config{RC} -}
302 RCFLAGS={- join(' ', @{$config{RCFLAGS}}) -} {- $target{shared_rcflag} -}
303
304 RM= rm -f
305 RMDIR= rmdir
306 TAR= {- $target{TAR} || "tar" -}
307 TARFLAGS= {- $target{TARFLAGS} -}
308
309 BASENAME=       openssl
310 NAME=           $(BASENAME)-$(VERSION)
311 # Relative to $(SRCDIR)
312 TARFILE=        ../$(NAME).tar
313
314 ##### Project flags ##################################################
315
316 # Variables starting with CNF_ are common variables for all product types
317
318 CNF_CPPFLAGS={- our $cppflags2 =
319                     join(' ', $target{cppflags} || (),
320                               (map { "-D".$_} @{$target{defines}},
321                                               @{$config{defines}}),
322                               (map { "-I".$_} @{$target{includes}},
323                                               @{$config{includes}}),
324                               @{$config{cppflags}}) -}
325 CNF_CFLAGS={- join(' ', $target{cflags} || (),
326                         @{$config{cflags}}) -}
327 CNF_CXXFLAGS={- join(' ', $target{cxxflags} || (),
328                           @{$config{cxxflags}}) -}
329 CNF_LDFLAGS={- join(' ', $target{lflags} || (),
330                          @{$config{lflags}}) -}
331 CNF_EX_LIBS={- join(' ', $target{ex_libs} || (),
332                          @{$config{ex_libs}}) -}
333
334 # Variables starting with LIB_ are used to build library object files
335 # and shared libraries.
336 # Variables starting with DSO_ are used to build DSOs and their object files.
337 # Variables starting with BIN_ are used to build programs and their object
338 # files.
339
340 LIB_CPPFLAGS={- our $lib_cppflags =
341                 join(' ', $target{lib_cppflags} || (),
342                           $target{shared_cppflag} || (),
343                           (map { '-D'.$_ }
344                                @{$target{lib_defines} || ()},
345                                @{$target{shared_defines} || ()},
346                                @{$config{lib_defines} || ()},
347                                @{$config{shared_defines} || ()}),
348                           (map { '-I'.quotify1($_) }
349                                @{$target{lib_includes}},
350                                @{$target{shared_includes}},
351                                @{$config{lib_includes}},
352                                @{$config{shared_includes}}),
353                           @{$config{lib_cppflags}},
354                           @{$config{shared_cppflag}});
355                 join(' ', $lib_cppflags,
356                           (map { '-D'.$_ }
357                                'OPENSSLDIR="\"$(OPENSSLDIR)\""',
358                                'ENGINESDIR="\"$(ENGINESDIR)\""',
359                                'MODULESDIR="\"$(MODULESDIR)\""'),
360                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
361 LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
362                         $target{shared_cflag} || (),
363                         @{$config{lib_cflags}},
364                         @{$config{shared_cflag}},
365                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
366 LIB_CXXFLAGS={- join(' ', $target{lib_cxxflags} || (),
367                           $target{shared_cxxflag} || (),
368                           @{$config{lib_cxxflags}},
369                           @{$config{shared_cxxflag}},
370                           '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
371 LIB_LDFLAGS={- join(' ', $target{shared_ldflag} || (),
372                          $config{shared_ldflag} || (),
373                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
374 LIB_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
375 DSO_CPPFLAGS={- join(' ', $target{dso_cppflags} || (),
376                           $target{module_cppflags} || (),
377                           (map { '-D'.$_ }
378                                @{$target{dso_defines}},
379                                @{$target{module_defines}},
380                                @{$config{dso_defines} || ()},
381                                @{$config{module_defines} || ()}),
382                           (map { '-I'.quotify1($_) }
383                                @{$target{dso_includes}},
384                                @{$target{module_includes}},
385                                @{$config{dso_includes}},
386                                @{$config{module_includes}}),
387                           @{$config{dso_cppflags}},
388                           @{$config{module_cppflags}},
389                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
390 DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
391                         $target{module_cflags} || (),
392                         @{$config{dso_cflags}},
393                         @{$config{module_cflags}},
394                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
395 DSO_CXXFLAGS={- join(' ', $target{dso_cxxflags} || (),
396                           $target{module_cxxflags} || (),
397                           @{$config{dso_cxxflags}},
398                           @{$config{module_cxxflag}},
399                           '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
400 DSO_LDFLAGS={- join(' ', $target{dso_ldflags} || (),
401                          $target{module_ldflags} || (),
402                          @{$config{dso_ldflags}},
403                          @{$config{module_ldflags}},
404                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
405 DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
406 BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
407                           (map { '-D'.$_ } @{$config{bin_defines} || ()}),
408                           @{$config{bin_cppflags}},
409                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
410 BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
411                         @{$config{bin_cflags}},
412                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
413 BIN_CXXFLAGS={- join(' ', $target{bin_cxxflags} || (),
414                           @{$config{bin_cxxflags}},
415                           '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
416 BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
417                          @{$config{bin_lflags}},
418                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
419 BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
420
421 # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
422 CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
423               $cppflags2 =~ s|([\\"])|\\$1|g;
424               $lib_cppflags =~ s|([\\"])|\\$1|g;
425               join(' ', $lib_cppflags || (), $cppflags2 || (),
426                         $cppflags1 || ()) -}
427
428 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
429
430 # For x86 assembler: Set PROCESSOR to 386 if you want to support
431 # the 80386.
432 PROCESSOR= {- $config{processor} -}
433
434 # We want error [and other] messages in English. Trouble is that make(1)
435 # doesn't pass macros down as environment variables unless there already
436 # was corresponding variable originally set. In other words we can only
437 # reassign environment variables, but not set new ones, not in portable
438 # manner that is. That's why we reassign several, just to be sure...
439 LC_ALL=C
440 LC_MESSAGES=C
441 LANG=C
442
443 # The main targets ###################################################
444
445 {- dependmagic('build_sw'); -}: build_libs_nodep build_modules_nodep build_programs_nodep link-utils
446 {- dependmagic('build_libs'); -}: build_libs_nodep
447 {- dependmagic('build_modules'); -}: build_modules_nodep
448 {- dependmagic('build_programs'); -}: build_programs_nodep
449
450 build_docs: build_man_docs build_html_docs
451 build_man_docs: $(MANDOCS1) $(MANDOCS3) $(MANDOCS5) $(MANDOCS7)
452 build_html_docs: $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
453
454 build_generated: $(GENERATED_MANDATORY)
455 build_libs_nodep: libcrypto.pc libssl.pc openssl.pc
456 build_modules_nodep: $(MODULES)
457 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
458
459 # Kept around for backward compatibility
460 build_apps build_tests: build_programs
461
462 # Convenience target to prebuild all generated files, not just the mandatory
463 # ones
464 build_all_generated: $(GENERATED_MANDATORY) $(GENERATED) build_docs
465         @ : {- output_off() if $disabled{makedepend}; "" -}
466         @echo "Warning: consider configuring with no-makedepend, because if"
467         @echo "         target system doesn't have $(PERL),"
468         @echo "         then make will fail..."
469         @ : {- output_on() if $disabled{makedepend}; "" -}
470
471 all: build_sw build_docs
472
473 test: tests
474 {- dependmagic('tests'); -}: build_programs_nodep build_modules_nodep link-utils
475         @ : {- output_off() if $disabled{tests}; "" -}
476         ( SRCTOP=$(SRCDIR) \
477           BLDTOP=$(BLDDIR) \
478           PERL="$(PERL)" \
479           FIPSKEY="$(FIPSKEY)" \
480           EXE_EXT={- platform->binext() -} \
481           $(PERL) $(SRCDIR)/test/run_tests.pl $(TESTS) )
482         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
483         @echo "Tests are not supported with your chosen Configure options"
484         @ : {- output_on() if !$disabled{tests}; "" -}
485
486 list-tests:
487         @ : {- output_off() if $disabled{tests}; "" -}
488         @SRCTOP="$(SRCDIR)" \
489          $(PERL) $(SRCDIR)/test/run_tests.pl list
490         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
491         @echo "Tests are not supported with your chosen Configure options"
492         @ : {- output_on() if !$disabled{tests}; "" -}
493
494 install: install_sw install_ssldirs install_docs
495
496 uninstall: uninstall_docs uninstall_sw
497
498 libclean:
499         @set -e; for s in $(SHLIB_INFO); do \
500                 if [ "$$s" = ";" ]; then continue; fi; \
501                 s1=`echo "$$s" | cut -f1 -d";"`; \
502                 s2=`echo "$$s" | cut -f2 -d";"`; \
503                 $(ECHO) $(RM) $$s1; {- output_off() unless windowsdll(); "" -}\
504                 $(RM) apps/$$s1; \
505                 $(RM) test/$$s1; \
506                 $(RM) fuzz/$$s1; {- output_on() unless windowsdll(); "" -}\
507                 $(RM) $$s1; \
508                 if [ "$$s1" != "$$s2" ]; then \
509                         $(ECHO) $(RM) $$s2; \
510                         $(RM) $$s2; \
511                 fi; \
512         done
513         $(RM) $(LIBS)
514         $(RM) *{- platform->defext() -}
515
516 clean: libclean
517         $(RM) $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
518         $(RM) $(MANDOCS1) $(MANDOCS3) $(MANDOCS5) $(MANDOCS7)
519         $(RM) $(PROGRAMS) $(TESTPROGS) $(MODULES) $(SCRIPTS)
520         $(RM) $(GENERATED_MANDATORY) $(GENERATED)
521         -$(RM) `find . -name '*{- platform->depext() -}' \! -name '.*' \! -type d -print`
522         -$(RM) `find . -name '*{- platform->objext() -}' \! -name '.*' \! -type d -print`
523         $(RM) core
524         $(RM) tags TAGS doc-nits cmd-nits md-nits
525         $(RM) -r test/test-runs
526         $(RM) openssl.pc libcrypto.pc libssl.pc
527         -$(RM) `find . -type l \! -name '.*' -print`
528         $(RM) $(TARFILE)
529
530 distclean: clean
531         $(RM) configdata.pm
532         $(RM) Makefile
533
534 # We check if any depfile is newer than Makefile and decide to
535 # concatenate only if that is true.
536 depend:
537         @: {- output_off() if $disabled{makedepend}; "" -}
538         @$(PERL) $(SRCDIR)/util/add-depends.pl {-
539                  defined $makedepprog  && $makedepprog =~ /\/makedepend/
540                  ? 'makedepend' : 'gcc' -}
541         @: {- output_on() if $disabled{makedepend}; "" -}
542
543 # Install helper targets #############################################
544
545 install_sw: install_dev install_engines install_modules install_runtime
546
547 uninstall_sw: uninstall_runtime uninstall_modules uninstall_engines uninstall_dev
548
549 install_docs: install_man_docs install_html_docs
550
551 uninstall_docs: uninstall_man_docs uninstall_html_docs
552         $(RM) -r $(DESTDIR)$(DOCDIR)
553
554 install_ssldirs:
555         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/certs
556         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/private
557         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/misc
558         @set -e; for x in dummy $(MISC_SCRIPTS); do \
559                 if [ "$$x" = "dummy" ]; then continue; fi; \
560                 x1=`echo "$$x" | cut -f1 -d:`; \
561                 x2=`echo "$$x" | cut -f2 -d:`; \
562                 fn=`basename $$x1`; \
563                 $(ECHO) "install $$x1 -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
564                 cp $$x1 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
565                 chmod 755 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
566                 mv -f $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new \
567                       $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
568                 if [ "$$x1" != "$$x2" ]; then \
569                         ln=`basename "$$x2"`; \
570                         : {- output_off() unless windowsdll(); "" -}; \
571                         $(ECHO) "copy $(DESTDIR)$(OPENSSLDIR)/misc/$$ln -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
572                         cp $(DESTDIR)$(OPENSSLDIR)/misc/$$fn $(DESTDIR)$(OPENSSLDIR)/misc/$$ln; \
573                         : {- output_on() unless windowsdll();
574                              output_off() if windowsdll(); "" -}; \
575                         $(ECHO) "link $(DESTDIR)$(OPENSSLDIR)/misc/$$ln -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
576                         ln -sf $$fn $(DESTDIR)$(OPENSSLDIR)/misc/$$ln; \
577                         : {- output_on() if windowsdll(); "" -}; \
578                 fi; \
579         done
580         @$(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist"
581         @cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
582         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
583         @mv -f  $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist
584         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf" ]; then \
585                 $(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
586                 cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
587                 chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
588         fi
589         @$(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist"
590         @cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
591         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
592         @mv -f  $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist
593         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf" ]; then \
594                 $(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
595                 cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
596                 chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
597         fi
598
599 install_dev: install_runtime_libs
600         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
601         @$(ECHO) "*** Installing development files"
602         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/include/openssl
603         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
604         @$(ECHO) "install $(SRCDIR)/ms/applink.c -> $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
605         @cp $(SRCDIR)/ms/applink.c $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
606         @chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
607         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
608         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
609                           $(BLDDIR)/include/openssl/*.h; do \
610                 fn=`basename $$i`; \
611                 $(ECHO) "install $$i -> $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
612                 cp $$i $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
613                 chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
614         done
615         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(libdir)
616         @set -e; for l in $(INSTALL_LIBS); do \
617                 fn=`basename $$l`; \
618                 $(ECHO) "install $$l -> $(DESTDIR)$(libdir)/$$fn"; \
619                 cp $$l $(DESTDIR)$(libdir)/$$fn.new; \
620                 $(RANLIB) $(DESTDIR)$(libdir)/$$fn.new; \
621                 chmod 644 $(DESTDIR)$(libdir)/$$fn.new; \
622                 mv -f $(DESTDIR)$(libdir)/$$fn.new \
623                       $(DESTDIR)$(libdir)/$$fn; \
624         done
625         @ : {- output_off() if $disabled{shared}; "" -}
626         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
627                 s1=`echo "$$s" | cut -f1 -d";"`; \
628                 s2=`echo "$$s" | cut -f2 -d";"`; \
629                 fn1=`basename $$s1`; \
630                 fn2=`basename $$s2`; \
631                 : {- output_off(); output_on() unless windowsdll() or sharedaix(); "" -}; \
632                 if [ "$$fn1" != "$$fn2" ]; then \
633                         $(ECHO) "link $(DESTDIR)$(libdir)/$$fn2 -> $(DESTDIR)$(libdir)/$$fn1"; \
634                         ln -sf $$fn1 $(DESTDIR)$(libdir)/$$fn2; \
635                 fi; \
636                 : {- output_off() unless windowsdll() or sharedaix(); output_on() if windowsdll(); "" -}; \
637                 $(ECHO) "install $$s2 -> $(DESTDIR)$(libdir)/$$fn2"; \
638                 cp $$s2 $(DESTDIR)$(libdir)/$$fn2.new; \
639                 chmod 755 $(DESTDIR)$(libdir)/$$fn2.new; \
640                 mv -f $(DESTDIR)$(libdir)/$$fn2.new \
641                       $(DESTDIR)$(libdir)/$$fn2; \
642                 : {- output_off() if windowsdll(); output_on() if sharedaix(); "" -}; \
643                 a=$(DESTDIR)$(libdir)/$$fn2; \
644                 $(ECHO) "install $$s1 -> $$a"; \
645                 if [ -f $$a ]; then ( trap "rm -rf /tmp/ar.$$$$" INT 0; \
646                         mkdir /tmp/ar.$$$$; ( cd /tmp/ar.$$$$; \
647                         cp -f $$a $$a.new; \
648                         for so in `$(AR) t $$a`; do \
649                                 $(AR) x $$a $$so; \
650                                 chmod u+w $$so; \
651                                 strip -X32_64 -e $$so; \
652                                 $(AR) r $$a.new $$so; \
653                         done; \
654                 )); fi; \
655                 $(AR) r $$a.new $$s1; \
656                 mv -f $$a.new $$a; \
657                 : {- output_off() if sharedaix(); output_on(); "" -}; \
658         done
659         @ : {- output_on() if $disabled{shared}; "" -}
660         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(libdir)/pkgconfig
661         @$(ECHO) "install libcrypto.pc -> $(DESTDIR)$(libdir)/pkgconfig/libcrypto.pc"
662         @cp libcrypto.pc $(DESTDIR)$(libdir)/pkgconfig
663         @chmod 644 $(DESTDIR)$(libdir)/pkgconfig/libcrypto.pc
664         @$(ECHO) "install libssl.pc -> $(DESTDIR)$(libdir)/pkgconfig/libssl.pc"
665         @cp libssl.pc $(DESTDIR)$(libdir)/pkgconfig
666         @chmod 644 $(DESTDIR)$(libdir)/pkgconfig/libssl.pc
667         @$(ECHO) "install openssl.pc -> $(DESTDIR)$(libdir)/pkgconfig/openssl.pc"
668         @cp openssl.pc $(DESTDIR)$(libdir)/pkgconfig
669         @chmod 644 $(DESTDIR)$(libdir)/pkgconfig/openssl.pc
670
671 uninstall_dev: uninstall_runtime_libs
672         @$(ECHO) "*** Uninstalling development files"
673         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
674         @$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
675         @$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
676         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
677         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
678                           $(BLDDIR)/include/openssl/*.h; do \
679                 fn=`basename $$i`; \
680                 $(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
681                 $(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
682         done
683         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include/openssl
684         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include
685         @set -e; for l in $(INSTALL_LIBS); do \
686                 fn=`basename $$l`; \
687                 $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn"; \
688                 $(RM) $(DESTDIR)$(libdir)/$$fn; \
689         done
690         @ : {- output_off() if $disabled{shared}; "" -}
691         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
692                 s1=`echo "$$s" | cut -f1 -d";"`; \
693                 s2=`echo "$$s" | cut -f2 -d";"`; \
694                 fn1=`basename $$s1`; \
695                 fn2=`basename $$s2`; \
696                 : {- output_off() if windowsdll(); "" -}; \
697                 $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn2"; \
698                 $(RM) $(DESTDIR)$(libdir)/$$fn2; \
699                 if [ "$$fn1" != "$$fn2" -a -f "$(DESTDIR)$(libdir)/$$fn1" ]; then \
700                         $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn1"; \
701                         $(RM) $(DESTDIR)$(libdir)/$$fn1; \
702                 fi; \
703                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
704                 $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn2"; \
705                 $(RM) $(DESTDIR)$(libdir)/$$fn2; \
706                 : {- output_on() unless windowsdll(); "" -}; \
707         done
708         @ : {- output_on() if $disabled{shared}; "" -}
709         $(RM) $(DESTDIR)$(libdir)/pkgconfig/libcrypto.pc
710         $(RM) $(DESTDIR)$(libdir)/pkgconfig/libssl.pc
711         $(RM) $(DESTDIR)$(libdir)/pkgconfig/openssl.pc
712         -$(RMDIR) $(DESTDIR)$(libdir)/pkgconfig
713         -$(RMDIR) $(DESTDIR)$(libdir)
714
715 _install_modules_deps: install_runtime_libs build_modules
716
717 install_engines: _install_modules_deps
718         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
719         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(ENGINESDIR)/
720         @$(ECHO) "*** Installing engines"
721         @set -e; for e in dummy $(INSTALL_ENGINES); do \
722                 if [ "$$e" = "dummy" ]; then continue; fi; \
723                 fn=`basename $$e`; \
724                 $(ECHO) "install $$e -> $(DESTDIR)$(ENGINESDIR)/$$fn"; \
725                 cp $$e $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
726                 chmod 755 $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
727                 mv -f $(DESTDIR)$(ENGINESDIR)/$$fn.new \
728                       $(DESTDIR)$(ENGINESDIR)/$$fn; \
729         done
730
731 uninstall_engines:
732         @$(ECHO) "*** Uninstalling engines"
733         @set -e; for e in dummy $(INSTALL_ENGINES); do \
734                 if [ "$$e" = "dummy" ]; then continue; fi; \
735                 fn=`basename $$e`; \
736                 if [ "$$fn" = '{- platform->dso("ossltest") -}' ]; then \
737                         continue; \
738                 fi; \
739                 $(ECHO) "$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn"; \
740                 $(RM) $(DESTDIR)$(ENGINESDIR)/$$fn; \
741         done
742         -$(RMDIR) $(DESTDIR)$(ENGINESDIR)
743
744 install_modules: _install_modules_deps
745         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
746         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MODULESDIR)/
747         @$(ECHO) "*** Installing modules"
748         @set -e; for e in dummy $(INSTALL_MODULES); do \
749                 if [ "$$e" = "dummy" ]; then continue; fi; \
750                 fn=`basename $$e`; \
751                 $(ECHO) "install $$e -> $(DESTDIR)$(MODULESDIR)/$$fn"; \
752                 cp $$e $(DESTDIR)$(MODULESDIR)/$$fn.new; \
753                 chmod 755 $(DESTDIR)$(MODULESDIR)/$$fn.new; \
754                 mv -f $(DESTDIR)$(MODULESDIR)/$$fn.new \
755                       $(DESTDIR)$(MODULESDIR)/$$fn; \
756         done
757
758 uninstall_modules:
759         @$(ECHO) "*** Uninstalling modules"
760         @set -e; for e in dummy $(INSTALL_MODULES); do \
761                 if [ "$$e" = "dummy" ]; then continue; fi; \
762                 fn=`basename $$e`; \
763                 if [ "$$fn" = '{- platform->dso("ossltest") -}' ]; then \
764                         continue; \
765                 fi; \
766                 $(ECHO) "$(RM) $(DESTDIR)$(MODULESDIR)/$$fn"; \
767                 $(RM) $(DESTDIR)$(MODULESDIR)/$$fn; \
768         done
769         -$(RMDIR) $(DESTDIR)$(MODULESDIR)
770
771 install_runtime: install_programs
772
773 install_runtime_libs: build_libs
774         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
775         @ : {- output_off() if windowsdll(); "" -}
776         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(libdir)
777         @ : {- output_on() if windowsdll(); output_off() unless windowsdll(); "" -}
778         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
779         @ : {- output_on() unless windowsdll(); "" -}
780         @$(ECHO) "*** Installing runtime libraries"
781         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
782                 if [ "$$s" = "dummy" ]; then continue; fi; \
783                 fn=`basename $$s`; \
784                 : {- output_off() unless windowsdll(); "" -}; \
785                 $(ECHO) "install $$s -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
786                 cp $$s $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
787                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
788                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
789                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
790                 : {- output_on() unless windowsdll(); "" -}{- output_off() if windowsdll(); "" -}; \
791                 $(ECHO) "install $$s -> $(DESTDIR)$(libdir)/$$fn"; \
792                 cp $$s $(DESTDIR)$(libdir)/$$fn.new; \
793                 chmod 755 $(DESTDIR)$(libdir)/$$fn.new; \
794                 mv -f $(DESTDIR)$(libdir)/$$fn.new \
795                       $(DESTDIR)$(libdir)/$$fn; \
796                 : {- output_on() if windowsdll(); "" -}; \
797         done
798
799 install_programs: install_runtime_libs build_programs
800         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
801         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
802         @$(ECHO) "*** Installing runtime programs"
803         @set -e; for x in dummy $(INSTALL_PROGRAMS); do \
804                 if [ "$$x" = "dummy" ]; then continue; fi; \
805                 fn=`basename $$x`; \
806                 $(ECHO) "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
807                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
808                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
809                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
810                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
811         done
812         @set -e; for x in dummy $(BIN_SCRIPTS); do \
813                 if [ "$$x" = "dummy" ]; then continue; fi; \
814                 fn=`basename $$x`; \
815                 $(ECHO) "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
816                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
817                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
818                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
819                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
820         done
821
822 uninstall_runtime: uninstall_programs uninstall_runtime_libs
823
824 uninstall_programs:
825         @$(ECHO) "*** Uninstalling runtime programs"
826         @set -e; for x in dummy $(INSTALL_PROGRAMS); \
827         do  \
828                 if [ "$$x" = "dummy" ]; then continue; fi; \
829                 fn=`basename $$x`; \
830                 $(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
831                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
832         done;
833         @set -e; for x in dummy $(BIN_SCRIPTS); \
834         do  \
835                 if [ "$$x" = "dummy" ]; then continue; fi; \
836                 fn=`basename $$x`; \
837                 $(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
838                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
839         done
840         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin
841
842 uninstall_runtime_libs:
843         @$(ECHO) "*** Uninstalling runtime libraries"
844         @ : {- output_off() unless windowsdll(); "" -}
845         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
846                 if [ "$$s" = "dummy" ]; then continue; fi; \
847                 fn=`basename $$s`; \
848                 $(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
849                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
850         done
851         @ : {- output_on() unless windowsdll(); "" -}
852
853
854 install_man_docs: build_man_docs
855         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
856         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MANDIR)/man1
857         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MANDIR)/man3
858         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MANDIR)/man5
859         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MANDIR)/man7
860         @$(ECHO) "*** Installing manpages"
861         @set -e; for x in dummy $(MANDOCS1); do \
862                 if [ "$$x" = "dummy" ]; then continue; fi; \
863                 fn=`basename $$x`; \
864                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX)"; \
865                 cp $$x $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX); \
866                 chmod 755 $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX); \
867         done
868         @set -e; for x in dummy $(MANDOCS3); do \
869                 if [ "$$x" = "dummy" ]; then continue; fi; \
870                 fn=`basename $$x`; \
871                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX)"; \
872                 cp $$x $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX); \
873                 chmod 755 $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX); \
874         done
875         @set -e; for x in dummy $(MANDOCS5); do \
876                 if [ "$$x" = "dummy" ]; then continue; fi; \
877                 fn=`basename $$x`; \
878                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX)"; \
879                 cp $$x $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX); \
880                 chmod 755 $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX); \
881         done
882         @set -e; for x in dummy $(MANDOCS7); do \
883                 if [ "$$x" = "dummy" ]; then continue; fi; \
884                 fn=`basename $$x`; \
885                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX)"; \
886                 cp $$x $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX); \
887                 chmod 755 $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX); \
888         done
889
890 uninstall_man_docs:
891         @$(ECHO) "*** Uninstalling manpages"
892         @set -e; for x in dummy $(MANDOCS1); do \
893                 if [ "$$x" = "dummy" ]; then continue; fi; \
894                 fn=`basename $$x`; \
895                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX)"; \
896                 $(RM) $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX); \
897         done
898         @set -e; for x in dummy $(MANDOCS3); do \
899                 if [ "$$x" = "dummy" ]; then continue; fi; \
900                 fn=`basename $$x`; \
901                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX)"; \
902                 $(RM) $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX); \
903         done
904         @set -e; for x in dummy $(MANDOCS5); do \
905                 if [ "$$x" = "dummy" ]; then continue; fi; \
906                 fn=`basename $$x`; \
907                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX)"; \
908                 $(RM) $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX); \
909         done
910         @set -e; for x in dummy $(MANDOCS7); do \
911                 if [ "$$x" = "dummy" ]; then continue; fi; \
912                 fn=`basename $$x`; \
913                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX)"; \
914                 $(RM) $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX); \
915         done
916
917 install_html_docs: build_html_docs
918         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
919         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(HTMLDIR)/man1
920         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(HTMLDIR)/man3
921         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(HTMLDIR)/man5
922         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(HTMLDIR)/man7
923         @$(ECHO) "*** Installing HTML manpages"
924         @set -e; for x in dummy $(HTMLDOCS1); do \
925                 if [ "$$x" = "dummy" ]; then continue; fi; \
926                 fn=`basename $$x`; \
927                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man1/$$fn"; \
928                 cp $$x $(DESTDIR)$(HTMLDIR)/man1/$$fn; \
929                 chmod 755 $(DESTDIR)$(HTMLDIR)/man1/$$fn; \
930         done
931         @set -e; for x in dummy $(HTMLDOCS3); do \
932                 if [ "$$x" = "dummy" ]; then continue; fi; \
933                 fn=`basename $$x`; \
934                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man3/$$fn"; \
935                 cp $$x $(DESTDIR)$(HTMLDIR)/man3/$$fn; \
936                 chmod 755 $(DESTDIR)$(HTMLDIR)/man3/$$fn; \
937         done
938         @set -e; for x in dummy $(HTMLDOCS5); do \
939                 if [ "$$x" = "dummy" ]; then continue; fi; \
940                 fn=`basename $$x`; \
941                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man5/$$fn"; \
942                 cp $$x $(DESTDIR)$(HTMLDIR)/man5/$$fn; \
943                 chmod 755 $(DESTDIR)$(HTMLDIR)/man5/$$fn; \
944         done
945         @set -e; for x in dummy $(HTMLDOCS7); do \
946                 if [ "$$x" = "dummy" ]; then continue; fi; \
947                 fn=`basename $$x`; \
948                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man7/$$fn"; \
949                 cp $$x $(DESTDIR)$(HTMLDIR)/man7/$$fn; \
950                 chmod 755 $(DESTDIR)$(HTMLDIR)/man7/$$fn; \
951         done
952
953 uninstall_html_docs:
954         @$(ECHO) "*** Uninstalling HTML manpages"
955         @set -e; for x in dummy $(HTMLDOCS1); do \
956                 if [ "$$x" = "dummy" ]; then continue; fi; \
957                 fn=`basename $$x`; \
958                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man1/$$fn"; \
959                 $(RM) $(DESTDIR)$(HTMLDIR)/man1/$$fn; \
960         done
961         @set -e; for x in dummy $(HTMLDOCS3); do \
962                 if [ "$$x" = "dummy" ]; then continue; fi; \
963                 fn=`basename $$x`; \
964                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man3/$$fn"; \
965                 $(RM) $(DESTDIR)$(HTMLDIR)/man3/$$fn; \
966         done
967         @set -e; for x in dummy $(HTMLDOCS5); do \
968                 if [ "$$x" = "dummy" ]; then continue; fi; \
969                 fn=`basename $$x`; \
970                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man5/$$fn"; \
971                 $(RM) $(DESTDIR)$(HTMLDIR)/man5/$$fn; \
972         done
973         @set -e; for x in dummy $(HTMLDOCS7); do \
974                 if [ "$$x" = "dummy" ]; then continue; fi; \
975                 fn=`basename $$x`; \
976                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man7/$$fn"; \
977                 $(RM) $(DESTDIR)$(HTMLDIR)/man7/$$fn; \
978         done
979
980 # Developer targets (note: these are only available on Unix) #########
981
982 update: generate errors ordinals
983
984 generate: generate_apps generate_crypto_bn generate_crypto_objects \
985           generate_crypto_conf generate_crypto_asn1 generate_fuzz_oids
986
987 .PHONY: doc-nits cmd-nits md-nits
988 doc-nits: build_generated
989         $(PERL) $(SRCDIR)/util/find-doc-nits -n -l -e
990
991 cmd-nits: build_generated apps/openssl
992         $(PERL) $(SRCDIR)/util/find-doc-nits -c
993
994 # This uses "mdl", the markdownlint application, which is written in ruby.
995 # The source is at https://github.com/markdownlint/markdownlint
996 # If you have ruby installed, "gem install mdl" should work.
997 # Another option is at https://snapcraft.io/install/mdl/debian
998 # Finally, there's a Node.js version, which we haven't tried, that
999 # can be found at https://github.com/DavidAnson/markdownlint
1000 md-nits:
1001         mdl -s util/markdownlint.rb .
1002
1003 # Test coverage is a good idea for the future
1004 #coverage: $(PROGRAMS) $(TESTPROGRAMS)
1005 #       ...
1006
1007 lint:
1008         lint -DLINT $(INCLUDES) $(SRCS)
1009
1010 generate_apps:
1011         ( cd $(SRCDIR); $(PERL) VMS/VMSify-conf.pl \
1012                                 < apps/openssl.cnf > apps/openssl-vms.cnf )
1013
1014 generate_crypto_bn:
1015         ( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h )
1016
1017 generate_crypto_objects:
1018         ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl -n \
1019                                 crypto/objects/objects.txt \
1020                                 crypto/objects/obj_mac.num \
1021                                 > crypto/objects/obj_mac.new && \
1022             mv crypto/objects/obj_mac.new crypto/objects/obj_mac.num )
1023         ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl \
1024                                 crypto/objects/objects.txt \
1025                                 crypto/objects/obj_mac.num \
1026                                 > include/openssl/obj_mac.h )
1027         ( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
1028                                 include/openssl/obj_mac.h \
1029                                 > crypto/objects/obj_dat.h )
1030         ( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
1031                                 crypto/objects/obj_mac.num \
1032                                 crypto/objects/obj_xref.txt \
1033                                 > crypto/objects/obj_xref.h )
1034         ( cd $(SRCDIR); cat crypto/objects/obj_compat.h >> include/openssl/obj_mac.h )
1035
1036 generate_crypto_conf:
1037         ( cd $(SRCDIR); $(PERL) crypto/conf/keysets.pl \
1038                                 > crypto/conf/conf_def.h )
1039
1040 generate_crypto_asn1:
1041         ( cd $(SRCDIR); $(PERL) crypto/asn1/charmap.pl \
1042                                 > crypto/asn1/charmap.h )
1043
1044 generate_fuzz_oids:
1045         ( cd $(SRCDIR); $(PERL) fuzz/mkfuzzoids.pl \
1046                                 crypto/objects/obj_dat.h \
1047                                 > fuzz/oids.txt )
1048
1049 # Set to -force to force a rebuild
1050 ERROR_REBUILD=
1051 errors:
1052         ( b=`pwd`; set -e; cd $(SRCDIR); \
1053           $(PERL) util/ck_errf.pl -strict -internal; \
1054           $(PERL) -I$$b util/mkerr.pl $(ERROR_REBUILD) -internal )
1055         ( b=`pwd`; set -e; cd $(SRCDIR)/engines; \
1056           for E in *.ec ; do \
1057               $(PERL) ../util/ck_errf.pl -strict \
1058                 -conf $$E `basename $$E .ec`.c; \
1059               $(PERL) -I$$b ../util/mkerr.pl $(ERROR_REBUILD) -static \
1060                 -conf $$E `basename $$E .ec`.c ; \
1061           done )
1062
1063 {- use File::Basename;
1064
1065    our @sslheaders =
1066        qw( include/openssl/ssl.h
1067            include/openssl/ssl2.h
1068            include/openssl/ssl3.h
1069            include/openssl/sslerr.h
1070            include/openssl/tls1.h
1071            include/openssl/dtls1.h
1072            include/openssl/srtp.h );
1073    our @cryptoheaders =
1074        qw( include/internal/dso.h
1075            include/internal/o_dir.h
1076            include/internal/err.h
1077            include/internal/evp.h
1078            include/internal/sslconf.h );
1079    our @cryptoskipheaders = ( @sslheaders,
1080        qw( include/openssl/conf_api.h
1081            include/openssl/ebcdic.h
1082            include/openssl/opensslconf.h
1083            include/openssl/symhacks.h ) );
1084    foreach my $f ( glob(catfile($config{sourcedir},
1085                                 'include','openssl','*.h')) ) {
1086        my $fn = "include/openssl/" . basename($f);
1087        push @cryptoheaders, $fn unless grep { $_ eq $fn } @cryptoskipheaders;
1088    }
1089    "";
1090 -}
1091 CRYPTOHEADERS={- join(" \\\n" . ' ' x 14,
1092                       fill_lines(" ", $COLUMNS - 14, sort @cryptoheaders)) -}
1093 SSLHEADERS={- join(" \\\n" . ' ' x 11,
1094                    fill_lines(" ", $COLUMNS - 11, sort @sslheaders)) -}
1095 ordinals:
1096         ( cd $(SRCDIR); \
1097           $(PERL) util/mknum.pl --version $(VERSION) --no-warnings \
1098                   --ordinals util/libcrypto.num \
1099                   --symhacks include/openssl/symhacks.h \
1100                   $(CRYPTOHEADERS) )
1101         ( cd $(SRCDIR); \
1102           $(PERL) util/mknum.pl --version $(VERSION) --no-warnings \
1103                   --ordinals util/libssl.num \
1104                   --symhacks include/openssl/symhacks.h \
1105                   $(SSLHEADERS))
1106
1107 test_ordinals:
1108         ( cd test; \
1109           SRCTOP=../$(SRCDIR) \
1110           BLDTOP=../$(BLDDIR) \
1111             $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
1112
1113 tags TAGS: FORCE
1114         rm -f TAGS tags
1115         -ctags -R .
1116         -etags `find . -name '*.[ch]' -o -name '*.pm'`
1117
1118 # Release targets (note: only available on Unix) #####################
1119
1120 tar:
1121         (cd $(SRCDIR); ./util/mktar.sh --name='$(NAME)' --tarfile='$(TARFILE)')
1122
1123 # Helper targets #####################################################
1124
1125 link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/util/wrap.pl
1126
1127 $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/util/wrap.pl: configdata.pm
1128         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
1129             mkdir -p "$(BLDDIR)/util"; \
1130             ln -sf "../$(SRCDIR)/util/`basename "$@"`" "$(BLDDIR)/util"; \
1131         fi
1132
1133 FORCE:
1134
1135 # Building targets ###################################################
1136
1137 libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { platform->sharedlib_simple($_) // () } @{$unified_info{libraries}}) -}
1138 libcrypto.pc:
1139         @ ( echo 'prefix=$(INSTALLTOP)'; \
1140             echo 'exec_prefix=$${prefix}'; \
1141             if [ -n "$(LIBDIR)" ]; then \
1142                 echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
1143             else \
1144                 echo 'libdir=$(libdir)'; \
1145             fi; \
1146             echo 'includedir=$${prefix}/include'; \
1147             echo 'enginesdir=$${libdir}/engines-{- $sover_dirname -}'; \
1148             echo ''; \
1149             echo 'Name: OpenSSL-libcrypto'; \
1150             echo 'Description: OpenSSL cryptography library'; \
1151             echo 'Version: '$(VERSION); \
1152             echo 'Libs: -L$${libdir} -lcrypto'; \
1153             echo 'Libs.private: $(LIB_EX_LIBS)'; \
1154             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
1155
1156 libssl.pc:
1157         @ ( echo 'prefix=$(INSTALLTOP)'; \
1158             echo 'exec_prefix=$${prefix}'; \
1159             if [ -n "$(LIBDIR)" ]; then \
1160                 echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
1161             else \
1162                 echo 'libdir=$(libdir)'; \
1163             fi; \
1164             echo 'includedir=$${prefix}/include'; \
1165             echo ''; \
1166             echo 'Name: OpenSSL-libssl'; \
1167             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
1168             echo 'Version: '$(VERSION); \
1169             echo 'Requires.private: libcrypto'; \
1170             echo 'Libs: -L$${libdir} -lssl'; \
1171             echo 'Cflags: -I$${includedir}' ) > libssl.pc
1172
1173 openssl.pc:
1174         @ ( echo 'prefix=$(INSTALLTOP)'; \
1175             echo 'exec_prefix=$${prefix}'; \
1176             if [ -n "$(LIBDIR)" ]; then \
1177                 echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
1178             else \
1179                 echo 'libdir=$(libdir)'; \
1180             fi; \
1181             echo 'includedir=$${prefix}/include'; \
1182             echo ''; \
1183             echo 'Name: OpenSSL'; \
1184             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
1185             echo 'Version: '$(VERSION); \
1186             echo 'Requires: libssl libcrypto' ) > openssl.pc
1187
1188 configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config \
1189                {- join(" \\\n" . ' ' x 15,
1190                        fill_lines(" ", $COLUMNS - 15,
1191                                   @{$config{build_file_templates}},
1192                                   @{$config{build_infos}},
1193                                   @{$config{conf_files}})) -}
1194         @echo "Detected changed: $?"
1195         $(PERL) configdata.pm -r
1196         @echo "**************************************************"
1197         @echo "***                                            ***"
1198         @echo "***   Please run the same make command again   ***"
1199         @echo "***                                            ***"
1200         @echo "**************************************************"
1201         @false
1202
1203 reconfigure reconf:
1204         $(PERL) configdata.pm -r
1205
1206 {-
1207   use File::Basename;
1208   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
1209
1210   # Helper function to figure out dependencies on libraries
1211   # It takes a list of library names and outputs a list of dependencies
1212   sub compute_lib_depends {
1213       # Depending on shared libraries:
1214       # On Windows POSIX layers, we depend on {libname}.dll.a
1215       # On Unix platforms, we depend on {shlibname}.so
1216       return map { platform->sharedlib_simple($_) // platform->staticlib($_) } @_;
1217   }
1218
1219   sub generatesrc {
1220       my %args = @_;
1221       my $generator = join(" ", @{$args{generator}});
1222       my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
1223       my $incs = join("", map { " -I".$_ } @{$args{incs}});
1224       my $defs = join("", map { " -D".$_ } @{$args{defs}});
1225       my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
1226
1227       if ($args{src} =~ /\.html$/) {
1228           my $title = basename($args{src}, ".html");
1229           my $pod = $args{generator}->[0];
1230           return <<"EOF";
1231 $args{src}: $pod
1232         \$(PERL) \$(SRCDIR)/util/mkpod2html.pl -i "$pod" -o \$\@ -t "$title" -r "\$(SRCDIR)/doc"
1233 EOF
1234       } elsif ($args{src} =~ /\.(\d)$/) {
1235           my $section = $1;
1236           my $name = uc basename($args{src}, ".$section");
1237           my $pod = $args{generator}->[0];
1238           return <<"EOF";
1239 $args{src}: $pod
1240         pod2man --name=$name --section=$section --center=OpenSSL \\
1241                 --release=\$(VERSION) $pod >\$\@
1242 EOF
1243       } elsif (platform->isdef($args{src})) {
1244           my $target = platform->def($args{src});
1245           (my $mkdef_os = $target{shared_target}) =~ s|-shared$||;
1246           my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION)' : '';
1247           my $ord_name = $args{generator}->[1] || $args{product};
1248           return <<"EOF";
1249 $target: $args{generator}->[0] $deps \$(SRCDIR)/util/mkdef.pl
1250         \$(PERL) \$(SRCDIR)/util/mkdef.pl$ord_ver --ordinals $args{generator}->[0]  --name $ord_name --OS $mkdef_os > $target
1251 EOF
1252       } elsif (!platform->isasm($args{src})) {
1253           if ($args{generator}->[0] =~ m|^.*\.in$|) {
1254               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1255                                                    "util", "dofile.pl")),
1256                                    rel2abs($config{builddir}));
1257               my @modules = ( 'configdata.pm',
1258                               grep { $_ =~ m|\.pm$| } @{$args{deps}} );
1259               my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules;
1260               @modules = map { "-M".basename($_, '.pm') } @modules;
1261               my $modules = join(' ', '', sort keys %moduleincs, @modules);
1262               return <<"EOF";
1263 $args{src}: $args{generator}->[0] $deps \$(BLDDIR)/configdata.pm
1264         \$(PERL)$modules "$dofile" "-o$target{build_file}" $generator > \$@
1265 EOF
1266           } else {
1267               return <<"EOF";
1268 $args{src}: $args{generator}->[0] $deps
1269         \$(PERL)$generator_incs $generator > \$@
1270 EOF
1271           }
1272       } else {
1273           my $cppflags = {
1274               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1275               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1276               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
1277               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
1278           } -> {$args{intent}};
1279
1280           if ($args{generator}->[0] =~ /\.pl$/) {
1281               $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator
1282                   .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSOR)';
1283           } elsif ($args{generator}->[0] =~ /\.m4$/) {
1284               $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
1285           } elsif ($args{generator}->[0] =~ /\.S$/) {
1286               $generator = undef;
1287           } else {
1288               die "Generator type for $args{src} unknown: $generator\n";
1289           }
1290
1291           if (defined($generator)) {
1292               return <<"EOF";
1293 $args{src}: $args{generator}->[0] $deps
1294         $generator \$@
1295 EOF
1296           }
1297           return <<"EOF";
1298 $args{src}: $args{generator}->[0] $deps
1299         \$(CC) $incs $cppflags $defs -E $args{generator}->[0] | \\
1300         \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
1301 EOF
1302       }
1303   }
1304
1305   # Should one wonder about the end of the Perl snippet, it's because this
1306   # second regexp eats up line endings as well, if the removed path is the
1307   # last in the line.  We may therefore need to put back a line ending.
1308   sub src2obj {
1309       my %args = @_;
1310       my $obj = platform->convertext($args{obj});
1311       my $dep = platform->dep($args{obj});
1312       my @srcs = @{$args{srcs}};
1313       my $srcs = join(" ",  @srcs);
1314       my $deps = join(" ", @srcs, @{$args{deps}});
1315       my $incs = join("", map { " -I".$_ } @{$args{incs}});
1316       my $defs = join("", map { " -D".$_ } @{$args{defs}});
1317       my $cmd;
1318       my $cmdflags;
1319       my $cmdcompile;
1320       if (grep /\.rc$/, @srcs) {
1321           $cmd = '$(RC)';
1322           $cmdflags = '$(RCFLAGS)';
1323           $cmdcompile = '';
1324       } elsif (grep /\.(cc|cpp)$/, @srcs) {
1325           $cmd = '$(CXX)';
1326           $cmdcompile = ' -c';
1327           $cmdflags = {
1328               shlib => '$(LIB_CXXFLAGS) $(LIB_CPPFLAGS)',
1329               lib => '$(LIB_CXXFLAGS) $(LIB_CPPFLAGS)',
1330               dso => '$(DSO_CXXFLAGS) $(DSO_CPPFLAGS)',
1331               bin => '$(BIN_CXXFLAGS) $(BIN_CPPFLAGS)'
1332           } -> {$args{intent}};
1333       } else {
1334           $cmd = '$(CC)';
1335           $cmdcompile = ' -c';
1336           $cmdflags = {
1337               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1338               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1339               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
1340               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
1341           } -> {$args{intent}};
1342       }
1343       my $recipe;
1344       # extension-specific rules
1345       if (grep /\.s$/, @srcs) {
1346           $recipe .= <<"EOF";
1347 $obj: $deps
1348         $cmd $cmdflags -c -o \$\@ $srcs
1349 EOF
1350       } elsif (grep /\.S$/, @srcs) {
1351           # Originally there was mutli-step rule with $(CC) -E file.S
1352           # followed by $(CC) -c file.s. It compensated for one of
1353           # legacy platform compiler's inability to handle .S files.
1354           # The platform is long discontinued by vendor so there is
1355           # hardly a point to drag it along...
1356           $recipe .= <<"EOF";
1357 $obj: $deps
1358         $cmd $incs $defs $cmdflags -c -o \$\@ $srcs
1359 EOF
1360       } elsif (defined $makedepprog && $makedepprog !~ /\/makedepend/
1361                && !grep /\.rc$/, @srcs) {
1362           $recipe .= <<"EOF";
1363 $obj: $deps
1364         $cmd $incs $defs $cmdflags -MMD -MF $dep.tmp -MT \$\@ -c -o \$\@ $srcs
1365         \@touch $dep.tmp
1366         \@if cmp $dep.tmp $dep > /dev/null 2> /dev/null; then \\
1367                 rm -f $dep.tmp; \\
1368         else \\
1369                 mv $dep.tmp $dep; \\
1370         fi
1371 EOF
1372       } else {
1373           $recipe .= <<"EOF";
1374 $obj: $deps
1375         $cmd $incs $defs $cmdflags $cmdcompile -o \$\@ $srcs
1376 EOF
1377           if (defined $makedepprog  && $makedepprog =~ /\/makedepend/) {
1378               $recipe .= <<"EOF";
1379         \$(MAKEDEPEND) -f- -Y -- $incs $cmdflags -- $srcs 2>/dev/null \\
1380             > $dep
1381 EOF
1382           }
1383       }
1384       return $recipe;
1385   }
1386   # We *know* this routine is only called when we've configure 'shared'.
1387   sub obj2shlib {
1388       my %args = @_;
1389       my @linkdirs = ();
1390       my @linklibs = ();
1391       foreach (@{$args{deps}}) {
1392           if (platform->isstaticlib($_)) {
1393               push @linklibs, platform->convertext($_);
1394           } else {
1395               my $d = "-L" . dirname($_);
1396               my $l = basename($_);
1397               $l =~ s/^lib//;
1398               $l = "-l" . $l;
1399               push @linklibs, $l;
1400               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1401           }
1402       }
1403       my $linkflags = join("", map { $_." " } @linkdirs);
1404       my $linklibs = join("", map { $_." " } @linklibs);
1405       my @objs = map { platform->convertext($_) }
1406                  grep { !platform->isdef($_) }
1407                  @{$args{objs}};
1408       my @defs = map { platform->def($_) }
1409                  grep { platform->isdef($_) }
1410                  @{$args{objs}};
1411       my @deps = compute_lib_depends(@{$args{deps}});
1412       die "More than one exported symbol map" if scalar @defs > 1;
1413
1414       my $simple = platform->sharedlib_simple($args{lib});
1415       my $full = platform->sharedlib($args{lib});
1416       my $shared_soname = "";
1417       $shared_soname .= ' '.$target{shared_sonameflag}.basename($full)
1418           if defined $target{shared_sonameflag};
1419       my $shared_imp = "";
1420       $shared_imp .= ' '.$target{shared_impflag}.basename($simple)
1421           if defined $target{shared_impflag};
1422       my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
1423
1424       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1425       my $deps = join(" \\\n" . ' ' x (length($full) + 2),
1426                       fill_lines(' ', $COLUMNS - length($full) - 2,
1427                                  @objs, @defs, @deps));
1428
1429       my $recipe = <<"EOF";
1430 $simple: $full
1431 EOF
1432       if (sharedaix()) {
1433           $recipe .= <<"EOF";
1434         rm -f $simple && \\
1435         \$(AR) r $simple $full
1436 EOF
1437       } elsif ($simple ne $full) {
1438           $recipe .= <<"EOF";
1439         rm -f $simple && \\
1440         ln -s $full $simple
1441 EOF
1442       }
1443       $recipe .= <<"EOF";
1444 $full: $deps
1445         \$(CC) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\
1446                 -o $full$shared_def \\
1447                 $objs \\
1448                 $linklibs \$(LIB_EX_LIBS)
1449 EOF
1450       if (windowsdll()) {
1451           $recipe .= <<"EOF";
1452         rm -f apps/$full
1453         rm -f test/$full
1454         rm -f fuzz/$full
1455         cp -p $full apps/
1456         cp -p $full test/
1457         cp -p $full fuzz/
1458 EOF
1459       }
1460       return $recipe;
1461   }
1462   sub obj2dso {
1463       my %args = @_;
1464       my $dso = platform->dso($args{module});
1465       my @linkdirs = ();
1466       my @linklibs = ();
1467       foreach (@{$args{deps}}) {
1468           next unless defined $_;
1469           if (platform->isstaticlib($_)) {
1470               push @linklibs, platform->convertext($_);
1471           } else {
1472               my $d = "-L" . dirname($_);
1473               my $l = basename($_);
1474               $l =~ s/^lib//;
1475               $l = "-l" . $l;
1476               push @linklibs, $l;
1477               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1478           }
1479       }
1480       my $linkflags = join("", map { $_." " } @linkdirs);
1481       my $linklibs = join("", map { $_." " } @linklibs);
1482       my @objs = map { platform->convertext($_) }
1483                  grep { !platform->isdef($_) }
1484                  @{$args{objs}};
1485       my @defs = map { platform->def($_) }
1486                  grep { platform->isdef($_) }
1487                  @{$args{objs}};
1488       my @deps = compute_lib_depends(@{$args{deps}});
1489       my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
1490       # TODO(3.0): next line needs to become "less magic" (see PR #11950)
1491       $shared_def .= ' '.$target{shared_fipsflag} if (m/providers\/fips/ && defined $target{shared_fipsflag});
1492       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1493       my $deps = join(" \\\n" . ' ' x (length($dso) + 2),
1494                       fill_lines(' ', $COLUMNS - length($dso) - 2,
1495                                  @objs, @defs, @deps));
1496
1497       return <<"EOF";
1498 $dso: $deps
1499         \$(CC) \$(DSO_CFLAGS) $linkflags\$(DSO_LDFLAGS) \\
1500                 -o $dso$shared_def \\
1501                 $objs \\
1502                 $linklibs\$(DSO_EX_LIBS)
1503 EOF
1504   }
1505   sub obj2lib {
1506       my %args = @_;
1507       my $lib = platform->staticlib($args{lib});
1508       my @objs = map { platform->obj($_) } @{$args{objs}};
1509       my $objs = join(" \\\n" . ' ' x (length($lib) + 2),
1510                       fill_lines(' ', $COLUMNS - length($lib) - 2, @objs));
1511       return <<"EOF";
1512 $lib: $objs
1513         \$(AR) \$(ARFLAGS) \$\@ \$\?
1514         \$(RANLIB) \$\@ || echo Never mind.
1515 EOF
1516   }
1517   sub obj2bin {
1518       my %args = @_;
1519       my $bin = platform->bin($args{bin});
1520       my @objs = map { platform->obj($_) } @{$args{objs}};
1521       my @deps = compute_lib_depends(@{$args{deps}});
1522       my $objs = join(" \\\n" . ' ' x (length($bin) + 2),
1523                       fill_lines(' ', $COLUMNS - length($bin) - 2, @objs));
1524       my @linkdirs = ();
1525       my @linklibs = ();
1526       foreach (@{$args{deps}}) {
1527           next unless defined $_;
1528           if (platform->isstaticlib($_)) {
1529               push @linklibs, platform->convertext($_);
1530           } else {
1531               my $d = "-L" . dirname($_);
1532               my $l = basename($_);
1533               $l =~ s/^lib//;
1534               $l = "-l" . $l;
1535               push @linklibs, $l;
1536               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1537           }
1538       }
1539       my $linkflags = join("", map { $_." " } @linkdirs);
1540       my $linklibs = join("", map { $_." " } @linklibs);
1541       my $cmd = '$(CC)';
1542       my $cmdflags = '$(BIN_CFLAGS)';
1543       if (grep /_cc\.o$/, @{$args{objs}}) {
1544           $cmd = '$(CXX)';
1545           $cmdflags = '$(BIN_CXXFLAGS)';
1546       }
1547
1548       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1549       my $deps = join(" \\\n" . ' ' x (length($bin) + 2),
1550                       fill_lines(' ', $COLUMNS - length($bin) - 2,
1551                                  @objs, @deps));
1552
1553       return <<"EOF";
1554 $bin: $deps
1555         rm -f $bin
1556         \$\${LDCMD:-$cmd} $cmdflags $linkflags\$(BIN_LDFLAGS) \\
1557                 -o $bin \\
1558                 $objs \\
1559                 $linklibs\$(BIN_EX_LIBS)
1560 EOF
1561   }
1562   sub in2script {
1563       my %args = @_;
1564       my $script = $args{script};
1565       my $sources = join(" ", @{$args{sources}});
1566       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1567                                            "util", "dofile.pl")),
1568                            rel2abs($config{builddir}));
1569       return <<"EOF";
1570 $script: $sources
1571         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1572             "-o$target{build_file}" $sources > "$script"
1573         chmod a+x $script
1574 EOF
1575   }
1576   sub generatedir {
1577       my %args = @_;
1578       my $dir = $args{dir};
1579       my @deps = map { platform->convertext($_) } @{$args{deps}};
1580       my @comments = ();
1581       my %extinfo = ( dso => platform->dsoext(),
1582                       lib => platform->libext(),
1583                       bin => platform->binext() );
1584
1585       # We already have a 'test' target, and the top directory is just plain
1586       # silly
1587       return if $dir eq "test" || $dir eq ".";
1588
1589       foreach my $type (("dso", "lib", "bin", "script")) {
1590           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
1591           # For lib object files, we could update the library.  However, it
1592           # was decided that it's enough to build the directory local object
1593           # files, so we don't need to add any actions, and the dependencies
1594           # are already taken care of.
1595           if ($type ne "lib") {
1596               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
1597                   if (dirname($prod) eq $dir) {
1598                       push @deps, $prod.$extinfo{$type};
1599                   } else {
1600                       push @comments, "# No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
1601                   }
1602               }
1603           }
1604       }
1605
1606       my $target = "$dir $dir/";
1607       my $deps = join(" \\\n\t",
1608                       fill_lines(' ', $COLUMNS - 8, @deps));
1609       my $comments = join("\n", "", @comments);
1610       return <<"EOF";
1611 $target: \\
1612         $deps$comments
1613 EOF
1614   }
1615   ""    # Important!  This becomes part of the template result.
1616 -}