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