Remove the source directory .num targets
[openssl.git] / Configurations / unix-Makefile.tmpl
1 ##
2 ## Makefile for OpenSSL
3 ##
4 ## {- join("\n## ", @autowarntext) -}
5 {-
6      use OpenSSL::Util;
7
8      our $makedep_scheme = $config{makedep_scheme};
9      our $makedepcmd = platform->makedepcmd();
10
11      sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }
12
13      # Shared AIX support is special. We put libcrypto[64].so.ver into
14      # libcrypto.a and use libcrypto_a.a as static one.
15      sub sharedaix  { !$disabled{shared} && $config{target} =~ /^aix/ }
16
17      our $sover_dirname = platform->shlib_version_as_filename();
18
19      # This makes sure things get built in the order they need
20      # to. You're welcome.
21      sub dependmagic {
22          my $target = shift;
23          my $help = shift;
24
25          return "$target: build_generated ## $help\n\t\$(MAKE) depend && \$(MAKE) _$target\n_$target";
26      }
27
28      our $COLUMNS = $ENV{COLUMNS};
29      if ($COLUMNS =~ /^\d+$/) {
30          $COLUMNS = int($COLUMNS) - 2; # 2 to leave space for ending ' \'
31      } else {
32          $COLUMNS = 76;
33      }
34
35      sub fill_lines {
36          my $item_sep = shift;                  # string
37          my $line_length = shift;               # number of chars
38
39          my @result = ();
40          my $resultpos = 0;
41
42          foreach (@_) {
43              my $fill_line = $result[$resultpos] // '';
44              my $newline =
45                  ($fill_line eq '' ? '' : $fill_line . $item_sep) . $_;
46
47              if (length($newline) > $line_length) {
48                  # If this is a single item and the intended result line
49                  # is empty, we put it there anyway
50                  if ($fill_line eq '') {
51                      $result[$resultpos++] = $newline;
52                  } else {
53                      $result[++$resultpos] = $_;
54                  }
55              } else {
56                  $result[$resultpos] = $newline;
57              }
58          }
59          return @result;
60      }
61      '';
62 -}
63 PLATFORM={- $config{target} -}
64 OPTIONS={- $config{options} -}
65 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
66 SRCDIR={- $config{sourcedir} -}
67 BLDDIR={- $config{builddir} -}
68 FIPSKEY={- $config{FIPSKEY} -}
69
70 VERSION={- "$config{full_version}" -}
71 VERSION_NUMBER={- "$config{version}" -}
72 MAJOR={- $config{major} -}
73 MINOR={- $config{minor} -}
74 SHLIB_VERSION_NUMBER={- $config{shlib_version} -}
75 SHLIB_TARGET={- $target{shared_target} -}
76
77 LIBS={- join(" \\\n" . ' ' x 5,
78              fill_lines(" ", $COLUMNS - 5,
79                         map { platform->staticlib($_) // () }
80                         @{$unified_info{libraries}})) -}
81 SHLIBS={- join(" \\\n" . ' ' x 7,
82                fill_lines(" ", $COLUMNS - 7,
83                           map { platform->sharedlib($_) // () }
84                           @{$unified_info{libraries}})) -}
85 SHLIB_INFO={- join(" \\\n" . ' ' x 11,
86                    fill_lines(" ", $COLUMNS - 11,
87                           map { my $x = platform->sharedlib($_);
88                                 my $y = platform->sharedlib_simple($_) // '';
89                                 my $z = platform->sharedlib_import($_) // '';
90                                 $x ? "\"$x;$y;$z\"" : () }
91                           @{$unified_info{libraries}})) -}
92 MODULES={- join(" \\\n" . ' ' x 8,
93                 fill_lines(" ", $COLUMNS - 8,
94                            map { platform->dso($_) }
95                            # Drop all modules that are dependencies, they will
96                            # be processed through their dependents
97                            grep { my $x = $_;
98                                   !grep { grep { $_ eq $x } @$_ }
99                                         values %{$unified_info{depends}} }
100                            @{$unified_info{modules}})) -}
101 FIPSMODULE={- # We do some extra checking here, as there should be only one
102               use File::Basename;
103               our @fipsmodules =
104                   grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
105                          && $unified_info{attributes}->{modules}->{$_}->{fips} }
106                   @{$unified_info{modules}};
107               die "More that one FIPS module" if scalar @fipsmodules > 1;
108               join(" ", map { platform->dso($_) } @fipsmodules) -}
109 FIPSMODULENAME={- die "More that one FIPS module" if scalar @fipsmodules > 1;
110                   join(" ", map { basename(platform->dso($_)) } @fipsmodules) -}
111
112 PROGRAMS={- join(" \\\n" . ' ' x 9,
113                  fill_lines(" ", $COLUMNS - 9,
114                             map { platform->bin($_) }
115                             @{$unified_info{programs}})) -}
116 SCRIPTS={- join(" \\\n" . ' ' x 8,
117                 fill_lines(" ", $COLUMNS - 8, @{$unified_info{scripts}})) -}
118 {- output_off() if $disabled{makedepend}; "" -}
119 DEPS={- join(" \\\n" . ' ' x 5,
120              fill_lines(" ", $COLUMNS - 5,
121                         map { platform->isobj($_) ? platform->dep($_) : () }
122                         grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
123                         keys %{$unified_info{sources}})); -}
124 {- output_on() if $disabled{makedepend}; "" -}
125 GENERATED_MANDATORY={- join(" \\\n" . ' ' x 20,
126                             fill_lines(" ", $COLUMNS - 20,
127                                        @{$unified_info{depends}->{""}})) -}
128 GENERATED_PODS={- # common0.tmpl provides @generated
129                   join(" \\\n" . ' ' x 15,
130                        fill_lines(" ", $COLUMNS - 15,
131                                   map { my $x = $_;
132                                         (
133                                           grep { 
134                                                  $unified_info{attributes}->{depends}
135                                                  ->{$x}->{$_}->{pod} // 0
136                                                }
137                                               keys %{$unified_info{attributes}->{depends}->{$x}}
138                                         ) ? $x : ();
139                                       }
140                                       @generated)) -}
141 GENERATED={- # common0.tmpl provides @generated
142              join(" \\\n" . ' ' x 5,
143                   fill_lines(" ", $COLUMNS - 5,
144                              map { platform->convertext($_) } @generated )) -}
145
146 INSTALL_LIBS={-
147         join(" \\\n" . ' ' x 13,
148              fill_lines(" ", $COLUMNS - 13,
149                         map { platform->staticlib($_) // () }
150                         grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
151                         @{$unified_info{libraries}}))
152 -}
153 INSTALL_SHLIBS={-
154         join(" \\\n" . ' ' x 15,
155              fill_lines(" ", $COLUMNS - 15,
156                         map { platform->sharedlib($_) // () }
157                         grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
158                         @{$unified_info{libraries}}))
159 -}
160 INSTALL_SHLIB_INFO={-
161         join(" \\\n" . ' ' x 19,
162              fill_lines(" ", $COLUMNS - 19,
163                         map { my $x = platform->sharedlib($_);
164                               my $y = platform->sharedlib_simple($_) // '';
165                               my $z = platform->sharedlib_import($_) // '';
166                               $x ? "\"$x;$y;$z\"" : () }
167                         grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
168                         @{$unified_info{libraries}}))
169 -}
170 INSTALL_ENGINES={-
171         join(" \\\n" . ' ' x 16,
172              fill_lines(" ", $COLUMNS - 16,
173                         map { platform->dso($_) }
174                         grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
175                                && $unified_info{attributes}->{modules}->{$_}->{engine} }
176                         @{$unified_info{modules}}))
177 -}
178 INSTALL_MODULES={-
179         join(" \\\n" . ' ' x 16,
180              fill_lines(" ", $COLUMNS - 16,
181                         map { platform->dso($_) }
182                         grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
183                                && !$unified_info{attributes}->{modules}->{$_}->{engine}
184                                && !$unified_info{attributes}->{modules}->{$_}->{fips} }
185                         @{$unified_info{modules}}))
186 -}
187 INSTALL_FIPSMODULE={-
188         join(" \\\n" . ' ' x 16,
189              fill_lines(" ", $COLUMNS - 16,
190                         map { platform->dso($_) }
191                         grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
192                                && $unified_info{attributes}->{modules}->{$_}->{fips} }
193                         @{$unified_info{modules}}))
194 -}
195 INSTALL_FIPSMODULECONF=providers/fipsmodule.cnf
196 INSTALL_PROGRAMS={-
197         join(" \\\n" . ' ' x 16,
198              fill_lines(" ", $COLUMNS - 16, map { platform->bin($_) }
199                         grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
200                         @{$unified_info{programs}}))
201 -}
202 INSTALL_EXPORTERS_PKGCONFIG={-
203         join(" \\\n" . ' ' x 28,
204              fill_lines(" ", $COLUMNS - 28,
205                         grep { $unified_info{attributes}->{generate}->{$_}->{exporter} eq 'pkg-config'}
206                         sort keys %{$unified_info{generate}}))
207 -}
208 INSTALL_EXPORTERS_CMAKE={-
209         join(" \\\n" . ' ' x 24,
210              fill_lines(" ", $COLUMNS - 24,
211                         grep { $unified_info{attributes}->{generate}->{$_}->{exporter} eq 'cmake'}
212                         sort keys %{$unified_info{generate}}))
213 -}
214 BIN_SCRIPTS={-
215         join(" \\\n" . ' ' x 12,
216              fill_lines(" ", $COLUMNS - 12,
217                         map { my $x = $unified_info{attributes}->{scripts}->{$_}->{linkname};
218                               $x ? "$_:$x" : $_ }
219                         grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
220                                && !$unified_info{attributes}->{scripts}->{$_}->{misc} }
221                         @{$unified_info{scripts}}))
222 -}
223 MISC_SCRIPTS={-
224         join(" \\\n" . ' ' x 13,
225              fill_lines(" ", $COLUMNS - 13,
226                         map { my $x = $unified_info{attributes}->{scripts}->{$_}->{linkname};
227                               $x ? "$_:$x" : $_ }
228                         grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
229                                && $unified_info{attributes}->{scripts}->{$_}->{misc} }
230                         @{$unified_info{scripts}}))
231 -}
232 IMAGEDOCS1={-
233         join(" \\\n" . ' ' x 10,
234              fill_lines(" ", $COLUMNS - 10,
235                         @{$unified_info{imagedocs}->{man1}})) -}
236 IMAGEDOCS3={-
237         join(" \\\n" . ' ' x 10,
238              fill_lines(" ", $COLUMNS - 10,
239                         @{$unified_info{imagedocs}->{man3}})) -}
240 IMAGEDOCS5={-
241         join(" \\\n" . ' ' x 10,
242              fill_lines(" ", $COLUMNS - 10,
243                         @{$unified_info{imagedocs}->{man5}})) -}
244 IMAGEDOCS7={-
245         join(" \\\n" . ' ' x 10,
246              fill_lines(" ", $COLUMNS - 10,
247                         @{$unified_info{imagedocs}->{man7}})) -}
248 HTMLDOCS1={-
249         join(" \\\n" . ' ' x 10,
250              fill_lines(" ", $COLUMNS - 10,
251                         @{$unified_info{htmldocs}->{man1}})) -}
252 HTMLDOCS3={-
253         join(" \\\n" . ' ' x 10,
254              fill_lines(" ", $COLUMNS - 10,
255                         @{$unified_info{htmldocs}->{man3}})) -}
256 HTMLDOCS5={-
257         join(" \\\n" . ' ' x 10,
258              fill_lines(" ", $COLUMNS - 10,
259                         @{$unified_info{htmldocs}->{man5}})) -}
260 HTMLDOCS7={-
261         join(" \\\n" . ' ' x 10,
262              fill_lines(" ", $COLUMNS - 10,
263                         @{$unified_info{htmldocs}->{man7}})) -}
264 MANDOCS1={-
265         join(" \\\n" . ' ' x 9,
266              fill_lines(" ", $COLUMNS - 9,
267                         @{$unified_info{mandocs}->{man1}})) -}
268 MANDOCS3={-
269         join(" \\\n" . ' ' x 9,
270              fill_lines(" ", $COLUMNS - 9,
271                         @{$unified_info{mandocs}->{man3}})) -}
272 MANDOCS5={-
273         join(" \\\n" . ' ' x 9,
274              fill_lines(" ", $COLUMNS - 9,
275                         @{$unified_info{mandocs}->{man5}})) -}
276 MANDOCS7={-
277         join(" \\\n" . ' ' x 9,
278              fill_lines(" ", $COLUMNS - 9,
279                         @{$unified_info{mandocs}->{man7}})) -}
280
281 APPS_OPENSSL="{- use File::Spec::Functions;
282                  catfile("apps","openssl") -}"
283
284 # DESTDIR is for package builders so that they can configure for, say,
285 # /usr/ and yet have everything installed to /tmp/somedir/usr/.
286 # Normally it is left empty.
287 DESTDIR=
288
289 # Do not edit these manually. Use Configure with --prefix or --openssldir
290 # to change this!  Short explanation in the top comment in Configure
291 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
292               #
293               our $prefix = $config{prefix} || "/usr/local";
294               $prefix -}
295 OPENSSLDIR={- #
296               # The logic here is that if no --openssldir was given,
297               # OPENSSLDIR will get the value from $prefix plus "/ssl".
298               # If --openssldir was given and the value is an absolute
299               # path, OPENSSLDIR will get its value without change.
300               # If the value from --openssldir is a relative path,
301               # OPENSSLDIR will get $prefix with the --openssldir
302               # value appended as a subdirectory.
303               #
304               use File::Spec::Functions;
305               our $openssldir =
306                   $config{openssldir} ?
307                       (file_name_is_absolute($config{openssldir}) ?
308                            $config{openssldir}
309                            : catdir($prefix, $config{openssldir}))
310                       : catdir($prefix, "ssl");
311               $openssldir -}
312 LIBDIR={- our $libdir = $config{libdir};
313           unless ($libdir) {
314               $libdir = "lib$target{multilib}";
315           }
316           file_name_is_absolute($libdir) ? "" : $libdir -}
317 # $(libdir) is chosen to be compatible with the GNU coding standards
318 libdir={- file_name_is_absolute($libdir)
319           ? $libdir : '$(INSTALLTOP)/$(LIBDIR)' -}
320 ENGINESDIR=$(libdir)/engines-{- $sover_dirname -}
321 MODULESDIR=$(libdir)/ossl-modules
322
323 # Convenience variable for those who want to set the rpath in shared
324 # libraries and applications
325 LIBRPATH=$(libdir)
326
327 BINDIR={- our $bindir = $config{bindir};
328           unless ($bindir) {
329               $bindir = "bin$target{multibin}";
330           }
331           file_name_is_absolute($bindir) ? "" : $bindir -}
332 bindir={- file_name_is_absolute($bindir)
333           ? $bindir : '$(INSTALLTOP)/$(BINDIR)' -}
334
335 PKGCONFIGDIR=$(libdir)/pkgconfig
336 CMAKECONFIGDIR=$(libdir)/cmake/OpenSSL
337
338 MANDIR=$(INSTALLTOP)/share/man
339 DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)
340 HTMLDIR=$(DOCDIR)/html
341
342 # MANSUFFIX is for the benefit of anyone who may want to have a suffix
343 # appended after the manpage file section number.  "ssl" is popular,
344 # resulting in files such as config.5ssl rather than config.5.
345 MANSUFFIX=ossl
346 HTMLSUFFIX=html
347
348 # For "optional" echo messages, to get "real" silence
349 ECHO = echo
350
351 ##### User defined commands and flags ################################
352
353 # We let the C compiler driver to take care of .s files. This is done in
354 # order to be excused from maintaining a separate set of architecture
355 # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
356 # gcc, then the driver will automatically translate it to -xarch=v8plus
357 # and pass it down to assembler.  In any case, we do not define AS or
358 # ASFLAGS for this reason.
359
360 CROSS_COMPILE={- $config{CROSS_COMPILE} -}
361 CC=$(CROSS_COMPILE){- $config{CC} -}
362 CXX={- $config{CXX} ? "\$(CROSS_COMPILE)$config{CXX}" : '' -}
363 CPPFLAGS={- our $cppflags1 = join(" ",
364                                   (map { "-D".$_} @{$config{CPPDEFINES}}),
365                                   (map { "-I".$_} @{$config{CPPINCLUDES}}),
366                                   @{$config{CPPFLAGS}}) -}
367 CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
368 CXXFLAGS={- join(' ', @{$config{CXXFLAGS}}) -}
369 LDFLAGS= {- join(' ', @{$config{LDFLAGS}}) -}
370 EX_LIBS= {- join(' ', @{$config{LDLIBS}}) -}
371
372 MAKEDEPEND={- $config{makedepcmd} -}
373
374 PERL={- $config{PERL} -}
375
376 AR=$(CROSS_COMPILE){- $config{AR} -}
377 ARFLAGS= {- join(' ', @{$config{ARFLAGS}}) -}
378 RANLIB={- $config{RANLIB} ? "\$(CROSS_COMPILE)$config{RANLIB}" : "true"; -}
379 RC= $(CROSS_COMPILE){- $config{RC} -}
380 RCFLAGS={- join(' ', @{$config{RCFLAGS}}) -} {- $target{shared_rcflag} -}
381
382 RM= rm -f
383 RMDIR= rmdir
384 TAR= {- $target{TAR} || "tar" -}
385 TARFLAGS= {- $target{TARFLAGS} -}
386
387 BASENAME=       openssl
388 NAME=           $(BASENAME)-$(VERSION)
389 # Relative to $(SRCDIR)
390 TARFILE=        ../$(NAME).tar
391
392 ##### Project flags ##################################################
393
394 # Variables starting with CNF_ are common variables for all product types
395
396 CNF_CPPFLAGS={- our $cppflags2 =
397                     join(' ', $target{cppflags} || (),
398                               (map { "-D".$_} @{$target{defines}},
399                                               @{$config{defines}}),
400                               (map { "-I".$_} @{$target{includes}},
401                                               @{$config{includes}}),
402                               @{$config{cppflags}}) -}
403 CNF_CFLAGS={- join(' ', $target{cflags} || (),
404                         @{$config{cflags}}) -}
405 CNF_CXXFLAGS={- join(' ', $target{cxxflags} || (),
406                           @{$config{cxxflags}}) -}
407 CNF_LDFLAGS={- join(' ', $target{lflags} || (),
408                          @{$config{lflags}}) -}
409 CNF_EX_LIBS={- join(' ', $target{ex_libs} || (),
410                          @{$config{ex_libs}}) -}
411
412 # Variables starting with LIB_ are used to build library object files
413 # and shared libraries.
414 # Variables starting with DSO_ are used to build DSOs and their object files.
415 # Variables starting with BIN_ are used to build programs and their object
416 # files.
417
418 LIB_CPPFLAGS={- our $lib_cppflags =
419                 join(' ', $target{lib_cppflags} || (),
420                           $target{shared_cppflag} || (),
421                           (map { '-D'.$_ }
422                                @{$target{lib_defines} || ()},
423                                @{$target{shared_defines} || ()},
424                                @{$config{lib_defines} || ()},
425                                @{$config{shared_defines} || ()}),
426                           (map { '-I'.quotify1($_) }
427                                @{$target{lib_includes}},
428                                @{$target{shared_includes}},
429                                @{$config{lib_includes}},
430                                @{$config{shared_includes}}),
431                           @{$config{lib_cppflags}},
432                           @{$config{shared_cppflag}});
433                 join(' ', $lib_cppflags,
434                           (map { '-D'.$_ }
435                                'OPENSSLDIR="\"$(OPENSSLDIR)\""',
436                                'ENGINESDIR="\"$(ENGINESDIR)\""',
437                                'MODULESDIR="\"$(MODULESDIR)\""'),
438                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
439 LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
440                         $target{shared_cflag} || (),
441                         @{$config{lib_cflags}},
442                         @{$config{shared_cflag}},
443                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
444 LIB_CXXFLAGS={- join(' ', $target{lib_cxxflags} || (),
445                           $target{shared_cxxflag} || (),
446                           @{$config{lib_cxxflags}},
447                           @{$config{shared_cxxflag}},
448                           '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
449 LIB_LDFLAGS={- join(' ', $target{shared_ldflag} || (),
450                          $config{shared_ldflag} || (),
451                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
452 LIB_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
453 DSO_CPPFLAGS={- join(' ', $target{dso_cppflags} || (),
454                           $target{module_cppflags} || (),
455                           (map { '-D'.$_ }
456                                @{$target{dso_defines}},
457                                @{$target{module_defines}},
458                                @{$config{dso_defines} || ()},
459                                @{$config{module_defines} || ()}),
460                           (map { '-I'.quotify1($_) }
461                                @{$target{dso_includes}},
462                                @{$target{module_includes}},
463                                @{$config{dso_includes}},
464                                @{$config{module_includes}}),
465                           @{$config{dso_cppflags}},
466                           @{$config{module_cppflags}},
467                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
468 DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
469                         $target{module_cflags} || (),
470                         @{$config{dso_cflags}},
471                         @{$config{module_cflags}},
472                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
473 DSO_CXXFLAGS={- join(' ', $target{dso_cxxflags} || (),
474                           $target{module_cxxflags} || (),
475                           @{$config{dso_cxxflags}},
476                           @{$config{module_cxxflag}},
477                           '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
478 DSO_LDFLAGS={- join(' ', $target{dso_ldflags} || (),
479                          $target{module_ldflags} || (),
480                          @{$config{dso_ldflags}},
481                          @{$config{module_ldflags}},
482                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
483 DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
484 BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
485                           (map { '-D'.$_ } @{$config{bin_defines} || ()}),
486                           @{$config{bin_cppflags}},
487                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
488 BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
489                         @{$config{bin_cflags}},
490                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
491 BIN_CXXFLAGS={- join(' ', $target{bin_cxxflags} || (),
492                           @{$config{bin_cxxflags}},
493                           '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
494 BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
495                          @{$config{bin_lflags}},
496                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
497 BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
498
499 # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
500 CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
501               $cppflags2 =~ s|([\\"])|\\$1|g;
502               $lib_cppflags =~ s|([\\"])|\\$1|g;
503               join(' ', $lib_cppflags || (), $cppflags2 || (),
504                         $cppflags1 || ()) -}
505
506 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
507
508 # For x86 assembler: Set PROCESSOR to 386 if you want to support
509 # the 80386.
510 PROCESSOR= {- $config{processor} -}
511
512 # We want error [and other] messages in English. Trouble is that make(1)
513 # doesn't pass macros down as environment variables unless there already
514 # was corresponding variable originally set. In other words we can only
515 # reassign environment variables, but not set new ones, not in portable
516 # manner that is. That's why we reassign several, just to be sure...
517 LC_ALL=C
518 LC_MESSAGES=C
519 LANG=C
520
521 # The main targets ###################################################
522
523 ##@ Software
524
525 {- dependmagic('build_sw', 'Build all the software (default target)'); -}: build_libs_nodep build_modules_nodep build_programs_nodep link-utils
526 {- dependmagic('build_libs', 'Build the libraries libssl and libcrypto'); -}: build_libs_nodep
527 {- dependmagic('build_modules', 'Build the modules (i.e. providers and engines)'); -}: build_modules_nodep
528 {- dependmagic('build_programs', 'Build the openssl executables and scripts'); -}: build_programs_nodep
529
530 all: build_sw {- "build_docs" if !$disabled{docs}; -} ## Build software and documentation
531
532 ##@ Documentation
533 build_generated_pods: $(GENERATED_PODS)
534 build_docs: build_man_docs build_html_docs ## Create documentation
535 build_man_docs: $(MANDOCS1) $(MANDOCS3) $(MANDOCS5) $(MANDOCS7) ## Create manpages
536 build_html_docs: $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7) ## Create HTML documentation
537
538 build_generated: $(GENERATED_MANDATORY)
539 build_libs_nodep: $(LIBS) {- join(" ",map { platform->sharedlib_simple($_) // platform->sharedlib_import($_) // platform->sharedlib($_) // () } @{$unified_info{libraries}}) -}
540 build_modules_nodep: $(MODULES)
541 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
542
543 # Kept around for backward compatibility
544 build_apps build_tests: build_programs
545
546 # Convenience target to prebuild all generated files, not just the mandatory
547 # ones
548 build_all_generated: $(GENERATED_MANDATORY) $(GENERATED) build_docs
549         @ : {- output_off() if $disabled{makedepend}; "" -}
550         @echo "Warning: consider configuring with no-makedepend, because if"
551         @echo "         target system doesn't have $(PERL),"
552         @echo "         then make will fail..."
553         @ : {- output_on() if $disabled{makedepend}; "" -}
554
555 ##@ Help
556 .PHONY: help
557 help: ## Show this help screen
558         @$(PERL) $(SRCDIR)/util/help.pl $(BLDDIR)/Makefile
559
560 ##@ Testing
561 test: tests ## Run tests (alias of "tests")
562 {- dependmagic('tests', 'Run tests'); -}: build_programs_nodep build_modules_nodep link-utils run_tests
563 run_tests:
564         @ : {- output_off() if $disabled{tests}; "" -}
565         ( SRCTOP=$(SRCDIR) \
566           BLDTOP=$(BLDDIR) \
567           PERL="$(PERL)" \
568           FIPSKEY="$(FIPSKEY)" \
569           EXE_EXT={- platform->binext() -} \
570           $(PERL) $(SRCDIR)/test/run_tests.pl $(TESTS) )
571         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
572         @echo "Tests are not supported with your chosen Configure options"
573         @ : {- output_on() if !$disabled{tests}; "" -}
574
575 list-tests: ## List available tests that can be invoked via "make test TESTS=<name>"
576         @ : {- output_off() if $disabled{tests}; "" -}
577         $(MAKE) run_tests TESTS=list
578         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
579         @echo "Tests are not supported with your chosen Configure options"
580         @ : {- output_on() if !$disabled{tests}; "" -}
581
582 ##@ Workspace cleaning
583
584 libclean:
585         @set -e; for s in $(SHLIB_INFO); do \
586                 if [ "$$s" = ";" ]; then continue; fi; \
587                 s1=`echo "$$s" | cut -f1 -d";"`; \
588                 s2=`echo "$$s" | cut -f2 -d";"`; \
589                 s3=`echo "$$s" | cut -f3 -d";"`; \
590                 $(ECHO) $(RM) $$s1; {- output_off() unless windowsdll(); "" -}\
591                 $(RM) apps/$$s1; \
592                 $(RM) test/$$s1; \
593                 $(RM) fuzz/$$s1; {- output_on() unless windowsdll(); "" -}\
594                 $(RM) $$s1; \
595                 if [ "$$s2" != "" ]; then \
596                         $(ECHO) $(RM) $$s2; \
597                         $(RM) $$s2; \
598                 fi; \
599                 if [ "$$s3" != "" ]; then \
600                         $(ECHO) $(RM) $$s3; \
601                         $(RM) $$s3; \
602                 fi; \
603         done
604         $(RM) $(LIBS)
605         $(RM) *{- platform->defext() -}
606
607 clean: libclean ## Clean the workspace, keep the configuration
608         $(RM) $(HTMLDOCS1)
609         $(RM) $(HTMLDOCS3)
610         $(RM) $(HTMLDOCS5)
611         $(RM) $(HTMLDOCS7)
612         $(RM) $(MANDOCS1)
613         $(RM) $(MANDOCS3)
614         $(RM) $(MANDOCS5)
615         $(RM) $(MANDOCS7)
616         $(RM) $(PROGRAMS) $(TESTPROGS) $(MODULES) $(FIPSMODULE) $(SCRIPTS)
617         $(RM) $(GENERATED_MANDATORY) $(GENERATED)
618         -find . -name '*{- platform->depext() -}' \! -name '.*' \! -type d -exec $(RM) {} \;
619         -find . -name '*{- platform->objext() -}' \! -name '.*' \! -type d -exec $(RM) {} \;
620         $(RM) core
621         $(RM) tags TAGS doc-nits md-nits
622         $(RM) -r test/test-runs
623         $(RM) providers/fips*.new
624         -find . -type l \! -name '.*' -exec $(RM) {} \;
625
626 distclean: clean ## Clean and remove the configuration
627         $(RM) include/openssl/configuration.h
628         $(RM) configdata.pm
629         $(RM) Makefile
630
631 # We check if any depfile is newer than Makefile and decide to
632 # concatenate only if that is true.
633 depend: Makefile
634         @: {- output_off() if $disabled{makedepend}; "" -}
635         @$(PERL) $(SRCDIR)/util/add-depends.pl "{- $makedep_scheme -}"
636         @: {- output_on() if $disabled{makedepend}; "" -}
637
638 # Install helper targets #############################################
639 ##@ Installation
640
641 install: install_sw install_ssldirs {- "install_docs" if !$disabled{docs}; -} {- $disabled{fips} ? "" : "install_fips" -} ## Install software and documentation, create OpenSSL directories
642
643 uninstall: {- "uninstall_docs" if !$disabled{docs}; -} uninstall_sw {- $disabled{fips} ? "" : "uninstall_fips" -} ## Uninstall software and documentation
644
645 install_sw: install_dev install_engines install_modules install_runtime ## Install just the software and libraries
646
647 uninstall_sw: uninstall_runtime uninstall_modules uninstall_engines uninstall_dev ## Uninstall the software and libraries
648
649 install_docs: install_man_docs install_html_docs ## Install manpages and HTML documentation
650
651 uninstall_docs: uninstall_man_docs uninstall_html_docs ## Uninstall manpages and HTML documentation
652         $(RM) -r "$(DESTDIR)$(DOCDIR)"
653
654 {- output_off() if $disabled{fips}; "" -}
655 install_fips: build_sw $(INSTALL_FIPSMODULECONF)
656         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
657         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(MODULESDIR)"
658         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)"
659         @$(ECHO) "*** Installing FIPS module"
660         @$(ECHO) "install $(INSTALL_FIPSMODULE) -> $(DESTDIR)$(MODULESDIR)/$(FIPSMODULENAME)"
661         @cp "$(INSTALL_FIPSMODULE)" "$(DESTDIR)$(MODULESDIR)/$(FIPSMODULENAME).new"
662         @chmod 755 "$(DESTDIR)$(MODULESDIR)/$(FIPSMODULENAME).new"
663         @mv -f "$(DESTDIR)$(MODULESDIR)/$(FIPSMODULENAME).new" \
664                "$(DESTDIR)$(MODULESDIR)/$(FIPSMODULENAME)"
665         @$(ECHO) "*** Installing FIPS module configuration"
666         @$(ECHO) "install $(INSTALL_FIPSMODULECONF) -> $(DESTDIR)$(OPENSSLDIR)/fipsmodule.cnf"
667         @cp $(INSTALL_FIPSMODULECONF) "$(DESTDIR)$(OPENSSLDIR)/fipsmodule.cnf"
668
669 uninstall_fips:
670         @$(ECHO) "*** Uninstalling FIPS module configuration"
671         $(RM) "$(DESTDIR)$(OPENSSLDIR)/fipsmodule.cnf"
672         @$(ECHO) "*** Uninstalling FIPS module"
673         $(RM) "$(DESTDIR)$(MODULESDIR)/$(FIPSMODULENAME)"
674 {- if ($disabled{fips}) { output_on(); } else { output_off(); } "" -}
675 install_fips:
676         @$(ECHO) "The 'install_fips' target requires the 'enable-fips' option"
677
678 uninstall_fips:
679         @$(ECHO) "The 'uninstall_fips' target requires the 'enable-fips' option"
680 {- output_on() if !$disabled{fips}; "" -}
681
682
683 install_ssldirs:
684         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)/certs"
685         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)/private"
686         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)/misc"
687         @set -e; for x in dummy $(MISC_SCRIPTS); do \
688                 if [ "$$x" = "dummy" ]; then continue; fi; \
689                 x1=`echo "$$x" | cut -f1 -d:`; \
690                 x2=`echo "$$x" | cut -f2 -d:`; \
691                 fn=`basename $$x1`; \
692                 $(ECHO) "install $$x1 -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
693                 cp $$x1 "$(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new"; \
694                 chmod 755 "$(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new"; \
695                 mv -f "$(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new" \
696                       "$(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
697                 if [ "$$x1" != "$$x2" ]; then \
698                         ln=`basename "$$x2"`; \
699                         : {- output_off() unless windowsdll(); "" -}; \
700                         $(ECHO) "copy $(DESTDIR)$(OPENSSLDIR)/misc/$$ln -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
701                         cp "$(DESTDIR)$(OPENSSLDIR)/misc/$$fn" "$(DESTDIR)$(OPENSSLDIR)/misc/$$ln"; \
702                         : {- output_on() unless windowsdll();
703                              output_off() if windowsdll(); "" -}; \
704                         $(ECHO) "link $(DESTDIR)$(OPENSSLDIR)/misc/$$ln -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
705                         ln -sf $$fn "$(DESTDIR)$(OPENSSLDIR)/misc/$$ln"; \
706                         : {- output_on() if windowsdll(); "" -}; \
707                 fi; \
708         done
709         @$(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist"
710         @cp $(SRCDIR)/apps/openssl.cnf "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new"
711         @chmod 644 "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new"
712         @mv -f  "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new" "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist"
713         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf" ]; then \
714                 $(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
715                 cp $(SRCDIR)/apps/openssl.cnf "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
716                 chmod 644 "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
717         fi
718         @$(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist"
719         @cp $(SRCDIR)/apps/ct_log_list.cnf "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new"
720         @chmod 644 "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new"
721         @mv -f  "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new" "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist"
722         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf" ]; then \
723                 $(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
724                 cp $(SRCDIR)/apps/ct_log_list.cnf "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
725                 chmod 644 "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
726         fi
727
728 install_dev: install_runtime_libs
729         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
730         @$(ECHO) "*** Installing development files"
731         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)/include/openssl"
732         @ : {- output_off() if $disabled{uplink}; "" -}
733         @$(ECHO) "install $(SRCDIR)/ms/applink.c -> $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
734         @cp $(SRCDIR)/ms/applink.c "$(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
735         @chmod 644 "$(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
736         @ : {- output_on() if $disabled{uplink}; "" -}
737         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
738                           $(BLDDIR)/include/openssl/*.h; do \
739                 fn=`basename $$i`; \
740                 $(ECHO) "install $$i -> $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
741                 cp $$i "$(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
742                 chmod 644 "$(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
743         done
744         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(libdir)"
745         @set -e; for l in $(INSTALL_LIBS); do \
746                 fn=`basename $$l`; \
747                 $(ECHO) "install $$l -> $(DESTDIR)$(libdir)/$$fn"; \
748                 cp $$l "$(DESTDIR)$(libdir)/$$fn.new"; \
749                 $(RANLIB) "$(DESTDIR)$(libdir)/$$fn.new"; \
750                 chmod 644 "$(DESTDIR)$(libdir)/$$fn.new"; \
751                 mv -f "$(DESTDIR)$(libdir)/$$fn.new" \
752                       "$(DESTDIR)$(libdir)/$$fn"; \
753         done
754         @ : {- output_off() if $disabled{shared}; "" -}
755         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
756                 s1=`echo "$$s" | cut -f1 -d";"`; \
757                 s2=`echo "$$s" | cut -f2 -d";"`; \
758                 s3=`echo "$$s" | cut -f3 -d";"`; \
759                 fn1=`basename "$$s1"`; \
760                 fn2=`basename "$$s2"`; \
761                 fn3=`basename "$$s3"`; \
762                 : {- output_off(); output_on() unless windowsdll() or sharedaix(); "" -}; \
763                 if [ "$$fn2" != "" ]; then \
764                         $(ECHO) "link $(DESTDIR)$(libdir)/$$fn2 -> $(DESTDIR)$(libdir)/$$fn1"; \
765                         ln -sf $$fn1 "$(DESTDIR)$(libdir)/$$fn2"; \
766                 fi; \
767                 : {- output_off() unless windowsdll() or sharedaix(); output_on() if windowsdll(); "" -}; \
768                 if [ "$$fn3" != "" ]; then \
769                         $(ECHO) "install $$s3 -> $(DESTDIR)$(libdir)/$$fn3"; \
770                         cp $$s3 "$(DESTDIR)$(libdir)/$$fn3.new"; \
771                         chmod 755 "$(DESTDIR)$(libdir)/$$fn3.new"; \
772                         mv -f "$(DESTDIR)$(libdir)/$$fn3.new" \
773                               "$(DESTDIR)$(libdir)/$$fn3"; \
774                 fi; \
775                 : {- output_off() if windowsdll(); output_on() if sharedaix(); "" -}; \
776                 a="$(DESTDIR)$(libdir)/$$fn2"; \
777                 $(ECHO) "install $$s1 -> $$a"; \
778                 if [ -f $$a ]; then ( trap "rm -rf /tmp/ar.$$$$" INT 0; \
779                         mkdir /tmp/ar.$$$$; ( cd /tmp/ar.$$$$; \
780                         cp -f $$a $$a.new; \
781                         for so in `$(AR) t $$a`; do \
782                                 $(AR) x $$a $$so; \
783                                 chmod u+w $$so; \
784                                 strip -X32_64 -e $$so; \
785                                 $(AR) r $$a.new $$so; \
786                         done; \
787                 )); fi; \
788                 $(AR) r $$a.new $$s1; \
789                 mv -f $$a.new $$a; \
790                 : {- output_off() if sharedaix(); output_on(); "" -}; \
791         done
792         @ : {- output_on() if $disabled{shared}; "" -}
793         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(PKGCONFIGDIR)"
794         @for e in $(INSTALL_EXPORTERS_PKGCONFIG); do \
795                 fn=`basename $$e`; \
796                 $(ECHO) "install $$e -> $(DESTDIR)$(PKGCONFIGDIR)/$$fn"; \
797                 cp $$e "$(DESTDIR)$(PKGCONFIGDIR)/$$fn"; \
798                 chmod 644 "$(DESTDIR)$(PKGCONFIGDIR)/$$fn"; \
799         done
800         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(CMAKECONFIGDIR)
801         @for e in $(INSTALL_EXPORTERS_CMAKE); do \
802                 fn=`basename $$e`; \
803                 $(ECHO) "install $$e -> $(DESTDIR)$(CMAKECONFIGDIR)/$$fn"; \
804                 cp $$e $(DESTDIR)$(CMAKECONFIGDIR)/$$fn; \
805                 chmod 644 $(DESTDIR)$(CMAKECONFIGDIR)/$$fn; \
806         done
807
808 uninstall_dev: uninstall_runtime_libs
809         @$(ECHO) "*** Uninstalling development files"
810         @ : {- output_off() if $disabled{uplink}; "" -}
811         @$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
812         @$(RM) "$(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
813         @ : {- output_on() if $disabled{uplink}; "" -}
814         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
815                           $(BLDDIR)/include/openssl/*.h; do \
816                 fn=`basename $$i`; \
817                 $(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
818                 $(RM) "$(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
819         done
820         -$(RMDIR) "$(DESTDIR)$(INSTALLTOP)/include/openssl"
821         -$(RMDIR) "$(DESTDIR)$(INSTALLTOP)/include"
822         @set -e; for l in $(INSTALL_LIBS); do \
823                 fn=`basename $$l`; \
824                 $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn"; \
825                 $(RM) "$(DESTDIR)$(libdir)/$$fn"; \
826         done
827         @ : {- output_off() if $disabled{shared}; "" -}
828         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
829                 s1=`echo "$$s" | cut -f1 -d";"`; \
830                 s2=`echo "$$s" | cut -f2 -d";"`; \
831                 s3=`echo "$$s" | cut -f3 -d";"`; \
832                 fn1=`basename "$$s1"`; \
833                 fn2=`basename "$$s2"`; \
834                 fn3=`basename "$$s3"`; \
835                 : {- output_off() if windowsdll(); "" -}; \
836                 $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn1"; \
837                 $(RM) "$(DESTDIR)$(libdir)/$$fn1"; \
838                 if [ -n "$$fn2" ]; then \
839                         $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn2"; \
840                         $(RM) "$(DESTDIR)$(libdir)/$$fn2"; \
841                 fi; \
842                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
843                 if [ -n "$$fn3" ]; then \
844                         $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn3"; \
845                         $(RM) "$(DESTDIR)$(libdir)/$$fn3"; \
846                 fi; \
847                 : {- output_on() unless windowsdll(); "" -}; \
848         done
849         @ : {- output_on() if $disabled{shared}; "" -}
850         @for e in $(INSTALL_EXPORTERS_PKGCONFIG); do \
851                 fn=`basename "$$e"`; \
852                 $(RM) "$(DESTDIR)$(PKGCONFIGDIR)/$$fn"; \
853         done
854         @for e in $(INSTALL_EXPORTERS_CMAKE); do \
855                 fn=`basename "$$e"`; \
856                 $(RM) "$(DESTDIR)$(CMAKECONFIGDIR)/$$fn"; \
857         done
858         -$(RMDIR) "$(DESTDIR)$(PKGCONFIGDIR)"
859         -$(RMDIR) "$(DESTDIR)$(CMAKECONFIGDIR)"
860         -$(RMDIR) "$(DESTDIR)$(libdir)"
861
862 _install_modules_deps: install_runtime_libs build_modules
863
864 install_engines: _install_modules_deps
865         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
866         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(ENGINESDIR)/"
867         @$(ECHO) "*** Installing engines"
868         @set -e; for e in dummy $(INSTALL_ENGINES); do \
869                 if [ "$$e" = "dummy" ]; then continue; fi; \
870                 fn=`basename $$e`; \
871                 $(ECHO) "install $$e -> $(DESTDIR)$(ENGINESDIR)/$$fn"; \
872                 cp $$e "$(DESTDIR)$(ENGINESDIR)/$$fn.new"; \
873                 chmod 755 "$(DESTDIR)$(ENGINESDIR)/$$fn.new"; \
874                 mv -f "$(DESTDIR)$(ENGINESDIR)/$$fn.new" \
875                       "$(DESTDIR)$(ENGINESDIR)/$$fn"; \
876         done
877
878 uninstall_engines:
879         @$(ECHO) "*** Uninstalling engines"
880         @set -e; for e in dummy $(INSTALL_ENGINES); do \
881                 if [ "$$e" = "dummy" ]; then continue; fi; \
882                 fn=`basename $$e`; \
883                 $(ECHO) "$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn"; \
884                 $(RM) "$(DESTDIR)$(ENGINESDIR)/$$fn"; \
885         done
886         -$(RMDIR) "$(DESTDIR)$(ENGINESDIR)"
887
888 install_modules: _install_modules_deps
889         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
890         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(MODULESDIR)/"
891         @$(ECHO) "*** Installing modules"
892         @set -e; for e in dummy $(INSTALL_MODULES); do \
893                 if [ "$$e" = "dummy" ]; then continue; fi; \
894                 fn=`basename $$e`; \
895                 $(ECHO) "install $$e -> $(DESTDIR)$(MODULESDIR)/$$fn"; \
896                 cp $$e "$(DESTDIR)$(MODULESDIR)/$$fn.new"; \
897                 chmod 755 "$(DESTDIR)$(MODULESDIR)/$$fn.new"; \
898                 mv -f "$(DESTDIR)$(MODULESDIR)/$$fn.new" \
899                       "$(DESTDIR)$(MODULESDIR)/$$fn"; \
900         done
901
902 uninstall_modules:
903         @$(ECHO) "*** Uninstalling modules"
904         @set -e; for e in dummy $(INSTALL_MODULES); do \
905                 if [ "$$e" = "dummy" ]; then continue; fi; \
906                 fn=`basename $$e`; \
907                 $(ECHO) "$(RM) $(DESTDIR)$(MODULESDIR)/$$fn"; \
908                 $(RM) "$(DESTDIR)$(MODULESDIR)/$$fn"; \
909         done
910         -$(RMDIR) "$(DESTDIR)$(MODULESDIR)"
911
912 install_runtime: install_programs
913
914 install_runtime_libs: build_libs
915         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
916         @ : {- output_off() if windowsdll(); "" -}
917         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(libdir)"
918         @ : {- output_on() if windowsdll(); output_off() unless windowsdll(); "" -}
919         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(bindir)/"
920         @ : {- output_on() unless windowsdll(); "" -}
921         @$(ECHO) "*** Installing runtime libraries"
922         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
923                 if [ "$$s" = "dummy" ]; then continue; fi; \
924                 fn=`basename $$s`; \
925                 : {- output_off() unless windowsdll(); "" -}; \
926                 $(ECHO) "install $$s -> $(DESTDIR)$(bindir)/$$fn"; \
927                 cp $$s "$(DESTDIR)$(bindir)/$$fn.new"; \
928                 chmod 755 "$(DESTDIR)$(bindir)/$$fn.new"; \
929                 mv -f "$(DESTDIR)$(bindir)/$$fn.new" \
930                       "$(DESTDIR)$(bindir)/$$fn"; \
931                 : {- output_on() unless windowsdll(); "" -}{- output_off() if windowsdll(); "" -}; \
932                 $(ECHO) "install $$s -> $(DESTDIR)$(libdir)/$$fn"; \
933                 cp $$s "$(DESTDIR)$(libdir)/$$fn.new"; \
934                 chmod 755 "$(DESTDIR)$(libdir)/$$fn.new"; \
935                 mv -f "$(DESTDIR)$(libdir)/$$fn.new" \
936                       "$(DESTDIR)$(libdir)/$$fn"; \
937                 : {- output_on() if windowsdll(); "" -}; \
938         done
939
940 install_programs: install_runtime_libs build_programs
941         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
942         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(bindir)"
943         @$(ECHO) "*** Installing runtime programs"
944         @set -e; for x in dummy $(INSTALL_PROGRAMS); do \
945                 if [ "$$x" = "dummy" ]; then continue; fi; \
946                 fn=`basename $$x`; \
947                 $(ECHO) "install $$x -> $(DESTDIR)$(bindir)/$$fn"; \
948                 cp $$x "$(DESTDIR)$(bindir)/$$fn.new"; \
949                 chmod 755 "$(DESTDIR)$(bindir)/$$fn.new"; \
950                 mv -f "$(DESTDIR)$(bindir)/$$fn.new" \
951                       "$(DESTDIR)$(bindir)/$$fn"; \
952         done
953         @set -e; for x in dummy $(BIN_SCRIPTS); do \
954                 if [ "$$x" = "dummy" ]; then continue; fi; \
955                 fn=`basename $$x`; \
956                 $(ECHO) "install $$x -> $(DESTDIR)$(bindir)/$$fn"; \
957                 cp $$x "$(DESTDIR)$(bindir)/$$fn.new"; \
958                 chmod 755 "$(DESTDIR)$(bindir)/$$fn.new"; \
959                 mv -f "$(DESTDIR)$(bindir)/$$fn.new" \
960                       "$(DESTDIR)$(bindir)/$$fn"; \
961         done
962
963 uninstall_runtime: uninstall_programs uninstall_runtime_libs
964
965 uninstall_programs:
966         @$(ECHO) "*** Uninstalling runtime programs"
967         @set -e; for x in dummy $(INSTALL_PROGRAMS); \
968         do  \
969                 if [ "$$x" = "dummy" ]; then continue; fi; \
970                 fn=`basename $$x`; \
971                 $(ECHO) "$(RM) $(DESTDIR)$(bindir)/$$fn"; \
972                 $(RM) "$(DESTDIR)$(bindir)/$$fn"; \
973         done;
974         @set -e; for x in dummy $(BIN_SCRIPTS); \
975         do  \
976                 if [ "$$x" = "dummy" ]; then continue; fi; \
977                 fn=`basename $$x`; \
978                 $(ECHO) "$(RM) $(DESTDIR)$(bindir)/$$fn"; \
979                 $(RM) "$(DESTDIR)$(bindir)/$$fn"; \
980         done
981         -$(RMDIR) "$(DESTDIR)$(bindir)"
982
983 uninstall_runtime_libs:
984         @$(ECHO) "*** Uninstalling runtime libraries"
985         @ : {- output_off() unless windowsdll(); "" -}
986         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
987                 if [ "$$s" = "dummy" ]; then continue; fi; \
988                 fn=`basename $$s`; \
989                 $(ECHO) "$(RM) $(DESTDIR)$(bindir)/$$fn"; \
990                 $(RM) "$(DESTDIR)$(bindir)/$$fn"; \
991         done
992         @ : {- output_on() unless windowsdll(); "" -}
993
994
995 install_man_docs: build_man_docs
996         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
997         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(MANDIR)/man1"
998         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(MANDIR)/man3"
999         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(MANDIR)/man5"
1000         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(MANDIR)/man7"
1001         @$(ECHO) "*** Installing manpages"
1002         @set -e; for x in dummy $(MANDOCS1); do \
1003                 if [ "$$x" = "dummy" ]; then continue; fi; \
1004                 fn=`basename $$x`; \
1005                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX)"; \
1006                 cp $$x "$(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX)"; \
1007                 chmod 644 "$(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX)"; \
1008                 $(PERL) $(SRCDIR)/util/write-man-symlinks install $(SRCDIR)/doc/man1 $(BLDDIR)/doc/man1 $${fn}$(MANSUFFIX) "$(DESTDIR)$(MANDIR)/man1"; \
1009         done
1010         @set -e; for x in dummy $(MANDOCS3); do \
1011                 if [ "$$x" = "dummy" ]; then continue; fi; \
1012                 fn=`basename $$x`; \
1013                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX)"; \
1014                 cp $$x "$(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX)"; \
1015                 chmod 644 "$(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX)"; \
1016                 $(PERL) $(SRCDIR)/util/write-man-symlinks install $(SRCDIR)/doc/man3 $(BLDDIR)/doc/man3 $${fn}$(MANSUFFIX) "$(DESTDIR)$(MANDIR)/man3"; \
1017         done
1018         @set -e; for x in dummy $(MANDOCS5); do \
1019                 if [ "$$x" = "dummy" ]; then continue; fi; \
1020                 fn=`basename $$x`; \
1021                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX)"; \
1022                 cp $$x "$(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX)"; \
1023                 chmod 644 "$(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX)"; \
1024                 $(PERL) $(SRCDIR)/util/write-man-symlinks install $(SRCDIR)/doc/man5 $(BLDDIR)/doc/man5 $${fn}$(MANSUFFIX) "$(DESTDIR)$(MANDIR)/man5"; \
1025         done
1026         @set -e; for x in dummy $(MANDOCS7); do \
1027                 if [ "$$x" = "dummy" ]; then continue; fi; \
1028                 fn=`basename $$x`; \
1029                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX)"; \
1030                 cp $$x "$(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX)"; \
1031                 chmod 644 "$(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX)"; \
1032                 $(PERL) $(SRCDIR)/util/write-man-symlinks install $(SRCDIR)/doc/man7 $(BLDDIR)/doc/man7 $${fn}$(MANSUFFIX) "$(DESTDIR)$(MANDIR)/man7"; \
1033         done
1034
1035 uninstall_man_docs: build_man_docs
1036         @$(ECHO) "*** Uninstalling manpages"
1037         @set -e; for x in dummy $(MANDOCS1); do \
1038                 if [ "$$x" = "dummy" ]; then continue; fi; \
1039                 fn=`basename $$x`; \
1040                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX)"; \
1041                 $(RM) "$(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX)"; \
1042                 $(PERL) $(SRCDIR)/util/write-man-symlinks uninstall $(SRCDIR)/doc/man1 $(BLDDIR)/doc/man1 $${fn}$(MANSUFFIX) "$(DESTDIR)$(MANDIR)/man1"; \
1043         done
1044         @set -e; for x in dummy $(MANDOCS3); do \
1045                 if [ "$$x" = "dummy" ]; then continue; fi; \
1046                 fn=`basename $$x`; \
1047                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX)"; \
1048                 $(RM) "$(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX)"; \
1049                 $(PERL) $(SRCDIR)/util/write-man-symlinks uninstall $(SRCDIR)/doc/man3 $(BLDDIR)/doc/man3 $${fn}$(MANSUFFIX) "$(DESTDIR)$(MANDIR)/man3"; \
1050         done
1051         @set -e; for x in dummy $(MANDOCS5); do \
1052                 if [ "$$x" = "dummy" ]; then continue; fi; \
1053                 fn=`basename $$x`; \
1054                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX)"; \
1055                 $(RM) "$(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX)"; \
1056                 $(PERL) $(SRCDIR)/util/write-man-symlinks uninstall $(SRCDIR)/doc/man5 $(BLDDIR)/doc/man5 $${fn}$(MANSUFFIX) "$(DESTDIR)$(MANDIR)/man5"; \
1057         done
1058         @set -e; for x in dummy $(MANDOCS7); do \
1059                 if [ "$$x" = "dummy" ]; then continue; fi; \
1060                 fn=`basename $$x`; \
1061                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX)"; \
1062                 $(RM) "$(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX)"; \
1063                 $(PERL) $(SRCDIR)/util/write-man-symlinks uninstall $(SRCDIR)/doc/man7 $(BLDDIR)/doc/man7 $${fn}$(MANSUFFIX) "$(DESTDIR)$(MANDIR)/man7"; \
1064         done
1065
1066 install_html_docs: install_image_docs build_html_docs
1067         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
1068         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(HTMLDIR)/man1"
1069         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(HTMLDIR)/man3"
1070         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(HTMLDIR)/man5"
1071         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(HTMLDIR)/man7"
1072         @$(ECHO) "*** Installing HTML manpages"
1073         @set -e; for x in dummy $(HTMLDOCS1); do \
1074                 if [ "$$x" = "dummy" ]; then continue; fi; \
1075                 fn=`basename $$x`; \
1076                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man1/$$fn"; \
1077                 cp $$x "$(DESTDIR)$(HTMLDIR)/man1/$$fn"; \
1078                 chmod 644 "$(DESTDIR)$(HTMLDIR)/man1/$$fn"; \
1079         done
1080         @set -e; for x in dummy $(HTMLDOCS3); do \
1081                 if [ "$$x" = "dummy" ]; then continue; fi; \
1082                 fn=`basename $$x`; \
1083                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man3/$$fn"; \
1084                 cp $$x "$(DESTDIR)$(HTMLDIR)/man3/$$fn"; \
1085                 chmod 644 "$(DESTDIR)$(HTMLDIR)/man3/$$fn"; \
1086         done
1087         @set -e; for x in dummy $(HTMLDOCS5); do \
1088                 if [ "$$x" = "dummy" ]; then continue; fi; \
1089                 fn=`basename $$x`; \
1090                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man5/$$fn"; \
1091                 cp $$x "$(DESTDIR)$(HTMLDIR)/man5/$$fn"; \
1092                 chmod 644 "$(DESTDIR)$(HTMLDIR)/man5/$$fn"; \
1093         done
1094         @set -e; for x in dummy $(HTMLDOCS7); do \
1095                 if [ "$$x" = "dummy" ]; then continue; fi; \
1096                 fn=`basename $$x`; \
1097                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man7/$$fn"; \
1098                 cp $$x "$(DESTDIR)$(HTMLDIR)/man7/$$fn"; \
1099                 chmod 644 "$(DESTDIR)$(HTMLDIR)/man7/$$fn"; \
1100         done
1101
1102 uninstall_html_docs: uninstall_image_docs
1103         @$(ECHO) "*** Uninstalling HTML manpages"
1104         @set -e; for x in dummy $(HTMLDOCS1); do \
1105                 if [ "$$x" = "dummy" ]; then continue; fi; \
1106                 fn=`basename $$x`; \
1107                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man1/$$fn"; \
1108                 $(RM) "$(DESTDIR)$(HTMLDIR)/man1/$$fn"; \
1109         done
1110         @set -e; for x in dummy $(HTMLDOCS3); do \
1111                 if [ "$$x" = "dummy" ]; then continue; fi; \
1112                 fn=`basename $$x`; \
1113                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man3/$$fn"; \
1114                 $(RM) "$(DESTDIR)$(HTMLDIR)/man3/$$fn"; \
1115         done
1116         @set -e; for x in dummy $(HTMLDOCS5); do \
1117                 if [ "$$x" = "dummy" ]; then continue; fi; \
1118                 fn=`basename $$x`; \
1119                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man5/$$fn"; \
1120                 $(RM) "$(DESTDIR)$(HTMLDIR)/man5/$$fn"; \
1121         done
1122         @set -e; for x in dummy $(HTMLDOCS7); do \
1123                 if [ "$$x" = "dummy" ]; then continue; fi; \
1124                 fn=`basename $$x`; \
1125                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man7/$$fn"; \
1126                 $(RM) "$(DESTDIR)$(HTMLDIR)/man7/$$fn"; \
1127         done
1128
1129 install_image_docs:
1130         @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(HTMLDIR)/man7/img"
1131         @set -e; for x in dummy $(IMAGEDOCS7); do \
1132                 if [ "$$x" = "dummy" ]; then continue; fi; \
1133                 fn=`basename $$x`; \
1134                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man7/img/$$fn"; \
1135                 cp $(SRCDIR)/$$x "$(DESTDIR)$(HTMLDIR)/man7/img/$$fn"; \
1136                 chmod 644 "$(DESTDIR)$(HTMLDIR)/man7/img/$$fn"; \
1137         done
1138
1139 uninstall_image_docs:
1140         @set -e; for x in dummy $(IMAGEDOCS7); do \
1141                 if [ "$$x" = "dummy" ]; then continue; fi; \
1142                 fn=`basename $$x`; \
1143                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man7/img/$$fn"; \
1144                 $(RM) "$(DESTDIR)$(HTMLDIR)/man7/img/$$fn"; \
1145         done
1146
1147 # Developer targets (note: these are only available on Unix) #########
1148 ##@ Code maintenance
1149
1150 # It's important that generate_buildinfo comes after ordinals, as ordinals
1151 # is sensitive to build.info changes.
1152 update: generate errors ordinals generate_buildinfo ## Update errors, ordinals and build info
1153
1154 .PHONY: generate generate_apps generate_crypto_bn generate_crypto_objects \
1155           generate_crypto_conf generate_crypto_asn1 generate_fuzz_oids
1156 generate: generate_apps generate_crypto_bn generate_crypto_objects \
1157           generate_crypto_conf generate_crypto_asn1 generate_fuzz_oids
1158
1159 .PHONY: generate_buildinfo generate_doc_buildinfo
1160 generate_buildinfo: generate_doc_buildinfo
1161
1162 .PHONY: doc-nits md-nits
1163 doc-nits: build_generated_pods ## Evaluate OpenSSL documentation
1164         $(PERL) $(SRCDIR)/util/find-doc-nits -c -n -l -e
1165
1166 # This uses "mdl", the markdownlint application, which is written in ruby.
1167 # The source is at https://github.com/markdownlint/markdownlint
1168 # If you have ruby installed, "gem install mdl" should work.
1169 # Another option is at https://snapcraft.io/install/mdl/debian
1170 # Finally, there's a Node.js version, which we haven't tried, that
1171 # can be found at https://github.com/DavidAnson/markdownlint
1172 md-nits: ## Evaluate markdown files via "mdl"
1173         mdl -s $(SRCDIR)/util/markdownlint.rb .
1174
1175 # Test coverage is a good idea for the future
1176 #coverage: $(PROGRAMS) $(TESTPROGRAMS)
1177 #       ...
1178
1179 .PHONY: lint
1180 lint: ## Evaluate C code via "splint"
1181         @( cd $(SRCDIR); \
1182            echo splint -DLINT -posixlib -preproc -D__gnuc_va_list=void \
1183            -I. -Iinclude -Iapps/include $(CRYPTOHEADERS) $(SSLHEADERS) $(SRCS) )
1184
1185 .PHONY: check-format
1186 check-format: ## Evaluate C code according to OpenSSL coding standards
1187         ( cd $(SRCDIR); $(PERL) util/check-format.pl \
1188                         $(SRCS) \$(CRYPTOHEADERS) $(SSLHEADERS) )
1189
1190 generate_apps:
1191         ( cd $(SRCDIR); $(PERL) VMS/VMSify-conf.pl \
1192                                 < apps/openssl.cnf > apps/openssl-vms.cnf )
1193
1194 generate_crypto_bn:
1195         ( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h )
1196
1197 generate_crypto_objects:
1198         ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl -n \
1199                                 crypto/objects/objects.txt \
1200                                 crypto/objects/obj_mac.num \
1201                                 > crypto/objects/obj_mac.new && \
1202             mv crypto/objects/obj_mac.new crypto/objects/obj_mac.num )
1203         ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl \
1204                                 crypto/objects/objects.txt \
1205                                 crypto/objects/obj_mac.num \
1206                                 > include/openssl/obj_mac.h )
1207         ( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
1208                                 include/openssl/obj_mac.h \
1209                                 > crypto/objects/obj_dat.h )
1210         ( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
1211                                 crypto/objects/obj_mac.num \
1212                                 crypto/objects/obj_xref.txt \
1213                                 > crypto/objects/obj_xref.h )
1214         ( cd $(SRCDIR); sed -e '1,8d' crypto/objects/obj_compat.h >> include/openssl/obj_mac.h )
1215
1216 generate_crypto_conf:
1217         ( cd $(SRCDIR); $(PERL) crypto/conf/keysets.pl \
1218                                 > crypto/conf/conf_def.h )
1219
1220 generate_crypto_asn1:
1221         ( cd $(SRCDIR); $(PERL) crypto/asn1/charmap.pl \
1222                                 > crypto/asn1/charmap.h )
1223
1224 generate_fuzz_oids:
1225         ( cd $(SRCDIR); $(PERL) fuzz/mkfuzzoids.pl \
1226                                 crypto/objects/obj_dat.h \
1227                                 > fuzz/oids.txt )
1228
1229 generate_doc_buildinfo:
1230         ( $(PERL) -I$(BLDDIR) -Mconfigdata \
1231                 $(SRCDIR)/util/dofile.pl -o Makefile \
1232                         $(SRCDIR)/doc/build.info.in \
1233                         > $(SRCDIR)/doc/build.info.new; \
1234           if ( test -e $(SRCDIR)/doc/build.info \
1235                && cmp $(SRCDIR)/doc/build.info.new $(SRCDIR)/doc/build.info \
1236                   > /dev/null ); \
1237           then \
1238                 rm $(SRCDIR)/doc/build.info.new; \
1239           else \
1240                 mv $(SRCDIR)/doc/build.info.new $(SRCDIR)/doc/build.info; \
1241           fi )
1242
1243 generate_fips_sources: providers/fips.module.sources.new
1244 providers/fips.module.sources.new: configdata.pm
1245         rm -rf sources-tmp
1246         mkdir sources-tmp
1247         ( \
1248           srcdir=`cd $(SRCDIR); pwd`; \
1249           cd sources-tmp \
1250           && $$srcdir/Configure --banner=Configured enable-fips -O0 \
1251           && ./configdata.pm --query 'get_sources("providers/fips")' > sources1 \
1252           && $(MAKE) -sj 4 build_generated providers/fips.so \
1253           && find . -name '*.d' | xargs cat > dep1 \
1254           && $(MAKE) distclean \
1255           && $$srcdir/Configure --banner=Configured enable-fips no-asm -O0 \
1256           && ./configdata.pm --query 'get_sources("providers/fips")' > sources2 \
1257           && $(MAKE) -sj 4 build_generated providers/fips.so \
1258           && find . -name '*.d' | xargs cat > dep2 \
1259           && cat sources1 sources2 \
1260              | grep -v ' : \\$$' | grep -v util/providers.num \
1261              | sed -e 's/^ *//' -e 's/ *\\$$//' \
1262              | sort | uniq > sources \
1263           && cat dep1 dep2 \
1264              | $(PERL) -p -e 's/\\\n//' \
1265              | sed -e 's/^.*: *//' -e 's/  */ /g' \
1266              | fgrep -f sources \
1267              | tr ' ' '\n' \
1268              | sort | uniq > deps.raw \
1269           && cat deps.raw \
1270              | xargs ./configdata.pm --query 'get_sources(@ARGV)' \
1271              | $(PERL) -p -e 's/\\\n//' \
1272              | sed -e 's/\./\\\./g' -e 's/ : */:/' -e 's/^/s:/' -e 's/$$/:/' \
1273              > deps.sed \
1274           && cat deps.raw | sed -f deps.sed > deps \
1275         )
1276         ( \
1277           cat sources-tmp/sources sources-tmp/deps \
1278              | $(PERL) -p -e 's:^ *\Q../\E:: ;' \
1279                           -e 's:^\Q$(SRCDIR)/\E:: if "$(SRCDIR)" ne "." ;' \
1280                           -e 'my $$x; do { $$x = $$_; s:(^|/)((?!\Q../\E)[^/]*/)\Q..\E($$|/):$$1: } while ($$x ne $$_) ;' ; \
1281           cd $(SRCDIR); \
1282           for x in crypto/bn/asm/*.pl crypto/bn/asm/*.S \
1283                    crypto/aes/asm/*.pl crypto/aes/asm/*.S \
1284                    crypto/ec/asm/*.pl \
1285                    crypto/modes/asm/*.pl \
1286                    crypto/sha/asm/*.pl \
1287                    crypto/*cpuid.pl crypto/*cpuid.S \
1288                    crypto/*cap.c; do \
1289             echo "$$x"; \
1290           done \
1291         ) | grep -v sm2p256 | sort | uniq > providers/fips.module.sources.new
1292         rm -rf sources-tmp
1293
1294 # Set to -force to force a rebuild
1295 ERROR_REBUILD=
1296 errors:
1297         ( b=`pwd`; set -e; cd $(SRCDIR); \
1298           $(PERL) util/ck_errf.pl -strict -internal; \
1299           $(PERL) -I$$b util/mkerr.pl $(ERROR_REBUILD) -internal )
1300         ( b=`pwd`; set -e; cd $(SRCDIR)/engines; \
1301           for E in *.ec ; do \
1302               $(PERL) ../util/ck_errf.pl -strict \
1303                 -conf $$E `basename $$E .ec`.c; \
1304               $(PERL) -I$$b ../util/mkerr.pl $(ERROR_REBUILD) -static \
1305                 -conf $$E `basename $$E .ec`.c ; \
1306           done )
1307
1308 {- use File::Basename;
1309
1310    my @sslheaders_tmpl =
1311        qw( include/openssl/ssl.h
1312            include/openssl/ssl2.h
1313            include/openssl/ssl3.h
1314            include/openssl/sslerr.h
1315            include/openssl/tls1.h
1316            include/openssl/dtls1.h
1317            include/openssl/srtp.h
1318            include/openssl/quic.h
1319            include/openssl/sslerr_legacy.h );
1320    my @cryptoheaders_tmpl =
1321        qw( include/internal/dso.h
1322            include/internal/o_dir.h
1323            include/internal/err.h
1324            include/internal/evp.h
1325            include/internal/pem.h
1326            include/internal/asn1.h
1327            include/internal/sslconf.h );
1328    my @cryptoskipheaders = ( @sslheaders_tmpl,
1329        qw( include/openssl/asn1_mac.h
1330            include/openssl/conf_api.h
1331            include/openssl/ebcdic.h
1332            include/openssl/opensslconf.h
1333            include/openssl/symhacks.h ) );
1334    our %cryptoheaders = ();
1335    our %sslheaders = ();
1336    foreach my $d ( qw( include/openssl include/internal ) ) {
1337        my @header_patterns =
1338            map { catfile($config{sourcedir}, $d, $_) } ( '*.h', '*.h.in' );
1339        foreach my $f ( map { glob($_) } @header_patterns ) {
1340            my $base = basename($f);
1341            my $base_in = basename($f, '.in');
1342            my $dir = catfile($config{sourcedir}, $d);
1343            if ($base ne $base_in) {
1344                # We have a .h.in file, which means the header file is in the
1345                # build tree.
1346                $base = $base_in;
1347                $dir = catfile($config{builddir}, $d);
1348            }
1349            my $new_f = catfile($dir, $base);
1350            my $fn = "$d/$base";
1351            # The logic to add files to @cryptoheaders is a bit complex.  The
1352            # file to be added must be either in the public header directory
1353            # or one of the pre-declared internal headers, and must under no
1354            # circumstances be one of those that must be skipped.
1355            $cryptoheaders{$new_f} = 1
1356                if (($d eq 'include/openssl'
1357                     || ( grep { $_ eq $fn } @cryptoheaders_tmpl ))
1358                    && !( grep { $_ eq $fn } @cryptoskipheaders ));
1359            # The logic to add files to @sslheaders is much simpler...
1360            $sslheaders{$new_f} = 1 if grep { $_ eq $fn } @sslheaders_tmpl;
1361        }
1362    }
1363    "";
1364 -}
1365 SRCS={-
1366 sub uniq { my %seen; grep !$seen{$_}++, @_; }
1367 sub flat(@) { return map { ref eq 'ARRAY' ? @$_ : $_ } @_; }
1368 join(" \\\n" . ' ' x 5, fill_lines(" ", $COLUMNS - 5,
1369      uniq(grep /\.(c|cc|cpp)$/,
1370           flat (map { $unified_info{sources}->{$_} }
1371                 (sort keys %{$unified_info{sources}})))))
1372 -}
1373 CRYPTOHEADERS={- join(" \\\n" . ' ' x 14,
1374                       fill_lines(" ", $COLUMNS - 14, sort keys %cryptoheaders)) -}
1375 SSLHEADERS={- join(" \\\n" . ' ' x 11,
1376                    fill_lines(" ", $COLUMNS - 11, sort keys %sslheaders)) -}
1377
1378 renumber: build_generated
1379         $(PERL) $(SRCDIR)/util/mknum.pl --version $(VERSION_NUMBER) --no-warnings \
1380                 --ordinals $(SRCDIR)/util/libcrypto.num \
1381                 --symhacks $(SRCDIR)/include/openssl/symhacks.h \
1382                 --renumber \
1383                 $(CRYPTOHEADERS)
1384         $(PERL) $(SRCDIR)/util/mknum.pl --version $(VERSION_NUMBER) --no-warnings \
1385                 --ordinals $(SRCDIR)/util/libssl.num \
1386                 --symhacks $(SRCDIR)/include/openssl/symhacks.h \
1387                 --renumber \
1388                 $(SSLHEADERS)
1389
1390 .PHONY: ordinals
1391 ordinals: build_generated
1392         $(PERL) $(SRCDIR)/util/mknum.pl --version $(VERSION_NUMBER) --no-warnings \
1393                 --ordinals $(SRCDIR)/util/libcrypto.num \
1394                 --symhacks $(SRCDIR)/include/openssl/symhacks.h \
1395                 $(CRYPTOHEADERS)
1396         $(PERL) $(SRCDIR)/util/mknum.pl --version $(VERSION_NUMBER) --no-warnings \
1397                 --ordinals $(SRCDIR)/util/libssl.num \
1398                 --symhacks $(SRCDIR)/include/openssl/symhacks.h \
1399                 $(SSLHEADERS)
1400
1401 test_ordinals:
1402         $(MAKE) run_tests TESTS=test_ordinals
1403
1404 tags TAGS: FORCE
1405         rm -f TAGS tags
1406         -( cd $(SRCDIR); util/ctags.sh )
1407         -etags `find . -name '*.[ch]' -o -name '*.pm'`
1408
1409 providers/fips.checksum.new: providers/fips.module.sources.new
1410         @which unifdef > /dev/null || \
1411         ( echo >&2 "ERROR: unifdef not in your \$$PATH, FIPS checksums not calculated"; \
1412           false )
1413         ( sources=`pwd`/providers/fips.module.sources.new; \
1414           cd $(SRCDIR) \
1415           && cat $$sources \
1416                  | xargs ./util/fips-checksums.sh ) \
1417                  > providers/fips-sources.checksums.new \
1418         && sha256sum providers/fips-sources.checksums.new \
1419              | sed -e 's|\.new||' > providers/fips.checksum.new
1420
1421 fips-checksums: providers/fips.checksum.new
1422
1423 $(SRCDIR)/providers/fips.checksum: providers/fips.checksum.new
1424         cp -p providers/fips.module.sources.new $(SRCDIR)/providers/fips.module.sources
1425         cp -p providers/fips-sources.checksums.new $(SRCDIR)/providers/fips-sources.checksums
1426         cp -p providers/fips.checksum.new $(SRCDIR)/providers/fips.checksum
1427
1428 update-fips-checksums: $(SRCDIR)/providers/fips.checksum
1429
1430 diff-fips-checksums: fips-checksums
1431         diff -u $(SRCDIR)/providers/fips.module.sources providers/fips.module.sources.new
1432         diff -u $(SRCDIR)/providers/fips-sources.checksums providers/fips-sources.checksums.new
1433         diff -u $(SRCDIR)/providers/fips.checksum providers/fips.checksum.new
1434
1435 # Release targets (note: only available on Unix) #####################
1436
1437 tar:
1438         (cd $(SRCDIR); ./util/mktar.sh --name='$(NAME)' --tarfile='$(TARFILE)')
1439
1440 # Helper targets #####################################################
1441
1442 link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/apps/openssl.cnf
1443
1444 $(BLDDIR)/util/opensslwrap.sh: Makefile
1445         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
1446             mkdir -p "$(BLDDIR)/util"; \
1447             ln -sf "../$(SRCDIR)/util/`basename "$@"`" "$(BLDDIR)/util"; \
1448         fi
1449
1450 $(BLDDIR)/apps/openssl.cnf: Makefile
1451         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
1452             mkdir -p "$(BLDDIR)/apps"; \
1453             ln -sf "../$(SRCDIR)/apps/`basename "$@"`" "$(BLDDIR)/apps"; \
1454         fi
1455
1456 FORCE:
1457
1458 # Building targets ###################################################
1459
1460 Makefile: configdata.pm \
1461           {- join(" \\\n" . ' ' x 10,
1462                   fill_lines(" ", $COLUMNS - 10,
1463                              @{$config{build_file_templates}})) -}
1464         @echo "Detected changed: $?"
1465         $(PERL) configdata.pm
1466         @echo "**************************************************"
1467         @echo "***                                            ***"
1468         @echo "***   Please run the same make command again   ***"
1469         @echo "***                                            ***"
1470         @echo "**************************************************"
1471         @false
1472
1473 configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config \
1474                {- join(" \\\n" . ' ' x 15,
1475                        fill_lines(" ", $COLUMNS - 15,
1476                                   @{$config{build_infos}},
1477                                   @{$config{conf_files}})) -}
1478         @echo "Detected changed: $?"
1479         $(PERL) configdata.pm -r
1480         @echo "**************************************************"
1481         @echo "***                                            ***"
1482         @echo "***   Please run the same make command again   ***"
1483         @echo "***                                            ***"
1484         @echo "**************************************************"
1485         @false
1486
1487 reconfigure reconf:
1488         $(PERL) configdata.pm -r
1489
1490 {-
1491   use File::Basename;
1492   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
1493
1494   # Helper function to convert dependencies in platform agnostic form to
1495   # dependencies in platform form.
1496   sub compute_platform_depends {
1497       map { my $x = $_;
1498
1499             grep { $x eq $_ } @{$unified_info{programs}} and platform->bin($x)
1500             or grep { $x eq $_ } @{$unified_info{modules}} and platform->dso($x)
1501             or grep { $x eq $_ } @{$unified_info{libraries}} and platform->lib($x)
1502             or platform->convertext($x); } @_;
1503   }
1504
1505   # Helper function to figure out dependencies on libraries
1506   # It takes a list of library names and outputs a list of dependencies
1507   sub compute_lib_depends {
1508       # Depending on shared libraries:
1509       # On Windows POSIX layers, we depend on {libname}.dll.a
1510       # On Unix platforms, we depend on {shlibname}.so
1511       return map { platform->sharedlib_simple($_)
1512                    // platform->sharedlib_import($_)
1513                    // platform->sharedlib($_)
1514                    // platform->staticlib($_)
1515                  } @_;
1516   }
1517
1518   sub generatetarget {
1519       my %args = @_;
1520       my $deps = join(" ", compute_platform_depends(@{$args{deps}}));
1521       return <<"EOF";
1522 $args{target}: $deps
1523 EOF
1524   }
1525
1526   sub generatesrc {
1527       my %args = @_;
1528       my $gen0 = $args{generator}->[0];
1529       my $gen_args = join('', map { " $_" }
1530                               @{$args{generator}}[1..$#{$args{generator}}]);
1531       my $gen_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
1532       my $incs = join("", map { " -I".$_ } @{$args{incs}});
1533       my $defs = join("", map { " -D".$_ } @{$args{defs}});
1534       my $deps = join(" ", compute_platform_depends(@{$args{generator_deps}},
1535                                                     @{$args{deps}}));
1536
1537       if ($args{src} =~ /\.html$/) {
1538           #
1539           # HTML generator
1540           #
1541           my $title = basename($args{src}, ".html");
1542           my $pod = $gen0;
1543           return <<"EOF";
1544 $args{src}: $pod
1545         \$(PERL) \$(SRCDIR)/util/mkpod2html.pl -i "$pod" -o \$\@ -t "$title" -r "\$(SRCDIR)/doc"
1546 EOF
1547       } elsif ($args{src} =~ /\.(\d)$/) {
1548           #
1549           # Man-page generator
1550           #
1551           my $section = $1;
1552           my $name = uc basename($args{src}, ".$section");
1553           my $pod = $gen0;
1554           return <<"EOF";
1555 $args{src}: $pod
1556         pod2man --name=$name --section=$section\$(MANSUFFIX) --center=OpenSSL \\
1557                 --release=\$(VERSION) $pod >\$\@
1558 EOF
1559       } elsif (platform->isdef($args{src})) {
1560           #
1561           # Linker script-ish generator
1562           #
1563           my $target = platform->def($args{src});
1564           (my $mkdef_os = $target{shared_target}) =~ s|-shared$||;
1565           my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION_NUMBER)' : '';
1566           my $ord_name = $args{generator}->[1] || $args{product};
1567           return <<"EOF";
1568 $target: $gen0 $deps \$(SRCDIR)/util/mkdef.pl
1569         \$(PERL) \$(SRCDIR)/util/mkdef.pl$ord_ver --type $args{intent} --ordinals $gen0  --name $ord_name --OS $mkdef_os > $target
1570 EOF
1571       } elsif (platform->isasm($args{src})
1572                || platform->iscppasm($args{src})) {
1573           #
1574           # Assembler generator
1575           #
1576           my $cppflags = {
1577               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1578               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1579               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
1580               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
1581           } -> {$args{intent}};
1582
1583           my $generator;
1584           if ($gen0 =~ /\.pl$/) {
1585               $generator = 'CC="$(CC)" $(PERL)'.$gen_incs.' '.$gen0.$gen_args
1586                   .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSOR)';
1587           } elsif ($gen0 =~ /\.m4$/) {
1588               $generator = 'm4 -B 8192'.$gen_incs.' '.$gen0.$gen_args.' >'
1589           } elsif ($gen0 =~ /\.S$/) {
1590               $generator = undef;
1591           } else {
1592               die "Generator type for $args{src} unknown: $gen0\n";
1593           }
1594
1595           if (defined($generator)) {
1596               return <<"EOF";
1597 $args{src}: $gen0 $deps
1598         $generator \$@
1599 EOF
1600           }
1601           return <<"EOF";
1602 $args{src}: $gen0 $deps
1603         \$(CC) $incs $cppflags $defs -E $gen0 | \\
1604         \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
1605 EOF
1606       } elsif ($gen0 =~ m|^.*\.in$|) {
1607           #
1608           # "dofile" generator (file.in -> file)
1609           #
1610           my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1611                                                "util", "dofile.pl")),
1612                                rel2abs($config{builddir}));
1613           my @perlmodules = ();
1614           my %perlmoduleincs = ();
1615           my %perlmoduledeps = ();
1616           foreach my $x (('configdata.pm', @{$args{deps}})) {
1617               # Compute (i)nclusion directory, (m)odule name and (d)ependency
1618               my $i, $m, $d;
1619               if ($x =~ /\|/) {
1620                   $i = $`;
1621                   $d = $';
1622
1623                   # Massage the module part to become a real perl module spec
1624                   $m = $d;
1625                   $m =~ s|\.pm$||;
1626                   # Directory specs are :: in perl package names
1627                   $m =~ s|/|::|g;
1628
1629                   # Full file name of the dependency
1630                   $d = catfile($i, $d) if $i;
1631               } elsif ($x =~ /\.pm$/) {
1632                   $i = dirname($x);
1633                   $m = basename($x, '.pm');
1634                   $d = $x;
1635               } else {
1636                   # All other dependencies are simply collected
1637                   $d = $x;
1638               }
1639               push @perlmodules, '"-M'.$m.'"' if $m;
1640               $perlmoduledeps{$d} = 1;
1641               $perlmoduleincs{'"-I'.$i.'"'} = 1 if $i;
1642           }
1643
1644           # Because of the special treatment of dependencies, we need to
1645           # recompute $deps completely
1646           my $deps
1647               = join(" ", compute_platform_depends(@{$args{generator_deps}},
1648                                                    sort keys %perlmoduledeps));
1649           my $perlmodules = join(' ', '', ( sort keys %perlmoduleincs ), @perlmodules);
1650
1651           return <<"EOF";
1652 $args{src}: $gen0 $deps
1653         \$(PERL)$perlmodules "$dofile" "-o$target{build_file}" $gen0$gen_args > \$@
1654 EOF
1655       } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) {
1656           #
1657           # Generic generator using OpenSSL programs
1658           #
1659
1660           # Redo $gen0, to ensure that we have the proper extension where
1661           # necessary.
1662           $gen0 = platform->bin($gen0);
1663           # Use $(PERL) to execute wrap.pl directly to avoid calling env
1664           return <<"EOF";
1665 $args{src}: $gen0 $deps \$(BLDDIR)/util/wrap.pl
1666         \$(PERL) \$(BLDDIR)/util/wrap.pl $gen0$gen_args > \$@
1667 EOF
1668       } else {
1669           #
1670           # Generic generator using Perl
1671           #
1672           return <<"EOF";
1673 $args{src}: $gen0 $deps
1674         \$(PERL)$gen_incs $gen0$gen_args > \$@
1675 EOF
1676       }
1677   }
1678
1679   # Should one wonder about the end of the Perl snippet, it's because this
1680   # second regexp eats up line endings as well, if the removed path is the
1681   # last in the line.  We may therefore need to put back a line ending.
1682   sub src2obj {
1683       my %args = @_;
1684       my $obj = platform->convertext($args{obj});
1685       my $dep = platform->dep($args{obj});
1686       my @srcs = @{$args{srcs}};
1687       my $srcs = join(" ",  @srcs);
1688       my $deps = join(" ", @srcs, @{$args{deps}});
1689       my $incs = join("", map { " -I".$_ } @{$args{incs}});
1690       my $defs = join("", map { " -D".$_ } @{$args{defs}});
1691       my $cmd;
1692       my $cmdflags;
1693       my $cmdcompile;
1694       if (grep /\.rc$/, @srcs) {
1695           $cmd = '$(RC)';
1696           $cmdflags = '$(RCFLAGS)';
1697           $cmdcompile = '';
1698       } elsif (grep /\.(cc|cpp)$/, @srcs) {
1699           $cmd = '$(CXX)';
1700           $cmdcompile = ' -c';
1701           $cmdflags = {
1702               shlib => '$(LIB_CXXFLAGS) $(LIB_CPPFLAGS)',
1703               lib => '$(LIB_CXXFLAGS) $(LIB_CPPFLAGS)',
1704               dso => '$(DSO_CXXFLAGS) $(DSO_CPPFLAGS)',
1705               bin => '$(BIN_CXXFLAGS) $(BIN_CPPFLAGS)'
1706           } -> {$args{intent}};
1707       } else {
1708           $cmd = '$(CC)';
1709           $cmdcompile = ' -c';
1710           $cmdflags = {
1711               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1712               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1713               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
1714               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
1715           } -> {$args{intent}};
1716       }
1717       my $recipe;
1718       # extension-specific rules
1719       if (grep /\.s$/, @srcs) {
1720           $recipe .= <<"EOF";
1721 $obj: $deps
1722         $cmd $cmdflags -c -o \$\@ $srcs
1723 EOF
1724       } elsif (grep /\.S$/, @srcs) {
1725           # Originally there was multi-step rule with $(CC) -E file.S
1726           # followed by $(CC) -c file.s. It compensated for one of
1727           # legacy platform compiler's inability to handle .S files.
1728           # The platform is long discontinued by vendor so there is
1729           # hardly a point to drag it along...
1730           $recipe .= <<"EOF";
1731 $obj: $deps
1732         $cmd $incs $defs $cmdflags -c -o \$\@ $srcs
1733 EOF
1734       } elsif ($makedep_scheme eq 'gcc' && !grep /\.rc$/, @srcs) {
1735           $recipe .= <<"EOF";
1736 $obj: $deps
1737         $cmd $incs $defs $cmdflags -MMD -MF $dep.tmp -MT \$\@ -c -o \$\@ $srcs
1738         \@touch $dep.tmp
1739         \@if cmp $dep.tmp $dep > /dev/null 2> /dev/null; then \\
1740                 rm -f $dep.tmp; \\
1741         else \\
1742                 mv $dep.tmp $dep; \\
1743         fi
1744 EOF
1745       } else {
1746           $recipe .= <<"EOF";
1747 $obj: $deps
1748         $cmd $incs $defs $cmdflags $cmdcompile -o \$\@ $srcs
1749 EOF
1750           if ($makedep_scheme eq 'makedepend') {
1751               $recipe .= <<"EOF";
1752         \$(MAKEDEPEND) -f- -Y -- $incs $cmdflags -- $srcs 2>/dev/null \\
1753             > $dep
1754 EOF
1755           }
1756       }
1757       return $recipe;
1758   }
1759   # We *know* this routine is only called when we've configure 'shared'.
1760   sub obj2shlib {
1761       my %args = @_;
1762       my @linkdirs = ();
1763       my @linklibs = ();
1764       foreach (@{$args{deps}}) {
1765           if (platform->isstaticlib($_)) {
1766               push @linklibs, platform->convertext($_);
1767           } else {
1768               my $d = "-L" . dirname($_);
1769               my $l = basename($_);
1770               $l =~ s/^lib//;
1771               $l = "-l" . $l;
1772               push @linklibs, $l;
1773               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1774           }
1775       }
1776       my $linkflags = join("", map { $_." " } @linkdirs);
1777       my $linklibs = join("", map { $_." " } @linklibs);
1778       my @objs = map { platform->convertext($_) }
1779                  grep { !platform->isdef($_) }
1780                  @{$args{objs}};
1781       my @defs = map { platform->def($_) }
1782                  grep { platform->isdef($_) }
1783                  @{$args{objs}};
1784       my @deps = compute_lib_depends(@{$args{deps}});
1785       die "More than one exported symbol map" if scalar @defs > 1;
1786
1787       my $full = platform->sharedlib($args{lib});
1788       # $import is for Windows and subsystems thereof, where static import
1789       # libraries for DLLs are a thing.  On platforms that have this mechanism,
1790       # $import has the name of this import library.  On platforms that don't
1791       # have this mechanism, $import will be |undef|.
1792       my $import = platform->sharedlib_import($args{lib});
1793       # $simple is for platforms where full shared library names include the
1794       # shared library version, and there's a simpler name that doesn't include
1795       # that version.  On such platforms, $simple has the simpler name.  On
1796       # other platforms, it will be |undef|.
1797       my $simple = platform->sharedlib_simple($args{lib});
1798
1799       my $argfile = defined $target{shared_argfileflag} ? $full.".args" : undef;
1800       my $shared_soname = "";
1801       $shared_soname .= ' '.$target{shared_sonameflag}.basename($full)
1802           if defined $target{shared_sonameflag};
1803       my $shared_imp = "";
1804       $shared_imp .= ' '.$target{shared_impflag}.basename($import)
1805           if defined $target{shared_impflag} && defined $import;
1806       my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
1807
1808       # There is at least one platform where the compiler-as-linker needs to
1809       # have one object file directly on the command line.  That won't hurt
1810       # any other platform, so we do that for everyone when there's an argfile
1811       # to be had.  This depends heavily on splice, which removes elements from
1812       # the given array, and returns them so they can be captured.
1813       my @argfileobjs = $argfile
1814           ? splice(@objs, 1)
1815           : ();
1816       my $argfilecmds = $argfile
1817           ? join("\n\t", map { "echo $_ >> $argfile" } @argfileobjs)
1818           : undef;
1819       my $argfiledeps = $argfile
1820           ? join(" \\\n" . ' ' x (length($argfile) + 2),
1821                  fill_lines(' ', $COLUMNS - length($full) - 2, @argfileobjs))
1822           : undef;
1823       my @fulldeps = (@objs, ($argfile ? $argfile : ()), @defs, @deps);
1824       my @fullobjs = (
1825           @objs,
1826           ($argfile ? $target{shared_argfileflag}.$argfile : ())
1827       );
1828       my $fulldeps =
1829           join(" \\\n" . ' ' x (length($full) + 2),
1830                fill_lines(' ', $COLUMNS - length($full) - 2, @fulldeps));
1831       my $fullobjs =
1832           join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @fullobjs));
1833
1834       my $recipe = '';
1835
1836       if (defined $simple && $simple ne $full) {
1837           if (sharedaix()) {
1838               $recipe .= <<"EOF";
1839 $simple: $full
1840         rm -f $simple && \\
1841         \$(AR) r $simple $full
1842 EOF
1843           } else {
1844               $recipe .= <<"EOF";
1845 $simple: $full
1846         rm -f $simple && \\
1847         ln -s $full $simple
1848 EOF
1849           }
1850       }
1851       if (defined $import) {
1852       $recipe .= <<"EOF";
1853 $import: $full
1854 EOF
1855       }
1856       $recipe .= <<"EOF";
1857 $full: $fulldeps
1858         \$(CC) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\
1859                 -o $full$shared_def \\
1860                 $fullobjs \\
1861                 $linklibs \$(LIB_EX_LIBS)
1862 EOF
1863       if (windowsdll()) {
1864           $recipe .= <<"EOF";
1865         rm -f apps/$full
1866         rm -f fuzz/$full
1867         cp -p $full apps/
1868         cp -p $full fuzz/
1869 EOF
1870           if (!$disabled{tests}) {
1871             $recipe .= <<"EOF";
1872         rm -f test/$full
1873         cp -p $full test/
1874 EOF
1875           }
1876       }
1877       $recipe .= <<"EOF" if defined $argfile;
1878 $argfile: $argfiledeps
1879         \$(RM) $argfile
1880         $argfilecmds
1881 EOF
1882       return $recipe;
1883   }
1884   sub obj2dso {
1885       my %args = @_;
1886       my $dso = platform->dso($args{module});
1887       my @linkdirs = ();
1888       my @linklibs = ();
1889       foreach (@{$args{deps}}) {
1890           next unless defined $_;
1891           if (platform->isstaticlib($_)) {
1892               push @linklibs, platform->convertext($_);
1893           } else {
1894               my $d = "-L" . dirname($_);
1895               my $l = basename($_);
1896               $l =~ s/^lib//;
1897               $l = "-l" . $l;
1898               push @linklibs, $l;
1899               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1900           }
1901       }
1902       my $linkflags = join("", map { $_." " } @linkdirs);
1903       my $linklibs = join("", map { $_." " } @linklibs);
1904       my @objs = map { platform->convertext($_) }
1905                  grep { !platform->isdef($_) }
1906                  @{$args{objs}};
1907       my @defs = map { platform->def($_) }
1908                  grep { platform->isdef($_) }
1909                  @{$args{objs}};
1910       my @deps = compute_lib_depends(@{$args{deps}});
1911       my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
1912       # Next line needs to become "less magic" (see PR #11950)
1913       $shared_def .= ' '.$target{shared_fipsflag} if (defined $target{shared_fipsflag} && $shared_def =~ m/providers\/fips/);
1914       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1915       my $deps = join(" \\\n" . ' ' x (length($dso) + 2),
1916                       fill_lines(' ', $COLUMNS - length($dso) - 2,
1917                                  @objs, @defs, @deps));
1918
1919       return <<"EOF";
1920 $dso: $deps
1921         \$(CC) \$(DSO_CFLAGS) $linkflags\$(DSO_LDFLAGS) \\
1922                 -o $dso$shared_def \\
1923                 $objs \\
1924                 $linklibs\$(DSO_EX_LIBS)
1925 EOF
1926   }
1927   sub obj2lib {
1928       my %args = @_;
1929       my $lib = platform->staticlib($args{lib});
1930       my @objs = map { platform->obj($_) } @{$args{objs}};
1931       my $deps = join(" \\\n" . ' ' x (length($lib) + 2),
1932                       fill_lines(' ', $COLUMNS - length($lib) - 2, @objs));
1933       my $max_per_call = 500;
1934       my @objs_grouped;
1935       push @objs_grouped, join(" ", splice @objs, 0, $max_per_call) while @objs;
1936       my $fill_lib =
1937           join("\n\t", (map { "\$(AR) \$(ARFLAGS) $lib $_" } @objs_grouped));
1938       return <<"EOF";
1939 $lib: $deps
1940         \$(RM) $lib
1941         $fill_lib
1942         \$(RANLIB) \$\@ || echo Never mind.
1943 EOF
1944   }
1945   sub obj2bin {
1946       my %args = @_;
1947       my $bin = platform->bin($args{bin});
1948       my @objs = map { platform->obj($_) } @{$args{objs}};
1949       my @deps = compute_lib_depends(@{$args{deps}});
1950       my $objs = join(" \\\n" . ' ' x (length($bin) + 2),
1951                       fill_lines(' ', $COLUMNS - length($bin) - 2, @objs));
1952       my @linkdirs = ();
1953       my @linklibs = ();
1954       foreach (@{$args{deps}}) {
1955           next unless defined $_;
1956           if (platform->isstaticlib($_)) {
1957               push @linklibs, platform->convertext($_);
1958           } else {
1959               my $d = "-L" . dirname($_);
1960               my $l = basename($_);
1961               $l =~ s/^lib//;
1962               $l = "-l" . $l;
1963               push @linklibs, $l;
1964               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1965           }
1966       }
1967       my $linkflags = join("", map { $_." " } @linkdirs);
1968       my $linklibs = join("", map { $_." " } @linklibs);
1969       my $cmd = '$(CC)';
1970       my $cmdflags = '$(BIN_CFLAGS)';
1971       if (grep /_cc\.o$/, @{$args{objs}}) {
1972           $cmd = '$(CXX)';
1973           $cmdflags = '$(BIN_CXXFLAGS)';
1974       }
1975
1976       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1977       my $deps = join(" \\\n" . ' ' x (length($bin) + 2),
1978                       fill_lines(' ', $COLUMNS - length($bin) - 2,
1979                                  @objs, @deps));
1980
1981       return <<"EOF";
1982 $bin: $deps
1983         rm -f $bin
1984         \$\${LDCMD:-$cmd} $cmdflags $linkflags\$(BIN_LDFLAGS) \\
1985                 -o $bin \\
1986                 $objs \\
1987                 $linklibs\$(BIN_EX_LIBS)
1988 EOF
1989   }
1990   sub in2script {
1991       my %args = @_;
1992       my $script = $args{script};
1993       my $sources = join(" ", @{$args{sources}});
1994       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1995                                            "util", "dofile.pl")),
1996                            rel2abs($config{builddir}));
1997       return <<"EOF";
1998 $script: $sources configdata.pm
1999         \$(RM) "$script"
2000         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
2001             "-o$target{build_file}" $sources > "$script"
2002         chmod a+x $script
2003 EOF
2004   }
2005   sub generatedir {
2006       my %args = @_;
2007       my $dir = $args{dir};
2008       my @deps = compute_platform_depends(@{$args{deps}});
2009       my @comments = ();
2010
2011       # We already have a 'test' target, and the top directory is just plain
2012       # silly
2013       return if $dir eq "test" || $dir eq ".";
2014
2015       foreach my $type (("dso", "lib", "bin", "script")) {
2016           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
2017           # For lib object files, we could update the library.  However, it
2018           # was decided that it's enough to build the directory local object
2019           # files, so we don't need to add any actions, and the dependencies
2020           # are already taken care of.
2021           if ($type ne "lib") {
2022               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
2023                   if (dirname($prod) eq $dir) {
2024                       push @deps, compute_platform_depends($prod);
2025                   } else {
2026                       push @comments, "# No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
2027                   }
2028               }
2029           }
2030       }
2031
2032       my $target = "$dir $dir/";
2033       my $deps = join(" \\\n\t",
2034                       fill_lines(' ', $COLUMNS - 8, @deps));
2035       my $comments = join("\n", "", @comments);
2036       return <<"EOF";
2037 $target: \\
2038         $deps$comments
2039 EOF
2040   }
2041   ""    # Important!  This becomes part of the template result.
2042 -}