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