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