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