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