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