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