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