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