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