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