windows-makefile.tmpl 25.0 KB
Newer Older
1 2 3 4 5 6
##
## Makefile for OpenSSL
##
## {- join("\n## ", @autowarntext) -}
{-
 our $objext = $target{obj_extension} || ".obj";
7
 our $resext = $target{res_extension} || ".res";
8 9 10 11 12 13 14
 our $depext = $target{dep_extension} || ".d";
 our $exeext = $target{exe_extension} || ".exe";
 our $libext = $target{lib_extension} || ".lib";
 our $shlibext = $target{shared_extension} || ".dll";
 our $shlibextimport = $target{shared_import_extension} || ".lib";
 our $dsoext = $target{dso_extension} || ".dll";

15
 (our $sover_dirname = $config{shlib_version_number}) =~ s|\.|_|g;
16

17 18 19 20 21 22 23 24
 my $win_installenv =
     $target{build_scheme}->[2] eq "VC-W32" ?
     "ProgramFiles(x86)" : "ProgramW6432";
 my $win_commonenv =
     $target{build_scheme}->[2] eq "VC-W32"
     ? "CommonProgramFiles(x86)" : "CommonProgramW6432";
 our $win_installroot =
     defined($ENV{$win_installenv})
25
     ? $win_installenv : 'ProgramFiles';
26 27
 our $win_commonroot =
     defined($ENV{$win_commonenv})
28 29 30 31 32
     ? $win_commonenv : 'CommonProgramFiles';

 # expand variables early
 $win_installroot = $ENV{$win_installroot};
 $win_commonroot = $ENV{$win_commonroot};
33

34 35
 sub shlib {
     my $lib = shift;
36 37
     return () if $disabled{shared} || $lib =~ /\.a$/;
     return () unless defined $unified_info{sharednames}->{$lib};
38 39 40
     return $unified_info{sharednames}->{$lib} . $shlibext;
 }

41 42 43 44 45
 sub lib {
     (my $lib = shift) =~ s/\.a$//;
     return $lib . $libext;
 }

46 47
 sub shlib_import {
     my $lib = shift;
48
     return () if $disabled{shared} || $lib =~ /\.a$/;
49 50 51 52 53 54 55 56
     return $lib . $shlibextimport;
 }

 sub dso {
     my $dso = shift;

     return $dso . $dsoext;
 }
57 58 59 60 61
 # This makes sure things get built in the order they need
 # to. You're welcome.
 sub dependmagic {
     my $target = shift;

62
     return "$target: build_generated\n\t\$(MAKE) /\$(MAKEFLAGS) depend && \$(MAKE) /\$(MAKEFLAGS) _$target\n_$target";
63
 }
64 65 66 67 68 69 70 71 72 73 74 75 76
 '';
-}

PLATFORM={- $config{target} -}
SRCDIR={- $config{sourcedir} -}
BLDDIR={- $config{builddir} -}

VERSION={- $config{version} -}
MAJOR={- $config{major} -}
MINOR={- $config{minor} -}

SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}

77
LIBS={- join(" ", map { lib($_) } @{$unified_info{libraries}}) -}
78
SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
79
SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{libraries}}) -}
80
ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
81
ENGINEPDBS={- join(" ", map { local $dsoext = ".pdb"; dso($_) } @{$unified_info{engines}}) -}
82
PROGRAMS={- our @PROGRAMS = map { $_.$exeext } @{$unified_info{programs}}; join(" ", @PROGRAMS) -}
83
PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -}
84
SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
85
{- output_off() if $disabled{makedepend}; "" -}
86 87 88
DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
                  grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
                  keys %{$unified_info{sources}}); -}
89
{- output_on() if $disabled{makedepend}; "" -}
90
GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
91 92 93 94 95 96
GENERATED={- join(" ",
                  ( map { (my $x = $_) =~ s|\.[sS]$|\.asm|; $x }
                    grep { defined $unified_info{generate}->{$_} }
                    map { @{$unified_info{sources}->{$_}} }
                    grep { /\.o$/ } keys %{$unified_info{sources}} ),
                  ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
97

98
INSTALL_LIBS={- join(" ", map { lib($_) } @{$unified_info{install}->{libraries}}) -}
99 100 101 102 103 104 105 106 107 108 109
INSTALL_SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{install}->{libraries}}) -}
INSTALL_SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{install}->{libraries}}) -}
INSTALL_ENGINES={- join(" ", map { dso($_) } @{$unified_info{install}->{engines}}) -}
INSTALL_ENGINEPDBS={- join(" ", map { local $dsoext = ".pdb"; dso($_) } @{$unified_info{install}->{engines}}) -}
INSTALL_PROGRAMS={- join(" ", map { $_.$exeext } grep { !m|^test\\| } @{$unified_info{install}->{programs}}) -}
INSTALL_PROGRAMPDBS={- join(" ", map { $_.".pdb" } grep { !m|^test\\| } @{$unified_info{install}->{programs}}) -}
{- output_off() if $disabled{apps}; "" -}
BIN_SCRIPTS=$(BLDDIR)\tools\c_rehash.pl
MISC_SCRIPTS=$(BLDDIR)\apps\CA.pl $(BLDDIR)\apps\tsget.pl
{- output_on() if $disabled{apps}; "" -}

R
Richard Levitte 已提交
110 111 112
APPS_OPENSSL={- use File::Spec::Functions;
                catfile("apps","openssl") -}

113 114
# Do not edit these manually. Use Configure with --prefix or --openssldir
# to change this!  Short explanation in the top comment in Configure
R
Richard Levitte 已提交
115 116 117
INSTALLTOP_dev={- # $prefix is used in the OPENSSLDIR perl snippet
                  #
                  use File::Spec::Functions qw(:DEFAULT splitpath);
118 119
                  our $prefix = canonpath($config{prefix}
                                          || "$win_installroot\\OpenSSL");
R
Richard Levitte 已提交
120
                  our ($prefix_dev, $prefix_dir, $prefix_file) =
121
                      splitpath($prefix, 1);
R
Richard Levitte 已提交
122
                  $prefix_dev -}
123
INSTALLTOP_dir={- canonpath($prefix_dir) -}
R
Richard Levitte 已提交
124 125
OPENSSLDIR_dev={- #
                  # The logic here is that if no --openssldir was given,
126
                  # OPENSSLDIR will get the value "$win_commonroot\\SSL".
R
Richard Levitte 已提交
127 128 129 130 131 132 133
                  # If --openssldir was given and the value is an absolute
                  # path, OPENSSLDIR will get its value without change.
                  # If the value from --openssldir is a relative path,
                  # OPENSSLDIR will get $prefix with the --openssldir
                  # value appended as a subdirectory.
                  #
                  use File::Spec::Functions qw(:DEFAULT splitpath);
134
                  our $openssldir =
R
Richard Levitte 已提交
135 136
                      $config{openssldir} ?
                          (file_name_is_absolute($config{openssldir}) ?
137
                               canonpath($config{openssldir})
R
Richard Levitte 已提交
138
                               : catdir($prefix, $config{openssldir}))
139
                          : canonpath("$win_commonroot\\SSL");
R
Richard Levitte 已提交
140 141 142
                  our ($openssldir_dev, $openssldir_dir, $openssldir_file) =
                      splitpath($openssldir, 1);
                  $openssldir_dev -}
143
OPENSSLDIR_dir={- canonpath($openssldir_dir) -}
144
LIBDIR={- our $libdir = $config{libdir} || "lib";
145
          $libdir -}
R
Richard Levitte 已提交
146
ENGINESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath);
147
                  our $enginesdir = catdir($prefix,$libdir,"engines-$sover_dirname");
R
Richard Levitte 已提交
148 149 150
                  our ($enginesdir_dev, $enginesdir_dir, $enginesdir_file) =
                      splitpath($enginesdir, 1);
                  $enginesdir_dev -}
151
ENGINESDIR_dir={- canonpath($enginesdir_dir) -}
R
Richard Levitte 已提交
152 153 154 155 156 157 158 159 160
!IF "$(DESTDIR)" != ""
INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir)
OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir)
ENGINESDIR=$(DESTDIR)$(ENGINESDIR_dir)
!ELSE
INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
!ENDIF
161

162
CC={- $config{cc} -}
R
Richard Levitte 已提交
163
CPP={- $config{cpp} -}
164
CPPFLAGS={- our $cppflags = join(" ",
165 166 167
                                 (map { "-D".$_} @{$config{defines}}),
                                 (map { " /I ".$_} @{$config{includes}}),
                                 @{$config{cppflags}}) -}
168
CPPFLAGS_Q={- $cppflags =~ s|([\\"])|\\$1|g; $cppflags -}
169
CFLAGS={- join(' ', @{$config{cflags}}) -}
170
COUTFLAG={- $target{coutflag} || "/Fo" -}$(OSSL_EMPTY)
171
RC={- $config{rc} -}
172
RCOUTFLAG={- $target{rcoutflag} || "/fo" -}$(OSSL_EMPTY)
173 174
LD={- $config{ld} -}
LDFLAGS={- join(' ', @{$config{lflags}}) -}
175
LDOUTFLAG={- $target{loutflag} || "/out:" -}$(OSSL_EMPTY)
176
EX_LIBS={- join(' ', @{$config{ex_libs}}) -}
177 178 179 180 181 182 183 184 185 186 187 188 189 190

LIB_CPPFLAGS={- join(' ', '$(CPPFLAGS)',
                          $target{shared_cppflag} || (),
                          (map { quotify_l("-D".$_) }
                           "OPENSSLDIR=\"$openssldir\"",
                           "ENGINESDIR=\"$enginesdir\"")) -}
LIB_CFLAGS={- join(' ', '$(CFLAGS)', $target{lib_cflags} || (), $target{shared_cflag} || ()) -}
LIB_LDFLAGS={- join(' ', '$(LDFLAGS)', $target{shared_ldflag} || (), $config{shared_ldflag} || ()) -}
DSO_CPPFLAGS={- join(' ', '$(CPPFLAGS)', $target{dso_cppflags} || ()) -}
DSO_CFLAGS={- join(' ', '$(CFLAGS)', $target{dso_cflags} || ()) -}
DSO_LDFLAGS={- join(' ', '$(LDFLAGS)', $target{dso_ldflag} || ()) -}
BIN_CPPFLAGS={- join(' ', '$(CPPFLAGS)', $target{dso_cppflags} || ()) -}
BIN_CFLAGS={- join(' ', '$(CFLAGS)', $target{bin_cflags} || ()) -}
BIN_LDFLAGS={- join(' ', '$(LDFLAGS)', $target{bin_lflags} || ()) -}
191 192 193

PERL={- $config{perl} -}

194 195
AR={- $config{ar} -}
ARFLAGS= {- join(' ', @{$config{arflags}}) -}
196
AROUTFLAG={- $target{aroutflag} || "/out:" -}$(OSSL_EMPTY)
197

198 199
MT={- $config{mt} -}
MTFLAGS= {- join(' ', @{$config{mtflags}}) -}
200 201
MTINFLAG={- $target{mtinflag} || "-manifest " -}$(OSSL_EMPTY)
MTOUTFLAG={- $target{mtoutflag} || "-outputresource:" -}$(OSSL_EMPTY)
202

203 204
AS={- $config{as} -}
ASFLAGS={- join(' ', @{$config{asflags}}) -}
205
ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
206 207 208 209 210 211
PERLASM_SCHEME= {- $target{perlasm_scheme} -}

PROCESSOR= {- $config{processor} -}

# The main targets ###################################################

212 213 214 215
{- dependmagic('all'); -}: build_libs_nodep build_engines_nodep build_programs_nodep
{- dependmagic('build_libs'); -}: build_libs_nodep
{- dependmagic('build_engines'); -}: build_engines_nodep
{- dependmagic('build_programs'); -}: build_programs_nodep
216

217
build_generated: $(GENERATED_MANDATORY)
218
build_libs_nodep: $(LIBS) {- join(" ",map { shlib_import($_) } @{$unified_info{libraries}}) -}
219
build_engines_nodep: $(ENGINES)
220
build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
221

222 223 224
# Kept around for backward compatibility
build_apps build_tests: build_programs

225 226 227 228
# Convenience target to prebuild all generated files, not just the mandatory
# ones
build_all_generated: $(GENERATED_MANDATORY) $(GENERATED)

229
test: tests
230
{- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep
M
Matt Caswell 已提交
231
	@rem {- output_off() if $disabled{tests}; "" -}
232
	-mkdir $(BLDDIR)\test\test-runs
233 234
	set SRCTOP=$(SRCDIR)
	set BLDTOP=$(BLDDIR)
235
	set RESULT_D=$(BLDDIR)\test\test-runs
236
	set PERL=$(PERL)
B
Bernd Edlinger 已提交
237
	set OPENSSL_ENGINES=$(MAKEDIR)\engines
238
	set OPENSSL_DEBUG_MEMORY=on
239
	"$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
M
Matt Caswell 已提交
240 241 242
	@rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
	@echo "Tests are not supported with your chosen Configure options"
	@rem {- output_on() if !$disabled{tests}; "" -}
243 244

list-tests:
245 246
	@rem {- output_off() if $disabled{tests}; "" -}
	@set SRCTOP=$(SRCDIR)
247
	@"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
248 249 250
	@rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
	@echo "Tests are not supported with your chosen Configure options"
	@rem {- output_on() if !$disabled{tests}; "" -}
251

252 253 254 255
install: install_sw install_ssldirs install_docs

uninstall: uninstall_docs uninstall_sw

256
libclean:
257 258 259
	"$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
	"$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """apps/$$1.*"""; } @ARGV" $(SHLIBS)
	"$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """test/$$1.*"""; } @ARGV" $(SHLIBS)
M
Matt Caswell 已提交
260
	"$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """fuzz/$$1.*"""; } @ARGV" $(SHLIBS)
261
	-del /Q /F $(LIBS)
R
Richard Levitte 已提交
262
	-del /Q ossl_static.pdb
263 264

clean: libclean
265 266 267
	{- join("\n\t", map { "-del /Q /F $_" } @PROGRAMS) -}
	-del /Q /F $(ENGINES)
	-del /Q /F $(SCRIPTS)
268
	-del /Q /F $(GENERATED)
269 270 271
	-del /Q /S /F *.d
	-del /Q /S /F *.obj
	-del /Q /S /F *.pdb
F
FdaSilvaYY 已提交
272 273 274
	-del /Q /F *.exp
	-del /Q /F apps\*.exp
	-del /Q /F engines\*.exp
275 276
	-del /Q /S /F engines\*.ilk
	-del /Q /S /F engines\*.lib
277 278 279
	-del /Q /S /F apps\*.lib
	-del /Q /S /F engines\*.manifest
	-del /Q /S /F apps\*.manifest
280
	-del /Q /S /F test\*.manifest
281

282 283 284 285
distclean: clean
	-del /Q /F configdata.pm
	-del /Q /F makefile

286 287
depend:

288 289 290 291 292 293
# Install helper targets #############################################

install_sw: all install_dev install_engines install_runtime

uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev

294
install_docs: install_html_docs
295

296
uninstall_docs: uninstall_html_docs
297 298

install_ssldirs:
R
Richard Levitte 已提交
299 300 301
	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\certs"
	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\private"
	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\misc"
302
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
303 304 305 306
                                        "$(OPENSSLDIR)\openssl.cnf.dist"
	@IF NOT EXIST "$(OPENSSLDIR)\openssl.cnf" \
         "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
                                        "$(OPENSSLDIR)\openssl.cnf"
307
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
R
Richard Levitte 已提交
308
                                        "$(OPENSSLDIR)\misc"
R
Rich Salz 已提交
309 310 311 312 313
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
                                        "$(OPENSSLDIR)\ct_log_list.cnf.dist"
	@IF NOT EXIST "$(OPENSSLDIR)\ct_log_list.cnf" \
         "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
                                        "$(OPENSSLDIR)\ct_log_list.cnf"
314 315 316 317

install_dev:
	@if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
	@echo *** Installing development files
R
Richard Levitte 已提交
318
	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\include\openssl"
319
	@rem {- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$config{defines}}; "" -}
320 321
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\ms\applink.c" \
				       "$(INSTALLTOP)\include\openssl"
322
	@rem {- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } @{$config{defines}}; "" -}
323
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\include\openssl\*.h" \
R
Richard Levitte 已提交
324
				       "$(INSTALLTOP)\include\openssl"
325
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\include\openssl\*.h \
R
Richard Levitte 已提交
326 327
				       "$(INSTALLTOP)\include\openssl"
	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\$(LIBDIR)"
328
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) \
R
Richard Levitte 已提交
329
				       "$(INSTALLTOP)\$(LIBDIR)"
330
	@if "$(SHLIBS)"=="" \
331
	 "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb \
R
Richard Levitte 已提交
332
                                       "$(INSTALLTOP)\$(LIBDIR)"
333 334 335 336 337 338

uninstall_dev:

install_engines:
	@if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
	@echo *** Installing engines
R
Richard Levitte 已提交
339
	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(ENGINESDIR)"
340
	@if not "$(ENGINES)"=="" \
341
	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINES) "$(ENGINESDIR)"
342
	@if not "$(ENGINES)"=="" \
343
	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINEPDBS) "$(ENGINESDIR)"
344 345 346 347 348 349

uninstall_engines:

install_runtime:
	@if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
	@echo *** Installing runtime files
R
Richard Levitte 已提交
350
	@"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
351
	@if not "$(SHLIBS)"=="" \
352
	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBS) "$(INSTALLTOP)\bin"
353
	@if not "$(SHLIBS)"=="" \
354
	 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBPDBS) \
R
Richard Levitte 已提交
355
                                        "$(INSTALLTOP)\bin"
356
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \
R
Richard Levitte 已提交
357
                                        "$(INSTALLTOP)\bin"
358
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \
R
Richard Levitte 已提交
359
                                        "$(INSTALLTOP)\bin"
360
	@"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
R
Richard Levitte 已提交
361
                                        "$(INSTALLTOP)\bin"
362 363 364

uninstall_runtime:

365 366
install_html_docs:
        "$(PERL)" "$(SRCDIR)\util\process_docs.pl" \
R
Richard Levitte 已提交
367
                "--destdir=$(INSTALLTOP)\html" --type=html
368 369 370

uninstall_html_docs:

371 372
# Building targets ###################################################

373
configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
374
	@echo "Detected changed: $?"
375
	"$(PERL)" configdata.pm -r
376 377 378 379 380
	@echo "**************************************************"
	@echo "***                                            ***"
	@echo "***   Please run the same make command again   ***"
	@echo "***                                            ***"
	@echo "**************************************************"
A
Andy Polyakov 已提交
381
	@exit 1
382

383
reconfigure reconf:
384
	"$(PERL)" configdata.pm -r
385

386 387 388 389 390 391 392 393
{-
 use File::Basename;
 use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;

 # Helper function to figure out dependencies on libraries
 # It takes a list of library names and outputs a list of dependencies
 sub compute_lib_depends {
     if ($disabled{shared}) {
394
	 return map { lib($_) } @_;
395
     }
396 397 398 399 400 401
     foreach (@_) {
         (my $l = $_) =~ s/\.a$//;
         die "Linking with static variants of shared libraries is not supported in this configuration\n"
             if $l ne $_ && shlib($l);
     }
     return map { shlib_import($_) or lib($_) } @_;
402 403
 }

404 405 406
  sub generatesrc {
      my %args = @_;
      (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
407 408 409 410 411
      my $generator = '"'.join('" "', @{$args{generator}}).'"';
      my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
      my $incs = join("", map { " /I \"$_\"" } @{$args{incs}});
      my $deps = @{$args{deps}} ?
          '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
412 413

      if ($target !~ /\.asm$/) {
414 415 416 417 418 419 420 421 422 423 424
          if ($args{generator}->[0] =~ m|^.*\.in$|) {
              my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
                                                   "util", "dofile.pl")),
                                   rel2abs($config{builddir}));
              return <<"EOF";
$target: "$args{generator}->[0]" $deps
	"\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
	    "-o$target{build_file}" $generator > \$@
EOF
	  } else {
              return <<"EOF";
425 426
$target: "$args{generator}->[0]" $deps
	"\$(PERL)"$generator_incs $generator > \$@
427
EOF
428
	  }
429 430
      } else {
          if ($args{generator}->[0] =~ /\.pl$/) {
431
              $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
432 433 434 435 436 437
          } elsif ($args{generator}->[0] =~ /\.S$/) {
              $generator = undef;
          } else {
              die "Generator type for $src unknown: $generator\n";
          }

438
          my $cppflags = $incs;
439 440 441 442 443
          $cppflags .= {
              lib => ' $(LIB_CFLAGS) $(LIB_CPPFLAGS)',
              dso => ' $(DSO_CFLAGS) $(DSO_CPPFLAGS)',
              bin => ' $(BIN_CFLAGS) $(BIN_CPPFLAGS)'
          } -> {$args{intent}};
444 445 446 447 448
          if (defined($generator)) {
              # If the target is named foo.S in build.info, we want to
              # end up generating foo.s in two steps.
              if ($args{src} =~ /\.S$/) {
                   return <<"EOF";
449
$target: "$args{generator}->[0]" $deps
450 451
	set ASM=\$(AS)
	$generator \$@.S
R
Richard Levitte 已提交
452
	\$(CPP) $cppflags \$@.S > \$@.i && move /Y \$@.i \$@
453 454 455 456 457
        del /Q \$@.S
EOF
              }
              # Otherwise....
              return <<"EOF";
458
$target: "$args{generator}->[0]" $deps
459 460 461 462 463
	set ASM=\$(AS)
	$generator \$@
EOF
          }
          return <<"EOF";
464
$target: "$args{generator}->[0]" $deps
R
Richard Levitte 已提交
465
	\$(CPP) $incs $cppflags "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
466 467 468 469
EOF
      }
  }

470 471
 sub src2obj {
     my %args = @_;
A
Andy Polyakov 已提交
472 473
     my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
                    } ( @{$args{srcs}} );
474 475 476
     my $srcs = '"'.join('" "',  @srcs).'"';
     my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
     my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
477 478 479
     my $cflags = { lib => ' $(LIB_CFLAGS)',
		    dso => ' $(DSO_CFLAGS)',
		    bin => ' $(BIN_CFLAGS)' } -> {$args{intent}};
480 481 482 483
     $cflags .= $incs;
     $cflags .= { lib => ' $(LIB_CPPFLAGS)',
		  dso => ' $(DSO_CPPFLAGS)',
		  bin => ' $(BIN_CPPFLAGS)' } -> {$args{intent}};
484
     my $makedepprog = $config{makedepprog};
485 486 487 488 489 490 491
     if ($srcs[0] =~ /\.rc$/) {
         return <<"EOF";
$args{obj}: $deps
	\$(RC) \$(RCOUTFLAG)\$\@ $srcs
EOF
     }
     (my $obj = $args{obj}) =~ s|\.o$||;
492 493 494 495 496 497
     if ($srcs[0] =~ /\.asm$/) {
         return <<"EOF";
$obj$objext: $deps
	\$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
EOF
     }
498
     return <<"EOF"	if (!$disabled{makedepend});
499
$obj$depext: $deps
500
	\$(CC) $cflags /Zs /showIncludes $srcs 2>&1 | \\
501
	    "\$(PERL)" -n << > $obj$depext
502 503 504 505
chomp;
s/^Note: including file: *//;
\$\$collect{\$\$_} = 1;
END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
506
<<
507
$obj$objext: $obj$depext
508
	\$(CC) $cflags -c \$(COUTFLAG)\$\@ @<<
509
$srcs
510
<<
511 512 513
EOF
    return <<"EOF"	if ($disabled{makedepend});
$obj$objext: $deps
514
	\$(CC) $cflags -c \$(COUTFLAG)\$\@ $srcs
515 516 517 518 519 520 521 522 523 524
EOF
 }

 # On Unix, we build shlibs from static libs, so we're ignoring the
 # object file array.  We *know* this routine is only called when we've
 # configure 'shared'.
 sub libobj2shlib {
     my %args = @_;
     my $lib = $args{lib};
     my $shlib = $args{shlib};
525
     my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x }
526
                grep { $_ =~ m/\.(?:o|res)$/ }
527 528 529 530 531 532 533
                @{$args{objs}};
     my @defs = grep { $_ =~ /\.def$/ } @{$args{objs}};
     my @deps = compute_lib_depends(@{$args{deps}});
     die "More than one exported symbols list" if scalar @defs > 1;
     my $linklibs = join("", map { "$_\n" } @deps);
     my $objs = join("\n", @objs);
     my $deps = join(" ", @objs, @defs, @deps);
534
     my $target = shlib_import($lib);
535
     my $shared_def = join("", map { " /def:$_" } @defs);
536
     return <<"EOF"
537
$target: $deps
538
	IF EXIST $shlib$shlibext.manifest DEL /F /Q $shlib$shlibext.manifest
539
	\$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
540 541 542
		/implib:\$@ \$(LDOUTFLAG)$shlib$shlibext$shared_def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
$objs
$linklibs\$(EX_LIBS)
543
<<
544
	IF EXIST $shlib$shlibext.manifest \\
545
	   \$(MT) \$(MTFLAGS) \$(MTINFLAG)$shlib$shlibext.manifest \$(MTOUTFLAG)$shlib$shlibext
R
Richard Levitte 已提交
546 547
	IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext
	IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext
M
Matt Caswell 已提交
548
	IF EXIST fuzz\\$shlib$shlibext DEL /Q /F fuzz\\$shlib$shlibext
549 550
	COPY $shlib$shlibext apps
	COPY $shlib$shlibext test
M
Matt Caswell 已提交
551
	COPY $shlib$shlibext fuzz
552 553 554 555 556
EOF
 }
 sub obj2dso {
     my %args = @_;
     my $dso = $args{lib};
557
     my $dso_n = basename($dso);
558 559 560 561 562
     my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
     my @deps = compute_lib_depends(@{$args{deps}});
     my $objs = join("\n", @objs);
     my $linklibs = join("", map { "$_\n" } @deps);
     my $deps = join(" ", @objs, @deps);
563 564
     return <<"EOF";
$dso$dsoext: $deps
565
	IF EXIST $dso$dsoext.manifest DEL /F /Q $dso$dsoext.manifest
566 567
	\$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
LIBRARY         $dso_n
568 569 570 571
EXPORTS
    bind_engine		@1
    v_check		@2
<<
572 573
$objs
$linklibs \$(EX_LIBS)
574
<<
575
	IF EXIST $dso$dsoext.manifest \\
576
	   \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso$dsoext.manifest \$(MTOUTFLAG)$dso$dsoext
577 578 579
EOF
 }
 sub obj2lib {
580 581 582
     my %args = @_;
     my $lib = $args{lib};

583 584 585
     # Because static libs and import libs are both named the same in native
     # Windows, we can't have both.  We skip the static lib in that case,
     # as the shared libs are what we use anyway.
586
     return "" unless $disabled{"shared"} || $lib =~ /\.a$/;
587

588
     $lib =~ s/\.a$//;
589 590 591
     my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
     my $objs = join("\n", @objs);
     my $deps = join(" ", @objs);
592 593 594
     return <<"EOF";
$lib$libext: $deps
	\$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
595
$objs
596 597 598 599 600 601
<<
EOF
 }
 sub obj2bin {
     my %args = @_;
     my $bin = $args{bin};
602 603 604 605 606
     my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
     my @deps = compute_lib_depends(@{$args{deps}});
     my $objs = join("\n", @objs);
     my $linklibs = join("", map { "$_\n" } @deps);
     my $deps = join(" ", @objs, @deps);
607 608
     return <<"EOF";
$bin$exeext: $deps
609
	IF EXIST $bin$exeext.manifest DEL /F /Q $bin$exeext.manifest
610
	\$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
611 612 613
$objs
setargv.obj
$linklibs\$(EX_LIBS)
614
<<
615
	IF EXIST $bin$exeext.manifest \\
616
	   \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin$exeext.manifest \$(MTOUTFLAG)$bin$exeext
617 618 619 620 621
EOF
  }
  sub in2script {
      my %args = @_;
      my $script = $args{script};
622
      my $sources = '"'.join('" "', @{$args{sources}}).'"';
623 624 625 626 627
      my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
                                           "util", "dofile.pl")),
                           rel2abs($config{builddir}));
      return <<"EOF";
$script: $sources
628
	"\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
629
	    "-o$target{build_file}" $sources > "$script"
630 631 632 633 634 635 636 637 638 639 640 641 642
EOF
  }
  sub generatedir {
      my %args = @_;
      my $dir = $args{dir};
      my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
      my @actions = ();
      my %extinfo = ( dso => $dsoext,
                      lib => $libext,
                      bin => $exeext );

      foreach my $type (("dso", "lib", "bin", "script")) {
          next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
643 644 645 646
          # For lib object files, we could update the library.  However,
          # LIB on Windows doesn't work that way, so we won't create any
          # actions for it, and the dependencies are already taken care of.
          if ($type ne "lib") {
647 648 649 650
              foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
                  if (dirname($prod) eq $dir) {
                      push @deps, $prod.$extinfo{$type};
                  } else {
651
                      push @actions, "\t@rem No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
652 653 654 655 656 657 658 659 660
                  }
              }
          }
      }

      my $deps = join(" ", @deps);
      my $actions = join("\n", "", @actions);
      return <<"EOF";
$args{dir} $args{dir}\\ : $deps$actions
661 662 663 664
EOF
  }
  ""    # Important!  This becomes part of the template result.
-}