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