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