b1c087272d2df31ddac97aa4c4227a108c49c1ad
[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                                @{$config{lib_defines} || ()},
336                                @{$config{shared_defines} || ()}),
337                           @{$config{lib_cppflags}},
338                           @{$config{shared_cppflag}});
339                 join(' ', $lib_cppflags,
340                           (map { '-D'.$_ }
341                                'OPENSSLDIR="\"$(OPENSSLDIR)\""',
342                                'ENGINESDIR="\"$(ENGINESDIR)\""',
343                                'MODULESDIR="\"$(MODULESDIR)\""'),
344                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
345 LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
346                         $target{shared_cflag} || (),
347                         @{$config{lib_cflags}},
348                         @{$config{shared_cflag}},
349                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
350 LIB_CXXFLAGS={- join(' ', $target{lib_cxxflags} || (),
351                           $target{shared_cxxflag} || (),
352                           @{$config{lib_cxxflags}},
353                           @{$config{shared_cxxflag}},
354                           '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
355 LIB_LDFLAGS={- join(' ', $target{shared_ldflag} || (),
356                          $config{shared_ldflag} || (),
357                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
358 LIB_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
359 DSO_CPPFLAGS={- join(' ', $target{dso_cppflags} || (),
360                           $target{module_cppflags} || (),
361                           (map { '-D'.$_ }
362                                @{$config{dso_defines} || ()},
363                                @{$config{module_defines} || ()}),
364                           @{$config{dso_cppflags}},
365                           @{$config{module_cppflags}},
366                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
367 DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
368                         $target{module_cflags} || (),
369                         @{$config{dso_cflags}},
370                         @{$config{module_cflags}},
371                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
372 DSO_CXXFLAGS={- join(' ', $target{dso_cxxflags} || (),
373                           $target{module_cxxflags} || (),
374                           @{$config{dso_cxxflags}},
375                           @{$config{module_cxxflag}},
376                           '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
377 DSO_LDFLAGS={- join(' ', $target{dso_ldflags} || (),
378                          $target{module_ldflags} || (),
379                          @{$config{dso_ldflags}},
380                          @{$config{module_ldflags}},
381                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
382 DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
383 BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
384                           (map { '-D'.$_ } @{$config{bin_defines} || ()}),
385                           @{$config{bin_cppflags}},
386                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
387 BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
388                         @{$config{bin_cflags}},
389                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
390 BIN_CXXFLAGS={- join(' ', $target{bin_cxxflags} || (),
391                           @{$config{bin_cxxflags}},
392                           '$(CNF_CXXFLAGS)', '$(CXXFLAGS)') -}
393 BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
394                          @{$config{bin_lflags}},
395                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
396 BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
397
398 # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
399 CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
400               $cppflags2 =~ s|([\\"])|\\$1|g;
401               $lib_cppflags =~ s|([\\"])|\\$1|g;
402               join(' ', $lib_cppflags || (), $cppflags2 || (),
403                         $cppflags1 || ()) -}
404
405 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
406
407 # For x86 assembler: Set PROCESSOR to 386 if you want to support
408 # the 80386.
409 PROCESSOR= {- $config{processor} -}
410
411 # We want error [and other] messages in English. Trouble is that make(1)
412 # doesn't pass macros down as environment variables unless there already
413 # was corresponding variable originally set. In other words we can only
414 # reassign environment variables, but not set new ones, not in portable
415 # manner that is. That's why we reassign several, just to be sure...
416 LC_ALL=C
417 LC_MESSAGES=C
418 LANG=C
419
420 # The main targets ###################################################
421
422 {- dependmagic('build_sw'); -}: build_libs_nodep build_modules_nodep build_programs_nodep link-utils
423 {- dependmagic('build_libs'); -}: build_libs_nodep
424 {- dependmagic('build_modules'); -}: build_modules_nodep
425 {- dependmagic('build_programs'); -}: build_programs_nodep
426
427 build_docs: build_man_docs build_html_docs
428 build_man_docs: $(MANDOCS1) $(MANDOCS3) $(MANDOCS5) $(MANDOCS7)
429 build_html_docs: $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
430
431 build_generated: $(GENERATED_MANDATORY)
432 build_libs_nodep: libcrypto.pc libssl.pc openssl.pc
433 build_modules_nodep: $(MODULES)
434 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
435
436 # Kept around for backward compatibility
437 build_apps build_tests: build_programs
438
439 # Convenience target to prebuild all generated files, not just the mandatory
440 # ones
441 build_all_generated: $(GENERATED_MANDATORY) $(GENERATED) build_docs
442         @ : {- output_off() if $disabled{makedepend}; "" -}
443         @echo "Warning: consider configuring with no-makedepend, because if"
444         @echo "         target system doesn't have $(PERL),"
445         @echo "         then make will fail..."
446         @ : {- output_on() if $disabled{makedepend}; "" -}
447
448 all: build_sw build_docs
449
450 test: tests
451 {- dependmagic('tests'); -}: build_programs_nodep build_modules_nodep link-utils
452         @ : {- output_off() if $disabled{tests}; "" -}
453         ( cd test; \
454           mkdir -p test-runs; \
455           SRCTOP=../$(SRCDIR) \
456           BLDTOP=../$(BLDDIR) \
457           RESULT_D=test-runs \
458           PERL="$(PERL)" \
459           EXE_EXT={- platform->binext() -} \
460           OPENSSL_ENGINES=`cd ../$(BLDDIR)/engines 2>/dev/null && pwd` \
461           OPENSSL_MODULES=`cd ../$(BLDDIR)/providers 2>/dev/null && pwd` \
462           $(PERL) ../$(SRCDIR)/test/run_tests.pl $(TESTS) )
463         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
464         @echo "Tests are not supported with your chosen Configure options"
465         @ : {- output_on() if !$disabled{tests}; "" -}
466
467 list-tests:
468         @ : {- output_off() if $disabled{tests}; "" -}
469         @SRCTOP="$(SRCDIR)" \
470          $(PERL) $(SRCDIR)/test/run_tests.pl list
471         @ : {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
472         @echo "Tests are not supported with your chosen Configure options"
473         @ : {- output_on() if !$disabled{tests}; "" -}
474
475 install: install_sw install_ssldirs install_docs
476
477 uninstall: uninstall_docs uninstall_sw
478
479 libclean:
480         @set -e; for s in $(SHLIB_INFO); do \
481                 if [ "$$s" = ";" ]; then continue; fi; \
482                 s1=`echo "$$s" | cut -f1 -d";"`; \
483                 s2=`echo "$$s" | cut -f2 -d";"`; \
484                 $(ECHO) $(RM) $$s1; {- output_off() unless windowsdll(); "" -}\
485                 $(RM) apps/$$s1; \
486                 $(RM) test/$$s1; \
487                 $(RM) fuzz/$$s1; {- output_on() unless windowsdll(); "" -}\
488                 $(RM) $$s1; \
489                 if [ "$$s1" != "$$s2" ]; then \
490                         $(ECHO) $(RM) $$s2; \
491                         $(RM) $$s2; \
492                 fi; \
493         done
494         $(RM) $(LIBS)
495         $(RM) *{- platform->defext() -}
496
497 clean: libclean
498         $(RM) $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
499         $(RM) $(MANDOCS1) $(MANDOCS3) $(MANDOCS5) $(MANDOCS7)
500         $(RM) $(PROGRAMS) $(TESTPROGS) $(MODULES) $(SCRIPTS)
501         $(RM) $(GENERATED_MANDATORY) $(GENERATED)
502         -$(RM) `find . -name '*{- platform->depext() -}' \! -name '.*' \! -type d -print`
503         -$(RM) `find . -name '*{- platform->objext() -}' \! -name '.*' \! -type d -print`
504         $(RM) core
505         $(RM) tags TAGS doc-nits
506         $(RM) -r test/test-runs
507         $(RM) openssl.pc libcrypto.pc libssl.pc
508         -$(RM) `find . -type l \! -name '.*' -print`
509         $(RM) $(TARFILE)
510
511 distclean: clean
512         $(RM) configdata.pm
513         $(RM) Makefile
514
515 # We check if any depfile is newer than Makefile and decide to
516 # concatenate only if that is true.
517 depend:
518         @: {- output_off() if $disabled{makedepend}; "" -}
519         @$(PERL) $(SRCDIR)/util/add-depends.pl {-
520                  defined $makedepprog  && $makedepprog =~ /\/makedepend/
521                  ? 'makedepend' : 'gcc' -}
522         @: {- output_on() if $disabled{makedepend}; "" -}
523
524 # Install helper targets #############################################
525
526 install_sw: install_dev install_engines install_runtime
527
528 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
529
530 install_docs: install_man_docs install_html_docs
531
532 uninstall_docs: uninstall_man_docs uninstall_html_docs
533         $(RM) -r $(DESTDIR)$(DOCDIR)
534
535 install_ssldirs:
536         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/certs
537         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/private
538         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(OPENSSLDIR)/misc
539         @set -e; for x in dummy $(MISC_SCRIPTS); do \
540                 if [ "$$x" = "dummy" ]; then continue; fi; \
541                 x1=`echo "$$x" | cut -f1 -d:`; \
542                 x2=`echo "$$x" | cut -f2 -d:`; \
543                 fn=`basename $$x1`; \
544                 $(ECHO) "install $$x1 -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
545                 cp $$x1 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
546                 chmod 755 $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new; \
547                 mv -f $(DESTDIR)$(OPENSSLDIR)/misc/$$fn.new \
548                       $(DESTDIR)$(OPENSSLDIR)/misc/$$fn; \
549                 if [ "$$x1" != "$$x2" ]; then \
550                         ln=`basename "$$x2"`; \
551                         : {- output_off() unless windowsdll(); "" -}; \
552                         $(ECHO) "copy $(DESTDIR)$(OPENSSLDIR)/misc/$$ln -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
553                         cp $(DESTDIR)$(OPENSSLDIR)/misc/$$fn $(DESTDIR)$(OPENSSLDIR)/misc/$$ln; \
554                         : {- output_on() unless windowsdll();
555                              output_off() if windowsdll(); "" -}; \
556                         $(ECHO) "link $(DESTDIR)$(OPENSSLDIR)/misc/$$ln -> $(DESTDIR)$(OPENSSLDIR)/misc/$$fn"; \
557                         ln -sf $$fn $(DESTDIR)$(OPENSSLDIR)/misc/$$ln; \
558                         : {- output_on() if windowsdll(); "" -}; \
559                 fi; \
560         done
561         @$(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist"
562         @cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
563         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new
564         @mv -f  $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.new $(DESTDIR)$(OPENSSLDIR)/openssl.cnf.dist
565         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/openssl.cnf" ]; then \
566                 $(ECHO) "install $(SRCDIR)/apps/openssl.cnf -> $(DESTDIR)$(OPENSSLDIR)/openssl.cnf"; \
567                 cp $(SRCDIR)/apps/openssl.cnf $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
568                 chmod 644 $(DESTDIR)$(OPENSSLDIR)/openssl.cnf; \
569         fi
570         @$(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist"
571         @cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
572         @chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new
573         @mv -f  $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.new $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf.dist
574         @if [ ! -f "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf" ]; then \
575                 $(ECHO) "install $(SRCDIR)/apps/ct_log_list.cnf -> $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \
576                 cp $(SRCDIR)/apps/ct_log_list.cnf $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
577                 chmod 644 $(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf; \
578         fi
579
580 install_dev: install_runtime_libs
581         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
582         @$(ECHO) "*** Installing development files"
583         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/include/openssl
584         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
585         @$(ECHO) "install $(SRCDIR)/ms/applink.c -> $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
586         @cp $(SRCDIR)/ms/applink.c $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
587         @chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
588         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
589         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
590                           $(BLDDIR)/include/openssl/*.h; do \
591                 fn=`basename $$i`; \
592                 $(ECHO) "install $$i -> $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
593                 cp $$i $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
594                 chmod 644 $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
595         done
596         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(libdir)
597         @set -e; for l in $(INSTALL_LIBS); do \
598                 fn=`basename $$l`; \
599                 $(ECHO) "install $$l -> $(DESTDIR)$(libdir)/$$fn"; \
600                 cp $$l $(DESTDIR)$(libdir)/$$fn.new; \
601                 $(RANLIB) $(DESTDIR)$(libdir)/$$fn.new; \
602                 chmod 644 $(DESTDIR)$(libdir)/$$fn.new; \
603                 mv -f $(DESTDIR)$(libdir)/$$fn.new \
604                       $(DESTDIR)$(libdir)/$$fn; \
605         done
606         @ : {- output_off() if $disabled{shared}; "" -}
607         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
608                 s1=`echo "$$s" | cut -f1 -d";"`; \
609                 s2=`echo "$$s" | cut -f2 -d";"`; \
610                 fn1=`basename $$s1`; \
611                 fn2=`basename $$s2`; \
612                 : {- output_off(); output_on() unless windowsdll() or sharedaix(); "" -}; \
613                 if [ "$$fn1" != "$$fn2" ]; then \
614                         $(ECHO) "link $(DESTDIR)$(libdir)/$$fn2 -> $(DESTDIR)$(libdir)/$$fn1"; \
615                         ln -sf $$fn1 $(DESTDIR)$(libdir)/$$fn2; \
616                 fi; \
617                 : {- output_off() unless windowsdll() or sharedaix(); output_on() if windowsdll(); "" -}; \
618                 $(ECHO) "install $$s2 -> $(DESTDIR)$(libdir)/$$fn2"; \
619                 cp $$s2 $(DESTDIR)$(libdir)/$$fn2.new; \
620                 chmod 755 $(DESTDIR)$(libdir)/$$fn2.new; \
621                 mv -f $(DESTDIR)$(libdir)/$$fn2.new \
622                       $(DESTDIR)$(libdir)/$$fn2; \
623                 : {- output_off() if windowsdll(); output_on() if sharedaix(); "" -}; \
624                 a=$(DESTDIR)$(libdir)/$$fn2; \
625                 $(ECHO) "install $$s1 -> $$a"; \
626                 if [ -f $$a ]; then ( trap "rm -rf /tmp/ar.$$$$" INT 0; \
627                         mkdir /tmp/ar.$$$$; ( cd /tmp/ar.$$$$; \
628                         cp -f $$a $$a.new; \
629                         for so in `$(AR) t $$a`; do \
630                                 $(AR) x $$a $$so; \
631                                 chmod u+w $$so; \
632                                 strip -X32_64 -e $$so; \
633                                 $(AR) r $$a.new $$so; \
634                         done; \
635                 )); fi; \
636                 $(AR) r $$a.new $$s1; \
637                 mv -f $$a.new $$a; \
638                 : {- output_off() if sharedaix(); output_on(); "" -}; \
639         done
640         @ : {- output_on() if $disabled{shared}; "" -}
641         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(libdir)/pkgconfig
642         @$(ECHO) "install libcrypto.pc -> $(DESTDIR)$(libdir)/pkgconfig/libcrypto.pc"
643         @cp libcrypto.pc $(DESTDIR)$(libdir)/pkgconfig
644         @chmod 644 $(DESTDIR)$(libdir)/pkgconfig/libcrypto.pc
645         @$(ECHO) "install libssl.pc -> $(DESTDIR)$(libdir)/pkgconfig/libssl.pc"
646         @cp libssl.pc $(DESTDIR)$(libdir)/pkgconfig
647         @chmod 644 $(DESTDIR)$(libdir)/pkgconfig/libssl.pc
648         @$(ECHO) "install openssl.pc -> $(DESTDIR)$(libdir)/pkgconfig/openssl.pc"
649         @cp openssl.pc $(DESTDIR)$(libdir)/pkgconfig
650         @chmod 644 $(DESTDIR)$(libdir)/pkgconfig/openssl.pc
651
652 uninstall_dev: uninstall_runtime_libs
653         @$(ECHO) "*** Uninstalling development files"
654         @ : {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
655         @$(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c"
656         @$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/applink.c
657         @ : {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
658         @set -e; for i in $(SRCDIR)/include/openssl/*.h \
659                           $(BLDDIR)/include/openssl/*.h; do \
660                 fn=`basename $$i`; \
661                 $(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn"; \
662                 $(RM) $(DESTDIR)$(INSTALLTOP)/include/openssl/$$fn; \
663         done
664         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include/openssl
665         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/include
666         @set -e; for l in $(INSTALL_LIBS); do \
667                 fn=`basename $$l`; \
668                 $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn"; \
669                 $(RM) $(DESTDIR)$(libdir)/$$fn; \
670         done
671         @ : {- output_off() if $disabled{shared}; "" -}
672         @set -e; for s in $(INSTALL_SHLIB_INFO); do \
673                 s1=`echo "$$s" | cut -f1 -d";"`; \
674                 s2=`echo "$$s" | cut -f2 -d";"`; \
675                 fn1=`basename $$s1`; \
676                 fn2=`basename $$s2`; \
677                 : {- output_off() if windowsdll(); "" -}; \
678                 $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn2"; \
679                 $(RM) $(DESTDIR)$(libdir)/$$fn2; \
680                 if [ "$$fn1" != "$$fn2" -a -f "$(DESTDIR)$(libdir)/$$fn1" ]; then \
681                         $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn1"; \
682                         $(RM) $(DESTDIR)$(libdir)/$$fn1; \
683                 fi; \
684                 : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \
685                 $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn2"; \
686                 $(RM) $(DESTDIR)$(libdir)/$$fn2; \
687                 : {- output_on() unless windowsdll(); "" -}; \
688         done
689         @ : {- output_on() if $disabled{shared}; "" -}
690         $(RM) $(DESTDIR)$(libdir)/pkgconfig/libcrypto.pc
691         $(RM) $(DESTDIR)$(libdir)/pkgconfig/libssl.pc
692         $(RM) $(DESTDIR)$(libdir)/pkgconfig/openssl.pc
693         -$(RMDIR) $(DESTDIR)$(libdir)/pkgconfig
694         -$(RMDIR) $(DESTDIR)$(libdir)
695
696 install_engines: install_runtime_libs build_modules
697         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
698         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(ENGINESDIR)/
699         @$(ECHO) "*** Installing ENGINE modules"
700         @set -e; for e in dummy $(INSTALL_ENGINES); do \
701                 if [ "$$e" = "dummy" ]; then continue; fi; \
702                 fn=`basename $$e`; \
703                 $(ECHO) "install $$e -> $(DESTDIR)$(ENGINESDIR)/$$fn"; \
704                 cp $$e $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
705                 chmod 755 $(DESTDIR)$(ENGINESDIR)/$$fn.new; \
706                 mv -f $(DESTDIR)$(ENGINESDIR)/$$fn.new \
707                       $(DESTDIR)$(ENGINESDIR)/$$fn; \
708         done
709
710 uninstall_engines:
711         @$(ECHO) "*** Uninstalling ENGINE modules"
712         @set -e; for e in dummy $(INSTALL_ENGINES); do \
713                 if [ "$$e" = "dummy" ]; then continue; fi; \
714                 fn=`basename $$e`; \
715                 if [ "$$fn" = '{- platform->dso("ossltest") -}' ]; then \
716                         continue; \
717                 fi; \
718                 $(ECHO) "$(RM) $(DESTDIR)$(ENGINESDIR)/$$fn"; \
719                 $(RM) $(DESTDIR)$(ENGINESDIR)/$$fn; \
720         done
721         -$(RMDIR) $(DESTDIR)$(ENGINESDIR)
722
723 install_runtime: install_programs
724
725 install_runtime_libs: build_libs
726         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
727         @ : {- output_off() if windowsdll(); "" -}
728         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(libdir)
729         @ : {- output_on() if windowsdll(); output_off() unless windowsdll(); "" -}
730         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
731         @ : {- output_on() unless windowsdll(); "" -}
732         @$(ECHO) "*** Installing runtime libraries"
733         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
734                 if [ "$$s" = "dummy" ]; then continue; fi; \
735                 fn=`basename $$s`; \
736                 : {- output_off() unless windowsdll(); "" -}; \
737                 $(ECHO) "install $$s -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
738                 cp $$s $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
739                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
740                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
741                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
742                 : {- output_on() unless windowsdll(); "" -}{- output_off() if windowsdll(); "" -}; \
743                 $(ECHO) "install $$s -> $(DESTDIR)$(libdir)/$$fn"; \
744                 cp $$s $(DESTDIR)$(libdir)/$$fn.new; \
745                 chmod 755 $(DESTDIR)$(libdir)/$$fn.new; \
746                 mv -f $(DESTDIR)$(libdir)/$$fn.new \
747                       $(DESTDIR)$(libdir)/$$fn; \
748                 : {- output_on() if windowsdll(); "" -}; \
749         done
750
751 install_programs: install_runtime_libs build_programs
752         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
753         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)/bin
754         @$(ECHO) "*** Installing runtime programs"
755         @set -e; for x in dummy $(INSTALL_PROGRAMS); do \
756                 if [ "$$x" = "dummy" ]; then continue; fi; \
757                 fn=`basename $$x`; \
758                 $(ECHO) "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
759                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
760                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
761                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
762                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
763         done
764         @set -e; for x in dummy $(BIN_SCRIPTS); do \
765                 if [ "$$x" = "dummy" ]; then continue; fi; \
766                 fn=`basename $$x`; \
767                 $(ECHO) "install $$x -> $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
768                 cp $$x $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
769                 chmod 755 $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new; \
770                 mv -f $(DESTDIR)$(INSTALLTOP)/bin/$$fn.new \
771                       $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
772         done
773
774 uninstall_runtime: uninstall_programs uninstall_runtime_libs
775
776 uninstall_programs:
777         @$(ECHO) "*** Uninstalling runtime programs"
778         @set -e; for x in dummy $(INSTALL_PROGRAMS); \
779         do  \
780                 if [ "$$x" = "dummy" ]; then continue; fi; \
781                 fn=`basename $$x`; \
782                 $(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
783                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
784         done;
785         @set -e; for x in dummy $(BIN_SCRIPTS); \
786         do  \
787                 if [ "$$x" = "dummy" ]; then continue; fi; \
788                 fn=`basename $$x`; \
789                 $(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
790                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
791         done
792         -$(RMDIR) $(DESTDIR)$(INSTALLTOP)/bin
793
794 uninstall_runtime_libs:
795         @$(ECHO) "*** Uninstalling runtime libraries"
796         @ : {- output_off() unless windowsdll(); "" -}
797         @set -e; for s in dummy $(INSTALL_SHLIBS); do \
798                 if [ "$$s" = "dummy" ]; then continue; fi; \
799                 fn=`basename $$s`; \
800                 $(ECHO) "$(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn"; \
801                 $(RM) $(DESTDIR)$(INSTALLTOP)/bin/$$fn; \
802         done
803         @ : {- output_on() unless windowsdll(); "" -}
804
805
806 install_man_docs: build_man_docs
807         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
808         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MANDIR)/man1
809         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MANDIR)/man3
810         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MANDIR)/man5
811         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MANDIR)/man7
812         @$(ECHO) "*** Installing manpages"
813         @set -e; for x in dummy $(MANDOCS1); do \
814                 if [ "$$x" = "dummy" ]; then continue; fi; \
815                 fn=`basename $$x`; \
816                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man1/$$fn"; \
817                 cp $$x $(DESTDIR)$(MANDIR)/man1/$$fn$(MANSUFFIX); \
818                 chmod 755 $(DESTDIR)$(MANDIR)/man1/$$fn$(MANSUFFIX); \
819         done
820         @set -e; for x in dummy $(MANDOCS3); do \
821                 if [ "$$x" = "dummy" ]; then continue; fi; \
822                 fn=`basename $$x`; \
823                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man3/$$fn"; \
824                 cp $$x $(DESTDIR)$(MANDIR)/man3/$$fn$(MANSUFFIX); \
825                 chmod 755 $(DESTDIR)$(MANDIR)/man3/$$fn$(MANSUFFIX); \
826         done
827         @set -e; for x in dummy $(MANDOCS5); do \
828                 if [ "$$x" = "dummy" ]; then continue; fi; \
829                 fn=`basename $$x`; \
830                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man5/$$fn"; \
831                 cp $$x $(DESTDIR)$(MANDIR)/man5/$$fn$(MANSUFFIX); \
832                 chmod 755 $(DESTDIR)$(MANDIR)/man5/$$fn$(MANSUFFIX); \
833         done
834         @set -e; for x in dummy $(MANDOCS7); do \
835                 if [ "$$x" = "dummy" ]; then continue; fi; \
836                 fn=`basename $$x`; \
837                 $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man7/$$fn"; \
838                 cp $$x $(DESTDIR)$(MANDIR)/man7/$$fn$(MANSUFFIX); \
839                 chmod 755 $(DESTDIR)$(MANDIR)/man7/$$fn$(MANSUFFIX); \
840         done
841
842 uninstall_man_docs:
843         @$(ECHO) "*** Uninstalling manpages"
844         @set -e; for x in dummy $(MANDOCS1); do \
845                 if [ "$$x" = "dummy" ]; then continue; fi; \
846                 fn=`basename $$x`; \
847                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man1/$$fn"; \
848                 $(RM) $(DESTDIR)$(MANDIR)/man1/$$fn$(MANSUFFIX); \
849         done
850         @set -e; for x in dummy $(MANDOCS3); do \
851                 if [ "$$x" = "dummy" ]; then continue; fi; \
852                 fn=`basename $$x`; \
853                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man3/$$fn"; \
854                 $(RM) $(DESTDIR)$(MANDIR)/man3/$$fn$(MANSUFFIX); \
855         done
856         @set -e; for x in dummy $(MANDOCS5); do \
857                 if [ "$$x" = "dummy" ]; then continue; fi; \
858                 fn=`basename $$x`; \
859                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man5/$$fn"; \
860                 $(RM) $(DESTDIR)$(MANDIR)/man5/$$fn$(MANSUFFIX); \
861         done
862         @set -e; for x in dummy $(MANDOCS7); do \
863                 if [ "$$x" = "dummy" ]; then continue; fi; \
864                 fn=`basename $$x`; \
865                 $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man7/$$fn"; \
866                 $(RM) $(DESTDIR)$(MANDIR)/man7/$$fn$(MANSUFFIX); \
867         done
868
869 install_html_docs: build_html_docs
870         @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
871         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(HTMLDIR)/man1
872         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(HTMLDIR)/man3
873         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(HTMLDIR)/man5
874         @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(HTMLDIR)/man7
875         @$(ECHO) "*** Installing HTML manpages"
876         @set -e; for x in dummy $(HTMLDOCS1); do \
877                 if [ "$$x" = "dummy" ]; then continue; fi; \
878                 fn=`basename $$x`; \
879                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man1/$$fn"; \
880                 cp $$x $(DESTDIR)$(HTMLDIR)/man1/$$fn; \
881                 chmod 755 $(DESTDIR)$(HTMLDIR)/man1/$$fn; \
882         done
883         @set -e; for x in dummy $(HTMLDOCS3); do \
884                 if [ "$$x" = "dummy" ]; then continue; fi; \
885                 fn=`basename $$x`; \
886                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man3/$$fn"; \
887                 cp $$x $(DESTDIR)$(HTMLDIR)/man3/$$fn; \
888                 chmod 755 $(DESTDIR)$(HTMLDIR)/man3/$$fn; \
889         done
890         @set -e; for x in dummy $(HTMLDOCS5); do \
891                 if [ "$$x" = "dummy" ]; then continue; fi; \
892                 fn=`basename $$x`; \
893                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man5/$$fn"; \
894                 cp $$x $(DESTDIR)$(HTMLDIR)/man5/$$fn; \
895                 chmod 755 $(DESTDIR)$(HTMLDIR)/man5/$$fn; \
896         done
897         @set -e; for x in dummy $(HTMLDOCS7); do \
898                 if [ "$$x" = "dummy" ]; then continue; fi; \
899                 fn=`basename $$x`; \
900                 $(ECHO) "install $$x -> $(DESTDIR)$(HTMLDIR)/man7/$$fn"; \
901                 cp $$x $(DESTDIR)$(HTMLDIR)/man7/$$fn; \
902                 chmod 755 $(DESTDIR)$(HTMLDIR)/man7/$$fn; \
903         done
904
905 uninstall_html_docs:
906         @$(ECHO) "*** Uninstalling HTML manpages"
907         @set -e; for x in dummy $(HTMLDOCS1); do \
908                 if [ "$$x" = "dummy" ]; then continue; fi; \
909                 fn=`basename $$x`; \
910                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man1/$$fn"; \
911                 $(RM) $(DESTDIR)$(HTMLDIR)/man1/$$fn; \
912         done
913         @set -e; for x in dummy $(HTMLDOCS3); do \
914                 if [ "$$x" = "dummy" ]; then continue; fi; \
915                 fn=`basename $$x`; \
916                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man3/$$fn"; \
917                 $(RM) $(DESTDIR)$(HTMLDIR)/man3/$$fn; \
918         done
919         @set -e; for x in dummy $(HTMLDOCS5); do \
920                 if [ "$$x" = "dummy" ]; then continue; fi; \
921                 fn=`basename $$x`; \
922                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man5/$$fn"; \
923                 $(RM) $(DESTDIR)$(HTMLDIR)/man5/$$fn; \
924         done
925         @set -e; for x in dummy $(HTMLDOCS7); do \
926                 if [ "$$x" = "dummy" ]; then continue; fi; \
927                 fn=`basename $$x`; \
928                 $(ECHO) "$(RM) $(DESTDIR)$(HTMLDIR)/man7/$$fn"; \
929                 $(RM) $(DESTDIR)$(HTMLDIR)/man7/$$fn; \
930         done
931
932 # Developer targets (note: these are only available on Unix) #########
933
934 update: generate errors ordinals
935
936 generate: generate_apps generate_crypto_bn generate_crypto_objects \
937           generate_crypto_conf generate_crypto_asn1 generate_fuzz_oids
938
939 .PHONY: doc-nits
940 doc-nits: build_generated
941         (cd $(SRCDIR); $(PERL) util/find-doc-nits -n -e )
942
943 # Test coverage is a good idea for the future
944 #coverage: $(PROGRAMS) $(TESTPROGRAMS)
945 #       ...
946
947 lint:
948         lint -DLINT $(INCLUDES) $(SRCS)
949
950 generate_apps:
951         ( cd $(SRCDIR); $(PERL) VMS/VMSify-conf.pl \
952                                 < apps/openssl.cnf > apps/openssl-vms.cnf )
953         @ : {- output_off() if $disabled{apps}; "" -}
954         ( b=`pwd`; cd $(SRCDIR); \
955           $(PERL) -I$$b apps/progs.pl -H $(APPS_OPENSSL) > apps/progs.h )
956         ( b=`pwd`; cd $(SRCDIR); \
957           $(PERL) -I$$b apps/progs.pl -C $(APPS_OPENSSL) > apps/progs.c )
958         @ : {- output_on() if $disabled{apps}; "" -}
959
960 generate_crypto_bn:
961         ( cd $(SRCDIR); $(PERL) crypto/bn/bn_prime.pl > crypto/bn/bn_prime.h )
962
963 generate_crypto_objects:
964         ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl -n \
965                                 crypto/objects/objects.txt \
966                                 crypto/objects/obj_mac.num \
967                                 > crypto/objects/obj_mac.new && \
968             mv crypto/objects/obj_mac.new crypto/objects/obj_mac.num )
969         ( cd $(SRCDIR); $(PERL) crypto/objects/objects.pl \
970                                 crypto/objects/objects.txt \
971                                 crypto/objects/obj_mac.num \
972                                 > include/openssl/obj_mac.h )
973         ( cd $(SRCDIR); $(PERL) crypto/objects/obj_dat.pl \
974                                 include/openssl/obj_mac.h \
975                                 > crypto/objects/obj_dat.h )
976         ( cd $(SRCDIR); $(PERL) crypto/objects/objxref.pl \
977                                 crypto/objects/obj_mac.num \
978                                 crypto/objects/obj_xref.txt \
979                                 > crypto/objects/obj_xref.h )
980
981 generate_crypto_conf:
982         ( cd $(SRCDIR); $(PERL) crypto/conf/keysets.pl \
983                                 > crypto/conf/conf_def.h )
984
985 generate_crypto_asn1:
986         ( cd $(SRCDIR); $(PERL) crypto/asn1/charmap.pl \
987                                 > crypto/asn1/charmap.h )
988
989 generate_fuzz_oids:
990         ( cd $(SRCDIR); $(PERL) fuzz/mkfuzzoids.pl \
991                                 crypto/objects/obj_dat.h \
992                                 > fuzz/oids.txt )
993
994 # Set to -force to force a rebuild
995 ERROR_REBUILD=
996 errors:
997         ( b=`pwd`; set -e; cd $(SRCDIR); \
998           $(PERL) util/ck_errf.pl -strict -internal; \
999           $(PERL) -I$$b util/mkerr.pl $(ERROR_REBUILD) -internal )
1000         ( b=`pwd`; set -e; cd $(SRCDIR)/engines; \
1001           for E in *.ec ; do \
1002               $(PERL) ../util/ck_errf.pl -strict \
1003                 -conf $$E `basename $$E .ec`.c; \
1004               $(PERL) -I$$b ../util/mkerr.pl $(ERROR_REBUILD) -static \
1005                 -conf $$E `basename $$E .ec`.c ; \
1006           done )
1007
1008 {- use File::Basename;
1009
1010    our @sslheaders =
1011        qw( include/openssl/ssl.h
1012            include/openssl/ssl2.h
1013            include/openssl/ssl3.h
1014            include/openssl/sslerr.h
1015            include/openssl/tls1.h
1016            include/openssl/dtls1.h
1017            include/openssl/srtp.h );
1018    our @cryptoheaders =
1019        qw( include/internal/dso.h
1020            include/internal/o_dir.h
1021            include/internal/err.h
1022            include/internal/sslconf.h );
1023    our @cryptoskipheaders = ( @sslheaders,
1024        qw( include/openssl/conf_api.h
1025            include/openssl/ebcdic.h
1026            include/openssl/opensslconf.h
1027            include/openssl/symhacks.h ) );
1028    foreach my $f ( glob(catfile($config{sourcedir},
1029                                 'include','openssl','*.h')) ) {
1030        my $fn = "include/openssl/" . basename($f);
1031        push @cryptoheaders, $fn unless grep { $_ eq $fn } @cryptoskipheaders;
1032    }
1033    "";
1034 -}
1035 CRYPTOHEADERS={- join(" \\\n" . ' ' x 14,
1036                       fill_lines(" ", $COLUMNS - 14, sort @cryptoheaders)) -}
1037 SSLHEADERS={- join(" \\\n" . ' ' x 11,
1038                    fill_lines(" ", $COLUMNS - 11, sort @sslheaders)) -}
1039 ordinals:
1040         ( cd $(SRCDIR); \
1041           $(PERL) util/mknum.pl --version $(VERSION) --no-warnings \
1042                   --ordinals util/libcrypto.num \
1043                   --symhacks include/openssl/symhacks.h \
1044                   $(CRYPTOHEADERS) )
1045         ( cd $(SRCDIR); \
1046           $(PERL) util/mknum.pl --version $(VERSION) --no-warnings \
1047                   --ordinals util/libssl.num \
1048                   --symhacks include/openssl/symhacks.h \
1049                   $(SSLHEADERS))
1050
1051 test_ordinals:
1052         ( cd test; \
1053           SRCTOP=../$(SRCDIR) \
1054           BLDTOP=../$(BLDDIR) \
1055             $(PERL) ../$(SRCDIR)/test/run_tests.pl test_ordinals )
1056
1057 tags TAGS: FORCE
1058         rm -f TAGS tags
1059         -ctags -R .
1060         -etags `find . -name '*.[ch]' -o -name '*.pm'`
1061
1062 # Release targets (note: only available on Unix) #####################
1063
1064 tar:
1065         (cd $(SRCDIR); ./util/mktar.sh --name='$(NAME)' --tarfile='$(TARFILE)')
1066
1067 # Helper targets #####################################################
1068
1069 link-utils: $(BLDDIR)/util/opensslwrap.sh
1070
1071 $(BLDDIR)/util/opensslwrap.sh: configdata.pm
1072         @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
1073             mkdir -p "$(BLDDIR)/util"; \
1074             ln -sf "../$(SRCDIR)/util/opensslwrap.sh" "$(BLDDIR)/util"; \
1075         fi
1076
1077 FORCE:
1078
1079 # Building targets ###################################################
1080
1081 libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { platform->sharedlib_simple($_) // () } @{$unified_info{libraries}}) -}
1082 libcrypto.pc:
1083         @ ( echo 'prefix=$(INSTALLTOP)'; \
1084             echo 'exec_prefix=$${prefix}'; \
1085             if [ -n "$(LIBDIR)" ]; then \
1086                 echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
1087             else \
1088                 echo 'libdir=$(libdir)'; \
1089             fi; \
1090             echo 'includedir=$${prefix}/include'; \
1091             echo 'enginesdir=$${libdir}/engines-{- $sover_dirname -}'; \
1092             echo ''; \
1093             echo 'Name: OpenSSL-libcrypto'; \
1094             echo 'Description: OpenSSL cryptography library'; \
1095             echo 'Version: '$(VERSION); \
1096             echo 'Libs: -L$${libdir} -lcrypto'; \
1097             echo 'Libs.private: $(LIB_EX_LIBS)'; \
1098             echo 'Cflags: -I$${includedir}' ) > libcrypto.pc
1099
1100 libssl.pc:
1101         @ ( echo 'prefix=$(INSTALLTOP)'; \
1102             echo 'exec_prefix=$${prefix}'; \
1103             if [ -n "$(LIBDIR)" ]; then \
1104                 echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
1105             else \
1106                 echo 'libdir=$(libdir)'; \
1107             fi; \
1108             echo 'includedir=$${prefix}/include'; \
1109             echo ''; \
1110             echo 'Name: OpenSSL-libssl'; \
1111             echo 'Description: Secure Sockets Layer and cryptography libraries'; \
1112             echo 'Version: '$(VERSION); \
1113             echo 'Requires.private: libcrypto'; \
1114             echo 'Libs: -L$${libdir} -lssl'; \
1115             echo 'Cflags: -I$${includedir}' ) > libssl.pc
1116
1117 openssl.pc:
1118         @ ( echo 'prefix=$(INSTALLTOP)'; \
1119             echo 'exec_prefix=$${prefix}'; \
1120             if [ -n "$(LIBDIR)" ]; then \
1121                 echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
1122             else \
1123                 echo 'libdir=$(libdir)'; \
1124             fi; \
1125             echo 'includedir=$${prefix}/include'; \
1126             echo ''; \
1127             echo 'Name: OpenSSL'; \
1128             echo 'Description: Secure Sockets Layer and cryptography libraries and tools'; \
1129             echo 'Version: '$(VERSION); \
1130             echo 'Requires: libssl libcrypto' ) > openssl.pc
1131
1132 configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config \
1133                {- join(" \\\n" . ' ' x 15,
1134                        fill_lines(" ", $COLUMNS - 15,
1135                                   @{$config{build_file_templates}},
1136                                   @{$config{build_infos}},
1137                                   @{$config{conf_files}})) -}
1138         @echo "Detected changed: $?"
1139         $(PERL) configdata.pm -r
1140         @echo "**************************************************"
1141         @echo "***                                            ***"
1142         @echo "***   Please run the same make command again   ***"
1143         @echo "***                                            ***"
1144         @echo "**************************************************"
1145         @false
1146
1147 reconfigure reconf:
1148         $(PERL) configdata.pm -r
1149
1150 {-
1151   use File::Basename;
1152   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
1153
1154   # Helper function to figure out dependencies on libraries
1155   # It takes a list of library names and outputs a list of dependencies
1156   sub compute_lib_depends {
1157       # Depending on shared libraries:
1158       # On Windows POSIX layers, we depend on {libname}.dll.a
1159       # On Unix platforms, we depend on {shlibname}.so
1160       return map { platform->sharedlib_simple($_) // platform->staticlib($_) } @_;
1161   }
1162
1163   sub generatesrc {
1164       my %args = @_;
1165       my $generator = join(" ", @{$args{generator}});
1166       my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
1167       my $incs = join("", map { " -I".$_ } @{$args{incs}});
1168       my $defs = join("", map { " -D".$_ } @{$args{defs}});
1169       my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
1170
1171       if ($args{src} =~ /\.html$/) {
1172           my $title = basename($args{src}, ".html");
1173           return <<"EOF";
1174 $args{src}: $args{generator}->[0]
1175         pod2html "--podroot=\$(SRCDIR)/doc" --htmldir=.. \\
1176                  --podpath=man1:man3:man5:man7 "--infile=\$<" "--title=$title" \\
1177         | \$(PERL) -pe 's|href="http://man\\.he\\.net/(man\\d/[^"]+)(?:\\.html)?"|href="../\$1.html|g;' \\
1178         > \$\@
1179 EOF
1180       } elsif ($args{src} =~ /\.(\d)$/) {
1181           my $section = $1;
1182           my $name = uc basename($args{src}, ".$section");
1183           return <<"EOF";
1184 $args{src}: $args{generator}->[0]
1185         pod2man --name=$name --section=$section --center=OpenSSL \\
1186                 --release=\$(VERSION) \$< \\
1187         > \$\@
1188 EOF
1189       } elsif (platform->isdef($args{src})) {
1190           my $target = platform->def($args{src});
1191           (my $mkdef_os = $target{shared_target}) =~ s|-shared$||;
1192           my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION)' : '';
1193           my $ord_name = $args{generator}->[1] || $args{product};
1194           return <<"EOF";
1195 $target: $args{generator}->[0] $deps \$(SRCDIR)/util/mkdef.pl
1196         \$(PERL) \$(SRCDIR)/util/mkdef.pl$ord_ver --ordinals $args{generator}->[0]  --name $ord_name --OS $mkdef_os > $target
1197 EOF
1198       } elsif (!platform->isasm($args{src})) {
1199           if ($args{generator}->[0] =~ m|^.*\.in$|) {
1200               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1201                                                    "util", "dofile.pl")),
1202                                    rel2abs($config{builddir}));
1203               my @modules = ( 'configdata.pm',
1204                               grep { $_ =~ m|\.pm$| } @{$args{deps}} );
1205               my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules;
1206               @modules = map { "-M".basename($_, '.pm') } @modules;
1207               my $modules = join(' ', '', sort keys %moduleincs, @modules);
1208               return <<"EOF";
1209 $args{src}: $args{generator}->[0] $deps \$(BLDDIR)/configdata.pm
1210         \$(PERL)$modules "$dofile" "-o$target{build_file}" $generator > \$@
1211 EOF
1212           } else {
1213               return <<"EOF";
1214 $args{src}: $args{generator}->[0] $deps
1215         \$(PERL)$generator_incs $generator > \$@
1216 EOF
1217           }
1218       } else {
1219           my $cppflags = {
1220               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1221               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1222               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
1223               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
1224           } -> {$args{intent}};
1225
1226           if ($args{generator}->[0] =~ /\.pl$/) {
1227               $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator
1228                   .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSSOR)';
1229           } elsif ($args{generator}->[0] =~ /\.m4$/) {
1230               $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >'
1231           } elsif ($args{generator}->[0] =~ /\.S$/) {
1232               $generator = undef;
1233           } else {
1234               die "Generator type for $args{src} unknown: $generator\n";
1235           }
1236
1237           if (defined($generator)) {
1238               return <<"EOF";
1239 $args{src}: $args{generator}->[0] $deps
1240         $generator \$@
1241 EOF
1242           }
1243           return <<"EOF";
1244 $args{src}: $args{generator}->[0] $deps
1245         \$(CC) $incs $cppflags $defs -E $args{generator}->[0] | \\
1246         \$(PERL) -ne '/^#(line)?\\s*[0-9]+/ or print' > \$@
1247 EOF
1248       }
1249   }
1250
1251   # Should one wonder about the end of the Perl snippet, it's because this
1252   # second regexp eats up line endings as well, if the removed path is the
1253   # last in the line.  We may therefore need to put back a line ending.
1254   sub src2obj {
1255       my %args = @_;
1256       my $obj = platform->convertext($args{obj});
1257       my $dep = platform->dep($args{obj});
1258       my @srcs = @{$args{srcs}};
1259       my $srcs = join(" ",  @srcs);
1260       my $deps = join(" ", @srcs, @{$args{deps}});
1261       my $incs = join("", map { " -I".$_ } @{$args{incs}});
1262       my $defs = join("", map { " -D".$_ } @{$args{defs}});
1263       my $cmd;
1264       my $cmdflags;
1265       my $cmdcompile;
1266       if (grep /\.rc$/, @srcs) {
1267           $cmd = '$(RC)';
1268           $cmdflags = '$(RCFLAGS)';
1269           $cmdcompile = '';
1270       } elsif (grep /\.(cc|cpp)$/, @srcs) {
1271           $cmd = '$(CXX)';
1272           $cmdcompile = ' -c';
1273           $cmdflags = {
1274               shlib => '$(LIB_CXXFLAGS) $(LIB_CPPFLAGS)',
1275               lib => '$(LIB_CXXFLAGS) $(LIB_CPPFLAGS)',
1276               dso => '$(DSO_CXXFLAGS) $(DSO_CPPFLAGS)',
1277               bin => '$(BIN_CXXFLAGS) $(BIN_CPPFLAGS)'
1278           } -> {$args{intent}};
1279       } else {
1280           $cmd = '$(CC)';
1281           $cmdcompile = ' -c';
1282           $cmdflags = {
1283               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1284               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
1285               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
1286               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
1287           } -> {$args{intent}};
1288       }
1289       my $recipe;
1290       # extension-specific rules
1291       if (grep /\.s$/, @srcs) {
1292           $recipe .= <<"EOF";
1293 $obj: $deps
1294         $cmd $cmdflags -c -o \$\@ $srcs
1295 EOF
1296       } elsif (grep /\.S$/, @srcs) {
1297           # Originally there was mutli-step rule with $(CC) -E file.S
1298           # followed by $(CC) -c file.s. It compensated for one of
1299           # legacy platform compiler's inability to handle .S files.
1300           # The platform is long discontinued by vendor so there is
1301           # hardly a point to drag it along...
1302           $recipe .= <<"EOF";
1303 $obj: $deps
1304         $cmd $incs $defs $cmdflags -c -o \$\@ $srcs
1305 EOF
1306       } elsif (defined $makedepprog && $makedepprog !~ /\/makedepend/
1307                && !grep /\.rc$/, @srcs) {
1308           $recipe .= <<"EOF";
1309 $obj: $deps
1310         $cmd $incs $defs $cmdflags -MMD -MF $dep.tmp -MT \$\@ -c -o \$\@ $srcs
1311         \@touch $dep.tmp
1312         \@if cmp $dep.tmp $dep > /dev/null 2> /dev/null; then \\
1313                 rm -f $dep.tmp; \\
1314         else \\
1315                 mv $dep.tmp $dep; \\
1316         fi
1317 EOF
1318       } else {
1319           $recipe .= <<"EOF";
1320 $obj: $deps
1321         $cmd $incs $defs $cmdflags $cmdcompile -o \$\@ $srcs
1322 EOF
1323           if (defined $makedepprog  && $makedepprog =~ /\/makedepend/) {
1324               $recipe .= <<"EOF";
1325         \$(MAKEDEPEND) -f- -Y -- $incs $cmdflags -- $srcs 2>/dev/null \\
1326             > $dep
1327 EOF
1328           }
1329       }
1330       return $recipe;
1331   }
1332   # We *know* this routine is only called when we've configure 'shared'.
1333   sub obj2shlib {
1334       my %args = @_;
1335       my @linkdirs = ();
1336       my @linklibs = ();
1337       foreach (@{$args{deps}}) {
1338           if (platform->isstaticlib($_)) {
1339               push @linklibs, platform->convertext($_);
1340           } else {
1341               my $d = "-L" . dirname($_);
1342               my $l = basename($_);
1343               $l =~ s/^lib//;
1344               $l = "-l" . $l;
1345               push @linklibs, $l;
1346               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1347           }
1348       }
1349       my $linkflags = join("", map { $_." " } @linkdirs);
1350       my $linklibs = join("", map { $_." " } @linklibs);
1351       my @objs = map { platform->convertext($_) }
1352                  grep { !platform->isdef($_) }
1353                  @{$args{objs}};
1354       my @defs = map { platform->def($_) }
1355                  grep { platform->isdef($_) }
1356                  @{$args{objs}};
1357       my @deps = compute_lib_depends(@{$args{deps}});
1358       die "More than one exported symbol map" if scalar @defs > 1;
1359
1360       my $simple = platform->sharedlib_simple($args{lib});
1361       my $full = platform->sharedlib($args{lib});
1362       my $shared_soname = "";
1363       $shared_soname .= ' '.$target{shared_sonameflag}.basename($full)
1364           if defined $target{shared_sonameflag};
1365       my $shared_imp = "";
1366       $shared_imp .= ' '.$target{shared_impflag}.basename($simple)
1367           if defined $target{shared_impflag};
1368       my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
1369
1370       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1371       my $deps = join(" \\\n" . ' ' x (length($full) + 2),
1372                       fill_lines(' ', $COLUMNS - length($full) - 2,
1373                                  @objs, @defs, @deps));
1374
1375       my $recipe = <<"EOF";
1376 $simple: $full
1377 EOF
1378       if (sharedaix()) {
1379           $recipe .= <<"EOF";
1380         rm -f $simple && \\
1381         \$(AR) r $simple $full
1382 EOF
1383       } elsif ($simple ne $full) {
1384           $recipe .= <<"EOF";
1385         rm -f $simple && \\
1386         ln -s $full $simple
1387 EOF
1388       }
1389       $recipe .= <<"EOF";
1390 $full: $deps
1391         \$(CC) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\
1392                 -o $full$shared_def \\
1393                 $objs \\
1394                 $linklibs \$(LIB_EX_LIBS)
1395 EOF
1396       if (windowsdll()) {
1397           $recipe .= <<"EOF";
1398         rm -f apps/$full
1399         rm -f test/$full
1400         rm -f fuzz/$full
1401         cp -p $full apps/
1402         cp -p $full test/
1403         cp -p $full fuzz/
1404 EOF
1405       }
1406       return $recipe;
1407   }
1408   sub obj2dso {
1409       my %args = @_;
1410       my $dso = platform->dso($args{module});
1411       my @linkdirs = ();
1412       my @linklibs = ();
1413       foreach (@{$args{deps}}) {
1414           next unless defined $_;
1415           if (platform->isstaticlib($_)) {
1416               push @linklibs, platform->convertext($_);
1417           } else {
1418               my $d = "-L" . dirname($_);
1419               my $l = basename($_);
1420               $l =~ s/^lib//;
1421               $l = "-l" . $l;
1422               push @linklibs, $l;
1423               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1424           }
1425       }
1426       my $linkflags = join("", map { $_." " } @linkdirs);
1427       my $linklibs = join("", map { $_." " } @linklibs);
1428       my @objs = map { platform->convertext($_) }
1429                  grep { !platform->isdef($_) }
1430                  @{$args{objs}};
1431       my @defs = map { platform->def($_) }
1432                  grep { platform->isdef($_) }
1433                  @{$args{objs}};
1434       my @deps = compute_lib_depends(@{$args{deps}});
1435       my $shared_def = join("", map { ' '.$target{shared_defflag}.$_ } @defs);
1436
1437       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1438       my $deps = join(" \\\n" . ' ' x (length($dso) + 2),
1439                       fill_lines(' ', $COLUMNS - length($dso) - 2,
1440                                  @objs, @defs, @deps));
1441
1442       return <<"EOF";
1443 $dso: $deps
1444         \$(CC) \$(DSO_CFLAGS) $linkflags\$(DSO_LDFLAGS) \\
1445                 -o $dso$shared_def \\
1446                 $objs \\
1447                 $linklibs\$(DSO_EX_LIBS)
1448 EOF
1449   }
1450   sub obj2lib {
1451       my %args = @_;
1452       my $lib = platform->staticlib($args{lib});
1453       my @objs = map { platform->obj($_) } @{$args{objs}};
1454       my $objs = join(" \\\n" . ' ' x (length($lib) + 2),
1455                       fill_lines(' ', $COLUMNS - length($lib) - 2, @objs));
1456       return <<"EOF";
1457 $lib: $objs
1458         \$(AR) \$(ARFLAGS) \$\@ \$\?
1459         \$(RANLIB) \$\@ || echo Never mind.
1460 EOF
1461   }
1462   sub obj2bin {
1463       my %args = @_;
1464       my $bin = platform->bin($args{bin});
1465       my @objs = map { platform->obj($_) } @{$args{objs}};
1466       my @deps = compute_lib_depends(@{$args{deps}});
1467       my $objs = join(" \\\n" . ' ' x (length($bin) + 2),
1468                       fill_lines(' ', $COLUMNS - length($bin) - 2, @objs));
1469       my @linkdirs = ();
1470       my @linklibs = ();
1471       foreach (@{$args{deps}}) {
1472           next unless defined $_;
1473           if (platform->isstaticlib($_)) {
1474               push @linklibs, platform->convertext($_);
1475           } else {
1476               my $d = "-L" . dirname($_);
1477               my $l = basename($_);
1478               $l =~ s/^lib//;
1479               $l = "-l" . $l;
1480               push @linklibs, $l;
1481               push @linkdirs, $d unless grep { $d eq $_ } @linkdirs;
1482           }
1483       }
1484       my $linkflags = join("", map { $_." " } @linkdirs);
1485       my $linklibs = join("", map { $_." " } @linklibs);
1486       my $cmd = '$(CC)';
1487       my $cmdflags = '$(BIN_CFLAGS)';
1488       if (grep /_cc\.o$/, @{$args{objs}}) {
1489           $cmd = '$(CXX)';
1490           $cmdflags = '$(BIN_CXXFLAGS)';
1491       }
1492
1493       my $objs = join(" \\\n\t\t", fill_lines(' ', $COLUMNS - 16, @objs));
1494       my $deps = join(" \\\n" . ' ' x (length($bin) + 2),
1495                       fill_lines(' ', $COLUMNS - length($bin) - 2,
1496                                  @objs, @deps));
1497
1498       return <<"EOF";
1499 $bin: $deps
1500         rm -f $bin
1501         \$\${LDCMD:-$cmd} $cmdflags $linkflags\$(BIN_LDFLAGS) \\
1502                 -o $bin \\
1503                 $objs \\
1504                 $linklibs\$(BIN_EX_LIBS)
1505 EOF
1506   }
1507   sub in2script {
1508       my %args = @_;
1509       my $script = $args{script};
1510       my $sources = join(" ", @{$args{sources}});
1511       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1512                                            "util", "dofile.pl")),
1513                            rel2abs($config{builddir}));
1514       return <<"EOF";
1515 $script: $sources
1516         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1517             "-o$target{build_file}" $sources > "$script"
1518         chmod a+x $script
1519 EOF
1520   }
1521   sub generatedir {
1522       my %args = @_;
1523       my $dir = $args{dir};
1524       my @deps = map { platform->convertext($_) } @{$args{deps}};
1525       my @comments = ();
1526       my %extinfo = ( dso => platform->dsoext(),
1527                       lib => platform->libext(),
1528                       bin => platform->binext() );
1529
1530       # We already have a 'test' target, and the top directory is just plain
1531       # silly
1532       return if $dir eq "test" || $dir eq ".";
1533
1534       foreach my $type (("dso", "lib", "bin", "script")) {
1535           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
1536           # For lib object files, we could update the library.  However, it
1537           # was decided that it's enough to build the directory local object
1538           # files, so we don't need to add any actions, and the dependencies
1539           # are already taken care of.
1540           if ($type ne "lib") {
1541               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
1542                   if (dirname($prod) eq $dir) {
1543                       push @deps, $prod.$extinfo{$type};
1544                   } else {
1545                       push @comments, "# No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
1546                   }
1547               }
1548           }
1549       }
1550
1551       my $target = "$dir $dir/";
1552       my $deps = join(" \\\n\t",
1553                       fill_lines(' ', $COLUMNS - 8, @deps));
1554       my $comments = join("\n", "", @comments);
1555       return <<"EOF";
1556 $target: \\
1557         $deps$comments
1558 EOF
1559   }
1560   ""    # Important!  This becomes part of the template result.
1561 -}