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