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