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