Configurations/unix-Makefile.tmpl: use platform->sharedlib() as fallback
[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 build_generated providers/fips.so \
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 build_generated providers/fips.so \
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
1314 renumber: build_generated
1315         $(PERL) $(SRCDIR)/util/mknum.pl --version $(VERSION) --no-warnings \
1316                 --ordinals $(SRCDIR)/util/libcrypto.num \
1317                 --symhacks $(SRCDIR)/include/openssl/symhacks.h \
1318                 --renumber \
1319                 $(CRYPTOHEADERS)
1320         $(PERL) $(SRCDIR)/util/mknum.pl --version $(VERSION) --no-warnings \
1321                 --ordinals $(SRCDIR)/util/libssl.num \
1322                 --symhacks $(SRCDIR)/include/openssl/symhacks.h \
1323                 --renumber \
1324                 $(SSLHEADERS)
1325
1326 ordinals: build_generated
1327         $(PERL) $(SRCDIR)/util/mknum.pl --version $(VERSION) --no-warnings \
1328                 --ordinals $(SRCDIR)/util/libcrypto.num \
1329                 --symhacks $(SRCDIR)/include/openssl/symhacks.h \
1330                 $(CRYPTOHEADERS)
1331         $(PERL) $(SRCDIR)/util/mknum.pl --version $(VERSION) --no-warnings \
1332                 --ordinals $(SRCDIR)/util/libssl.num \
1333                 --symhacks $(SRCDIR)/include/openssl/symhacks.h \
1334                 $(SSLHEADERS)
1335
1336 test_ordinals:
1337         $(MAKE) run_tests TESTS=test_ordinals
1338
1339 tags TAGS: FORCE
1340         rm -f TAGS tags
1341         -ctags -R .
1342         -etags `find . -name '*.[ch]' -o -name '*.pm'`
1343
1344 providers/fips.checksum.new: providers/fips.module.sources.new
1345         @which unifdef > /dev/null || \
1346         ( echo >&2 "ERROR: unifdef not in your \$$PATH, FIPS checksums not calculated"; \
1347           false )
1348         ( sources=`pwd`/providers/fips.module.sources.new; \
1349           cd $(SRCDIR) \
1350           && cat $$sources \
1351                  | xargs ./util/fips-checksums.sh ) \
1352                  > providers/fips-sources.checksums.new \
1353         && sha256sum providers/fips-sources.checksums.new \
1354              | sed -e 's|\.new||' > providers/fips.checksum.new
1355
1356 fips-checksums: providers/fips.checksum.new
1357
1358 $(SRCDIR)/providers/fips.checksum: providers/fips.checksum.new
1359         cp -p providers/fips.module.sources.new $(SRCDIR)/providers/fips.module.sources
1360         cp -p providers/fips-sources.checksums.new $(SRCDIR)/providers/fips-sources.checksums
1361         cp -p providers/fips.checksum.new $(SRCDIR)/providers/fips.checksum
1362
1363 update-fips-checksums: $(SRCDIR)/providers/fips.checksum
1364
1365 diff-fips-checksums: fips-checksums
1366         diff -u $(SRCDIR)/providers/fips.module.sources providers/fips.module.sources.new
1367         diff -u $(SRCDIR)/providers/fips-sources.checksums providers/fips-sources.checksums.new
1368         diff -u $(SRCDIR)/providers/fips.checksum providers/fips.checksum.new
1369
1370 # Release targets (note: only available on Unix) #####################
1371
1372 tar:
1373         (cd $(SRCDIR); ./util/mktar.sh --name='$(NAME)' --tarfile='$(TARFILE)')
1374
1375 # Helper targets #####################################################
1376
1377 link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/apps/openssl.cnf
1378
1379 $(BLDDIR)/util/opensslwrap.sh: configdata.pm
1380         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
1381             mkdir -p "$(BLDDIR)/util"; \
1382             ln -sf "../$(SRCDIR)/util/`basename "$@"`" "$(BLDDIR)/util"; \
1383         fi
1384
1385 $(BLDDIR)/apps/openssl.cnf: configdata.pm
1386         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
1387             mkdir -p "$(BLDDIR)/apps"; \
1388             ln -sf "../$(SRCDIR)/apps/`basename "$@"`" "$(BLDDIR)/apps"; \
1389         fi
1390
1391 FORCE:
1392
1393 # Building targets ###################################################
1394
1395 libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { platform->sharedlib_simple($_) // platform->sharedlib_import($_) // platform->sharedlib($_) // () } @{$unified_info{libraries}}) -}
1396 libcrypto.pc:
1397         @ ( echo 'prefix=$(INSTALLTOP)'; \
1398             echo 'exec_prefix=$${prefix}'; \
1399             if [ -n "$(LIBDIR)" ]; then \
1400                 echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
1401             else \
1402                 echo 'libdir=$(libdir)'; \
1403             fi; \
1404             echo 'includedir=$${prefix}/include'; \
1405             echo 'enginesdir=$${libdir}/engines-{- $sover_dirname -}'; \
1406             echo ''; \
1407             echo 'Name: OpenSSL-libcrypto'; \
1408             echo 'Description: OpenSSL cryptography library'; \
1409             echo 'Version: '$(VERSION); \
1410             echo 'Libs: -L$${libdir} -lcrypto'; \
1411             echo 'Libs.private: $(LIB_EX_LIBS)'; \
1412             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
1413
1414 libssl.pc:
1415         @ ( echo 'prefix=$(INSTALLTOP)'; \
1416             echo 'exec_prefix=$${prefix}'; \
1417             if [ -n "$(LIBDIR)" ]; then \
1418                 echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
1419             else \
1420                 echo 'libdir=$(libdir)'; \
1421             fi; \
1422             echo 'includedir=$${prefix}/include'; \
1423             echo ''; \
1424             echo 'Name: OpenSSL-libssl'; \
1425             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
1426             echo 'Version: '$(VERSION); \
1427             echo 'Requires.private: libcrypto'; \
1428             echo 'Libs: -L$${libdir} -lssl'; \
1429             echo 'Cflags: -I$${includedir}' ) > libssl.pc
1430
1431 openssl.pc:
1432         @ ( echo 'prefix=$(INSTALLTOP)'; \
1433             echo 'exec_prefix=$${prefix}'; \
1434             if [ -n "$(LIBDIR)" ]; then \
1435                 echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
1436             else \
1437                 echo 'libdir=$(libdir)'; \
1438             fi; \
1439             echo 'includedir=$${prefix}/include'; \
1440             echo ''; \
1441             echo 'Name: OpenSSL'; \
1442             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
1443             echo 'Version: '$(VERSION); \
1444             echo 'Requires: libssl libcrypto' ) > openssl.pc
1445
1446 configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config \
1447                {- join(" \\\n" . ' ' x 15,
1448                        fill_lines(" ", $COLUMNS - 15,
1449                                   @{$config{build_file_templates}},
1450                                   @{$config{build_infos}},
1451                                   @{$config{conf_files}})) -}
1452         @echo "Detected changed: $?"
1453         $(PERL) configdata.pm -r
1454         @echo "**************************************************"
1455         @echo "***                                            ***"
1456         @echo "***   Please run the same make command again   ***"
1457         @echo "***                                            ***"
1458         @echo "**************************************************"
1459         @false
1460
1461 reconfigure reconf:
1462         $(PERL) configdata.pm -r
1463
1464 {-
1465   use File::Basename;
1466   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
1467
1468   # Helper function to convert dependencies in platform agnostic form to
1469   # dependencies in platform form.
1470   sub compute_platform_depends {
1471       map { my $x = $_;
1472
1473             grep { $x eq $_ } @{$unified_info{programs}} and platform->bin($x)
1474             or grep { $x eq $_ } @{$unified_info{modules}} and platform->dso($x)
1475             or grep { $x eq $_ } @{$unified_info{libraries}} and platform->lib($x)
1476             or platform->convertext($x); } @_;
1477   }
1478
1479   # Helper function to figure out dependencies on libraries
1480   # It takes a list of library names and outputs a list of dependencies
1481   sub compute_lib_depends {
1482       # Depending on shared libraries:
1483       # On Windows POSIX layers, we depend on {libname}.dll.a
1484       # On Unix platforms, we depend on {shlibname}.so
1485       return map { platform->sharedlib_simple($_)
1486                    // platform->sharedlib_import($_)
1487                    // platform->sharedlib($_)
1488                    // platform->staticlib($_)
1489                  } @_;
1490   }
1491
1492   sub generatetarget {
1493       my %args = @_;
1494       my $deps = join(" ", compute_platform_depends(@{$args{deps}}));
1495       return <<"EOF";
1496 $args{target}: $deps
1497 EOF
1498   }
1499
1500   sub generatesrc {
1501       my %args = @_;
1502       my $gen0 = $args{generator}->[0];
1503       my $gen_args = join('', map { " $_" }
1504                               @{$args{generator}}[1..$#{$args{generator}}]);
1505       my $gen_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
1506       my $incs = join("", map { " -I".$_ } @{$args{incs}});
1507       my $defs = join("", map { " -D".$_ } @{$args{defs}});
1508       my $deps = join(" ", compute_platform_depends(@{$args{generator_deps}},
1509                                                     @{$args{deps}}));
1510
1511       if ($args{src} =~ /\.html$/) {
1512           #
1513           # HTML generator
1514           #
1515           my $title = basename($args{src}, ".html");
1516           my $pod = $gen0;
1517           return <<"EOF";
1518 $args{src}: $pod
1519         \$(PERL) \$(SRCDIR)/util/mkpod2html.pl -i "$pod" -o \$\@ -t "$title" -r "\$(SRCDIR)/doc"
1520 EOF
1521       } elsif ($args{src} =~ /\.(\d)$/) {
1522           #
1523           # Man-page generator
1524           #
1525           my $section = $1;
1526           my $name = uc basename($args{src}, ".$section");
1527           my $pod = $gen0;
1528           return <<"EOF";
1529 $args{src}: $pod
1530         pod2man --name=$name --section=$section\$(MANSUFFIX) --center=OpenSSL \\
1531                 --release=\$(VERSION) $pod >\$\@
1532 EOF
1533       } elsif (platform->isdef($args{src})) {
1534           #
1535           # Linker script-ish generator
1536           #
1537           my $target = platform->def($args{src});
1538           (my $mkdef_os = $target{shared_target}) =~ s|-shared$||;
1539           my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION)' : '';
1540           my $ord_name = $args{generator}->[1] || $args{product};
1541           return <<"EOF";
1542 $target: $gen0 $deps \$(SRCDIR)/util/mkdef.pl
1543         \$(PERL) \$(SRCDIR)/util/mkdef.pl$ord_ver --ordinals $gen0  --name $ord_name --OS $mkdef_os > $target
1544 EOF
1545       } elsif (platform->isasm($args{src})) {
1546           #
1547           # Assembler generator
1548           #
1549           my $cppflags = {
1550               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1551               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1552               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
1553               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
1554           } -> {$args{intent}};
1555
1556           my $generator;
1557           if ($gen0 =~ /\.pl$/) {
1558               $generator = 'CC="$(CC)" $(PERL)'.$gen_incs.' '.$gen0.$gen_args
1559                   .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSOR)';
1560           } elsif ($gen0 =~ /\.m4$/) {
1561               $generator = 'm4 -B 8192'.$gen_incs.' '.$gen0.$gen_args.' >'
1562           } elsif ($gen0 =~ /\.S$/) {
1563               $generator = undef;
1564           } else {
1565               die "Generator type for $args{src} unknown: $gen0\n";
1566           }
1567
1568           if (defined($generator)) {
1569               return <<"EOF";
1570 $args{src}: $gen0 $deps
1571         $generator \$@
1572 EOF
1573           }
1574           return <<"EOF";
1575 $args{src}: $gen0 $deps
1576         \$(CC) $incs $cppflags $defs -E $gen0 | \\
1577         \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
1578 EOF
1579       } elsif ($gen0 =~ m|^.*\.in$|) {
1580           #
1581           # "dofile" generator (file.in -> file)
1582           #
1583           my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1584                                                "util", "dofile.pl")),
1585                                rel2abs($config{builddir}));
1586           my @perlmodules = ( 'configdata.pm',
1587                               grep { $_ =~ m|\.pm$| } @{$args{deps}} );
1588           my %perlmoduleincs = map { '"-I'.dirname($_).'"' => 1 } @perlmodules;
1589           $deps = join(' ', $deps, compute_platform_depends(@perlmodules));
1590           @perlmodules = map { "-M".basename($_, '.pm') } @perlmodules;
1591           my $perlmodules = join(' ', '', sort keys %perlmoduleincs, @perlmodules);
1592           return <<"EOF";
1593 $args{src}: $gen0 $deps
1594         \$(PERL)$perlmodules "$dofile" "-o$target{build_file}" $gen0$gen_args > \$@
1595 EOF
1596       } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) {
1597           #
1598           # Generic generator using OpenSSL programs
1599           #
1600
1601           # Redo $gen0, to ensure that we have the proper extension where
1602           # necessary.
1603           $gen0 = platform->bin($gen0);
1604           # Use $(PERL) to execute wrap.pl directly to avoid calling env
1605           return <<"EOF";
1606 $args{src}: $gen0 $deps \$(BLDDIR)/util/wrap.pl
1607         \$(PERL) \$(BLDDIR)/util/wrap.pl $gen0$gen_args > \$@
1608 EOF
1609       } else {
1610           #
1611           # Generic generator using Perl
1612           #
1613           return <<"EOF";
1614 $args{src}: $gen0 $deps
1615         \$(PERL)$gen_incs $gen0$gen_args > \$@
1616 EOF
1617       }
1618   }
1619
1620   # Should one wonder about the end of the Perl snippet, it's because this
1621   # second regexp eats up line endings as well, if the removed path is the
1622   # last in the line.  We may therefore need to put back a line ending.
1623   sub src2obj {
1624       my %args = @_;
1625       my $obj = platform->convertext($args{obj});
1626       my $dep = platform->dep($args{obj});
1627       my @srcs = @{$args{srcs}};
1628       my $srcs = join(" ",  @srcs);
1629       my $deps = join(" ", @srcs, @{$args{deps}});
1630       my $incs = join("", map { " -I".$_ } @{$args{incs}});
1631       my $defs = join("", map { " -D".$_ } @{$args{defs}});
1632       my $cmd;
1633       my $cmdflags;
1634       my $cmdcompile;
1635       if (grep /\.rc$/, @srcs) {
1636           $cmd = '$(RC)';
1637           $cmdflags = '$(RCFLAGS)';
1638           $cmdcompile = '';
1639       } elsif (grep /\.(cc|cpp)$/, @srcs) {
1640           $cmd = '$(CXX)';
1641           $cmdcompile = ' -c';
1642           $cmdflags = {
1643               shlib => '$(LIB_CXXFLAGS) $(LIB_CPPFLAGS)',
1644               lib => '$(LIB_CXXFLAGS) $(LIB_CPPFLAGS)',
1645               dso => '$(DSO_CXXFLAGS) $(DSO_CPPFLAGS)',
1646               bin => '$(BIN_CXXFLAGS) $(BIN_CPPFLAGS)'
1647           } -> {$args{intent}};
1648       } else {
1649           $cmd = '$(CC)';
1650           $cmdcompile = ' -c';
1651           $cmdflags = {
1652               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1653               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1654               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
1655               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
1656           } -> {$args{intent}};
1657       }
1658       my $recipe;
1659       # extension-specific rules
1660       if (grep /\.s$/, @srcs) {
1661           $recipe .= <<"EOF";
1662 $obj: $deps
1663         $cmd $cmdflags -c -o \$\@ $srcs
1664 EOF
1665       } elsif (grep /\.S$/, @srcs) {
1666           # Originally there was multi-step rule with $(CC) -E file.S
1667           # followed by $(CC) -c file.s. It compensated for one of
1668           # legacy platform compiler's inability to handle .S files.
1669           # The platform is long discontinued by vendor so there is
1670           # hardly a point to drag it along...
1671           $recipe .= <<"EOF";
1672 $obj: $deps
1673         $cmd $incs $defs $cmdflags -c -o \$\@ $srcs
1674 EOF
1675       } elsif ($makedep_scheme eq 'gcc' && !grep /\.rc$/, @srcs) {
1676           $recipe .= <<"EOF";
1677 $obj: $deps
1678         $cmd $incs $defs $cmdflags -MMD -MF $dep.tmp -MT \$\@ -c -o \$\@ $srcs
1679         \@touch $dep.tmp
1680         \@if cmp $dep.tmp $dep > /dev/null 2> /dev/null; then \\
1681                 rm -f $dep.tmp; \\
1682         else \\
1683                 mv $dep.tmp $dep; \\
1684         fi
1685 EOF
1686       } else {
1687           $recipe .= <<"EOF";
1688 $obj: $deps
1689         $cmd $incs $defs $cmdflags $cmdcompile -o \$\@ $srcs
1690 EOF
1691           if ($makedep_scheme eq 'makedepend') {
1692               $recipe .= <<"EOF";
1693         \$(MAKEDEPEND) -f- -Y -- $incs $cmdflags -- $srcs 2>/dev/null \\
1694             > $dep
1695 EOF
1696           }
1697       }
1698       return $recipe;
1699   }
1700   # We *know* this routine is only called when we've configure 'shared'.
1701   sub obj2shlib {
1702       my %args = @_;
1703       my @linkdirs = ();
1704       my @linklibs = ();
1705       foreach (@{$args{deps}}) {
1706           if (platform->isstaticlib($_)) {
1707               push @linklibs, platform->convertext($_);
1708           } else {
1709               my $d = "-L" . dirname($_);
1710               my $l = basename($_);
1711               $l =~ s/^lib//;
1712               $l = "-l" . $l;
1713               push @linklibs, $l;
1714               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1715           }
1716       }
1717       my $linkflags = join("", map { $_." " } @linkdirs);
1718       my $linklibs = join("", map { $_." " } @linklibs);
1719       my @objs = map { platform->convertext($_) }
1720                  grep { !platform->isdef($_) }
1721                  @{$args{objs}};
1722       my @defs = map { platform->def($_) }
1723                  grep { platform->isdef($_) }
1724                  @{$args{objs}};
1725       my @deps = compute_lib_depends(@{$args{deps}});
1726       die "More than one exported symbol map" if scalar @defs > 1;
1727
1728       my $full = platform->sharedlib($args{lib});
1729       # $import is for Windows and subsystems thereof, where static import
1730       # libraries for DLLs are a thing.  On platforms that have this mechanism,
1731       # $import has the name of this import library.  On platforms that don't
1732       # have this mechanism, $import will be |undef|.
1733       my $import = platform->sharedlib_import($args{lib});
1734       # $simple is for platforms where full shared library names include the
1735       # shared library version, and there's a simpler name that doesn't include
1736       # that version.  On such platforms, $simple has the simpler name.  On
1737       # other platforms, it will be |undef|.
1738       my $simple = platform->sharedlib_simple($args{lib});
1739
1740       my $argfile = defined $target{shared_argfileflag} ? $full.".args" : undef;
1741       my $shared_soname = "";
1742       $shared_soname .= ' '.$target{shared_sonameflag}.basename($full)
1743           if defined $target{shared_sonameflag};
1744       my $shared_imp = "";
1745       $shared_imp .= ' '.$target{shared_impflag}.basename($import)
1746           if defined $target{shared_impflag} && defined $import;
1747       my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
1748
1749       # There is at least one platform where the compiler-as-linker needs to
1750       # have one object file directly on the command line.  That won't hurt
1751       # any other platform, so we do that for everyone when there's an argfile
1752       # to be had.  This depends heavily on splice, which removes elements from
1753       # the given array, and returns them so they can be captured.
1754       my @argfileobjs = $argfile
1755           ? splice(@objs, 1)
1756           : ();
1757       my $argfilecmds = $argfile
1758           ? join("\n\t", map { "echo $_ >> $argfile" } @argfileobjs)
1759           : undef;
1760       my $argfiledeps = $argfile
1761           ? join(" \\\n" . ' ' x (length($argfile) + 2),
1762                  fill_lines(' ', $COLUMNS - length($full) - 2, @argfileobjs))
1763           : undef;
1764       my @fulldeps = (@objs, ($argfile ? $argfile : ()), @defs, @deps);
1765       my @fullobjs = (
1766           @objs,
1767           ($argfile ? $target{shared_argfileflag}.$argfile : ())
1768       );
1769       my $fulldeps =
1770           join(" \\\n" . ' ' x (length($full) + 2),
1771                fill_lines(' ', $COLUMNS - length($full) - 2, @fulldeps));
1772       my $fullobjs =
1773           join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @fullobjs));
1774
1775       my $recipe = '';
1776
1777       if (defined $simple && $simple ne $full) {
1778           if (sharedaix()) {
1779               $recipe .= <<"EOF";
1780 $simple: $full
1781         rm -f $simple && \\
1782         \$(AR) r $simple $full
1783 EOF
1784           } else {
1785               $recipe .= <<"EOF";
1786 $simple: $full
1787         rm -f $simple && \\
1788         ln -s $full $simple
1789 EOF
1790           }
1791       }
1792       if (defined $import) {
1793       $recipe .= <<"EOF";
1794 $import: $full
1795 EOF
1796       }
1797       $recipe .= <<"EOF";
1798 $full: $fulldeps
1799         \$(CC) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\
1800                 -o $full$shared_def \\
1801                 $fullobjs \\
1802                 $linklibs \$(LIB_EX_LIBS)
1803 EOF
1804       if (windowsdll()) {
1805           $recipe .= <<"EOF";
1806         rm -f apps/$full
1807         rm -f fuzz/$full
1808         cp -p $full apps/
1809         cp -p $full fuzz/
1810 EOF
1811           if (!$disabled{tests}) {
1812             $recipe .= <<"EOF";
1813         rm -f test/$full
1814         cp -p $full test/
1815 EOF
1816           }
1817       }
1818       $recipe .= <<"EOF" if defined $argfile;
1819 $argfile: $argfiledeps
1820         \$(RM) $argfile
1821         $argfilecmds
1822 EOF
1823       return $recipe;
1824   }
1825   sub obj2dso {
1826       my %args = @_;
1827       my $dso = platform->dso($args{module});
1828       my @linkdirs = ();
1829       my @linklibs = ();
1830       foreach (@{$args{deps}}) {
1831           next unless defined $_;
1832           if (platform->isstaticlib($_)) {
1833               push @linklibs, platform->convertext($_);
1834           } else {
1835               my $d = "-L" . dirname($_);
1836               my $l = basename($_);
1837               $l =~ s/^lib//;
1838               $l = "-l" . $l;
1839               push @linklibs, $l;
1840               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1841           }
1842       }
1843       my $linkflags = join("", map { $_." " } @linkdirs);
1844       my $linklibs = join("", map { $_." " } @linklibs);
1845       my @objs = map { platform->convertext($_) }
1846                  grep { !platform->isdef($_) }
1847                  @{$args{objs}};
1848       my @defs = map { platform->def($_) }
1849                  grep { platform->isdef($_) }
1850                  @{$args{objs}};
1851       my @deps = compute_lib_depends(@{$args{deps}});
1852       my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
1853       # Next line needs to become "less magic" (see PR #11950)
1854       $shared_def .= ' '.$target{shared_fipsflag} if (defined $target{shared_fipsflag} && $shared_def =~ m/providers\/fips/);
1855       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1856       my $deps = join(" \\\n" . ' ' x (length($dso) + 2),
1857                       fill_lines(' ', $COLUMNS - length($dso) - 2,
1858                                  @objs, @defs, @deps));
1859
1860       return <<"EOF";
1861 $dso: $deps
1862         \$(CC) \$(DSO_CFLAGS) $linkflags\$(DSO_LDFLAGS) \\
1863                 -o $dso$shared_def \\
1864                 $objs \\
1865                 $linklibs\$(DSO_EX_LIBS)
1866 EOF
1867   }
1868   sub obj2lib {
1869       my %args = @_;
1870       my $lib = platform->staticlib($args{lib});
1871       my @objs = map { platform->obj($_) } @{$args{objs}};
1872       my $deps = join(" \\\n" . ' ' x (length($lib) + 2),
1873                       fill_lines(' ', $COLUMNS - length($lib) - 2, @objs));
1874       my $max_per_call = 500;
1875       my @objs_grouped;
1876       push @objs_grouped, join(" ", splice @objs, 0, $max_per_call) while @objs;
1877       my $fill_lib =
1878           join("\n\t", (map { "\$(AR) \$(ARFLAGS) $lib $_" } @objs_grouped));
1879       return <<"EOF";
1880 $lib: $deps
1881         \$(RM) $lib
1882         $fill_lib
1883         \$(RANLIB) \$\@ || echo Never mind.
1884 EOF
1885   }
1886   sub obj2bin {
1887       my %args = @_;
1888       my $bin = platform->bin($args{bin});
1889       my @objs = map { platform->obj($_) } @{$args{objs}};
1890       my @deps = compute_lib_depends(@{$args{deps}});
1891       my $objs = join(" \\\n" . ' ' x (length($bin) + 2),
1892                       fill_lines(' ', $COLUMNS - length($bin) - 2, @objs));
1893       my @linkdirs = ();
1894       my @linklibs = ();
1895       foreach (@{$args{deps}}) {
1896           next unless defined $_;
1897           if (platform->isstaticlib($_)) {
1898               push @linklibs, platform->convertext($_);
1899           } else {
1900               my $d = "-L" . dirname($_);
1901               my $l = basename($_);
1902               $l =~ s/^lib//;
1903               $l = "-l" . $l;
1904               push @linklibs, $l;
1905               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1906           }
1907       }
1908       my $linkflags = join("", map { $_." " } @linkdirs);
1909       my $linklibs = join("", map { $_." " } @linklibs);
1910       my $cmd = '$(CC)';
1911       my $cmdflags = '$(BIN_CFLAGS)';
1912       if (grep /_cc\.o$/, @{$args{objs}}) {
1913           $cmd = '$(CXX)';
1914           $cmdflags = '$(BIN_CXXFLAGS)';
1915       }
1916
1917       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1918       my $deps = join(" \\\n" . ' ' x (length($bin) + 2),
1919                       fill_lines(' ', $COLUMNS - length($bin) - 2,
1920                                  @objs, @deps));
1921
1922       return <<"EOF";
1923 $bin: $deps
1924         rm -f $bin
1925         \$\${LDCMD:-$cmd} $cmdflags $linkflags\$(BIN_LDFLAGS) \\
1926                 -o $bin \\
1927                 $objs \\
1928                 $linklibs\$(BIN_EX_LIBS)
1929 EOF
1930   }
1931   sub in2script {
1932       my %args = @_;
1933       my $script = $args{script};
1934       my $sources = join(" ", @{$args{sources}});
1935       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1936                                            "util", "dofile.pl")),
1937                            rel2abs($config{builddir}));
1938       return <<"EOF";
1939 $script: $sources configdata.pm
1940         \$(RM) "$script"
1941         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1942             "-o$target{build_file}" $sources > "$script"
1943         chmod a+x $script
1944 EOF
1945   }
1946   sub generatedir {
1947       my %args = @_;
1948       my $dir = $args{dir};
1949       my @deps = compute_platform_depends(@{$args{deps}});
1950       my @comments = ();
1951
1952       # We already have a 'test' target, and the top directory is just plain
1953       # silly
1954       return if $dir eq "test" || $dir eq ".";
1955
1956       foreach my $type (("dso", "lib", "bin", "script")) {
1957           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
1958           # For lib object files, we could update the library.  However, it
1959           # was decided that it's enough to build the directory local object
1960           # files, so we don't need to add any actions, and the dependencies
1961           # are already taken care of.
1962           if ($type ne "lib") {
1963               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
1964                   if (dirname($prod) eq $dir) {
1965                       push @deps, compute_platform_depends($prod);
1966                   } else {
1967                       push @comments, "# No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
1968                   }
1969               }
1970           }
1971       }
1972
1973       my $target = "$dir $dir/";
1974       my $deps = join(" \\\n\t",
1975                       fill_lines(' ', $COLUMNS - 8, @deps));
1976       my $comments = join("\n", "", @comments);
1977       return <<"EOF";
1978 $target: \\
1979         $deps$comments
1980 EOF
1981   }
1982   ""    # Important!  This becomes part of the template result.
1983 -}