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