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