2 ## Makefile for OpenSSL
4 ## {- join("\n## ", @autowarntext) -}
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";
15 $target{build_scheme}->[2] eq "VC-W32" ?
16 "ProgramFiles(x86)" : "ProgramW6432";
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';
24 defined($ENV{$win_commonenv})
25 ? $win_commonenv : 'CommonProgramFiles';
27 # expand variables early
28 $win_installroot = $ENV{$win_installroot};
29 $win_commonroot = $ENV{$win_commonroot};
32 return () if $disabled{shared};
34 return $unified_info{sharednames}->{$lib} . $shlibext;
38 return () if $disabled{shared};
40 return $lib . $shlibextimport;
46 return $dso . $dsoext;
51 PLATFORM={- $config{target} -}
52 SRCDIR={- $config{sourcedir} -}
53 BLDDIR={- $config{builddir} -}
55 VERSION={- $config{version} -}
56 MAJOR={- $config{major} -}
57 MINOR={- $config{minor} -}
59 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
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 {- output_off() if $disabled{apps}; "" -}
71 BIN_SCRIPTS=$(BLDDIR)\tools\c_rehash.pl
72 MISC_SCRIPTS=$(BLDDIR)\apps\CA.pl $(BLDDIR)\apps\tsget.pl
73 {- output_on() if $disabled{apps}; "" -}
75 {- output_off() if $disabled{makedepend}; "" -}
76 DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
77 grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
78 keys %{$unified_info{sources}}); -}
79 {- output_on() if $disabled{makedepend}; "" -}
80 GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
81 GENERATED={- join(" ",
82 ( map { (my $x = $_) =~ s|\.[sS]$|\.asm|; $x }
83 grep { defined $unified_info{generate}->{$_} }
84 map { @{$unified_info{sources}->{$_}} }
85 grep { /\.o$/ } keys %{$unified_info{sources}} ),
86 ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
88 # Do not edit these manually. Use Configure with --prefix or --openssldir
89 # to change this! Short explanation in the top comment in Configure
90 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
92 our $prefix = $config{prefix} || "$win_installroot\\OpenSSL";
95 # The logic here is that if no --openssldir was given,
96 # OPENSSLDIR will get the value from $prefix plus "/ssl".
97 # If --openssldir was given and the value is an absolute
98 # path, OPENSSLDIR will get its value without change.
99 # If the value from --openssldir is a relative path,
100 # OPENSSLDIR will get $prefix with the --openssldir
101 # value appended as a subdirectory.
103 use File::Spec::Functions;
105 $config{openssldir} ?
106 (file_name_is_absolute($config{openssldir}) ?
108 : catdir($prefix, $config{openssldir}))
109 : "$win_commonroot\\SSL";
111 LIBDIR={- our $libdir = $config{libdir} || "lib";
113 ENGINESDIR={- use File::Spec::Functions;
114 our $enginesdir = catdir($prefix,$libdir,"engines");
118 CFLAGS={- join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}})) -} {- join(" ", quotify_l("-DENGINESDIR=\"$enginesdir\"", "-DOPENSSLDIR=\"$openssldir\"")) -} {- $target{cflags} -} {- $config{cflags} -}
119 COUTFLAG={- $target{coutflag} || "/Fo" -}
120 RC={- $target{rc} || "rc" -}
121 RCOUTFLAG={- $target{rcoutflag} || "/fo" -}
122 LD={- $target{ld} || "link" -}
123 LDFLAGS={- $target{lflags} -}
124 LDOUTFLAG={- $target{loutflag} || "/out:" -}
125 EX_LIBS={- $target{ex_libs} -}
126 LIB_CFLAGS={- join(" ", $target{lib_cflags}, $target{shared_cflag}) || "" -}
127 LIB_LDFLAGS={- $target{shared_ldflag} || "" -}
128 DSO_CFLAGS={- join(" ", $target{dso_cflags}, $target{shared_cflag}) || "" -}
129 DSO_LDFLAGS={- join(" ", $target{dso_lflags}, $target{shared_ldflag}) || "" -}
130 BIN_CFLAGS={- $target{bin_cflags} -}
131 BIN_LDFLAGS={- $target{bin_lflags} -}
133 PERL={- $config{perl} -}
136 ARFLAGS= {- $target{arflags} -}
137 AROUTFLAG={- $target{aroutflag} || "/out:" -}
140 ASFLAGS={- $target{asflags} -}
141 ASOUTFLAG={- $target{asoutflag} -}
142 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
144 PROCESSOR= {- $config{processor} -}
146 # The main targets ###################################################
148 all: $(GENERATED_MANDATORY) \
149 build_libs_nodep build_engines_nodep build_apps_nodep depend
151 build_libs: $(GENERATED_MANDATORY) build_libs_nodep depend
152 build_libs_nodep: $(LIBS)
153 build_engines: $(GENERATED_MANDATORY) build_engines_nodep depend
154 build_engines_nodep: $(ENGINES)
155 build_apps: $(GENERATED_MANDATORY) build_apps_nodep depend
156 build_apps_nodep: $(PROGRAMS) $(SCRIPTS)
157 build_tests: $(GENERATED_MANDATORY) build_tests_nodep depend
158 build_tests_nodep: $(TESTPROGS)
161 tests: $(GENERATED_MANDATORY) \
162 build_tests_nodep build_apps_nodep build_engines_nodep depend
163 @rem {- output_off() if $disabled{tests}; "" -}
167 "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
168 @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
169 @echo "Tests are not supported with your chosen Configure options"
170 @rem {- output_on() if !$disabled{tests}; "" -}
175 @"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
177 install: install_sw install_ssldirs install_docs
179 uninstall: uninstall_docs uninstall_sw
182 "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
183 "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """apps/$$1.*"""; } @ARGV" $(SHLIBS)
184 "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """test/$$1.*"""; } @ARGV" $(SHLIBS)
186 -del /Q ossl_static.pdb
189 -del /Q /F $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
190 -del /Q /S /F $(GENERATED)
195 -del /Q /S /F engines\*.ilk
196 -del /Q /S /F engines\*.lib
197 -del /Q /S /F apps\*.lib
198 -del /Q /S /F engines\*.manifest
199 -del /Q /S /F apps\*.manifest
200 -del /Q /S /F test\*.manifest
203 -del /Q /F configdata.pm
208 # Install helper targets #############################################
210 install_sw: all install_dev install_engines install_runtime
212 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
215 "$(PERL)" "$(SRCDIR)\util\process_docs.pl" \
216 "--destdir=$(DESTDIR)$(INSTALLTOP)\html" --type=html
221 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(OPENSSLDIR)\certs"
222 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(OPENSSLDIR)\private"
223 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(OPENSSLDIR)\misc"
224 @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
225 "$(DESTDIR)$(OPENSSLDIR)"
226 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
227 "$(DESTDIR)$(OPENSSLDIR)\misc"
230 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
231 @echo *** Installing development files
232 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(INSTALLTOP)\include\openssl"
233 @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\include\openssl\*.h" \
234 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
235 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\include\openssl\*.h \
236 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
237 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
238 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(LIBS) \
239 "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
240 @if "$(SHLIBS)"=="" \
241 "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb \
242 "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
247 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
248 @echo *** Installing engines
249 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(ENGINESDIR)"
250 @if not "$(ENGINES)"=="" \
251 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(ENGINES) "$(DESTDIR)$(ENGINESDIR)"
252 @if not "$(ENGINES)"=="" \
253 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(ENGINEPDBS) "$(DESTDIR)$(ENGINESDIR)"
258 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
259 @echo *** Installing runtime files
260 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(INSTALLTOP)\bin"
261 @if not "$(SHLIBS)"=="" \
262 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(SHLIBS) "$(DESTDIR)$(INSTALLTOP)\bin"
263 @if not "$(SHLIBS)"=="" \
264 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(SHLIBPDBS) \
265 "$(DESTDIR)$(INSTALLTOP)\bin"
266 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(PROGRAMS) \
267 "$(DESTDIR)$(INSTALLTOP)\bin"
268 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(PROGRAMPDBS) \
269 "$(DESTDIR)$(INSTALLTOP)\bin"
270 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
271 "$(DESTDIR)$(INSTALLTOP)\bin"
275 # Building targets ###################################################
277 configdata.pm: "{- $config{build_file_template} -}" "$(SRCDIR)\Configure"
278 @echo "Detected changed: $?"
279 @echo "Reconfiguring..."
280 "$(PERL)" "$(SRCDIR)\Configure" reconf
281 @echo "**************************************************"
283 @echo "*** Please run the same make command again ***"
285 @echo "**************************************************"
290 use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
292 # Helper function to figure out dependencies on libraries
293 # It takes a list of library names and outputs a list of dependencies
294 sub compute_lib_depends {
295 if ($disabled{shared}) {
296 return map { $_.$libext } @_;
298 return map { shlib_import($_) } @_;
303 (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
304 my $generator = '"'.join('" "', @{$args{generator}}).'"';
305 my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
306 my $incs = join("", map { " /I \"$_\"" } @{$args{incs}});
307 my $deps = @{$args{deps}} ?
308 '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
310 if ($target !~ /\.asm$/) {
311 if ($args{generator}->[0] =~ m|^.*\.in$|) {
312 my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
313 "util", "dofile.pl")),
314 rel2abs($config{builddir}));
316 $target: "$args{generator}->[0]" $deps
317 "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
318 "-o$target{build_file}" $generator > \$@
322 $target: "$args{generator}->[0]" $deps
323 "\$(PERL)"$generator_incs $generator > \$@
327 if ($args{generator}->[0] =~ /\.pl$/) {
328 $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
329 } elsif ($args{generator}->[0] =~ /\.S$/) {
332 die "Generator type for $src unknown: $generator\n";
335 if (defined($generator)) {
336 # If the target is named foo.S in build.info, we want to
337 # end up generating foo.s in two steps.
338 if ($args{src} =~ /\.S$/) {
340 $target: "$args{generator}->[0]" $deps
343 \$(CC) \$(CFLAGS) $incs /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
349 $target: "$args{generator}->[0]" $deps
355 $target: "$args{generator}->[0]" $deps
356 \$(CC) \$(CFLAGS) $incs /EP /C "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
363 my $obj = $args{obj};
364 my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
365 } ( @{$args{srcs}} );
366 my $srcs = '"'.join('" "', @srcs).'"';
367 my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
368 my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
369 unless ($disabled{zlib}) {
370 if ($withargs{zlib_include}) {
371 $incs .= ' /I "'.$withargs{zlib_include}.'"';
374 my $ecflags = { lib => '$(LIB_CFLAGS)',
375 dso => '$(DSO_CFLAGS)',
376 bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
377 my $makedepprog = $config{makedepprog};
378 if ($srcs[0] =~ /\.asm$/) {
381 \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
384 return <<"EOF" if (!$disabled{makedepend});
386 \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
387 "\$(PERL)" -n << > $obj$depext
389 s/^Note: including file: *//;
390 \$\$collect{\$\$_} = 1;
391 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
393 $obj$objext: $obj$depext
394 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ @<<
398 return <<"EOF" if ($disabled{makedepend});
400 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ $srcs
404 # On Unix, we build shlibs from static libs, so we're ignoring the
405 # object file array. We *know* this routine is only called when we've
406 # configure 'shared'.
409 my $lib = $args{lib};
410 my $shlib = $args{shlib};
411 (my $mkdef_key = $lib) =~ s/^lib//i;
412 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
413 my $linklibs = join("",
414 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
416 (map { $_.$objext } @{$args{objs}}),
417 compute_lib_depends(@{$args{deps}}));
418 my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
419 my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
420 "util", "mkdef.pl")),
421 rel2abs($config{builddir}));
422 my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
424 rel2abs($config{builddir}));
425 my $target = shlib_import($lib);
427 $target: $deps "$ordinalsfile" "$mkdef_pl"
428 "\$(PERL)" "$mkdef_pl" "$mkdef_key" 32 > $shlib.def
429 "\$(PERL)" -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
431 "\$(PERL)" "$mkrc_pl" $shlib$shlibext > $shlib.rc
432 \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
433 \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
434 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
435 $objs $shlib.res$linklibs \$(EX_LIBS)
437 IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext
438 IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext
439 COPY $shlib$shlibext apps
440 COPY $shlib$shlibext test
445 my $dso = $args{lib};
446 my $dso_n = basename($dso);
447 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
448 my $linklibs = join("",
449 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
451 (map { $_.$objext } @{$args{objs}}),
452 compute_lib_depends(@{$args{deps}}));
455 \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
461 $objs$linklibs \$(EX_LIBS)
466 # Because static libs and import libs are both named the same in native
467 # Windows, we can't have both. We skip the static lib in that case,
468 # as the shared libs are what we use anyway.
469 return "" unless $disabled{"shared"};
472 my $lib = $args{lib};
473 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
474 my $deps = join(" ", map { $_.$objext } @{$args{objs}});
477 \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
484 my $bin = $args{bin};
485 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
486 my $linklibs = join("",
487 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
489 (map { $_.$objext } @{$args{objs}}),
490 compute_lib_depends(@{$args{deps}}));
493 \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
494 $objs setargv.obj$linklibs \$(EX_LIBS)
500 my $script = $args{script};
501 my $sources = '"'.join('" "', @{$args{sources}}).'"';
502 my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
503 "util", "dofile.pl")),
504 rel2abs($config{builddir}));
507 "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
508 "-o$target{build_file}" $sources > "$script"
513 my $dir = $args{dir};
514 my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
516 my %extinfo = ( dso => $dsoext,
520 foreach my $type (("dso", "lib", "bin", "script")) {
521 next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
522 if ($type eq "lib") {
523 foreach my $lib (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
524 push @actions, <<"EOF";
525 \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
531 foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
532 if (dirname($prod) eq $dir) {
533 push @deps, $prod.$extinfo{$type};
535 push @actions, "\t@ : No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
541 my $deps = join(" ", @deps);
542 my $actions = join("\n", "", @actions);
544 $args{dir} $args{dir}\\ : $deps$actions
547 "" # Important! This becomes part of the template result.