Look for comma before - in POD pages
[oweals/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         set OPENSSL_DEBUG_MEMORY=on
202         "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
203         @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
204         @echo "Tests are not supported with your chosen Configure options"
205         @rem {- output_on() if !$disabled{tests}; "" -}
206
207 list-tests:
208         @rem {- output_off() if $disabled{tests}; "" -}
209         @set SRCTOP=$(SRCDIR)
210         @"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
211         @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
212         @echo "Tests are not supported with your chosen Configure options"
213         @rem {- output_on() if !$disabled{tests}; "" -}
214
215 install: install_sw install_ssldirs install_docs
216
217 uninstall: uninstall_docs uninstall_sw
218
219 libclean:
220         "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
221         "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """apps/$$1.*"""; } @ARGV" $(SHLIBS)
222         "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """test/$$1.*"""; } @ARGV" $(SHLIBS)
223         -del /Q /F $(LIBS)
224         -del /Q ossl_static.pdb
225
226 clean: libclean
227         -del /Q /F $(PROGRAMS) $(ENGINES) $(SCRIPTS)
228         -del /Q /F $(GENERATED)
229         -del /Q /S /F *.d
230         -del /Q /S /F *.obj
231         -del /Q /S /F *.pdb
232         -del /Q /S /F *.exp
233         -del /Q /S /F engines\*.ilk
234         -del /Q /S /F engines\*.lib
235         -del /Q /S /F apps\*.lib
236         -del /Q /S /F engines\*.manifest
237         -del /Q /S /F apps\*.manifest
238         -del /Q /S /F test\*.manifest
239
240 distclean: clean
241         -del /Q /F configdata.pm
242         -del /Q /F makefile
243
244 depend:
245
246 # Install helper targets #############################################
247
248 install_sw: all install_dev install_engines install_runtime
249
250 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
251
252 install_docs: install_html_docs
253
254 uninstall_docs: uninstall_html_docs
255
256 install_ssldirs:
257         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\certs"
258         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\private"
259         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\misc"
260         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
261                                         "$(OPENSSLDIR)\openssl.cnf.dist"
262         @IF NOT EXIST "$(OPENSSLDIR)\openssl.cnf" \
263          "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
264                                         "$(OPENSSLDIR)\openssl.cnf"
265         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
266                                         "$(OPENSSLDIR)\misc"
267
268 install_dev:
269         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
270         @echo *** Installing development files
271         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\include\openssl"
272         @rem {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
273         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\ms\applink.c" \
274                                        "$(INSTALLTOP)\include\openssl"
275         @rem {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$target{defines}}; "" -}
276         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\include\openssl\*.h" \
277                                        "$(INSTALLTOP)\include\openssl"
278         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\include\openssl\*.h \
279                                        "$(INSTALLTOP)\include\openssl"
280         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\$(LIBDIR)"
281         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) \
282                                        "$(INSTALLTOP)\$(LIBDIR)"
283         @if "$(SHLIBS)"=="" \
284          "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb \
285                                        "$(INSTALLTOP)\$(LIBDIR)"
286
287 uninstall_dev:
288
289 install_engines:
290         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
291         @echo *** Installing engines
292         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(ENGINESDIR)"
293         @if not "$(ENGINES)"=="" \
294          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINES) "$(ENGINESDIR)"
295         @if not "$(ENGINES)"=="" \
296          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINEPDBS) "$(ENGINESDIR)"
297
298 uninstall_engines:
299
300 install_runtime:
301         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
302         @echo *** Installing runtime files
303         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
304         @if not "$(SHLIBS)"=="" \
305          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBS) "$(INSTALLTOP)\bin"
306         @if not "$(SHLIBS)"=="" \
307          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBPDBS) \
308                                         "$(INSTALLTOP)\bin"
309         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \
310                                         "$(INSTALLTOP)\bin"
311         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \
312                                         "$(INSTALLTOP)\bin"
313         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
314                                         "$(INSTALLTOP)\bin"
315
316 uninstall_runtime:
317
318 install_html_docs:
319         "$(PERL)" "$(SRCDIR)\util\process_docs.pl" \
320                 "--destdir=$(INSTALLTOP)\html" --type=html
321
322 uninstall_html_docs:
323
324 # Building targets ###################################################
325
326 configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
327         @echo "Detected changed: $?"
328         @echo "Reconfiguring..."
329         "$(PERL)" "$(SRCDIR)\Configure" reconf
330         @echo "**************************************************"
331         @echo "***                                            ***"
332         @echo "***   Please run the same make command again   ***"
333         @echo "***                                            ***"
334         @echo "**************************************************"
335         @exit 1
336
337 {-
338  use File::Basename;
339  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
340
341  # Helper function to figure out dependencies on libraries
342  # It takes a list of library names and outputs a list of dependencies
343  sub compute_lib_depends {
344      if ($disabled{shared}) {
345          return map { $_.$libext } @_;
346      }
347      return map { shlib_import($_) } @_;
348  }
349
350   sub generatesrc {
351       my %args = @_;
352       (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
353       my $generator = '"'.join('" "', @{$args{generator}}).'"';
354       my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
355       my $incs = join("", map { " /I \"$_\"" } @{$args{incs}});
356       my $deps = @{$args{deps}} ?
357           '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
358
359       if ($target !~ /\.asm$/) {
360           if ($args{generator}->[0] =~ m|^.*\.in$|) {
361               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
362                                                    "util", "dofile.pl")),
363                                    rel2abs($config{builddir}));
364               return <<"EOF";
365 $target: "$args{generator}->[0]" $deps
366         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
367             "-o$target{build_file}" $generator > \$@
368 EOF
369           } else {
370               return <<"EOF";
371 $target: "$args{generator}->[0]" $deps
372         "\$(PERL)"$generator_incs $generator > \$@
373 EOF
374           }
375       } else {
376           if ($args{generator}->[0] =~ /\.pl$/) {
377               $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
378           } elsif ($args{generator}->[0] =~ /\.S$/) {
379               $generator = undef;
380           } else {
381               die "Generator type for $src unknown: $generator\n";
382           }
383
384           if (defined($generator)) {
385               # If the target is named foo.S in build.info, we want to
386               # end up generating foo.s in two steps.
387               if ($args{src} =~ /\.S$/) {
388                    return <<"EOF";
389 $target: "$args{generator}->[0]" $deps
390         set ASM=\$(AS)
391         $generator \$@.S
392         \$(CC) $incs \$(CFLAGS) /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
393         del /Q \$@.S
394 EOF
395               }
396               # Otherwise....
397               return <<"EOF";
398 $target: "$args{generator}->[0]" $deps
399         set ASM=\$(AS)
400         $generator \$@
401 EOF
402           }
403           return <<"EOF";
404 $target: "$args{generator}->[0]" $deps
405         \$(CC) $incs \$(CFLAGS) /EP /C "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
406 EOF
407       }
408   }
409
410  sub src2obj {
411      my %args = @_;
412      my $obj = $args{obj};
413      my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
414                     } ( @{$args{srcs}} );
415      my $srcs = '"'.join('" "',  @srcs).'"';
416      my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
417      my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
418      unless ($disabled{zlib}) {
419          if ($withargs{zlib_include}) {
420              $incs .= ' /I "'.$withargs{zlib_include}.'"';
421          }
422      }
423      my $ecflags = { lib => '$(LIB_CFLAGS)',
424                      dso => '$(DSO_CFLAGS)',
425                      bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
426      my $makedepprog = $config{makedepprog};
427      if ($srcs[0] =~ /\.asm$/) {
428          return <<"EOF";
429 $obj$objext: $deps
430         \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
431 EOF
432      }
433      return <<"EOF"     if (!$disabled{makedepend});
434 $obj$depext: $deps
435         \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
436             "\$(PERL)" -n << > $obj$depext
437 chomp;
438 s/^Note: including file: *//;
439 \$\$collect{\$\$_} = 1;
440 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
441 <<
442 $obj$objext: $obj$depext
443         \$(CC) $incs \$(CFLAGS) $ecflags -c \$(COUTFLAG)\$\@ @<<
444 $srcs
445 <<
446 EOF
447     return <<"EOF"      if ($disabled{makedepend});
448 $obj$objext: $deps
449         \$(CC) $incs \$(CFLAGS) $ecflags -c \$(COUTFLAG)\$\@ $srcs
450 EOF
451  }
452
453  # On Unix, we build shlibs from static libs, so we're ignoring the
454  # object file array.  We *know* this routine is only called when we've
455  # configure 'shared'.
456  sub libobj2shlib {
457      my %args = @_;
458      my $lib = $args{lib};
459      my $shlib = $args{shlib};
460      (my $mkdef_key = $lib) =~ s/^lib//i;
461      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
462      my $linklibs = join("",
463                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
464      my $deps = join(" ",
465                      (map { $_.$objext } @{$args{objs}}),
466                      compute_lib_depends(@{$args{deps}}));
467      my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
468      my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
469                                             "util", "mkdef.pl")),
470                             rel2abs($config{builddir}));
471      my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
472                                            "util", "mkrc.pl")),
473                            rel2abs($config{builddir}));
474      my $target = shlib_import($lib);
475      return <<"EOF"
476 $target: $deps "$ordinalsfile" "$mkdef_pl"
477         "\$(PERL)" "$mkdef_pl" "$mkdef_key" 32 > $shlib.def
478         "\$(PERL)" -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
479         DEL $shlib.def.tmp
480         "\$(PERL)" "$mkrc_pl" $shlib$shlibext > $shlib.rc
481         \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
482         IF EXIST $shlib$shlibext.manifest DEL /F /Q $shlib$shlibext.manifest
483         \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
484                 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
485 $objs $shlib.res$linklibs \$(EX_LIBS)
486 <<
487         IF EXIST $shlib$shlibext.manifest \\
488            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$shlib$shlibext.manifest \$(MTOUTFLAG)$shlib$shlibext
489         IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext
490         IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext
491         COPY $shlib$shlibext apps
492         COPY $shlib$shlibext test
493 EOF
494  }
495  sub obj2dso {
496      my %args = @_;
497      my $dso = $args{lib};
498      my $dso_n = basename($dso);
499      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
500      my $linklibs = join("",
501                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
502      my $deps = join(" ",
503                      (map { $_.$objext } @{$args{objs}}),
504                      compute_lib_depends(@{$args{deps}}));
505      return <<"EOF";
506 $dso$dsoext: $deps
507         IF EXIST $dso$dsoext.manifest DEL /F /Q $dso$dsoext.manifest
508         \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
509 LIBRARY         $dso_n
510 EXPORTS
511     bind_engine         @1
512     v_check             @2
513 <<
514 $objs$linklibs \$(EX_LIBS)
515 <<
516         IF EXIST $dso$dsoext.manifest \\
517            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso$dsoext.manifest \$(MTOUTFLAG)$dso$dsoext
518 EOF
519  }
520  sub obj2lib {
521      # Because static libs and import libs are both named the same in native
522      # Windows, we can't have both.  We skip the static lib in that case,
523      # as the shared libs are what we use anyway.
524      return "" unless $disabled{"shared"};
525
526      my %args = @_;
527      my $lib = $args{lib};
528      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
529      my $deps = join(" ", map { $_.$objext } @{$args{objs}});
530      return <<"EOF";
531 $lib$libext: $deps
532         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
533 \$**
534 <<
535 EOF
536  }
537  sub obj2bin {
538      my %args = @_;
539      my $bin = $args{bin};
540      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
541      my $linklibs = join("",
542                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
543      my $deps = join(" ",
544                      (map { $_.$objext } @{$args{objs}}),
545                      compute_lib_depends(@{$args{deps}}));
546      return <<"EOF";
547 $bin$exeext: $deps
548         IF EXIST $bin$exeext.manifest DEL /F /Q $bin$exeext.manifest
549         \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
550 $objs setargv.obj$linklibs \$(EX_LIBS)
551 <<
552         IF EXIST $bin$exeext.manifest \\
553            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin$exeext.manifest \$(MTOUTFLAG)$bin$exeext
554 EOF
555   }
556   sub in2script {
557       my %args = @_;
558       my $script = $args{script};
559       my $sources = '"'.join('" "', @{$args{sources}}).'"';
560       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
561                                            "util", "dofile.pl")),
562                            rel2abs($config{builddir}));
563       return <<"EOF";
564 $script: $sources
565         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
566             "-o$target{build_file}" $sources > "$script"
567 EOF
568   }
569   sub generatedir {
570       my %args = @_;
571       my $dir = $args{dir};
572       my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
573       my @actions = ();
574       my %extinfo = ( dso => $dsoext,
575                       lib => $libext,
576                       bin => $exeext );
577
578       foreach my $type (("dso", "lib", "bin", "script")) {
579           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
580           # For lib object files, we could update the library.  However,
581           # LIB on Windows doesn't work that way, so we won't create any
582           # actions for it, and the dependencies are already taken care of.
583           if ($type ne "lib") {
584               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
585                   if (dirname($prod) eq $dir) {
586                       push @deps, $prod.$extinfo{$type};
587                   } else {
588                       push @actions, "\t@rem No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
589                   }
590               }
591           }
592       }
593
594       my $deps = join(" ", @deps);
595       my $actions = join("\n", "", @actions);
596       return <<"EOF";
597 $args{dir} $args{dir}\\ : $deps$actions
598 EOF
599   }
600   ""    # Important!  This becomes part of the template result.
601 -}