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