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