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