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