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