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