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