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