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