1##
2## Makefile for OpenSSL
3##
4## {- join("\n## ", @autowarntext) -}
5{-
6 use File::Basename;
7 use OpenSSL::Util;
8
9 our $sover_dirname = platform->shlib_version_as_filename();
10
11 my $build_scheme = $target{build_scheme};
12 my $install_flavour = $build_scheme->[$#$build_scheme]; # last element
13 my $win_installenv =
14     $install_flavour eq "VC-WOW" ? "ProgramFiles(x86)"
15                                  : "ProgramW6432";
16 my $win_commonenv =
17     $install_flavour eq "VC-WOW" ? "CommonProgramFiles(x86)"
18                                  : "CommonProgramW6432";
19 our $win_installroot =
20     defined($ENV{$win_installenv}) ? $win_installenv : 'ProgramFiles';
21 our $win_commonroot =
22     defined($ENV{$win_commonenv}) ? $win_commonenv : 'CommonProgramFiles';
23
24 # expand variables early
25 $win_installroot = $ENV{$win_installroot};
26 $win_commonroot = $ENV{$win_commonroot};
27
28 # This makes sure things get built in the order they need
29 # to. You're welcome.
30 sub dependmagic {
31     my $target = shift;
32
33     return "$target: build_generated\n\t\$(MAKE) /\$(MAKEFLAGS) depend\n\t\$(MAKE) /\$(MAKEFLAGS) _$target\n_$target";
34 }
35 '';
36-}
37
38PLATFORM={- $config{target} -}
39SRCDIR={- $config{sourcedir} -}
40BLDDIR={- $config{builddir} -}
41FIPSKEY={- $config{FIPSKEY} -}
42
43VERSION={- "$config{full_version}" -}
44VERSION_NUMBER={- "$config{version}" -}
45MAJOR={- $config{major} -}
46MINOR={- $config{minor} -}
47
48SHLIB_VERSION_NUMBER={- $config{shlib_version} -}
49
50LIBS={- join(" ", map { ( platform->sharedlib_import($_), platform->staticlib($_) ) } @{$unified_info{libraries}}) -}
51SHLIBS={- join(" ", map { platform->sharedlib($_) // () } @{$unified_info{libraries}}) -}
52SHLIBPDBS={- join(" ", map { platform->sharedlibpdb($_) // () } @{$unified_info{libraries}}) -}
53MODULES={- our @MODULES = map { platform->dso($_) }
54                          # Drop all modules that are dependencies, they will
55                          # be processed through their dependents
56                          grep { my $x = $_;
57                                 !grep { grep { $_ eq $x } @$_ }
58                                       values %{$unified_info{depends}} }
59                          @{$unified_info{modules}};
60           join(" ", @MODULES) -}
61MODULEPDBS={- join(" ", map { platform->dsopdb($_) } @{$unified_info{modules}}) -}
62FIPSMODULE={- # We do some extra checking here, as there should be only one
63              use File::Basename;
64              our @fipsmodules =
65                  grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
66                         && $unified_info{attributes}->{modules}->{$_}->{fips} }
67                  @{$unified_info{modules}};
68              die "More that one FIPS module" if scalar @fipsmodules > 1;
69              join(" ", map { platform->dso($_) } @fipsmodules) -}
70FIPSMODULENAME={- die "More that one FIPS module" if scalar @fipsmodules > 1;
71                  join(", ", map { basename(platform->dso($_)) } @fipsmodules) -}
72PROGRAMS={- our @PROGRAMS = map { platform->bin($_) } @{$unified_info{programs}}; join(" ", @PROGRAMS) -}
73PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -}
74SCRIPTS={- our @SCRIPTS = @{$unified_info{scripts}}; join(" ", @SCRIPTS) -}
75{- output_off() if $disabled{makedepend}; "" -}
76DEPS={- join(" ", map { platform->isobj($_) ? platform->dep($_) : () }
77                  grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
78                  keys %{$unified_info{sources}}); -}
79{- output_on() if $disabled{makedepend}; "" -}
80GENERATED_MANDATORY={- our @GENERATED_MANDATORY = @{$unified_info{depends}->{""}};
81                       join(" ", @GENERATED_MANDATORY) -}
82GENERATED={- # common0.tmpl provides @generated
83             our @GENERATED = map { platform->convertext($_) } @generated;
84             join(" ", @GENERATED) -}
85
86INSTALL_LIBS={-
87        join(" ", map { quotify1(platform->sharedlib_import($_)
88                                 // platform->staticlib($_)) }
89                  grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
90                  @{$unified_info{libraries}})
91-}
92INSTALL_SHLIBS={-
93        join(" ", map { my $x = platform->sharedlib($_);
94                        $x ? quotify_l($x) : () }
95                  grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
96                  @{$unified_info{libraries}})
97-}
98INSTALL_SHLIBPDBS={-
99        join(" ", map { my $x = platform->sharedlibpdb($_);
100                        $x ? quotify_l($x) : () }
101                  grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
102                  @{$unified_info{libraries}})
103-}
104INSTALL_ENGINES={-
105        join(" ", map { quotify1(platform->dso($_)) }
106                  grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
107                         && $unified_info{attributes}->{modules}->{$_}->{engine} }
108                  @{$unified_info{modules}})
109-}
110INSTALL_ENGINEPDBS={-
111        join(" ", map { quotify1(platform->dsopdb($_)) }
112                  grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
113                         && $unified_info{attributes}->{modules}->{$_}->{engine} }
114                  @{$unified_info{modules}})
115-}
116INSTALL_MODULES={-
117        join(" ", map { quotify1(platform->dso($_)) }
118                  grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
119                          && !$unified_info{attributes}->{modules}->{$_}->{engine}
120                          && !$unified_info{attributes}->{modules}->{$_}->{fips} }
121                  @{$unified_info{modules}})
122-}
123INSTALL_MODULEPDBS={-
124        join(" ", map { quotify1(platform->dsopdb($_)) }
125                  grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
126                         && !$unified_info{attributes}->{modules}->{$_}->{engine} }
127                  @{$unified_info{modules}})
128-}
129INSTALL_FIPSMODULE={-
130        join(" ", map { quotify1(platform->dso($_)) }
131                  grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
132                          && $unified_info{attributes}->{modules}->{$_}->{fips} }
133                  @{$unified_info{modules}})
134-}
135INSTALL_FIPSMODULECONF=providers\fipsmodule.cnf
136INSTALL_PROGRAMS={-
137        join(" ", map { quotify1(platform->bin($_)) }
138                  grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
139                  @{$unified_info{programs}})
140-}
141INSTALL_PROGRAMPDBS={-
142        join(" ", map { quotify1(platform->binpdb($_)) }
143                  grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
144                  @{$unified_info{programs}})
145-}
146BIN_SCRIPTS={-
147        join(" ", map { quotify1($_) }
148                  grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
149                         && !$unified_info{attributes}->{scripts}->{$_}->{misc} }
150                  @{$unified_info{scripts}})
151-}
152MISC_SCRIPTS={-
153        join(" ", map { quotify1($_) }
154                  grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
155                         && $unified_info{attributes}->{scripts}->{$_}->{misc} }
156                  @{$unified_info{scripts}})
157-}
158INSTALL_EXPORTERS_CMAKE={-
159        join(" ", map { quotify1($_) }
160                  grep { $unified_info{attributes}->{generate}->{$_}->{exporter} eq 'cmake'}
161                  sort keys %{$unified_info{generate}})
162-}
163IMAGEDOCS1={- our @IMAGEDOCS1 = @{$unified_info{imagedocs}->{man1}};
164             join(" ", @IMAGEDOCS1) -}
165IMAGEDOCS3={- our @IMAGEDOCS3 = @{$unified_info{imagedocs}->{man3}};
166             join(" ", @IMAGEDOCS3) -}
167IMAGEDOCS5={- our @IMAGEDOCS5 = @{$unified_info{imagedocs}->{man5}};
168             join(" ", @IMAGEDOCS5) -}
169IMAGEDOCS7={- our @IMAGEDOCS7 = @{$unified_info{imagedocs}->{man7}};
170             join(" ", @IMAGEDOCS7) -}
171HTMLDOCS1={- our @HTMLDOCS1 = @{$unified_info{htmldocs}->{man1}};
172             join(" ", @HTMLDOCS1) -}
173HTMLDOCS3={- our @HTMLDOCS3 = @{$unified_info{htmldocs}->{man3}};
174             join(" ", @HTMLDOCS3) -}
175HTMLDOCS5={- our @HTMLDOCS5 = @{$unified_info{htmldocs}->{man5}};
176             join(" ", @HTMLDOCS5) -}
177HTMLDOCS7={- our @HTMLDOCS7 = @{$unified_info{htmldocs}->{man7}};
178             join(" ", @HTMLDOCS7) -}
179HTMLDOCS1_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS1;
180                     join(' ', sort keys %dirs) -}
181HTMLDOCS3_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS3;
182                     join(' ', sort keys %dirs) -}
183HTMLDOCS5_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS5;
184                     join(' ', sort keys %dirs) -}
185HTMLDOCS7_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS7;
186                     join(' ', sort keys %dirs) -}
187
188APPS_OPENSSL="{- use File::Spec::Functions;
189                 catfile("apps","openssl") -}"
190
191# Do not edit these manually. Use Configure with --prefix or --openssldir
192# to change this!  Short explanation in the top comment in Configure
193INSTALLTOP_dev={- # $prefix is used in the OPENSSLDIR perl snippet
194                  #
195                  use File::Spec::Functions qw(:DEFAULT splitpath);
196                  our $prefix = canonpath($config{prefix}
197                                          || "$win_installroot\\OpenSSL");
198                  our ($prefix_dev, $prefix_dir, $prefix_file) =
199                      splitpath($prefix, 1);
200                  $prefix_dev -}
201INSTALLTOP_dir={- canonpath($prefix_dir) -}
202OPENSSLDIR_dev={- #
203                  # The logic here is that if no --openssldir was given,
204                  # OPENSSLDIR will get the value "$win_commonroot\\SSL".
205                  # If --openssldir was given and the value is an absolute
206                  # path, OPENSSLDIR will get its value without change.
207                  # If the value from --openssldir is a relative path,
208                  # OPENSSLDIR will get $prefix with the --openssldir
209                  # value appended as a subdirectory.
210                  #
211                  use File::Spec::Functions qw(:DEFAULT splitpath);
212                  our $openssldir =
213                      $config{openssldir} ?
214                          (file_name_is_absolute($config{openssldir}) ?
215                               canonpath($config{openssldir})
216                               : catdir($prefix, $config{openssldir}))
217                          : canonpath("$win_commonroot\\SSL");
218                  our ($openssldir_dev, $openssldir_dir, $openssldir_file) =
219                      splitpath($openssldir, 1);
220                  $openssldir_dev -}
221OPENSSLDIR_dir={- canonpath($openssldir_dir) -}
222LIBDIR={- our $libdir = $config{libdir} || "lib";
223          file_name_is_absolute($libdir) ? "" : $libdir -}
224MODULESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath catpath);
225                  our $modulesprefix = catdir($prefix,$libdir);
226                  our ($modulesprefix_dev, $modulesprefix_dir,
227                       $modulesprefix_file) =
228                      splitpath($modulesprefix, 1);
229                  our $modulesdir_dev = $modulesprefix_dev;
230                  our $modulesdir_dir =
231                      catdir($modulesprefix_dir, "ossl-modules");
232                  our $modulesdir = catpath($modulesdir_dev, $modulesdir_dir);
233                  our $enginesdir_dev = $modulesprefix_dev;
234                  our $enginesdir_dir =
235                      catdir($modulesprefix_dir, "engines-$sover_dirname");
236                  our $enginesdir = catpath($enginesdir_dev, $enginesdir_dir);
237                  $modulesdir_dev -}
238MODULESDIR_dir={- canonpath($modulesdir_dir) -}
239ENGINESDIR_dev={- $enginesdir_dev -}
240ENGINESDIR_dir={- canonpath($enginesdir_dir) -}
241!IF "$(DESTDIR)" != ""
242INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir)
243OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir)
244ENGINESDIR=$(DESTDIR)$(ENGINESDIR_dir)
245MODULESDIR=$(DESTDIR)$(MODULESDIR_dir)
246!ELSE
247INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
248OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
249ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
250MODULESDIR=$(MODULESDIR_dev)$(MODULESDIR_dir)
251!ENDIF
252
253# $(libdir) is chosen to be compatible with the GNU coding standards
254libdir={- file_name_is_absolute($libdir)
255          ? $libdir : '$(INSTALLTOP)\$(LIBDIR)' -}
256
257CMAKECONFIGDIR=$(libdir)\cmake\OpenSSL
258
259##### User defined commands and flags ################################
260
261CC="{- $config{CC} -}"
262CPP={- $config{CPP} -}
263CPPFLAGS={- our $cppflags1 = join(" ",
264                                  (map { "-D".$_} @{$config{CPPDEFINES}}),
265                                  (map { " -I".$_} @{$config{CPPINCLUDES}}),
266                                  @{$config{CPPFLAGS}}) -}
267CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
268LD="{- $config{LD} -}"
269LDFLAGS={- join(' ', @{$config{LDFLAGS}}) -}
270EX_LIBS={- join(' ', @{$config{LDLIBS}}) -}
271
272PERL={- $config{PERL} -}
273
274AR="{- $config{AR} -}"
275ARFLAGS= {- join(' ', @{$config{ARFLAGS}}) -}
276
277MT="{- $config{MT} -}"
278MTFLAGS= {- join(' ', @{$config{MTFLAGS}}) -}
279
280AS="{- $config{AS} -}"
281ASFLAGS={- join(' ', @{$config{ASFLAGS}}) -}
282
283RC="{- $config{RC} -}"
284RCFLAGS={- join(' ', @{$config{RCFLAGS}}) -}
285
286ECHO="$(PERL)" "$(SRCDIR)\util\echo.pl"
287
288##### Special command flags ##########################################
289
290COUTFLAG={- $target{coutflag} -}$(OSSL_EMPTY)
291LDOUTFLAG={- $target{ldoutflag} -}$(OSSL_EMPTY)
292AROUTFLAG={- $target{aroutflag} -}$(OSSL_EMPTY)
293MTINFLAG={- $target{mtinflag} -}$(OSSL_EMPTY)
294MTOUTFLAG={- $target{mtoutflag} -}$(OSSL_EMPTY)
295ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
296RCOUTFLAG={- $target{rcoutflag} -}$(OSSL_EMPTY)
297
298##### Project flags ##################################################
299
300# Variables starting with CNF_ are common variables for all product types
301
302CNF_ASFLAGS={- join(' ', $target{asflags} || (),
303                         @{$config{asflags}}) -}
304CNF_CPPFLAGS={- our $cppflags2 =
305                    join(' ', $target{cppflags} || (),
306                              (map { '-D'.quotify1($_) } @{$target{defines}},
307                                                         @{$config{defines}}),
308                              (map { '-I'.'"'.$_.'"' } @{$target{includes}},
309                                                       @{$config{includes}}),
310                              @{$config{cppflags}}) -}
311CNF_CFLAGS={- join(' ', $target{cflags} || (),
312                        @{$config{cflags}}) -}
313CNF_CXXFLAGS={- join(' ', $target{cxxflags} || (),
314                          @{$config{cxxflags}}) -}
315CNF_LDFLAGS={- join(' ', $target{lflags} || (),
316                         @{$config{lflags}}) -}
317CNF_EX_LIBS={- join(' ', $target{ex_libs} || (),
318                         @{$config{ex_libs}}) -}
319
320# Variables starting with LIB_ are used to build library object files
321# and shared libraries.
322# Variables starting with DSO_ are used to build DSOs and their object files.
323# Variables starting with BIN_ are used to build programs and their object
324# files.
325
326LIB_ASFLAGS={- join(' ', $target{lib_asflags} || (),
327                         @{$config{lib_asflags}},
328                         '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
329LIB_CPPFLAGS={- our $lib_cppflags =
330                join(' ', $target{lib_cppflags} || (),
331                          $target{shared_cppflag} || (),
332                          (map { '-D'.quotify1($_) }
333                               @{$target{lib_defines}},
334                               @{$target{shared_defines}},
335                               @{$config{lib_defines}},
336                               @{$config{shared_defines}}),
337                          (map { '-I'.quotify1($_) }
338                               @{$target{lib_includes}},
339                               @{$target{shared_includes}},
340                               @{$config{lib_includes}},
341                               @{$config{shared_includes}}),
342                          @{$config{lib_cppflags}},
343                          @{$config{shared_cppflag}});
344                join(' ', $lib_cppflags,
345                          (map { '-D'.quotify1($_) }
346                               "OPENSSLDIR=\"$openssldir\"",
347                               "ENGINESDIR=\"$enginesdir\"",
348                               "MODULESDIR=\"$modulesdir\""),
349                          '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
350LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
351                        $target{shared_cflag} || (),
352                        @{$config{lib_cflags}},
353                        @{$config{shared_cflag}},
354                        '$(CNF_CFLAGS)', '$(CFLAGS)') -}
355LIB_LDFLAGS={- join(' ', $target{shared_ldflag} || (),
356                         $config{shared_ldflag} || (),
357                         '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
358LIB_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
359DSO_ASFLAGS={- join(' ', $target{dso_asflags} || (),
360                         $target{module_asflags} || (),
361                         @{$config{dso_asflags}},
362                         @{$config{module_asflags}},
363                         '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
364DSO_CPPFLAGS={- join(' ', $target{dso_cppflags} || (),
365                          $target{module_cppflag} || (),
366                          (map { '-D'.quotify1($_) }
367                               @{$target{dso_defines}},
368                               @{$target{module_defines}},
369                               @{$config{dso_defines}},
370                               @{$config{module_defines}}),
371                          (map { '-I'.quotify1($_) }
372                               @{$target{dso_includes}},
373                               @{$target{module_includes}},
374                               @{$config{dso_includes}},
375                               @{$config{module_includes}}),
376                          @{$config{dso_cppflags}},
377                          @{$config{module_cppflags}},
378                          '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
379DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
380                        $target{module_cflags} || (),
381                        @{$config{dso_cflags}},
382                        @{$config{module_cflags}},
383                        '$(CNF_CFLAGS)', '$(CFLAGS)') -}
384DSO_LDFLAGS={- join(' ', $target{dso_lflags} || (),
385                         $target{module_ldflags} || (),
386                         @{$config{dso_lflags}},
387                         @{$config{module_ldflags}},
388                         '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
389DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
390BIN_ASFLAGS={- join(' ', $target{bin_asflags} || (),
391                         @{$config{bin_asflags}},
392                         '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
393BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
394                          (map { '-D'.$_ } @{$config{bin_defines} || ()}),
395                          @{$config{bin_cppflags}},
396                          '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
397BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
398                        @{$config{bin_cflags}},
399                        '$(CNF_CFLAGS)', '$(CFLAGS)') -}
400BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
401                         @{$config{bin_lflags}},
402                         '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
403BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
404
405# CPPFLAGS_Q is used for one thing only: to build up buildinf.h
406CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
407              $cppflags2 =~ s|([\\"])|\\$1|g;
408              join(' ', $lib_cppflags || (), $cppflags2 || (),
409                        $cppflags1 || ()) -}
410
411PERLASM_SCHEME= {- $target{perlasm_scheme} -}
412
413PROCESSOR= {- $config{processor} -}
414
415# The main targets ###################################################
416
417{- dependmagic('build_sw'); -}: build_libs_nodep build_modules_nodep build_programs_nodep copy-utils
418{- dependmagic('build_libs'); -}: build_libs_nodep
419{- dependmagic('build_modules'); -}: build_modules_nodep
420{- dependmagic('build_programs'); -}: build_programs_nodep
421
422build_docs: build_html_docs
423build_html_docs: $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
424	@
425build_generated: $(GENERATED_MANDATORY)
426	@
427build_libs_nodep: $(LIBS) {- join(" ",map { platform->sharedlib_import($_) // () } @{$unified_info{libraries}}) -}
428	@
429build_modules_nodep: $(MODULES)
430	@
431build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
432	@
433
434# Kept around for backward compatibility
435build_apps build_tests: build_programs
436
437# Convenience target to prebuild all generated files, not just the mandatory
438# ones
439build_all_generated: $(GENERATED_MANDATORY) $(GENERATED) build_docs
440	@{- output_off() if $disabled{makedepend}; "\@rem" -}
441	@$(ECHO) "Warning: consider configuring with no-makedepend, because if"
442	@$(ECHO) "         target system doesn't have $(PERL),"
443	@$(ECHO) "         then make will fail..."
444	@{- output_on() if $disabled{makedepend}; "\@rem" -}
445
446all: build_sw {- "build_docs" if !$disabled{docs}; -}
447
448test: tests
449{- dependmagic('tests'); -}: build_programs_nodep build_modules_nodep copy-utils
450	$(MAKE) /$(MAKEFLAGS) run_tests
451run_tests:
452	@{- output_off() if $disabled{tests}; "\@rem" -}
453	cmd /C "set "SRCTOP=$(SRCDIR)" & set "BLDTOP=$(BLDDIR)" & set "PERL=$(PERL)" & set "FIPSKEY=$(FIPSKEY)" & "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)"
454	@{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
455	@$(ECHO) "Tests are not supported with your chosen Configure options"
456	@{- output_on() if !$disabled{tests}; "\@rem" -}
457
458list-tests:
459	@{- output_off() if $disabled{tests}; "\@rem" -}
460	@cmd /C "set "SRCTOP=$(SRCDIR)" & "$(PERL)" "$(SRCDIR)\test\run_tests.pl" list"
461	@{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
462	@$(ECHO) "Tests are not supported with your chosen Configure options"
463	@{- output_on() if !$disabled{tests}; "\@rem" -}
464
465install: install_sw install_ssldirs {- "install_docs" if !$disabled{docs}; -} {- $disabled{fips} ? "" : "install_fips" -}
466
467uninstall: {- "uninstall_docs" if !$disabled{docs}; -} uninstall_sw {- $disabled{fips} ? "" : "uninstall_fips" -}
468
469libclean:
470	"$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """{.,apps,test,fuzz}/$$1.*"""; } @ARGV" $(SHLIBS)
471	-del /Q /F $(LIBS) libcrypto.* libssl.* ossl_static.pdb
472
473clean: libclean
474	{- join("\n\t", map { "-del /Q /F $_" } @HTMLDOCS1) || "\@rem" -}
475	{- join("\n\t", map { "-del /Q /F $_" } @HTMLDOCS3) || "\@rem" -}
476	{- join("\n\t", map { "-del /Q /F $_" } @HTMLDOCS5) || "\@rem" -}
477	{- join("\n\t", map { "-del /Q /F $_" } @HTMLDOCS7) || "\@rem" -}
478	{- join("\n\t", map { "-del /Q /F $_" } @PROGRAMS) || "\@rem" -}
479	{- join("\n\t", map { "-del /Q /F $_" } @MODULES) || "\@rem" -}
480	{- join("\n\t", map { "-del /Q /F $_" } @SCRIPTS) || "\@rem" -}
481	{- join("\n\t", map { "-del /Q /F $_" } @GENERATED_MANDATORY) || "\@rem" -}
482	{- join("\n\t", map { "-del /Q /F $_" } @GENERATED) || "\@rem" -}
483	-del /Q /S /F *.d *.obj *.pdb *.ilk *.manifest
484	-del /Q /S /F engines\*.lib engines\*.exp
485	-del /Q /S /F apps\*.lib apps\*.rc apps\*.res apps\*.exp
486	-del /Q /S /F test\*.exp
487	-rd /Q /S test\test-runs
488
489distclean: clean
490	-del /Q /F include\openssl\configuration.h
491	-del /Q /F configdata.pm
492	-del /Q /F makefile
493
494depend: makefile
495	@ {- output_off() if $disabled{makedepend}; "\@rem" -}
496	@ "$(PERL)" "$(SRCDIR)\util\add-depends.pl" "{- $target{makedep_scheme} -}"
497	@ {- output_on() if $disabled{makedepend}; "\@rem" -}
498
499# Install helper targets #############################################
500
501install_sw: install_dev install_engines install_modules install_runtime
502
503uninstall_sw: uninstall_runtime uninstall_modules uninstall_engines uninstall_dev
504
505install_docs: install_html_docs
506
507uninstall_docs: uninstall_html_docs
508
509{- output_off() if $disabled{fips}; "" -}
510install_fips: build_sw $(INSTALL_FIPSMODULECONF)
511#	@[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1)
512	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(MODULESDIR)"
513	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)"
514	@$(ECHO) "*** Installing FIPS module"
515	@$(ECHO) "install $(INSTALL_FIPSMODULE) -> $(MODULESDIR)\$(FIPSMODULENAME)"
516	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(INSTALL_FIPSMODULE)" "$(MODULESDIR)"
517	@$(ECHO) "*** Installing FIPS module configuration"
518	@$(ECHO) "install $(INSTALL_FIPSMODULECONF) -> $(OPENSSLDIR)\fipsmodule.cnf"
519	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(INSTALL_FIPSMODULECONF)" "$(OPENSSLDIR)"
520
521uninstall_fips:
522	@$(ECHO) "*** Uninstalling FIPS module configuration"
523	$(RM) "$(OPENSSLDIR)\fipsmodule.cnf"
524	@$(ECHO) "*** Uninstalling FIPS module"
525	$(RM) "$(MODULESDIR)\$(FIPSMODULENAME)"
526{- if ($disabled{fips}) { output_on(); } else { output_off(); } "" -}
527install_fips:
528	@$(ECHO) "The 'install_fips' target requires the 'enable-fips' option"
529
530uninstall_fips:
531	@$(ECHO) "The 'uninstall_fips' target requires the 'enable-fips' option"
532{- output_on() if !$disabled{fips}; "" -}
533
534install_ssldirs:
535	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\certs"
536	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\private"
537	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\misc"
538	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
539                                        "$(OPENSSLDIR)\openssl.cnf.dist"
540	@IF NOT EXIST "$(OPENSSLDIR)\openssl.cnf" \
541         "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
542                                        "$(OPENSSLDIR)\openssl.cnf"
543	@if not "$(MISC_SCRIPTS)"=="" \
544	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
545                                        "$(OPENSSLDIR)\misc"
546	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
547                                        "$(OPENSSLDIR)\ct_log_list.cnf.dist"
548	@IF NOT EXIST "$(OPENSSLDIR)\ct_log_list.cnf" \
549         "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
550                                        "$(OPENSSLDIR)\ct_log_list.cnf"
551
552install_dev: install_runtime_libs
553	@if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
554	@$(ECHO) "*** Installing development files"
555	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\include\openssl"
556	@{- output_off() if $disabled{uplink}; "" -}
557	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\ms\applink.c" \
558				       "$(INSTALLTOP)\include\openssl"
559	@{- output_on() if $disabled{uplink}; "" -}
560	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "-exclude_re=/__DECC_" \
561				       "$(SRCDIR)\include\openssl\*.h" \
562				       "$(INSTALLTOP)\include\openssl"
563	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(BLDDIR)\include\openssl\*.h" \
564				       "$(INSTALLTOP)\include\openssl"
565	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(libdir)"
566	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) "$(libdir)"
567	@if "$(SHLIBS)"=="" \
568	 "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb "$(libdir)"
569	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(CMAKECONFIGDIR)"
570	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_EXPORTERS_CMAKE) "$(CMAKECONFIGDIR)"
571
572uninstall_dev:
573
574_install_modules_deps: install_runtime_libs build_modules
575
576install_engines: _install_modules_deps
577	@if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
578	@$(ECHO) "*** Installing engines"
579	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(ENGINESDIR)"
580	@if not "$(INSTALL_ENGINES)"=="" \
581	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINES) "$(ENGINESDIR)"
582	@if not "$(INSTALL_ENGINES)"=="" \
583	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINEPDBS) "$(ENGINESDIR)"
584
585uninstall_engines:
586
587install_modules: _install_modules_deps
588	@if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
589	@$(ECHO) "*** Installing modules"
590	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(MODULESDIR)"
591	@if not "$(INSTALL_MODULES)"=="" \
592	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_MODULES) "$(MODULESDIR)"
593	@if not "$(INSTALL_MODULES)"=="" \
594	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_MODULEPDBS) "$(MODULESDIR)"
595
596uninstall_modules:
597
598install_runtime: install_programs
599
600install_runtime_libs: build_libs
601	@if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
602	@$(ECHO) "*** Installing runtime libraries"
603	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
604	@if not "$(SHLIBS)"=="" \
605	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBS) "$(INSTALLTOP)\bin"
606	@if not "$(SHLIBS)"=="" \
607	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBPDBS) \
608                                        "$(INSTALLTOP)\bin"
609
610install_programs: install_runtime_libs build_programs
611	@if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
612	@$(ECHO) "*** Installing runtime programs"
613	@if not "$(INSTALL_PROGRAMS)"=="" \
614	 "$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
615	@if not "$(INSTALL_PROGRAMS)"=="" \
616	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \
617                                        "$(INSTALLTOP)\bin"
618	@if not "$(INSTALL_PROGRAMS)"=="" \
619	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \
620                                        "$(INSTALLTOP)\bin"
621	@if not "$(INSTALL_PROGRAMS)"=="" \
622	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
623                                        "$(INSTALLTOP)\bin"
624
625uninstall_runtime:
626
627install_html_docs: install_image_docs build_html_docs
628	@if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
629	@echo *** Installing HTML docs
630	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man1"
631	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man3"
632	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man5"
633	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man7"
634	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man1\*.html \
635                                        "$(INSTALLTOP)\html\man1"
636	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man3\*.html \
637                                        "$(INSTALLTOP)\html\man3"
638	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man5\*.html \
639                                        "$(INSTALLTOP)\html\man5"
640	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man7\*.html \
641                                        "$(INSTALLTOP)\html\man7"
642
643uninstall_html_docs: uninstall_image_docs
644
645install_image_docs:
646	@if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
647	@echo *** Installing HTML images
648	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man7\img"
649	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(SRCDIR)\doc\man7\img\*.png \
650                                        "$(INSTALLTOP)\html\man7\img"
651
652uninstall_image_docs:
653
654# Helper targets #####################################################
655
656copy-utils: $(BLDDIR)\apps\openssl.cnf
657
658$(BLDDIR)\apps\openssl.cnf: makefile
659	@if NOT EXIST "$(BLDDIR)\apps" mkdir "$(BLDDIR)\apps"
660	@if NOT "$(SRCDIR)"=="$(BLDDIR)" copy "$(SRCDIR)\apps\$(@F)" "$(BLDDIR)\apps"
661
662# Building targets ###################################################
663
664makefile: configdata.pm {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}) -}
665	@$(ECHO) "Detected changed: $?"
666	"$(PERL)" configdata.pm
667	@$(ECHO) "**************************************************"
668	@$(ECHO) "***                                            ***"
669	@$(ECHO) "***   Please run the same make command again   ***"
670	@$(ECHO) "***                                            ***"
671	@$(ECHO) "**************************************************"
672	@exit 1
673
674configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_infos}}, @{$config{conf_files}}) -}
675	@$(ECHO) "Detected changed: $?"
676	"$(PERL)" configdata.pm -r
677	@$(ECHO) "**************************************************"
678	@$(ECHO) "***                                            ***"
679	@$(ECHO) "***   Please run the same make command again   ***"
680	@$(ECHO) "***                                            ***"
681	@$(ECHO) "**************************************************"
682	@exit 1
683
684reconfigure reconf:
685	"$(PERL)" configdata.pm -r
686
687{-
688 use File::Basename;
689 use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs file_name_is_absolute/;
690
691  # Helper function to convert dependencies in platform agnostic form to
692  # dependencies in platform form.
693  sub compute_platform_depends {
694      map { my $x = $_;
695
696            grep { $x eq $_ } @{$unified_info{programs}} and platform->bin($x)
697            or grep { $x eq $_ } @{$unified_info{modules}} and platform->dso($x)
698            or grep { $x eq $_ } @{$unified_info{libraries}} and platform->lib($x)
699            or platform->convertext($x); } @_;
700  }
701
702 # Helper function to figure out dependencies on libraries
703 # It takes a list of library names and outputs a list of dependencies
704 sub compute_lib_depends {
705     if ($disabled{shared}) {
706	 return map { platform->staticlib($_) } @_;
707     }
708     return map { platform->sharedlib_import($_) // platform->staticlib($_) } @_;
709 }
710
711  sub generatetarget {
712      my %args = @_;
713      my $deps = join(" ", compute_platform_depends(@{$args{deps}}));
714      return <<"EOF";
715$args{target}: $deps
716EOF
717  }
718
719  # This function (and the next) avoids quoting paths of generated dependencies
720  # (in the build tree), but quotes paths of non-generated dependencies (in the
721  # source tree). This is a workaround for a limitation of C++Builder's make.exe
722  # in handling quoted paths: https://quality.embarcadero.com/browse/RSP-31756
723  sub generatesrc {
724      my %args = @_;
725      my $gen0 = $args{generator}->[0];
726      my $gen_args = join('', map { " $_" }
727                              @{$args{generator}}[1..$#{$args{generator}}]);
728      my $gen_incs = join("", map { " -I\"$_\"" } @{$args{generator_incs}});
729      my $incs = join("", map { " -I\"$_\"" } @{$args{incs}});
730      my $defs = join("", map { " -D".$_ } @{$args{defs}});
731      my $deps = join(' ',
732                      map { file_name_is_absolute($_) || ($_ =~ m|^../|) ? "\"$_\"" : $_ }
733                      compute_platform_depends(@{$args{generator_deps}},
734                                               @{$args{deps}}));
735
736      if ($args{src} =~ /\.html$/) {
737          #
738          # HTML generator
739          #
740          my $title = basename($args{src}, ".html");
741          my $pod = $gen0;
742          return <<"EOF";
743$args{src}: "$pod"
744	"\$(PERL)" "\$(SRCDIR)/util/mkpod2html.pl" -i "$pod" -o \$\@ -t "$title" -r "\$(SRCDIR)/doc"
745EOF
746      } elsif (platform->isdef($args{src})) {
747          #
748          # Linker script-ish generator
749          #
750          my $target = platform->def($args{src});
751          my $mkdef = abs2rel(rel2abs(catfile($config{sourcedir},
752                                              "util", "mkdef.pl")),
753                              rel2abs($config{builddir}));
754          my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION_NUMBER)' : '';
755          my $ord_name =
756              $args{generator}->[1] || basename(platform->dsoname($args{product}));
757          return <<"EOF";
758$target: $gen0 $deps $mkdef
759	"\$(PERL)" "$mkdef"$ord_ver --type $args{intent} --ordinals $gen0 --name $ord_name --OS windows > $target
760EOF
761      } elsif (platform->isasm($args{src})
762               || platform->iscppasm($args{src})) {
763          #
764          # Assembler generator
765          #
766          my $cppflags = {
767              shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
768              lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
769              dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
770              bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
771          } -> {$args{intent}};
772          my $target = platform->isasm($args{src})
773                       ? platform->asm($args{src})
774                       : $args{src};
775
776          my $generator;
777          if ($gen0 =~ /\.pl$/) {
778              $generator = '"$(PERL)"'.$gen_incs.' "'.$gen0.'"'.$gen_args
779                  .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSOR)';
780          } elsif ($gen0 =~ /\.S$/) {
781              $generator = undef;
782          } else {
783              die "Generator type for $src unknown: $gen0\n";
784          }
785
786          if (defined($generator)) {
787              return <<"EOF";
788$target: "$gen0" $deps
789	cmd /C "set "ASM=\$(AS)" & $generator \$@"
790EOF
791          }
792          return <<"EOF";
793$target: "$gen0" $deps
794	\$(CPP) /D__ASSEMBLER__ $incs $cppflags $defs "$gen0" > \$@.i
795	move /Y \$@.i \$@
796EOF
797      } elsif ($gen0 =~ m|^.*\.in$|) {
798          #
799          # "dofile" generator (file.in -> file)
800          #
801          my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
802                                               "util", "dofile.pl")),
803                               rel2abs($config{builddir}));
804          my @perlmodules = ();
805          my %perlmoduleincs = ();
806          my %perlmoduledeps = ();
807          foreach my $x (('configdata.pm', @{$args{deps}})) {
808              # Compute (i)nclusion directory, (m)odule name and (d)ependency
809              my $i, $m, $d;
810              if ($x =~ /\|/) {
811                  $i = $`;
812                  $d = $';
813
814                  # Massage the module part to become a real perl module spec
815                  $m = $d;
816                  $m =~ s|\.pm$||;
817                  # Directory specs are :: in perl package names
818                  $m =~ s|/|::|g;
819
820                  # Full file name of the dependency
821                  $d = catfile($i, $d) if $i;
822              } elsif ($x =~ /\.pm$/) {
823                  $i = dirname($x);
824                  $m = basename($x, '.pm');
825                  $d = $x;
826              } else {
827                  # All other dependencies are simply collected
828                  $d = $x;
829              }
830              push @perlmodules, '"-M'.$m.'"' if $m;
831              $perlmoduledeps{$d} = 1;
832              $perlmoduleincs{'"-I'.$i.'"'} = 1 if $i;
833          }
834
835          # Because of the special treatment of dependencies, we need to
836          # recompute $deps completely
837          my $deps
838              = join(" ", compute_platform_depends(@{$args{generator_deps}},
839                                                   sort keys %perlmoduledeps));
840          my $perlmodules = join(' ', '', ( sort keys %perlmoduleincs ), @perlmodules);
841
842          return <<"EOF";
843$args{src}: "$gen0" $deps
844	"\$(PERL)"$perlmodules "$dofile" "-o$target{build_file}" "$gen0"$gen_args > \$@
845EOF
846      } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) {
847          #
848          # Generic generator using OpenSSL programs
849          #
850
851          # Redo $gen0, to ensure that we have the proper extension.
852          $gen0 = platform->bin($gen0);
853          return <<"EOF";
854$args{src}: $gen0 $deps "\$(BLDDIR)\\util\\wrap.pl"
855	"\$(PERL)" "\$(BLDDIR)\\util\\wrap.pl" "$gen0"$gen_args > \$@
856EOF
857      } else {
858          #
859          # Generic generator using Perl
860          #
861          return <<"EOF";
862$args{src}: "$gen0" $deps
863	"\$(PERL)"$gen_incs "$gen0"$gen_args > \$@
864EOF
865      }
866  }
867
868 sub src2obj {
869     my $asmext = platform->asmext();
870     my %args = @_;
871     my @srcs =
872         map { my $x = $_;
873               (platform->isasm($x) && grep { $x eq $_ } @generated)
874               ? platform->asm($x) : $x }
875         ( @{$args{srcs}} );
876     my $srcs = '"'.join('" "',  @srcs).'"';
877     my $deps = join(' ',
878                     map { file_name_is_absolute($_) || ($_ =~ m|^../|) ? "\"$_\"" : $_ }
879                     (@srcs, @{$args{deps}}));
880     my $incs = join("", map { ' -I"'.$_.'"' } @{$args{incs}});
881     my $defs = join("", map { " -D".$_ } @{$args{defs}});
882     my $cflags = { shlib => ' $(LIB_CFLAGS)',
883		    lib => ' $(LIB_CFLAGS)',
884		    dso => ' $(DSO_CFLAGS)',
885		    bin => ' $(BIN_CFLAGS)' } -> {$args{intent}};
886     $cflags .= $incs;
887     $cflags .= { shlib => ' $(LIB_CPPFLAGS)',
888		  lib => ' $(LIB_CPPFLAGS)',
889		  dso => ' $(DSO_CPPFLAGS)',
890		  bin => ' $(BIN_CPPFLAGS)' } -> {$args{intent}};
891     my $asflags = { shlib => ' $(LIB_ASFLAGS)',
892		     lib => ' $(LIB_ASFLAGS)',
893		     dso => ' $(DSO_ASFLAGS)',
894		     bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}};
895     my $makedepcmd = $config{makedepcmd} unless $disabled{makedepend};
896     if ($srcs[0] =~ /\.rc$/) {
897         my $res = platform->res($args{obj});
898         return <<"EOF";
899$res: $deps
900	\$(RC) \$(RCFLAGS) \$(RCOUTFLAG)\$\@ $srcs
901EOF
902     }
903     my $obj = platform->obj($args{obj});
904     my $dep = platform->dep($args{obj});
905     if ($srcs[0] =~ /\Q${asmext}\E$/) {
906         return <<"EOF";
907$obj: $deps
908	\$(AS) $asflags \$(ASOUTFLAG)\$\@ $srcs
909EOF
910     } elsif ($srcs[0] =~ /.S$/) {
911         return <<"EOF";
912$obj: $deps
913	\$(CC) /EP -D__ASSEMBLER__ $cflags $defs $srcs > \$@.asm
914	\$(AS) $asflags \$(ASOUTFLAG)\$\@ \$@.asm
915EOF
916     }
917     my $recipe = <<"EOF";
918$obj: $deps
919	\$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
920EOF
921     $recipe .= <<"EOF"	unless $disabled{makedepend};
922	cmd /C "$makedepcmd $cflags $defs $srcs > $dep 2>&1"
923EOF
924     return $recipe;
925 }
926
927 # We *know* this routine is only called when we've configure 'shared'.
928 # Also, note that even though the import library built here looks like
929 # a static library, it really isn't.
930 sub obj2shlib {
931     my %args = @_;
932     my $lib = $args{lib};
933     my @objs = map { platform->convertext($_) }
934                grep { platform->isobj($_) }
935                @{$args{objs}};
936     my @ress = map { platform->convertext($_) }
937                grep { platform->isres($_) }
938                @{$args{objs}};
939     my @defs = map { platform->def($_) }
940                grep { platform->isdef($_) }
941                @{$args{objs}};
942     my @deps = compute_lib_depends(@{$args{deps}});
943     die "More than one exported symbols list" if scalar @defs > 1;
944     my $linklibs = join("", map { "$_$target{ld_resp_delim}" } @deps);
945     my $objs = join($target{ld_resp_delim}, @objs);
946     my $ress = join($target{ld_resp_delim}, @ress);
947     my $deps = join(" ", @objs, @ress, @defs, @deps);
948     my $import = platform->sharedlib_import($lib);
949     my $dll =  platform->sharedlib($lib);
950     my $shared_def = $target{lddefflag} . join("", @defs);
951     my $implib_rule = $target{ld_implib_rule} || "";
952     my $implib_flag = $target{ld_implib_flag}
953                       ? "$target{ld_implib_flag}$import"
954                       : "";
955     return <<"EOF"
956# The import library may look like a static library, but it is not.
957# We MUST make the import library depend on the DLL, in case someone
958# mistakenly removes the latter.
959$import: $dll
960	$implib_rule
961$dll: $deps
962	IF EXIST $full.manifest DEL /F /Q $full.manifest
963	IF EXIST \$@ DEL /F /Q \$@
964	cmd /C "\$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) @<< $implib_flag || (DEL /Q \$(\@B).* $import & EXIT 1)"
965$objs$target{ld_resp_delim}\$(LDOUTFLAG)$dll$target{ldpostoutflag}$target{ld_resp_delim}$linklibs\$(LIB_EX_LIBS)$target{ld_resp_delim}$shared_def$target{ldresflag}$ress
966<<
967	IF EXIST $dll.manifest \\
968	   \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dll.manifest \$(MTOUTFLAG)$dll
969	IF EXIST apps\\$dll DEL /Q /F apps\\$dll
970	IF EXIST test\\$dll DEL /Q /F test\\$dll
971	IF EXIST fuzz\\$dll DEL /Q /F fuzz\\$dll
972	COPY $dll apps
973	COPY $dll test
974	COPY $dll fuzz
975EOF
976 }
977 sub obj2dso {
978     my %args = @_;
979     my $dso = platform->dso($args{module});
980     my $dso_n = platform->dsoname($args{module});
981     my @objs = map { platform->convertext($_) }
982                grep { platform->isobj($_) }
983                @{$args{objs}};
984     my @ress = map { platform->convertext($_) }
985                grep { platform->isres($_) }
986                @{$args{objs}};
987     my @defs = map { platform->def($_) }
988                grep { platform->isdef($_) }
989                @{$args{objs}};
990     my @deps = compute_lib_depends(@{$args{deps}});
991     die "More than one exported symbols list" if scalar @defs > 1;
992     my $objs = join($target{ld_resp_delim}, @objs);
993     my $ress = join($target{ld_resp_delim}, @ress);
994     my $linklibs = join("", map { "$_$target{ld_resp_delim}" } @deps);
995     my $deps = join(" ", @objs, @ress, @defs, @deps);
996     my $shared_def = $target{lddefflag} . join("", @defs);
997     return <<"EOF";
998$dso: $deps
999	IF EXIST $dso.manifest DEL /F /Q $dso.manifest
1000	cmd /C "\$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) @<< || (DEL /Q \$(\@B).* $dso_n.* & EXIT 1)"
1001$objs$target{ld_resp_delim}\$(LDOUTFLAG)$dso$target{ldpostoutflag}$target{ld_resp_delim}$linklibs \$(DSO_EX_LIBS)$target{ld_resp_delim}$shared_def$target{ldresflag}$ress
1002<<
1003	IF EXIST $dso.manifest \\
1004	   \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso.manifest \$(MTOUTFLAG)$dso
1005EOF
1006 }
1007 sub obj2lib {
1008     my %args = @_;
1009     my $lib = platform->staticlib($args{lib});
1010     my @objs = map { platform->obj($_) } @{$args{objs}};
1011     my $objs = join($target{ar_resp_delim}, @objs);
1012     my $deps = join(" ", @objs);
1013     return <<"EOF";
1014$lib: $deps
1015	\$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib @<<
1016$objs
1017<<
1018EOF
1019 }
1020 sub obj2bin {
1021     my %args = @_;
1022     my $bin = platform->bin($args{bin});
1023     my @objs = map { platform->convertext($_) }
1024                grep { platform->isobj($_) }
1025                @{$args{objs}};
1026     my @ress = map { platform->convertext($_) }
1027                grep { platform->isres($_) }
1028                @{$args{objs}};
1029     my @deps = compute_lib_depends(@{$args{deps}});
1030     my $objs = join($target{ld_resp_delim}, @objs);
1031     my $ress = join($target{ld_resp_delim}, @ress);
1032     my $linklibs = join("", map { "$_$target{ld_resp_delim}" } @deps);
1033     my $deps = join(" ", @objs, @ress, @deps);
1034     return <<"EOF";
1035$bin: $deps
1036	IF EXIST $bin.manifest DEL /F /Q $bin.manifest
1037	\$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) @<<
1038$objs$target{ld_resp_delim}\$(LDOUTFLAG)$bin$target{ldpostoutflag}$target{ld_resp_delim}$linklibs\$(BIN_EX_LIBS)$target{ldresflag}$target{ldresflag}$ress
1039<<
1040	IF EXIST $bin.manifest \\
1041	   \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin.manifest \$(MTOUTFLAG)$bin
1042EOF
1043  }
1044  sub in2script {
1045      my %args = @_;
1046      my $script = $args{script};
1047      my $sources = '"'.join('" "', @{$args{sources}}).'"';
1048      my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1049                                           "util", "dofile.pl")),
1050                           rel2abs($config{builddir}));
1051      return <<"EOF";
1052$script: $sources configdata.pm
1053	"\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
1054	    "-o$target{build_file}" $sources > \$@
1055EOF
1056  }
1057  sub generatedir {
1058      my %args = @_;
1059      my $dir = $args{dir};
1060      my @deps = map { platform->convertext($_) } @{$args{deps}};
1061      my @actions = ();
1062      my %extinfo = ( dso => platform->dsoext(),
1063                      lib => platform->libext(),
1064                      bin => platform->binext() );
1065
1066      # We already have a 'test' target, and the top directory is just plain
1067      # silly
1068      return if $dir eq "test" || $dir eq ".";
1069
1070      foreach my $type (("dso", "lib", "bin", "script")) {
1071          next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
1072          # For lib object files, we could update the library.  However,
1073          # LIB on Windows doesn't work that way, so we won't create any
1074          # actions for it, and the dependencies are already taken care of.
1075          if ($type ne "lib") {
1076              foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
1077                  if (dirname($prod) eq $dir) {
1078                      push @deps, $prod.$extinfo{$type};
1079                  }
1080              }
1081          }
1082      }
1083
1084      my $deps = join(" ", @deps);
1085      my $actions = join("\n", "", @actions);
1086      return <<"EOF";
1087$dir $dir\\ : $deps$actions
1088EOF
1089  }
1090  ""    # Important!  This becomes part of the template result.
1091-}
1092