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