windows-makefile.tmpl 24.7 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 62 63
 # This makes sure things get built in the order they need
 # to. You're welcome.
 sub dependmagic {
     my $target = shift;

     return "$target: build_generated\n\t\$(MAKE) depend && \$(MAKE) _$target\n_$target";
 }
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} -}
163
CPPFLAGS={- our $cppflags = join(" ",
164 165 166
                                 (map { "-D".$_} @{$config{defines}}),
                                 (map { " /I ".$_} @{$config{includes}}),
                                 @{$config{cppflags}}) -}
167
CPPFLAGS_Q={- $cppflags =~ s|([\\"])|\\$1|g; $cppflags -}
168
CFLAGS={- join(' ', @{$config{cflags}}) -}
169
COUTFLAG={- $target{coutflag} || "/Fo" -}$(OSSL_EMPTY)
170
RC={- $config{rc} -}
171
RCOUTFLAG={- $target{rcoutflag} || "/fo" -}$(OSSL_EMPTY)
172 173
LD={- $config{ld} -}
LDFLAGS={- join(' ', @{$config{lflags}}) -}
174
LDOUTFLAG={- $target{loutflag} || "/out:" -}$(OSSL_EMPTY)
175
EX_LIBS={- join(' ', @{$config{ex_libs}}) -}
176 177
LIB_CPPFLAGS={- join(" ",
                     $target{shared_cppflag} || "",
178
                     (map { quotify_l("-D".$_) }
179 180
                      "OPENSSLDIR=\"$openssldir\"",
                      "ENGINESDIR=\"$enginesdir\"")) -}
181 182
LIB_CFLAGS={- join(" ", $target{lib_cflags}, $target{shared_cflag}) -}
LIB_LDFLAGS={- join(' ', $target{shared_ldflag}, $config{shared_ldflag}) -}
183
DSO_CPPFLAGS={- $target{dso_cppflags} || "" -}
184 185
DSO_CFLAGS={- $target{dso_cflags} || "" -}
DSO_LDFLAGS={- $target{dso_ldflag} || "" -}
186
BIN_CPPFLAGS={- $target{dso_cppflags} || "" -}
187
BIN_CFLAGS={- $target{bin_cflags} -}
188
BIN_LDFLAGS={- $target{bin_lflags} -}
189 190 191

PERL={- $config{perl} -}

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

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

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

PROCESSOR= {- $config{processor} -}

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

210 211 212 213
{- 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
214

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

220 221 222
# Kept around for backward compatibility
build_apps build_tests: build_programs

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

227
test: tests
228
{- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep
M
Matt Caswell 已提交
229
	@rem {- output_off() if $disabled{tests}; "" -}
230
	-mkdir $(BLDDIR)\test\test-runs
231 232
	set SRCTOP=$(SRCDIR)
	set BLDTOP=$(BLDDIR)
233
	set RESULT_D=$(BLDDIR)\test\test-runs
234
	set PERL=$(PERL)
B
Bernd Edlinger 已提交
235
	set OPENSSL_ENGINES=$(MAKEDIR)\engines
236
	set OPENSSL_DEBUG_MEMORY=on
237
	"$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
M
Matt Caswell 已提交
238 239 240
	@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}; "" -}
241 242

list-tests:
243 244
	@rem {- output_off() if $disabled{tests}; "" -}
	@set SRCTOP=$(SRCDIR)
245
	@"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
246 247 248
	@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}; "" -}
249

250 251 252 253
install: install_sw install_ssldirs install_docs

uninstall: uninstall_docs uninstall_sw

254
libclean:
255 256 257
	"$(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 已提交
258
	"$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """fuzz/$$1.*"""; } @ARGV" $(SHLIBS)
259
	-del /Q /F $(LIBS)
R
Richard Levitte 已提交
260
	-del /Q ossl_static.pdb
261 262

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

280 281 282 283
distclean: clean
	-del /Q /F configdata.pm
	-del /Q /F makefile

284 285
depend:

286 287 288 289 290 291
# Install helper targets #############################################

install_sw: all install_dev install_engines install_runtime

uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev

292
install_docs: install_html_docs
293

294
uninstall_docs: uninstall_html_docs
295 296

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

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

uninstall_dev:

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

uninstall_engines:

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

uninstall_runtime:

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

uninstall_html_docs:

369 370
# Building targets ###################################################

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

381 382 383
reconfigure reconf:
	"$(PERL)" configdata.pm -r -v

384 385 386 387 388 389 390 391
{-
 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}) {
392
	 return map { lib($_) } @_;
393
     }
394 395 396 397 398 399
     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($_) } @_;
400 401
 }

402 403 404
  sub generatesrc {
      my %args = @_;
      (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
405 406 407 408 409
      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}}).'"' : '';
410 411

      if ($target !~ /\.asm$/) {
412 413 414 415 416 417 418 419 420 421 422
          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";
423 424
$target: "$args{generator}->[0]" $deps
	"\$(PERL)"$generator_incs $generator > \$@
425
EOF
426
	  }
427 428
      } else {
          if ($args{generator}->[0] =~ /\.pl$/) {
429
              $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
430 431 432 433 434 435 436 437 438 439 440
          } elsif ($args{generator}->[0] =~ /\.S$/) {
              $generator = undef;
          } else {
              die "Generator type for $src unknown: $generator\n";
          }

          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";
441
$target: "$args{generator}->[0]" $deps
442 443
	set ASM=\$(AS)
	$generator \$@.S
444
	\$(CC) $incs \$(CFLAGS) \$(CPPFLAGS) /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
445 446 447 448 449
        del /Q \$@.S
EOF
              }
              # Otherwise....
              return <<"EOF";
450
$target: "$args{generator}->[0]" $deps
451 452 453 454 455
	set ASM=\$(AS)
	$generator \$@
EOF
          }
          return <<"EOF";
456
$target: "$args{generator}->[0]" $deps
457
	\$(CC) $incs \$(CFLAGS) \$(CPPFLAGS) /EP /C "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
458 459 460 461
EOF
      }
  }

462 463
 sub src2obj {
     my %args = @_;
A
Andy Polyakov 已提交
464 465
     my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
                    } ( @{$args{srcs}} );
466 467 468
     my $srcs = '"'.join('" "',  @srcs).'"';
     my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
     my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
469 470
     unless ($disabled{zlib}) {
         if ($withargs{zlib_include}) {
471
             $incs .= ' /I "'.$withargs{zlib_include}.'"';
472 473
         }
     }
474 475 476 477 478 479 480 481 482
     my $cflags = '$(CFLAGS)';
     $cflags .= { lib => ' $(LIB_CFLAGS)',
		  dso => ' $(DSO_CFLAGS)',
		  bin => ' $(BIN_CFLAGS)' } -> {$args{intent}};
     $cflags .= $incs;
     $cflags .= ' $(CPPFLAGS)';
     $cflags .= { lib => ' $(LIB_CPPFLAGS)',
		  dso => ' $(DSO_CPPFLAGS)',
		  bin => ' $(BIN_CPPFLAGS)' } -> {$args{intent}};
483
     my $makedepprog = $config{makedepprog};
484 485 486 487 488 489 490
     if ($srcs[0] =~ /\.rc$/) {
         return <<"EOF";
$args{obj}: $deps
	\$(RC) \$(RCOUTFLAG)\$\@ $srcs
EOF
     }
     (my $obj = $args{obj}) =~ s|\.o$||;
491 492 493 494 495 496
     if ($srcs[0] =~ /\.asm$/) {
         return <<"EOF";
$obj$objext: $deps
	\$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
EOF
     }
497
     return <<"EOF"	if (!$disabled{makedepend});
498
$obj$depext: $deps
499
	\$(CC) $cflags /Zs /showIncludes $srcs 2>&1 | \\
500
	    "\$(PERL)" -n << > $obj$depext
501 502 503 504
chomp;
s/^Note: including file: *//;
\$\$collect{\$\$_} = 1;
END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
505
<<
506
$obj$objext: $obj$depext
507
	\$(CC) $cflags -c \$(COUTFLAG)\$\@ @<<
508
$srcs
509
<<
510 511 512
EOF
    return <<"EOF"	if ($disabled{makedepend});
$obj$objext: $deps
513
	\$(CC) $cflags -c \$(COUTFLAG)\$\@ $srcs
514 515 516 517 518 519 520 521 522 523
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};
524
     my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x }
525
                grep { $_ =~ m/\.(?:o|res)$/ }
526 527 528 529 530 531 532
                @{$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);
533
     my $target = shlib_import($lib);
534
     my $shared_def = join("", map { " /def:$_" } @defs);
535
     return <<"EOF"
536
$target: $deps
537
	IF EXIST $shlib$shlibext.manifest DEL /F /Q $shlib$shlibext.manifest
538
	\$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
539 540 541
		/implib:\$@ \$(LDOUTFLAG)$shlib$shlibext$shared_def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
$objs
$linklibs\$(EX_LIBS)
542
<<
543
	IF EXIST $shlib$shlibext.manifest \\
544
	   \$(MT) \$(MTFLAGS) \$(MTINFLAG)$shlib$shlibext.manifest \$(MTOUTFLAG)$shlib$shlibext
R
Richard Levitte 已提交
545 546
	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 已提交
547
	IF EXIST fuzz\\$shlib$shlibext DEL /Q /F fuzz\\$shlib$shlibext
548 549
	COPY $shlib$shlibext apps
	COPY $shlib$shlibext test
M
Matt Caswell 已提交
550
	COPY $shlib$shlibext fuzz
551 552 553 554 555
EOF
 }
 sub obj2dso {
     my %args = @_;
     my $dso = $args{lib};
556
     my $dso_n = basename($dso);
557 558 559 560 561
     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);
562 563
     return <<"EOF";
$dso$dsoext: $deps
564
	IF EXIST $dso$dsoext.manifest DEL /F /Q $dso$dsoext.manifest
565 566
	\$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
LIBRARY         $dso_n
567 568 569 570
EXPORTS
    bind_engine		@1
    v_check		@2
<<
571 572
$objs
$linklibs \$(EX_LIBS)
573
<<
574
	IF EXIST $dso$dsoext.manifest \\
575
	   \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso$dsoext.manifest \$(MTOUTFLAG)$dso$dsoext
576 577 578
EOF
 }
 sub obj2lib {
579 580 581
     my %args = @_;
     my $lib = $args{lib};

582 583 584
     # 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.
585
     return "" unless $disabled{"shared"} || $lib =~ /\.a$/;
586

587
     $lib =~ s/\.a$//;
588 589 590
     my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
     my $objs = join("\n", @objs);
     my $deps = join(" ", @objs);
591 592 593
     return <<"EOF";
$lib$libext: $deps
	\$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
594
$objs
595 596 597 598 599 600
<<
EOF
 }
 sub obj2bin {
     my %args = @_;
     my $bin = $args{bin};
601 602 603 604 605
     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);
606 607
     return <<"EOF";
$bin$exeext: $deps
608
	IF EXIST $bin$exeext.manifest DEL /F /Q $bin$exeext.manifest
609
	\$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
610 611 612
$objs
setargv.obj
$linklibs\$(EX_LIBS)
613
<<
614
	IF EXIST $bin$exeext.manifest \\
615
	   \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin$exeext.manifest \$(MTOUTFLAG)$bin$exeext
616 617 618 619 620
EOF
  }
  sub in2script {
      my %args = @_;
      my $script = $args{script};
621
      my $sources = '"'.join('" "', @{$args{sources}}).'"';
622 623 624 625 626
      my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
                                           "util", "dofile.pl")),
                           rel2abs($config{builddir}));
      return <<"EOF";
$script: $sources
627
	"\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
628
	    "-o$target{build_file}" $sources > "$script"
629 630 631 632 633 634 635 636 637 638 639 640 641
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});
642 643 644 645
          # 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") {
646 647 648 649
              foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
                  if (dirname($prod) eq $dir) {
                      push @deps, $prod.$extinfo{$type};
                  } else {
650
                      push @actions, "\t@rem No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
651 652 653 654 655 656 657 658 659
                  }
              }
          }
      }

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