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