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={- join(" ",
81 ( map { (my $x = $_) =~ s|\.[sS]$|\.asm|; $x }
82 grep { defined $unified_info{generate}->{$_} }
83 map { @{$unified_info{sources}->{$_}} }
84 grep { /\.o$/ } keys %{$unified_info{sources}} ),
85 ( grep { /\.h$/ } keys %{$unified_info{generate}} )) -}
87 # Do not edit these manually. Use Configure with --prefix or --openssldir
88 # to change this! Short explanation in the top comment in Configure
89 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
91 our $prefix = $config{prefix} || "$win_installroot\\OpenSSL";
94 # The logic here is that if no --openssldir was given,
95 # OPENSSLDIR will get the value from $prefix plus "/ssl".
96 # If --openssldir was given and the value is an absolute
97 # path, OPENSSLDIR will get its value without change.
98 # If the value from --openssldir is a relative path,
99 # OPENSSLDIR will get $prefix with the --openssldir
100 # value appended as a subdirectory.
102 use File::Spec::Functions;
104 $config{openssldir} ?
105 (file_name_is_absolute($config{openssldir}) ?
107 : catdir($prefix, $config{openssldir}))
108 : "$win_commonroot\\SSL";
110 LIBDIR={- our $libdir = $config{libdir} || "lib";
112 ENGINESDIR={- use File::Spec::Functions;
113 our $enginesdir = catdir($prefix,$libdir,"engines");
117 CFLAGS={- join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}})) -} {- join(" ", quotify_l("-DENGINESDIR=\"$enginesdir\"", "-DOPENSSLDIR=\"$openssldir\"")) -} {- $target{cflags} -} {- $config{cflags} -}
118 COUTFLAG={- $target{coutflag} || "/Fo" -}
119 RC={- $target{rc} || "rc" -}
120 RCOUTFLAG={- $target{rcoutflag} || "/fo" -}
121 LD={- $target{ld} || "link" -}
122 LDFLAGS={- $target{lflags} -}
123 LDOUTFLAG={- $target{loutflag} || "/out:" -}
124 EX_LIBS={- $target{ex_libs} -}
125 LIB_CFLAGS={- join(" ", $target{lib_cflags}, $target{shared_cflag}) || "" -}
126 LIB_LDFLAGS={- $target{shared_ldflag} || "" -}
127 DSO_CFLAGS={- join(" ", $target{dso_cflags}, $target{shared_cflag}) || "" -}
128 DSO_LDFLAGS={- join(" ", $target{dso_lflags}, $target{shared_ldflag}) || "" -}
129 BIN_CFLAGS={- $target{bin_cflags} -}
130 BIN_LDFLAGS={- $target{bin_lflags} -}
132 PERL={- $config{perl} -}
135 ARFLAGS= {- $target{arflags} -}
136 AROUTFLAG={- $target{aroutflag} || "/out:" -}
139 ASFLAGS={- $target{asflags} -}
140 ASOUTFLAG={- $target{asoutflag} -}
141 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
143 PROCESSOR= {- $config{processor} -}
145 # The main targets ###################################################
147 all: configdata.pm build_libs_nodep build_engines_nodep build_apps_nodep depend
149 build_libs: configdata.pm build_libs_nodep depend
150 build_libs_nodep: $(LIBS)
151 build_engines: configdata.pm build_engines_nodep depend
152 build_engines_nodep: $(ENGINES)
153 build_apps: configdata.pm build_apps_nodep depend
154 build_apps_nodep: $(PROGRAMS) $(SCRIPTS)
155 build_tests: configdata.pm build_tests_nodep depend
156 build_tests_nodep: $(TESTPROGS)
159 tests: build_tests_nodep build_apps_nodep build_engines_nodep depend
160 @rem {- output_off() if $disabled{tests}; "" -}
164 "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
165 @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
166 @echo "Tests are not supported with your chosen Configure options"
167 @rem {- output_on() if !$disabled{tests}; "" -}
172 @"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
174 install: install_sw install_ssldirs install_docs
176 uninstall: uninstall_docs uninstall_sw
179 "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
180 "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """apps/$$1.*"""; } @ARGV" $(SHLIBS)
181 "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """test/$$1.*"""; } @ARGV" $(SHLIBS)
183 -del /Q ossl_static.pdb
186 -del /Q /F $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
187 -del /Q /S /F $(GENERATED)
192 -del /Q /S /F engines\*.ilk
193 -del /Q /S /F engines\*.lib
194 -del /Q /S /F apps\*.lib
195 -del /Q /S /F engines\*.manifest
196 -del /Q /S /F apps\*.manifest
200 # Install helper targets #############################################
202 install_sw: all install_dev install_engines install_runtime
204 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
207 "$(PERL)" "$(SRCDIR)\util\process_docs.pl" \
208 "--destdir=$(DESTDIR)$(INSTALLTOP)\html" --type=html
213 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(OPENSSLDIR)\certs"
214 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(OPENSSLDIR)\private"
215 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(OPENSSLDIR)\misc"
216 @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
217 "$(DESTDIR)$(OPENSSLDIR)"
218 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
219 "$(DESTDIR)$(OPENSSLDIR)\misc"
222 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
223 @echo *** Installing development files
224 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(INSTALLTOP)\include\openssl"
225 @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\include\openssl\*.h" \
226 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
227 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\include\openssl\*.h \
228 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
229 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
230 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(LIBS) \
231 "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
232 @if "$(SHLIBS)"=="" \
233 "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb \
234 "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
239 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
240 @echo *** Installing engines
241 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(ENGINESDIR)"
242 @if not "$(ENGINES)"=="" \
243 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(ENGINES) "$(DESTDIR)$(ENGINESDIR)"
244 @if not "$(ENGINES)"=="" \
245 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(ENGINEPDBS) "$(DESTDIR)$(ENGINESDIR)"
250 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
251 @echo *** Installing runtime files
252 @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(DESTDIR)$(INSTALLTOP)\bin"
253 @if not "$(SHLIBS)"=="" \
254 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(SHLIBS) "$(DESTDIR)$(INSTALLTOP)\bin"
255 @if not "$(SHLIBS)"=="" \
256 "$(PERL)" "$(SRCDIR)\util\copy.pl" $(SHLIBPDBS) \
257 "$(DESTDIR)$(INSTALLTOP)\bin"
258 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(PROGRAMS) \
259 "$(DESTDIR)$(INSTALLTOP)\bin"
260 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(PROGRAMPDBS) \
261 "$(DESTDIR)$(INSTALLTOP)\bin"
262 @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
263 "$(DESTDIR)$(INSTALLTOP)\bin"
267 # Building targets ###################################################
269 configdata.pm: "{- $config{build_file_template} -}" "$(SRCDIR)\Configure"
270 @echo "Detected changed: $?"
271 @echo "Reconfiguring..."
272 "$(PERL)" "$(SRCDIR)\Configure" reconf
273 @echo "**************************************************"
275 @echo "*** Please run the same make command again ***"
277 @echo "**************************************************"
282 use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
284 # Helper function to figure out dependencies on libraries
285 # It takes a list of library names and outputs a list of dependencies
286 sub compute_lib_depends {
287 if ($disabled{shared}) {
288 return map { $_.$libext } @_;
290 return map { shlib_import($_) } @_;
295 (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
296 my $generator = '"'.join('" "', @{$args{generator}}).'"';
297 my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
298 my $incs = join("", map { " /I \"$_\"" } @{$args{incs}});
299 my $deps = @{$args{deps}} ?
300 '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
302 if ($target !~ /\.asm$/) {
304 $target: "$args{generator}->[0]" $deps
305 "\$(PERL)"$generator_incs $generator > \$@
308 if ($args{generator}->[0] =~ /\.pl$/) {
309 $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
310 } elsif ($args{generator}->[0] =~ /\.S$/) {
313 die "Generator type for $src unknown: $generator\n";
316 if (defined($generator)) {
317 # If the target is named foo.S in build.info, we want to
318 # end up generating foo.s in two steps.
319 if ($args{src} =~ /\.S$/) {
321 $target: "$args{generator}->[0]" $deps
324 \$(CC) \$(CFLAGS) $incs /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
330 $target: "$args{generator}->[0]" $deps
336 $target: "$args{generator}->[0]" $deps
337 \$(CC) \$(CFLAGS) $incs /EP /C "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
344 my $obj = $args{obj};
345 my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
346 } ( @{$args{srcs}} );
347 my $srcs = '"'.join('" "', @srcs).'"';
348 my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
349 my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
350 unless ($disabled{zlib}) {
351 if ($withargs{zlib_include}) {
352 $incs .= ' /I "'.$withargs{zlib_include}.'"';
355 my $ecflags = { lib => '$(LIB_CFLAGS)',
356 dso => '$(DSO_CFLAGS)',
357 bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
358 my $makedepprog = $config{makedepprog};
359 if ($srcs[0] =~ /\.asm$/) {
362 \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
365 return <<"EOF" if (!$disabled{makedepend});
367 \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
368 "\$(PERL)" -n << > $obj$depext
370 s/^Note: including file: *//;
371 \$\$collect{\$\$_} = 1;
372 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
374 $obj$objext: $obj$depext
375 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ @<<
379 return <<"EOF" if ($disabled{makedepend});
381 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ $srcs
385 # On Unix, we build shlibs from static libs, so we're ignoring the
386 # object file array. We *know* this routine is only called when we've
387 # configure 'shared'.
390 my $lib = $args{lib};
391 my $shlib = $args{shlib};
392 (my $mkdef_key = $lib) =~ s/^lib//i;
393 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
394 my $linklibs = join("",
395 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
397 (map { $_.$objext } @{$args{objs}}),
398 compute_lib_depends(@{$args{deps}}));
399 my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
400 my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
401 "util", "mkdef.pl")),
402 rel2abs($config{builddir}));
403 my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
405 rel2abs($config{builddir}));
406 my $target = shlib_import($lib);
408 $target: $deps "$ordinalsfile" "$mkdef_pl"
409 "\$(PERL)" "$mkdef_pl" "$mkdef_key" 32 > $shlib.def
410 "\$(PERL)" -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
412 "\$(PERL)" "$mkrc_pl" $shlib$shlibext > $shlib.rc
413 \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
414 \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
415 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
416 $objs $shlib.res$linklibs \$(EX_LIBS)
418 IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext
419 IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext
420 COPY $shlib$shlibext apps
421 COPY $shlib$shlibext test
426 my $dso = $args{lib};
427 my $dso_n = basename($dso);
428 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
429 my $linklibs = join("",
430 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
432 (map { $_.$objext } @{$args{objs}}),
433 compute_lib_depends(@{$args{deps}}));
436 \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
442 $objs$linklibs \$(EX_LIBS)
447 # Because static libs and import libs are both named the same in native
448 # Windows, we can't have both. We skip the static lib in that case,
449 # as the shared libs are what we use anyway.
450 return "" unless $disabled{"shared"};
453 my $lib = $args{lib};
454 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
455 my $deps = join(" ", map { $_.$objext } @{$args{objs}});
458 \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
465 my $bin = $args{bin};
466 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
467 my $linklibs = join("",
468 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
470 (map { $_.$objext } @{$args{objs}}),
471 compute_lib_depends(@{$args{deps}}));
474 \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
475 $objs setargv.obj$linklibs \$(EX_LIBS)
481 my $script = $args{script};
482 my $sources = '"'.join('" "', @{$args{sources}}).'"';
483 my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
484 "util", "dofile.pl")),
485 rel2abs($config{builddir}));
488 "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
489 "-o$target{build_file}" $sources > "$script"
492 "" # Important! This becomes part of the template result.