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