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