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_dev={- # $prefix is used in the OPENSSLDIR perl snippet
92 use File::Spec::Functions qw(:DEFAULT splitpath);
93 our ($prefix_dev, $prefix_dir, $prefix_file) =
94 splitpath($config{prefix} || "$win_installroot\\OpenSSL",
97 INSTALLTOP_dir={- $prefix_dir -}
99 # The logic here is that if no --openssldir was given,
100 # OPENSSLDIR will get the value from $prefix plus "/ssl".
101 # If --openssldir was given and the value is an absolute
102 # path, OPENSSLDIR will get its value without change.
103 # If the value from --openssldir is a relative path,
104 # OPENSSLDIR will get $prefix with the --openssldir
105 # value appended as a subdirectory.
107 use File::Spec::Functions qw(:DEFAULT splitpath);
109 $config{openssldir} ?
110 (file_name_is_absolute($config{openssldir}) ?
112 : catdir($prefix, $config{openssldir}))
113 : "$win_commonroot\\SSL";
114 our ($openssldir_dev, $openssldir_dir, $openssldir_file) =
115 splitpath($openssldir, 1);
117 OPENSSLDIR_dir={- $openssldir_dir -}
118 LIBDIR={- our $libdir = $config{libdir} || "lib";
120 ENGINESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath);
121 my $enginesdir = catdir($prefix,$libdir,"engines");
122 our ($enginesdir_dev, $enginesdir_dir, $enginesdir_file) =
123 splitpath($enginesdir, 1);
125 ENGINESDIR_dir={- $enginesdir_dir -}
126 !IF "$(DESTDIR)" != ""
127 INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir)
128 OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir)
129 ENGINESDIR=$(DESTDIR)$(ENGINESDIR_dir)
131 INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
132 OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
133 ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
137 CFLAGS={- join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}})) -} {- join(" ", quotify_l("-DENGINESDIR=\"$enginesdir\"", "-DOPENSSLDIR=\"$openssldir\"")) -} {- $target{cflags} -} {- $config{cflags} -}
138 COUTFLAG={- $target{coutflag} || "/Fo" -}
139 RC={- $target{rc} || "rc" -}
140 RCOUTFLAG={- $target{rcoutflag} || "/fo" -}
141 LD={- $target{ld} || "link" -}
142 LDFLAGS={- $target{lflags} -}
143 LDOUTFLAG={- $target{loutflag} || "/out:" -}
144 EX_LIBS={- $target{ex_libs} -}
145 LIB_CFLAGS={- join(" ", $target{lib_cflags}, $target{shared_cflag}) || "" -}
146 LIB_LDFLAGS={- $target{shared_ldflag} || "" -}
147 DSO_CFLAGS={- join(" ", $target{dso_cflags}, $target{shared_cflag}) || "" -}
148 DSO_LDFLAGS={- join(" ", $target{dso_lflags}, $target{shared_ldflag}) || "" -}
149 BIN_CFLAGS={- $target{bin_cflags} -}
150 BIN_LDFLAGS={- $target{bin_lflags} -}
152 PERL={- $config{perl} -}
155 ARFLAGS= {- $target{arflags} -}
156 AROUTFLAG={- $target{aroutflag} || "/out:" -}
159 ASFLAGS={- $target{asflags} -}
160 ASOUTFLAG={- $target{asoutflag} -}
161 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
163 PROCESSOR= {- $config{processor} -}
165 # The main targets ###################################################
167 all: build_generated \
168 build_libs_nodep build_engines_nodep build_apps_nodep depend
170 build_libs: build_generated build_libs_nodep depend
171 build_libs_nodep: $(LIBS)
172 build_engines: build_generated build_engines_nodep depend
173 build_engines_nodep: $(ENGINES)
174 build_apps: build_generated build_apps_nodep depend
175 build_apps_nodep: $(PROGRAMS) $(SCRIPTS)
176 build_tests: build_generated build_tests_nodep depend
177 build_tests_nodep: $(TESTPROGS)
179 build_generated: $(GENERATED_MANDATORY)
182 tests: build_generated \
183 build_tests_nodep build_apps_nodep build_engines_nodep depend
184 @rem {- output_off() if $disabled{tests}; "" -}
188 "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
189 @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
190 @echo "Tests are not supported with your chosen Configure options"
191 @rem {- output_on() if !$disabled{tests}; "" -}
194 @rem {- output_off() if $disabled{tests}; "" -}
195 @set SRCTOP=$(SRCDIR)
196 @"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
197 @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
198 @echo "Tests are not supported with your chosen Configure options"
199 @rem {- output_on() if !$disabled{tests}; "" -}
201 install: install_sw install_ssldirs install_docs
203 uninstall: uninstall_docs uninstall_sw
206 "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
207 "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """apps/$$1.*"""; } @ARGV" $(SHLIBS)
208 "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """test/$$1.*"""; } @ARGV" $(SHLIBS)
210 -del /Q ossl_static.pdb
213 -del /Q /F $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
214 -del /Q /F $(GENERATED)
219 -del /Q /S /F engines\*.ilk
220 -del /Q /S /F engines\*.lib
221 -del /Q /S /F apps\*.lib
222 -del /Q /S /F engines\*.manifest
223 -del /Q /S /F apps\*.manifest
224 -del /Q /S /F test\*.manifest
227 -del /Q /F configdata.pm
232 # Install helper targets #############################################
234 install_sw: all install_dev install_engines install_runtime
236 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
238 install_docs: install_html_docs
240 uninstall_docs: uninstall_html_docs
243 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\certs"
244 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\private"
245 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\misc"
246 @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
248 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
252 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
253 @echo *** Installing development files
254 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\include\openssl"
255 @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\include\openssl\*.h" \
256 "$(INSTALLTOP)\include\openssl"
257 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\include\openssl\*.h \
258 "$(INSTALLTOP)\include\openssl"
259 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\$(LIBDIR)"
260 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(LIBS) \
261 "$(INSTALLTOP)\$(LIBDIR)"
262 @if "$(SHLIBS)"=="" \
263 "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb \
264 "$(INSTALLTOP)\$(LIBDIR)"
269 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
270 @echo *** Installing engines
271 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(ENGINESDIR)"
272 @if not "$(ENGINES)"=="" \
273 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(ENGINES) "$(ENGINESDIR)"
274 @if not "$(ENGINES)"=="" \
275 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(ENGINEPDBS) "$(ENGINESDIR)"
280 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
281 @echo *** Installing runtime files
282 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
283 @if not "$(SHLIBS)"=="" \
284 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(SHLIBS) "$(INSTALLTOP)\bin"
285 @if not "$(SHLIBS)"=="" \
286 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(SHLIBPDBS) \
288 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(PROGRAMS) \
290 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(PROGRAMPDBS) \
292 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
298 "$(PERL)" "$(SRCDIR)\util\process_docs.pl" \
299 "--destdir=$(INSTALLTOP)\html" --type=html
303 # Building targets ###################################################
305 configdata.pm: "{- $config{build_file_template} -}" "$(SRCDIR)\Configurations\common.tmpl" "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_infos}}) -}
306 @echo "Detected changed: $?"
307 @echo "Reconfiguring..."
308 "$(PERL)" "$(SRCDIR)\Configure" reconf
309 @echo "**************************************************"
311 @echo "*** Please run the same make command again ***"
313 @echo "**************************************************"
318 use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
320 # Helper function to figure out dependencies on libraries
321 # It takes a list of library names and outputs a list of dependencies
322 sub compute_lib_depends {
323 if ($disabled{shared}) {
324 return map { $_.$libext } @_;
326 return map { shlib_import($_) } @_;
331 (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
332 my $generator = '"'.join('" "', @{$args{generator}}).'"';
333 my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
334 my $incs = join("", map { " /I \"$_\"" } @{$args{incs}});
335 my $deps = @{$args{deps}} ?
336 '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
338 if ($target !~ /\.asm$/) {
339 if ($args{generator}->[0] =~ m|^.*\.in$|) {
340 my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
341 "util", "dofile.pl")),
342 rel2abs($config{builddir}));
344 $target: "$args{generator}->[0]" $deps
345 "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
346 "-o$target{build_file}" $generator > \$@
350 $target: "$args{generator}->[0]" $deps
351 "\$(PERL)"$generator_incs $generator > \$@
355 if ($args{generator}->[0] =~ /\.pl$/) {
356 $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
357 } elsif ($args{generator}->[0] =~ /\.S$/) {
360 die "Generator type for $src unknown: $generator\n";
363 if (defined($generator)) {
364 # If the target is named foo.S in build.info, we want to
365 # end up generating foo.s in two steps.
366 if ($args{src} =~ /\.S$/) {
368 $target: "$args{generator}->[0]" $deps
371 \$(CC) $incs \$(CFLAGS) /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
377 $target: "$args{generator}->[0]" $deps
383 $target: "$args{generator}->[0]" $deps
384 \$(CC) $incs \$(CFLAGS) /EP /C "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
391 my $obj = $args{obj};
392 my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
393 } ( @{$args{srcs}} );
394 my $srcs = '"'.join('" "', @srcs).'"';
395 my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
396 my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
397 unless ($disabled{zlib}) {
398 if ($withargs{zlib_include}) {
399 $incs .= ' /I "'.$withargs{zlib_include}.'"';
402 my $ecflags = { lib => '$(LIB_CFLAGS)',
403 dso => '$(DSO_CFLAGS)',
404 bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
405 my $makedepprog = $config{makedepprog};
406 if ($srcs[0] =~ /\.asm$/) {
409 \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
412 return <<"EOF" if (!$disabled{makedepend});
414 \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
415 "\$(PERL)" -n << > $obj$depext
417 s/^Note: including file: *//;
418 \$\$collect{\$\$_} = 1;
419 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
421 $obj$objext: $obj$depext
422 \$(CC) $incs \$(CFLAGS) $ecflags -c \$(COUTFLAG)\$\@ @<<
426 return <<"EOF" if ($disabled{makedepend});
428 \$(CC) $incs \$(CFLAGS) $ecflags -c \$(COUTFLAG)\$\@ $srcs
432 # On Unix, we build shlibs from static libs, so we're ignoring the
433 # object file array. We *know* this routine is only called when we've
434 # configure 'shared'.
437 my $lib = $args{lib};
438 my $shlib = $args{shlib};
439 (my $mkdef_key = $lib) =~ s/^lib//i;
440 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
441 my $linklibs = join("",
442 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
444 (map { $_.$objext } @{$args{objs}}),
445 compute_lib_depends(@{$args{deps}}));
446 my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
447 my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
448 "util", "mkdef.pl")),
449 rel2abs($config{builddir}));
450 my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
452 rel2abs($config{builddir}));
453 my $target = shlib_import($lib);
455 $target: $deps "$ordinalsfile" "$mkdef_pl"
456 "\$(PERL)" "$mkdef_pl" "$mkdef_key" 32 > $shlib.def
457 "\$(PERL)" -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
459 "\$(PERL)" "$mkrc_pl" $shlib$shlibext > $shlib.rc
460 \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
461 \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
462 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
463 $objs $shlib.res$linklibs \$(EX_LIBS)
465 IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext
466 IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext
467 COPY $shlib$shlibext apps
468 COPY $shlib$shlibext test
473 my $dso = $args{lib};
474 my $dso_n = basename($dso);
475 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
476 my $linklibs = join("",
477 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
479 (map { $_.$objext } @{$args{objs}}),
480 compute_lib_depends(@{$args{deps}}));
483 \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
489 $objs$linklibs \$(EX_LIBS)
494 # Because static libs and import libs are both named the same in native
495 # Windows, we can't have both. We skip the static lib in that case,
496 # as the shared libs are what we use anyway.
497 return "" unless $disabled{"shared"};
500 my $lib = $args{lib};
501 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
502 my $deps = join(" ", map { $_.$objext } @{$args{objs}});
505 \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
512 my $bin = $args{bin};
513 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
514 my $linklibs = join("",
515 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
517 (map { $_.$objext } @{$args{objs}}),
518 compute_lib_depends(@{$args{deps}}));
521 \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
522 $objs setargv.obj$linklibs \$(EX_LIBS)
528 my $script = $args{script};
529 my $sources = '"'.join('" "', @{$args{sources}}).'"';
530 my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
531 "util", "dofile.pl")),
532 rel2abs($config{builddir}));
535 "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
536 "-o$target{build_file}" $sources > "$script"
541 my $dir = $args{dir};
542 my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
544 my %extinfo = ( dso => $dsoext,
548 foreach my $type (("dso", "lib", "bin", "script")) {
549 next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
550 # For lib object files, we could update the library. However,
551 # LIB on Windows doesn't work that way, so we won't create any
552 # actions for it, and the dependencies are already taken care of.
553 if ($type ne "lib") {
554 foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
555 if (dirname($prod) eq $dir) {
556 push @deps, $prod.$extinfo{$type};
558 push @actions, "\t@rem No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}});
564 my $deps = join(" ", @deps);
565 my $actions = join("\n", "", @actions);
567 $args{dir} $args{dir}\\ : $deps$actions
570 "" # Important! This becomes part of the template result.