894834cfb7efd07c641fc5870aecc65695129d12
[openssl.git] / Configurations / windows-makefile.tmpl
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
38 PLATFORM={- $config{target} -}
39 SRCDIR={- $config{sourcedir} -}
40 BLDDIR={- $config{builddir} -}
41 FIPSKEY={- $config{FIPSKEY} -}
42
43 VERSION={- "$config{full_version}" -}
44 VERSION_NUMBER={- "$config{version}" -}
45 MAJOR={- $config{major} -}
46 MINOR={- $config{minor} -}
47
48 SHLIB_VERSION_NUMBER={- $config{shlib_version} -}
49
50 LIBS={- join(" ", map { ( platform->sharedlib_import($_), platform->staticlib($_) ) } @{$unified_info{libraries}}) -}
51 SHLIBS={- join(" ", map { platform->sharedlib($_) // () } @{$unified_info{libraries}}) -}
52 SHLIBPDBS={- join(" ", map { platform->sharedlibpdb($_) // () } @{$unified_info{libraries}}) -}
53 MODULES={- 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) -}
61 MODULEPDBS={- join(" ", map { platform->dsopdb($_) } @{$unified_info{modules}}) -}
62 FIPSMODULE={- # 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) -}
70 FIPSMODULENAME={- die "More that one FIPS module" if scalar @fipsmodules > 1;
71                   join(", ", map { basename(platform->dso($_)) } @fipsmodules) -}
72 PROGRAMS={- our @PROGRAMS = map { platform->bin($_) } @{$unified_info{programs}}; join(" ", @PROGRAMS) -}
73 PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -}
74 SCRIPTS={- our @SCRIPTS = @{$unified_info{scripts}}; join(" ", @SCRIPTS) -}
75 {- output_off() if $disabled{makedepend}; "" -}
76 DEPS={- join(" ", map { platform->isobj($_) ? platform->dep($_) : () }
77                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
78                   keys %{$unified_info{sources}}); -}
79 {- output_on() if $disabled{makedepend}; "" -}
80 GENERATED_MANDATORY={- our @GENERATED_MANDATORY = @{$unified_info{depends}->{""}};
81                        join(" ", @GENERATED_MANDATORY) -}
82 GENERATED={- # common0.tmpl provides @generated
83              our @GENERATED = map { platform->convertext($_) } @generated;
84              join(" ", @GENERATED) -}
85
86 INSTALL_LIBS={-
87         join(" ", map { quotify1(platform->sharedlib_import($_)
88                                  // platform->staticlib($_)) }
89                   grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
90                   @{$unified_info{libraries}})
91 -}
92 INSTALL_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 -}
98 INSTALL_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 -}
104 INSTALL_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 -}
110 INSTALL_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 -}
116 INSTALL_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 -}
123 INSTALL_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 -}
129 INSTALL_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 -}
135 INSTALL_FIPSMODULECONF=providers\fipsmodule.cnf
136 INSTALL_PROGRAMS={-
137         join(" ", map { quotify1(platform->bin($_)) }
138                   grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
139                   @{$unified_info{programs}})
140 -}
141 INSTALL_PROGRAMPDBS={-
142         join(" ", map { quotify1(platform->binpdb($_)) }
143                   grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
144                   @{$unified_info{programs}})
145 -}
146 BIN_SCRIPTS={-
147         join(" ", map { quotify1($_) }
148                   grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
149                          && !$unified_info{attributes}->{scripts}->{$_}->{misc} }
150                   @{$unified_info{scripts}})
151 -}
152 MISC_SCRIPTS={-
153         join(" ", map { quotify1($_) }
154                   grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
155                          && $unified_info{attributes}->{scripts}->{$_}->{misc} }
156                   @{$unified_info{scripts}})
157 -}
158 INSTALL_EXPORTERS_CMAKE={-
159         join(" ", map { quotify1($_) }
160                   grep { $unified_info{attributes}->{generate}->{$_}->{exporter} eq 'cmake'}
161                   sort keys %{$unified_info{generate}})
162 -}
163 IMAGEDOCS1={- our @IMAGEDOCS1 = @{$unified_info{imagedocs}->{man1}};
164              join(" ", @IMAGEDOCS1) -}
165 IMAGEDOCS3={- our @IMAGEDOCS3 = @{$unified_info{imagedocs}->{man3}};
166              join(" ", @IMAGEDOCS3) -}
167 IMAGEDOCS5={- our @IMAGEDOCS5 = @{$unified_info{imagedocs}->{man5}};
168              join(" ", @IMAGEDOCS5) -}
169 IMAGEDOCS7={- our @IMAGEDOCS7 = @{$unified_info{imagedocs}->{man7}};
170              join(" ", @IMAGEDOCS7) -}
171 HTMLDOCS1={- our @HTMLDOCS1 = @{$unified_info{htmldocs}->{man1}};
172              join(" ", @HTMLDOCS1) -}
173 HTMLDOCS3={- our @HTMLDOCS3 = @{$unified_info{htmldocs}->{man3}};
174              join(" ", @HTMLDOCS3) -}
175 HTMLDOCS5={- our @HTMLDOCS5 = @{$unified_info{htmldocs}->{man5}};
176              join(" ", @HTMLDOCS5) -}
177 HTMLDOCS7={- our @HTMLDOCS7 = @{$unified_info{htmldocs}->{man7}};
178              join(" ", @HTMLDOCS7) -}
179 HTMLDOCS1_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS1;
180                      join(' ', sort keys %dirs) -}
181 HTMLDOCS3_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS3;
182                      join(' ', sort keys %dirs) -}
183 HTMLDOCS5_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS5;
184                      join(' ', sort keys %dirs) -}
185 HTMLDOCS7_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS7;
186                      join(' ', sort keys %dirs) -}
187
188 APPS_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
193 INSTALLTOP_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 -}
201 INSTALLTOP_dir={- canonpath($prefix_dir) -}
202 OPENSSLDIR_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 -}
221 OPENSSLDIR_dir={- canonpath($openssldir_dir) -}
222 LIBDIR={- our $libdir = $config{libdir} || "lib";
223           file_name_is_absolute($libdir) ? "" : $libdir -}
224 MODULESDIR_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 -}
238 MODULESDIR_dir={- canonpath($modulesdir_dir) -}
239 ENGINESDIR_dev={- $enginesdir_dev -}
240 ENGINESDIR_dir={- canonpath($enginesdir_dir) -}
241 !IF "$(DESTDIR)" != ""
242 INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir)
243 OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir)
244 ENGINESDIR=$(DESTDIR)$(ENGINESDIR_dir)
245 MODULESDIR=$(DESTDIR)$(MODULESDIR_dir)
246 !ELSE
247 INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
248 OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
249 ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
250 MODULESDIR=$(MODULESDIR_dev)$(MODULESDIR_dir)
251 !ENDIF
252
253 # $(libdir) is chosen to be compatible with the GNU coding standards
254 libdir={- file_name_is_absolute($libdir)
255           ? $libdir : '$(INSTALLTOP)\$(LIBDIR)' -}
256
257 CMAKECONFIGDIR=$(libdir)\cmake\OpenSSL
258
259 ##### User defined commands and flags ################################
260
261 CC="{- $config{CC} -}"
262 CPP={- $config{CPP} -}
263 CPPFLAGS={- our $cppflags1 = join(" ",
264                                   (map { "-D".$_} @{$config{CPPDEFINES}}),
265                                   (map { " -I".$_} @{$config{CPPINCLUDES}}),
266                                   @{$config{CPPFLAGS}}) -}
267 CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
268 LD="{- $config{LD} -}"
269 LDFLAGS={- join(' ', @{$config{LDFLAGS}}) -}
270 EX_LIBS={- join(' ', @{$config{LDLIBS}}) -}
271
272 PERL={- $config{PERL} -}
273
274 AR="{- $config{AR} -}"
275 ARFLAGS= {- join(' ', @{$config{ARFLAGS}}) -}
276
277 MT="{- $config{MT} -}"
278 MTFLAGS= {- join(' ', @{$config{MTFLAGS}}) -}
279
280 AS="{- $config{AS} -}"
281 ASFLAGS={- join(' ', @{$config{ASFLAGS}}) -}
282
283 RC="{- $config{RC} -}"
284 RCFLAGS={- join(' ', @{$config{RCFLAGS}}) -}
285
286 ECHO="$(PERL)" "$(SRCDIR)\util\echo.pl"
287
288 ##### Special command flags ##########################################
289
290 COUTFLAG={- $target{coutflag} -}$(OSSL_EMPTY)
291 LDOUTFLAG={- $target{ldoutflag} -}$(OSSL_EMPTY)
292 AROUTFLAG={- $target{aroutflag} -}$(OSSL_EMPTY)
293 MTINFLAG={- $target{mtinflag} -}$(OSSL_EMPTY)
294 MTOUTFLAG={- $target{mtoutflag} -}$(OSSL_EMPTY)
295 ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
296 RCOUTFLAG={- $target{rcoutflag} -}$(OSSL_EMPTY)
297
298 ##### Project flags ##################################################
299
300 # Variables starting with CNF_ are common variables for all product types
301
302 CNF_ASFLAGS={- join(' ', $target{asflags} || (),
303                          @{$config{asflags}}) -}
304 CNF_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}}) -}
311 CNF_CFLAGS={- join(' ', $target{cflags} || (),
312                         @{$config{cflags}}) -}
313 CNF_CXXFLAGS={- join(' ', $target{cxxflags} || (),
314                           @{$config{cxxflags}}) -}
315 CNF_LDFLAGS={- join(' ', $target{lflags} || (),
316                          @{$config{lflags}}) -}
317 CNF_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
326 LIB_ASFLAGS={- join(' ', $target{lib_asflags} || (),
327                          @{$config{lib_asflags}},
328                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
329 LIB_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)') -}
350 LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
351                         $target{shared_cflag} || (),
352                         @{$config{lib_cflags}},
353                         @{$config{shared_cflag}},
354                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
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_ASFLAGS={- join(' ', $target{dso_asflags} || (),
360                          $target{module_asflags} || (),
361                          @{$config{dso_asflags}},
362                          @{$config{module_asflags}},
363                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
364 DSO_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)') -}
379 DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
380                         $target{module_cflags} || (),
381                         @{$config{dso_cflags}},
382                         @{$config{module_cflags}},
383                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
384 DSO_LDFLAGS={- join(' ', $target{dso_lflags} || (),
385                          $target{module_ldflags} || (),
386                          @{$config{dso_lflags}},
387                          @{$config{module_ldflags}},
388                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
389 DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
390 BIN_ASFLAGS={- join(' ', $target{bin_asflags} || (),
391                          @{$config{bin_asflags}},
392                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
393 BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
394                           (map { '-D'.$_ } @{$config{bin_defines} || ()}),
395                           @{$config{bin_cppflags}},
396                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
397 BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
398                         @{$config{bin_cflags}},
399                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
400 BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
401                          @{$config{bin_lflags}},
402                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
403 BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
404
405 # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
406 CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
407               $cppflags2 =~ s|([\\"])|\\$1|g;
408               join(' ', $lib_cppflags || (), $cppflags2 || (),
409                         $cppflags1 || ()) -}
410
411 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
412
413 PROCESSOR= {- $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
422 build_docs: build_html_docs
423 build_html_docs: $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
424         @
425 build_generated: $(GENERATED_MANDATORY)
426         @
427 build_libs_nodep: $(LIBS) {- join(" ",map { platform->sharedlib_import($_) // () } @{$unified_info{libraries}}) -}
428         @
429 build_modules_nodep: $(MODULES)
430         @
431 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
432         @
433
434 # Kept around for backward compatibility
435 build_apps build_tests: build_programs
436
437 # Convenience target to prebuild all generated files, not just the mandatory
438 # ones
439 build_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
446 all: build_sw {- "build_docs" if !$disabled{docs}; -}
447
448 test: tests
449 {- dependmagic('tests'); -}: build_programs_nodep build_modules_nodep copy-utils
450         $(MAKE) /$(MAKEFLAGS) run_tests
451 run_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
458 list-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
465 install: install_sw install_ssldirs {- "install_docs" if !$disabled{docs}; -} {- $disabled{fips} ? "" : "install_fips" -}
466
467 uninstall: {- "uninstall_docs" if !$disabled{docs}; -} uninstall_sw {- $disabled{fips} ? "" : "uninstall_fips" -}
468
469 libclean:
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
473 clean: 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
489 distclean: clean
490         -del /Q /F include\openssl\configuration.h
491         -del /Q /F configdata.pm
492         -del /Q /F makefile
493
494 depend: 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
501 install_sw: install_dev install_engines install_modules install_runtime
502
503 uninstall_sw: uninstall_runtime uninstall_modules uninstall_engines uninstall_dev
504
505 install_docs: install_html_docs
506
507 uninstall_docs: uninstall_html_docs
508
509 {- output_off() if $disabled{fips}; "" -}
510 install_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
521 uninstall_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(); } "" -}
527 install_fips:
528         @$(ECHO) "The 'install_fips' target requires the 'enable-fips' option"
529
530 uninstall_fips:
531         @$(ECHO) "The 'uninstall_fips' target requires the 'enable-fips' option"
532 {- output_on() if !$disabled{fips}; "" -}
533
534 install_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
552 install_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
572 uninstall_dev:
573
574 _install_modules_deps: install_runtime_libs build_modules
575
576 install_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
585 uninstall_engines:
586
587 install_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
596 uninstall_modules:
597
598 install_runtime: install_programs
599
600 install_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
610 install_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
625 uninstall_runtime:
626
627 install_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
643 uninstall_html_docs: uninstall_image_docs
644
645 install_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
652 uninstall_image_docs:
653
654 # Helper targets #####################################################
655
656 copy-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
664 makefile: 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
674 configdata.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
684 reconfigure 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
716 EOF
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"
745 EOF
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
760 EOF
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 \$@"
790 EOF
791           }
792           return <<"EOF";
793 $target: "$gen0" $deps
794         \$(CPP) /D__ASSEMBLER__ $incs $cppflags $defs "$gen0" > \$@.i
795         move /Y \$@.i \$@
796 EOF
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 > \$@
845 EOF
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 > \$@
856 EOF
857       } else {
858           #
859           # Generic generator using Perl
860           #
861           return <<"EOF";
862 $args{src}: "$gen0" $deps
863         "\$(PERL)"$gen_incs "$gen0"$gen_args > \$@
864 EOF
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
901 EOF
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
909 EOF
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
915 EOF
916      }
917      my $recipe = <<"EOF";
918 $obj: $deps
919         \$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
920 EOF
921      $recipe .= <<"EOF" unless $disabled{makedepend};
922         cmd /C "$makedepcmd $cflags $defs $srcs > $dep 2>&1"
923 EOF
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
975 EOF
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
1005 EOF
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 <<
1018 EOF
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
1042 EOF
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 > \$@
1055 EOF
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
1088 EOF
1089   }
1090   ""    # Important!  This becomes part of the template result.
1091 -}