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