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