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