]> git.ipfire.org Git - thirdparty/openssl.git/blob - Configurations/windows-makefile.tmpl
ecb0d4cfffcc275eb9fc536ca4566ec35d84b3fa
[thirdparty/openssl.git] / Configurations / windows-makefile.tmpl
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 my $win_installenv =
15 $target{build_scheme}->[2] eq "VC-W32" ?
16 "ProgramFiles(x86)" : "ProgramW6432";
17 my $win_commonenv =
18 $target{build_scheme}->[2] eq "VC-W32"
19 ? "CommonProgramFiles(x86)" : "CommonProgramW6432";
20 our $win_installroot =
21 defined($ENV{$win_installenv})
22 ? $win_installenv : 'ProgramFiles';
23 our $win_commonroot =
24 defined($ENV{$win_commonenv})
25 ? $win_commonenv : 'CommonProgramFiles';
26
27 # expand variables early
28 $win_installroot = $ENV{$win_installroot};
29 $win_commonroot = $ENV{$win_commonroot};
30
31 sub shlib {
32 return () if $disabled{shared};
33 my $lib = shift;
34 return $unified_info{sharednames}->{$lib} . $shlibext;
35 }
36
37 sub shlib_import {
38 return () if $disabled{shared};
39 my $lib = shift;
40 return $lib . $shlibextimport;
41 }
42
43 sub dso {
44 my $dso = shift;
45
46 return $dso . $dsoext;
47 }
48 '';
49 -}
50
51 PLATFORM={- $config{target} -}
52 SRCDIR={- $config{sourcedir} -}
53 BLDDIR={- $config{builddir} -}
54
55 VERSION={- $config{version} -}
56 MAJOR={- $config{major} -}
57 MINOR={- $config{minor} -}
58
59 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
60
61 LIBS={- join(" ", map { $_.$libext } @{$unified_info{libraries}}) -}
62 SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
63 SHLIBPDBS={- join(" ", map { local $shlibext = ".pdb"; shlib($_) } @{$unified_info{libraries}}) -}
64 ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
65 ENGINEPDBS={- join(" ", map { local $dsoext = ".pdb"; dso($_) } @{$unified_info{engines}}) -}
66 PROGRAMS={- join(" ", map { $_.$exeext } grep { !m|^test\\| } @{$unified_info{programs}}) -}
67 PROGRAMPDBS={- join(" ", map { $_.".pdb" } grep { !m|^test\\| } @{$unified_info{programs}}) -}
68 TESTPROGS={- join(" ", map { $_.$exeext } grep { m|^test\\| } @{$unified_info{programs}}) -}
69 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
70
71 {- output_off() if $disabled{makedepend}; "" -}
72 DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
73 grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
74 keys %{$unified_info{sources}}); -}
75 {- output_on() if $disabled{makedepend}; "" -}
76
77 # Do not edit these manually. Use Configure with --prefix or --openssldir
78 # to change this! Short explanation in the top comment in Configure
79 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
80 #
81 our $prefix = $config{prefix} || "$win_installroot\\OpenSSL";
82 $prefix -}
83 OPENSSLDIR={- #
84 # The logic here is that if no --openssldir was given,
85 # OPENSSLDIR will get the value from $prefix plus "/ssl".
86 # If --openssldir was given and the value is an absolute
87 # path, OPENSSLDIR will get its value without change.
88 # If the value from --openssldir is a relative path,
89 # OPENSSLDIR will get $prefix with the --openssldir
90 # value appended as a subdirectory.
91 #
92 use File::Spec::Functions;
93 our $openssldir =
94 $config{openssldir} ?
95 (file_name_is_absolute($config{openssldir}) ?
96 $config{openssldir}
97 : catdir($prefix, $config{openssldir}))
98 : "$win_commonroot\\SSL";
99 $openssldir -}
100 LIBDIR={- our $libdir = $config{libdir} || "lib";
101 $libdir -}
102 ENGINESDIR={- use File::Spec::Functions;
103 our $enginesdir = catdir($prefix,$libdir,"engines");
104 $enginesdir -}
105
106 CC={- $target{cc} -}
107 CFLAGS={- join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}})) -} {- join(" ", quotify_l("-DENGINESDIR=\"$enginesdir\"", "-DOPENSSLDIR=\"$openssldir\"")) -} {- $target{cflags} -} {- $config{cflags} -}
108 COUTFLAG={- $target{coutflag} || "/Fo" -}
109 RC={- $target{rc} || "rc" -}
110 RCOUTFLAG={- $target{rcoutflag} || "/fo" -}
111 LD={- $target{ld} || "link" -}
112 LDFLAGS={- $target{lflags} -}
113 LDOUTFLAG={- $target{loutflag} || "/out:" -}
114 EX_LIBS={- $target{ex_libs} -}
115 LIB_CFLAGS={- join(" ", $target{lib_cflags}, $target{shared_cflag}) || "" -}
116 LIB_LDFLAGS={- $target{shared_ldflag} || "" -}
117 DSO_CFLAGS={- join(" ", $target{dso_cflags}, $target{shared_cflag}) || "" -}
118 DSO_LDFLAGS={- join(" ", $target{dso_lflags}, $target{shared_ldflag}) || "" -}
119 BIN_CFLAGS={- $target{bin_cflags} -}
120 BIN_LDFLAGS={- $target{bin_lflags} -}
121
122 PERL={- $config{perl} -}
123
124 AR={- $target{ar} -}
125 ARFLAGS= {- $target{arflags} -}
126 AROUTFLAG={- $target{aroutflag} || "/out:" -}
127
128 AS={- $target{as} -}
129 ASFLAGS={- $target{asflags} -}
130 ASOUTFLAG={- $target{asoutflag} -}
131 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
132
133 PROCESSOR= {- $config{processor} -}
134
135 # The main targets ###################################################
136
137 all: configdata.pm build_libs_nodep build_engines_nodep build_apps_nodep depend
138
139 build_libs: configdata.pm build_libs_nodep depend
140 build_libs_nodep: $(LIBS)
141 build_engines: configdata.pm build_engines_nodep depend
142 build_engines_nodep: $(ENGINES)
143 build_apps: configdata.pm build_apps_nodep depend
144 build_apps_nodep: $(PROGRAMS) $(SCRIPTS)
145 build_tests: configdata.pm build_tests_nodep depend
146 build_tests_nodep: $(TESTPROGS)
147
148 test: tests
149 tests: build_tests_nodep build_apps_nodep build_engines_nodep depend
150 @rem {- output_off() if $disabled{tests}; "" -}
151 set SRCTOP=$(SRCDIR)
152 set BLDTOP=$(BLDDIR)
153 set PERL=$(PERL)
154 $(PERL) $(SRCDIR)\test\run_tests.pl $(TESTS)
155 @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
156 @echo "Tests are not supported with your chosen Configure options"
157 @rem {- output_on() if !$disabled{tests}; "" -}
158
159 list-tests:
160 @set TOP=$(SRCDIR)
161 @set PERL=$(PERL)
162 @$(PERL) $(SRCDIR)\test\run_tests.pl list
163
164 install: install_sw install_ssldirs install_docs
165
166 uninstall: uninstall_docs uninstall_sw
167
168 libclean:
169 $(PERL) -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
170 -del /Q /F $(LIBS)
171 -del /Q ossl_static.pdb
172
173 clean: libclean
174 -del /Q /F $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
175 -del /Q /S /F *.asm
176 -del /Q /S /F *.d
177 -del /Q /S /F *.obj
178 -del /Q /S /F *.pdb
179 -del /Q /S /F *.exp
180 -del /Q /S /F engines\*.ilk
181 -del /Q /S /F engines\*.lib
182
183 depend:
184
185 # Install helper targets #############################################
186
187 install_sw: all install_dev install_engines install_runtime
188
189 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
190
191 install_docs:
192 $(PERL) $(SRCDIR)\util\process_docs.pl \
193 "--destdir=$(DESTDIR)$(INSTALLTOP)\html" --type=html
194
195 uninstall_docs:
196
197 install_ssldirs:
198 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\certs"
199 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\private"
200 @$(PERL) $(SRCDIR)\util\copy.pl $(SRCDIR)\apps\openssl.cnf \
201 "$(DESTDIR)$(OPENSSLDIR)"
202
203 install_dev:
204 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
205 @echo *** Installing development files
206 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\include\openssl"
207 @$(PERL) $(SRCDIR)\util\copy.pl $(SRCDIR)\include\openssl\*.h \
208 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
209 @$(PERL) $(SRCDIR)\util\copy.pl $(BLDDIR)\include\openssl\*.h \
210 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
211 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
212 @$(PERL) $(SRCDIR)\util\copy.pl $(LIBS) \
213 "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
214 @if "$(SHLIBS)"=="" \
215 $(PERL) $(SRCDIR)\util\copy.pl ossl_static.pdb \
216 "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
217
218 uninstall_dev:
219
220 install_engines:
221 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
222 @echo *** Installing engines
223 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(ENGINESDIR)"
224 @if not "$(ENGINES)"=="" \
225 $(PERL) $(SRCDIR)\util\copy.pl $(ENGINES) "$(DESTDIR)$(ENGINESDIR)"
226 @if not "$(ENGINES)"=="" \
227 $(PERL) $(SRCDIR)\util\copy.pl $(ENGINEPDBS) "$(DESTDIR)$(ENGINESDIR)"
228
229 uninstall_engines:
230
231 install_runtime:
232 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
233 @echo *** Installing runtime files
234 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\bin"
235 @if not "$(SHLIBS)"=="" \
236 $(PERL) $(SRCDIR)\util\copy.pl $(SHLIBS) "$(DESTDIR)$(INSTALLTOP)\bin"
237 @if not "$(SHLIBS)"=="" \
238 $(PERL) $(SRCDIR)\util\copy.pl $(SHLIBPDBS) \
239 "$(DESTDIR)$(INSTALLTOP)\bin"
240 @$(PERL) $(SRCDIR)\util\copy.pl $(PROGRAMS) \
241 "$(DESTDIR)$(INSTALLTOP)\bin"
242 @$(PERL) $(SRCDIR)\util\copy.pl $(PROGRAMPDBS) \
243 "$(DESTDIR)$(INSTALLTOP)\bin"
244 @$(PERL) $(SRCDIR)\util\copy.pl $(SCRIPTS) \
245 "$(DESTDIR)$(INSTALLTOP)\bin"
246 @$(PERL) $(SRCDIR)\util\copy.pl tools\c_rehash.pl \
247 "$(DESTDIR)$(INSTALLTOP)\bin"
248
249 uninstall_runtime:
250
251 # Building targets ###################################################
252
253 configdata.pm: {- $config{build_file_template} -} $(SRCDIR)\Configure
254 @echo "Detected changed: $?"
255 @echo "Reconfiguring..."
256 $(PERL) $(SRCDIR)\Configure reconf
257 @echo "**************************************************"
258 @echo "*** ***"
259 @echo "*** Please run the same make command again ***"
260 @echo "*** ***"
261 @echo "**************************************************"
262 @exit 1
263
264 {-
265 use File::Basename;
266 use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
267
268 # Helper function to figure out dependencies on libraries
269 # It takes a list of library names and outputs a list of dependencies
270 sub compute_lib_depends {
271 if ($disabled{shared}) {
272 return map { $_.$libext } @_;
273 }
274 return map { shlib_import($_) } @_;
275 }
276
277 sub generatesrc {
278 my %args = @_;
279 (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
280 my $generator = join(" ", @{$args{generator}});
281 my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
282 my $incs = join("", map { " /I ".$_ } @{$args{incs}});
283 my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
284
285 if ($target !~ /\.asm$/) {
286 return <<"EOF";
287 $target: $args{generator}->[0] $deps
288 \$(PERL)$generator_incs $generator > \$@
289 EOF
290 } else {
291 if ($args{generator}->[0] =~ /\.pl$/) {
292 $generator = '$(PERL)'.$generator_incs.' '.$generator;
293 } elsif ($args{generator}->[0] =~ /\.S$/) {
294 $generator = undef;
295 } else {
296 die "Generator type for $src unknown: $generator\n";
297 }
298
299 if (defined($generator)) {
300 # If the target is named foo.S in build.info, we want to
301 # end up generating foo.s in two steps.
302 if ($args{src} =~ /\.S$/) {
303 return <<"EOF";
304 $target: $args{generator}->[0] $deps
305 set ASM=\$(AS)
306 $generator \$@.S
307 \$(CC) \$(CFLAGS) $incs /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
308 del /Q \$@.S
309 EOF
310 }
311 # Otherwise....
312 return <<"EOF";
313 $target: $args{generator}->[0] $deps
314 set ASM=\$(AS)
315 $generator \$@
316 EOF
317 }
318 return <<"EOF";
319 $target: $args{generator}->[0] $deps
320 \$(CC) \$(CFLAGS) $incs /EP /C $args{generator}->[0] > \$@.i && move /Y \$@.i \$@
321 EOF
322 }
323 }
324
325 sub src2obj {
326 my %args = @_;
327 my $obj = $args{obj};
328 my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
329 } ( @{$args{srcs}} );
330 my $srcs = join(" ", @srcs);
331 my $deps = join(" ", @srcs, @{$args{deps}});
332 my $incs = join("", map { " /I ".$_ } @{$args{incs}});
333 unless ($disabled{zlib}) {
334 if ($withargs{zlib_include}) {
335 $incs .= " /I ".$withargs{zlib_include};
336 }
337 }
338 my $ecflags = { lib => '$(LIB_CFLAGS)',
339 dso => '$(DSO_CFLAGS)',
340 bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
341 my $makedepprog = $config{makedepprog};
342 if ($srcs[0] =~ /\.asm$/) {
343 return <<"EOF";
344 $obj$objext: $deps
345 \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
346 EOF
347 }
348 return <<"EOF" if (!$disabled{makedepend});
349 $obj$depext: $deps
350 \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
351 \$(PERL) -n << > $obj$depext
352 chomp;
353 s/^Note: including file: *//;
354 \$\$collect{\$\$_} = 1;
355 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
356 <<
357 $obj$objext: $obj$depext
358 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ @<<
359 $srcs
360 <<
361 EOF
362 return <<"EOF" if ($disabled{makedepend});
363 $obj$objext: $deps
364 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ $srcs
365 EOF
366 }
367
368 # On Unix, we build shlibs from static libs, so we're ignoring the
369 # object file array. We *know* this routine is only called when we've
370 # configure 'shared'.
371 sub libobj2shlib {
372 my %args = @_;
373 my $lib = $args{lib};
374 my $shlib = $args{shlib};
375 (my $mkdef_key = $lib) =~ s/^lib//i;
376 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
377 my $linklibs = join("",
378 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
379 my $deps = join(" ",
380 (map { $_.$objext } @{$args{objs}}),
381 compute_lib_depends(@{$args{deps}}));
382 my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
383 my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
384 "util", "mkdef.pl")),
385 rel2abs($config{builddir}));
386 my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
387 "util", "mkrc.pl")),
388 rel2abs($config{builddir}));
389 my $target = shlib_import($lib);
390 return <<"EOF"
391 $target: $deps $ordinalsfile $mkdef_pl
392 \$(PERL) $mkdef_pl "$mkdef_key" 32 > $shlib.def
393 \$(PERL) -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
394 DEL $shlib.def.tmp
395 \$(PERL) $mkrc_pl $shlib$shlibext > $shlib.rc
396 \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
397 \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
398 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
399 $objs $shlib.res$linklibs \$(EX_LIBS)
400 <<
401 IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext
402 IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext
403 COPY $shlib$shlibext apps
404 COPY $shlib$shlibext test
405 EOF
406 }
407 sub obj2dso {
408 my %args = @_;
409 my $dso = $args{lib};
410 my $dso_n = basename($dso);
411 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
412 my $linklibs = join("",
413 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
414 my $deps = join(" ",
415 (map { $_.$objext } @{$args{objs}}),
416 compute_lib_depends(@{$args{deps}}));
417 return <<"EOF";
418 $dso$dsoext: $deps
419 \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
420 LIBRARY $dso_n
421 EXPORTS
422 bind_engine @1
423 v_check @2
424 <<
425 $objs$linklibs \$(EX_LIBS)
426 <<
427 EOF
428 }
429 sub obj2lib {
430 # Because static libs and import libs are both named the same in native
431 # Windows, we can't have both. We skip the static lib in that case,
432 # as the shared libs are what we use anyway.
433 return "" unless $disabled{"shared"};
434
435 my %args = @_;
436 my $lib = $args{lib};
437 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
438 my $deps = join(" ", map { $_.$objext } @{$args{objs}});
439 return <<"EOF";
440 $lib$libext: $deps
441 \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
442 \$\?
443 <<
444 EOF
445 }
446 sub obj2bin {
447 my %args = @_;
448 my $bin = $args{bin};
449 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
450 my $linklibs = join("",
451 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
452 my $deps = join(" ",
453 (map { $_.$objext } @{$args{objs}}),
454 compute_lib_depends(@{$args{deps}}));
455 return <<"EOF";
456 $bin$exeext: $deps
457 \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
458 $objs setargv.obj$linklibs \$(EX_LIBS)
459 <<
460 EOF
461 }
462 sub in2script {
463 my %args = @_;
464 my $script = $args{script};
465 my $sources = join(" ", @{$args{sources}});
466 my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
467 "util", "dofile.pl")),
468 rel2abs($config{builddir}));
469 return <<"EOF";
470 $script: $sources
471 \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
472 "-o$target{build_file}" $sources > "$script"
473 EOF
474 }
475 "" # Important! This becomes part of the template result.
476 -}