Configurations/10-main.conf: fix omittions in commentary.
[openssl.git] / Configurations / windows-makefile.tmpl
1 ##
2 ## Makefile for OpenSSL
3 ##
4 ## {- join("\n## ", @autowarntext) -}
5 {-
6  our $objext = $target{obj_extension} || ".obj";
7  our $depext = $target{dep_extension} || ".d";
8  our $exeext = $target{exe_extension} || ".exe";
9  our $libext = $target{lib_extension} || ".lib";
10  our $shlibext = $target{shared_extension} || ".dll";
11  our $shlibextimport = $target{shared_import_extension} || ".lib";
12  our $dsoext = $target{dso_extension} || ".dll";
13
14  our $sover = $config{shlib_major}."_".$config{shlib_minor};
15
16  my $win_installenv =
17      $target{build_scheme}->[2] eq "VC-W32" ?
18      "ProgramFiles(x86)" : "ProgramW6432";
19  my $win_commonenv =
20      $target{build_scheme}->[2] eq "VC-W32"
21      ? "CommonProgramFiles(x86)" : "CommonProgramW6432";
22  our $win_installroot =
23      defined($ENV{$win_installenv})
24      ? $win_installenv : 'ProgramFiles';
25  our $win_commonroot =
26      defined($ENV{$win_commonenv})
27      ? $win_commonenv : 'CommonProgramFiles';
28
29  # expand variables early
30  $win_installroot = $ENV{$win_installroot};
31  $win_commonroot = $ENV{$win_commonroot};
32
33  sub shlib {
34      return () if $disabled{shared};
35      my $lib = shift;
36      return $unified_info{sharednames}->{$lib} . $shlibext;
37  }
38
39  sub shlib_import {
40      return () if $disabled{shared};
41      my $lib = shift;
42      return $lib . $shlibextimport;
43  }
44
45  sub dso {
46      my $dso = shift;
47
48      return $dso . $dsoext;
49  }
50  '';
51 -}
52
53 PLATFORM={- $config{target} -}
54 SRCDIR={- $config{sourcedir} -}
55 BLDDIR={- $config{builddir} -}
56
57 VERSION={- $config{version} -}
58 MAJOR={- $config{major} -}
59 MINOR={- $config{minor} -}
60
61 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
62
63 LIBS={- join(" ", map { $_.$libext } @{$unified_info{libraries}}) -}
64 SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
65 SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{libraries}}) -}
66 ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
67 ENGINEPDBS={- join(" ", map { local $dsoext = ".pdb"; dso($_) } @{$unified_info{engines}}) -}
68 PROGRAMS={- join(" ", map { $_.$exeext } @{$unified_info{programs}}) -}
69 PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -}
70 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
71 {- output_off() if $disabled{makedepend}; "" -}
72 DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
73                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
74                   keys %{$unified_info{sources}}); -}
75 {- output_on() if $disabled{makedepend}; "" -}
76 GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
77 GENERATED={- join(" ",
78                   ( map { (my $x = $_) =~ s|\.[sS]$|\.asm|; $x }
79                     grep { defined $unified_info{generate}->{$_} }
80                     map { @{$unified_info{sources}->{$_}} }
81                     grep { /\.o$/ } keys %{$unified_info{sources}} ),
82                   ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
83
84 INSTALL_LIBS={- join(" ", map { $_.$libext } @{$unified_info{install}->{libraries}}) -}
85 INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -}
86 INSTALL_SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{install}->{libraries}}) -}
87 INSTALL_ENGINES={- join(" ", map { dso($_) } @{$unified_info{install}->{engines}}) -}
88 INSTALL_ENGINEPDBS={- join(" ", map { local $dsoext = ".pdb"; dso($_) } @{$unified_info{install}->{engines}}) -}
89 INSTALL_PROGRAMS={- join(" ", map { $_.$exeext } grep { !m|^test\\| } @{$unified_info{install}->{programs}}) -}
90 INSTALL_PROGRAMPDBS={- join(" ", map { $_.".pdb" } grep { !m|^test\\| } @{$unified_info{install}->{programs}}) -}
91 {- output_off() if $disabled{apps}; "" -}
92 BIN_SCRIPTS=$(BLDDIR)\tools\c_rehash.pl
93 MISC_SCRIPTS=$(BLDDIR)\apps\CA.pl $(BLDDIR)\apps\tsget.pl
94 {- output_on() if $disabled{apps}; "" -}
95
96 # Do not edit these manually. Use Configure with --prefix or --openssldir
97 # to change this!  Short explanation in the top comment in Configure
98 INSTALLTOP_dev={- # $prefix is used in the OPENSSLDIR perl snippet
99                   #
100                   use File::Spec::Functions qw(:DEFAULT splitpath);
101                   our $prefix = $config{prefix} || "$win_installroot\\OpenSSL";
102                   our ($prefix_dev, $prefix_dir, $prefix_file) =
103                       splitpath($prefix, 1);
104                   $prefix_dev -}
105 INSTALLTOP_dir={- $prefix_dir -}
106 OPENSSLDIR_dev={- #
107                   # The logic here is that if no --openssldir was given,
108                   # OPENSSLDIR will get the value from $prefix plus "/ssl".
109                   # If --openssldir was given and the value is an absolute
110                   # path, OPENSSLDIR will get its value without change.
111                   # If the value from --openssldir is a relative path,
112                   # OPENSSLDIR will get $prefix with the --openssldir
113                   # value appended as a subdirectory.
114                   #
115                   use File::Spec::Functions qw(:DEFAULT splitpath);
116                   our $openssldir =
117                       $config{openssldir} ?
118                           (file_name_is_absolute($config{openssldir}) ?
119                                $config{openssldir}
120                                : catdir($prefix, $config{openssldir}))
121                           : "$win_commonroot\\SSL";
122                   our ($openssldir_dev, $openssldir_dir, $openssldir_file) =
123                       splitpath($openssldir, 1);
124                   $openssldir_dev -}
125 OPENSSLDIR_dir={- $openssldir_dir -}
126 LIBDIR={- our $libdir = $config{libdir} || "lib";
127           $libdir -}
128 ENGINESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath);
129                   our $enginesdir = catdir($prefix,$libdir,"engines-$sover");
130                   our ($enginesdir_dev, $enginesdir_dir, $enginesdir_file) =
131                       splitpath($enginesdir, 1);
132                   $enginesdir_dev -}
133 ENGINESDIR_dir={- $enginesdir_dir -}
134 !IF "$(DESTDIR)" != ""
135 INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir)
136 OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir)
137 ENGINESDIR=$(DESTDIR)$(ENGINESDIR_dir)
138 !ELSE
139 INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
140 OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
141 ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
142 !ENDIF
143
144 CC={- $target{cc} -}
145 CFLAGS={- join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}})) -} {- join(" ", quotify_l("-DENGINESDIR=\"$enginesdir\"", "-DOPENSSLDIR=\"$openssldir\"")) -} {- $target{cflags} -} {- $config{cflags} -}
146 COUTFLAG={- $target{coutflag} || "/Fo" -}$(OSSL_EMPTY)
147 RC={- $target{rc} || "rc" -}
148 RCOUTFLAG={- $target{rcoutflag} || "/fo" -}$(OSSL_EMPTY)
149 LD={- $target{ld} || "link" -}
150 LDFLAGS={- $target{lflags} -}
151 LDOUTFLAG={- $target{loutflag} || "/out:" -}$(OSSL_EMPTY)
152 EX_LIBS={- $target{ex_libs} -}
153 LIB_CFLAGS={- join(" ", $target{lib_cflags}, $target{shared_cflag}) || "" -}
154 LIB_LDFLAGS={- $target{shared_ldflag} || "" -}
155 DSO_CFLAGS={- join(" ", $target{dso_cflags}, $target{shared_cflag}) || "" -}
156 DSO_LDFLAGS={- join(" ", $target{dso_lflags}, $target{shared_ldflag}) || "" -}
157 BIN_CFLAGS={- $target{bin_cflags} -}
158 BIN_LDFLAGS={- $target{bin_lflags} -}
159
160 PERL={- $config{perl} -}
161
162 AR={- $target{ar} -}
163 ARFLAGS= {- $target{arflags} -}
164 AROUTFLAG={- $target{aroutflag} || "/out:" -}$(OSSL_EMPTY)
165
166 MT={- $target{mt} -}
167 MTFLAGS= {- $target{mtflags} -}
168 MTINFLAG={- $target{mtinflag} || "-manifest " -}$(OSSL_EMPTY)
169 MTOUTFLAG={- $target{mtoutflag} || "-outputresource:" -}$(OSSL_EMPTY)
170
171 AS={- $target{as} -}
172 ASFLAGS={- $target{asflags} -}
173 ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
174 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
175
176 PROCESSOR= {- $config{processor} -}
177
178 # The main targets ###################################################
179
180 all: build_generated \
181      build_libs_nodep build_engines_nodep build_programs_nodep depend
182
183 build_libs: build_generated build_libs_nodep depend
184 build_libs_nodep: $(LIBS) {- join(" ",map { shlib_import($_) } @{$unified_info{libraries}}) -}
185 build_engines: build_generated build_engines_nodep depend
186 build_engines_nodep: $(ENGINES)
187 build_programs: build_generated build_programs_nodep depend
188 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
189
190 build_generated: $(GENERATED_MANDATORY)
191
192 # Kept around for backward compatibility
193 build_apps build_tests: build_programs
194
195 test: tests
196 tests: build_generated build_programs_nodep build_engines_nodep depend
197         @rem {- output_off() if $disabled{tests}; "" -}
198         set SRCTOP=$(SRCDIR)
199         set BLDTOP=$(BLDDIR)
200         set PERL=$(PERL)
201         "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
202         @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
203         @echo "Tests are not supported with your chosen Configure options"
204         @rem {- output_on() if !$disabled{tests}; "" -}
205
206 list-tests:
207         @rem {- output_off() if $disabled{tests}; "" -}
208         @set SRCTOP=$(SRCDIR)
209         @"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
210         @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
211         @echo "Tests are not supported with your chosen Configure options"
212         @rem {- output_on() if !$disabled{tests}; "" -}
213
214 install: install_sw install_ssldirs install_docs
215
216 uninstall: uninstall_docs uninstall_sw
217
218 libclean:
219         "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
220         "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """apps/$$1.*"""; } @ARGV" $(SHLIBS)
221         "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """test/$$1.*"""; } @ARGV" $(SHLIBS)
222         -del /Q /F $(LIBS)
223         -del /Q ossl_static.pdb
224
225 clean: libclean
226         -del /Q /F $(PROGRAMS) $(ENGINES) $(SCRIPTS)
227         -del /Q /F $(GENERATED)
228         -del /Q /S /F *.d
229         -del /Q /S /F *.obj
230         -del /Q /S /F *.pdb
231         -del /Q /S /F *.exp
232         -del /Q /S /F engines\*.ilk
233         -del /Q /S /F engines\*.lib
234         -del /Q /S /F apps\*.lib
235         -del /Q /S /F engines\*.manifest
236         -del /Q /S /F apps\*.manifest
237         -del /Q /S /F test\*.manifest
238
239 distclean: clean
240         -del /Q /F configdata.pm
241         -del /Q /F makefile
242
243 depend:
244
245 # Install helper targets #############################################
246
247 install_sw: all install_dev install_engines install_runtime
248
249 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
250
251 install_docs: install_html_docs
252
253 uninstall_docs: uninstall_html_docs
254
255 install_ssldirs:
256         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\certs"
257         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\private"
258         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\misc"
259         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
260                                         "$(OPENSSLDIR)\openssl.cnf.dist"
261         @IF NOT EXIST "$(OPENSSLDIR)\openssl.cnf" \
262          "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
263                                         "$(OPENSSLDIR)\openssl.cnf"
264         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
265                                         "$(OPENSSLDIR)\misc"
266
267 install_dev:
268         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
269         @echo *** Installing development files
270         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\include\openssl"
271         @rem {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
272         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\ms\applink.c" \
273                                        "$(INSTALLTOP)\include\openssl"
274         @rem {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
275         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\include\openssl\*.h" \
276                                        "$(INSTALLTOP)\include\openssl"
277         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\include\openssl\*.h \
278                                        "$(INSTALLTOP)\include\openssl"
279         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\$(LIBDIR)"
280         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) \
281                                        "$(INSTALLTOP)\$(LIBDIR)"
282         @if "$(SHLIBS)"=="" \
283          "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb \
284                                        "$(INSTALLTOP)\$(LIBDIR)"
285
286 uninstall_dev:
287
288 install_engines:
289         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
290         @echo *** Installing engines
291         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(ENGINESDIR)"
292         @if not "$(ENGINES)"=="" \
293          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINES) "$(ENGINESDIR)"
294         @if not "$(ENGINES)"=="" \
295          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINEPDBS) "$(ENGINESDIR)"
296
297 uninstall_engines:
298
299 install_runtime:
300         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
301         @echo *** Installing runtime files
302         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
303         @if not "$(SHLIBS)"=="" \
304          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBS) "$(INSTALLTOP)\bin"
305         @if not "$(SHLIBS)"=="" \
306          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBPDBS) \
307                                         "$(INSTALLTOP)\bin"
308         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \
309                                         "$(INSTALLTOP)\bin"
310         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \
311                                         "$(INSTALLTOP)\bin"
312         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
313                                         "$(INSTALLTOP)\bin"
314
315 uninstall_runtime:
316
317 install_html_docs:
318         "$(PERL)" "$(SRCDIR)\util\process_docs.pl" \
319                 "--destdir=$(INSTALLTOP)\html" --type=html
320
321 uninstall_html_docs:
322
323 # Building targets ###################################################
324
325 configdata.pm: "{- $config{build_file_template} -}" "$(SRCDIR)\Configurations\common.tmpl" "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_infos}}) -}
326         @echo "Detected changed: $?"
327         @echo "Reconfiguring..."
328         "$(PERL)" "$(SRCDIR)\Configure" reconf
329         @echo "**************************************************"
330         @echo "***                                            ***"
331         @echo "***   Please run the same make command again   ***"
332         @echo "***                                            ***"
333         @echo "**************************************************"
334         @exit 1
335
336 {-
337  use File::Basename;
338  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
339
340  # Helper function to figure out dependencies on libraries
341  # It takes a list of library names and outputs a list of dependencies
342  sub compute_lib_depends {
343      if ($disabled{shared}) {
344          return map { $_.$libext } @_;
345      }
346      return map { shlib_import($_) } @_;
347  }
348
349   sub generatesrc {
350       my %args = @_;
351       (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
352       my $generator = '"'.join('" "', @{$args{generator}}).'"';
353       my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
354       my $incs = join("", map { " /I \"$_\"" } @{$args{incs}});
355       my $deps = @{$args{deps}} ?
356           '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
357
358       if ($target !~ /\.asm$/) {
359           if ($args{generator}->[0] =~ m|^.*\.in$|) {
360               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
361                                                    "util", "dofile.pl")),
362                                    rel2abs($config{builddir}));
363               return <<"EOF";
364 $target: "$args{generator}->[0]" $deps
365         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
366             "-o$target{build_file}" $generator > \$@
367 EOF
368           } else {
369               return <<"EOF";
370 $target: "$args{generator}->[0]" $deps
371         "\$(PERL)"$generator_incs $generator > \$@
372 EOF
373           }
374       } else {
375           if ($args{generator}->[0] =~ /\.pl$/) {
376               $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
377           } elsif ($args{generator}->[0] =~ /\.S$/) {
378               $generator = undef;
379           } else {
380               die "Generator type for $src unknown: $generator\n";
381           }
382
383           if (defined($generator)) {
384               # If the target is named foo.S in build.info, we want to
385               # end up generating foo.s in two steps.
386               if ($args{src} =~ /\.S$/) {
387                    return <<"EOF";
388 $target: "$args{generator}->[0]" $deps
389         set ASM=\$(AS)
390         $generator \$@.S
391         \$(CC) $incs \$(CFLAGS) /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
392         del /Q \$@.S
393 EOF
394               }
395               # Otherwise....
396               return <<"EOF";
397 $target: "$args{generator}->[0]" $deps
398         set ASM=\$(AS)
399         $generator \$@
400 EOF
401           }
402           return <<"EOF";
403 $target: "$args{generator}->[0]" $deps
404         \$(CC) $incs \$(CFLAGS) /EP /C "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
405 EOF
406       }
407   }
408
409  sub src2obj {
410      my %args = @_;
411      my $obj = $args{obj};
412      my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
413                     } ( @{$args{srcs}} );
414      my $srcs = '"'.join('" "',  @srcs).'"';
415      my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
416      my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
417      unless ($disabled{zlib}) {
418          if ($withargs{zlib_include}) {
419              $incs .= ' /I "'.$withargs{zlib_include}.'"';
420          }
421      }
422      my $ecflags = { lib => '$(LIB_CFLAGS)',
423                      dso => '$(DSO_CFLAGS)',
424                      bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
425      my $makedepprog = $config{makedepprog};
426      if ($srcs[0] =~ /\.asm$/) {
427          return <<"EOF";
428 $obj$objext: $deps
429         \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
430 EOF
431      }
432      return <<"EOF"     if (!$disabled{makedepend});
433 $obj$depext: $deps
434         \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
435             "\$(PERL)" -n << > $obj$depext
436 chomp;
437 s/^Note: including file: *//;
438 \$\$collect{\$\$_} = 1;
439 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
440 <<
441 $obj$objext: $obj$depext
442         \$(CC) $incs \$(CFLAGS) $ecflags -c \$(COUTFLAG)\$\@ @<<
443 $srcs
444 <<
445 EOF
446     return <<"EOF"      if ($disabled{makedepend});
447 $obj$objext: $deps
448         \$(CC) $incs \$(CFLAGS) $ecflags -c \$(COUTFLAG)\$\@ $srcs
449 EOF
450  }
451
452  # On Unix, we build shlibs from static libs, so we're ignoring the
453  # object file array.  We *know* this routine is only called when we've
454  # configure 'shared'.
455  sub libobj2shlib {
456      my %args = @_;
457      my $lib = $args{lib};
458      my $shlib = $args{shlib};
459      (my $mkdef_key = $lib) =~ s/^lib//i;
460      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
461      my $linklibs = join("",
462                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
463      my $deps = join(" ",
464                      (map { $_.$objext } @{$args{objs}}),
465                      compute_lib_depends(@{$args{deps}}));
466      my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
467      my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
468                                             "util", "mkdef.pl")),
469                             rel2abs($config{builddir}));
470      my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
471                                            "util", "mkrc.pl")),
472                            rel2abs($config{builddir}));
473      my $target = shlib_import($lib);
474      return <<"EOF"
475 $target: $deps "$ordinalsfile" "$mkdef_pl"
476         "\$(PERL)" "$mkdef_pl" "$mkdef_key" 32 > $shlib.def
477         "\$(PERL)" -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
478         DEL $shlib.def.tmp
479         "\$(PERL)" "$mkrc_pl" $shlib$shlibext > $shlib.rc
480         \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
481         IF EXIST $shlib$shlibext.manifest DEL /F /Q $shlib$shlibext.manifest
482         \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
483                 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
484 $objs $shlib.res$linklibs \$(EX_LIBS)
485 <<
486         IF EXIST $shlib$shlibext.manifest \\
487            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$shlib$shlibext.manifest \$(MTOUTFLAG)$shlib$shlibext
488         IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext
489         IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext
490         COPY $shlib$shlibext apps
491         COPY $shlib$shlibext test
492 EOF
493  }
494  sub obj2dso {
495      my %args = @_;
496      my $dso = $args{lib};
497      my $dso_n = basename($dso);
498      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
499      my $linklibs = join("",
500                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
501      my $deps = join(" ",
502                      (map { $_.$objext } @{$args{objs}}),
503                      compute_lib_depends(@{$args{deps}}));
504      return <<"EOF";
505 $dso$dsoext: $deps
506         IF EXIST $dso$dsoext.manifest DEL /F /Q $dso$dsoext.manifest
507         \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
508 LIBRARY         $dso_n
509 EXPORTS
510     bind_engine         @1
511     v_check             @2
512 <<
513 $objs$linklibs \$(EX_LIBS)
514 <<
515         IF EXIST $dso$dsoext.manifest \\
516            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso$dsoext.manifest \$(MTOUTFLAG)$dso$dsoext
517 EOF
518  }
519  sub obj2lib {
520      # Because static libs and import libs are both named the same in native
521      # Windows, we can't have both.  We skip the static lib in that case,
522      # as the shared libs are what we use anyway.
523      return "" unless $disabled{"shared"};
524
525      my %args = @_;
526      my $lib = $args{lib};
527      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
528      my $deps = join(" ", map { $_.$objext } @{$args{objs}});
529      return <<"EOF";
530 $lib$libext: $deps
531         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
532 \$**
533 <<
534 EOF
535  }
536  sub obj2bin {
537      my %args = @_;
538      my $bin = $args{bin};
539      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
540      my $linklibs = join("",
541                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
542      my $deps = join(" ",
543                      (map { $_.$objext } @{$args{objs}}),
544                      compute_lib_depends(@{$args{deps}}));
545      return <<"EOF";
546 $bin$exeext: $deps
547         IF EXIST $bin$exeext.manifest DEL /F /Q $bin$exeext.manifest
548         \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
549 $objs setargv.obj$linklibs \$(EX_LIBS)
550 <<
551         IF EXIST $bin$exeext.manifest \\
552            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin$exeext.manifest \$(MTOUTFLAG)$bin$exeext
553 EOF
554   }
555   sub in2script {
556       my %args = @_;
557       my $script = $args{script};
558       my $sources = '"'.join('" "', @{$args{sources}}).'"';
559       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
560                                            "util", "dofile.pl")),
561                            rel2abs($config{builddir}));
562       return <<"EOF";
563 $script: $sources
564         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
565             "-o$target{build_file}" $sources > "$script"
566 EOF
567   }
568   sub generatedir {
569       my %args = @_;
570       my $dir = $args{dir};
571       my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
572       my @actions = ();
573       my %extinfo = ( dso => $dsoext,
574                       lib => $libext,
575                       bin => $exeext );
576
577       foreach my $type (("dso", "lib", "bin", "script")) {
578           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
579           # For lib object files, we could update the library.  However,
580           # LIB on Windows doesn't work that way, so we won't create any
581           # actions for it, and the dependencies are already taken care of.
582           if ($type ne "lib") {
583               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
584                   if (dirname($prod) eq $dir) {
585                       push @deps, $prod.$extinfo{$type};
586                   } else {
587                       push @actions, "\t@rem No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
588                   }
589               }
590           }
591       }
592
593       my $deps = join(" ", @deps);
594       my $actions = join("\n", "", @actions);
595       return <<"EOF";
596 $args{dir} $args{dir}\\ : $deps$actions
597 EOF
598   }
599   ""    # Important!  This becomes part of the template result.
600 -}