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}}) -}
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}; "" -}
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
81 our $prefix = $config{prefix} || "$win_installroot\\OpenSSL";
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.
92 use File::Spec::Functions;
95 (file_name_is_absolute($config{openssldir}) ?
97 : catdir($prefix, $config{openssldir}))
98 : "$win_commonroot\\SSL";
100 LIBDIR={- our $libdir = $config{libdir} || "lib";
102 ENGINESDIR={- use File::Spec::Functions;
103 our $enginesdir = catdir($prefix,$libdir,"engines");
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} -}
122 PERL={- $config{perl} -}
125 ARFLAGS= {- $target{arflags} -}
126 AROUTFLAG={- $target{aroutflag} || "/out:" -}
129 ASFLAGS={- $target{asflags} -}
130 ASOUTFLAG={- $target{asoutflag} -}
131 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
133 PROCESSOR= {- $config{processor} -}
135 # The main targets ###################################################
137 all: configdata.pm build_libs_nodep build_engines_nodep build_apps_nodep depend
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)
149 tests: build_tests_nodep build_apps_nodep build_engines_nodep depend
150 @rem {- output_off() if $disabled{tests}; "" -}
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}; "" -}
162 @$(PERL) $(SRCDIR)\test\run_tests.pl list
164 install: install_sw install_ssldirs install_docs
166 uninstall: uninstall_docs uninstall_sw
169 $(PERL) -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
171 -del /Q ossl_static.pdb
174 -del /Q /F $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
180 -del /Q /S /F engines\*.ilk
181 -del /Q /S /F engines\*.lib
185 # Install helper targets #############################################
187 install_sw: all install_dev install_engines install_runtime
189 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
196 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\certs"
197 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\private"
198 @$(PERL) $(SRCDIR)\util\copy.pl $(SRCDIR)\apps\openssl.cnf \
199 "$(DESTDIR)$(OPENSSLDIR)"
202 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
203 @echo *** Installing development files
204 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\include\openssl"
205 @$(PERL) $(SRCDIR)\util\copy.pl $(SRCDIR)\include\openssl\*.h \
206 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
207 @$(PERL) $(SRCDIR)\util\copy.pl $(BLDDIR)\include\openssl\*.h \
208 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
209 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
210 @$(PERL) $(SRCDIR)\util\copy.pl $(LIBS) \
211 "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
212 @if "$(SHLIBS)"=="" \
213 $(PERL) $(SRCDIR)\util\copy.pl ossl_static.pdb \
214 "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
219 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
220 @echo *** Installing engines
221 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(ENGINESDIR)"
222 @if not "$(ENGINES)"=="" \
223 $(PERL) $(SRCDIR)\util\copy.pl $(ENGINES) "$(DESTDIR)$(ENGINESDIR)"
224 @if not "$(ENGINES)"=="" \
225 $(PERL) $(SRCDIR)\util\copy.pl $(ENGINEPDBS) "$(DESTDIR)$(ENGINESDIR)"
230 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
231 @echo *** Installing runtime files
232 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\bin"
233 @if not "$(SHLIBS)"=="" \
234 $(PERL) $(SRCDIR)\util\copy.pl $(SHLIBS) "$(DESTDIR)$(INSTALLTOP)\bin"
235 @if not "$(SHLIBS)"=="" \
236 $(PERL) $(SRCDIR)\util\copy.pl $(SHLIBPDBS) \
237 "$(DESTDIR)$(INSTALLTOP)\bin"
238 @$(PERL) $(SRCDIR)\util\copy.pl $(PROGRAMS) \
239 "$(DESTDIR)$(INSTALLTOP)\bin"
240 @$(PERL) $(SRCDIR)\util\copy.pl $(PROGRAMPDBS) \
241 "$(DESTDIR)$(INSTALLTOP)\bin"
245 # Building targets ###################################################
247 configdata.pm: {- $config{build_file_template} -} $(SRCDIR)\Configure
248 @echo "Detected changed: $?"
249 @echo "Reconfiguring..."
250 $(PERL) $(SRCDIR)\Configure reconf
251 @echo "**************************************************"
253 @echo "*** Please run the same make command again ***"
255 @echo "**************************************************"
260 use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
262 # Helper function to figure out dependencies on libraries
263 # It takes a list of library names and outputs a list of dependencies
264 sub compute_lib_depends {
265 if ($disabled{shared}) {
266 return map { $_.$libext } @_;
268 return map { shlib_import($_) } @_;
273 (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
274 my $generator = join(" ", @{$args{generator}});
275 my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
276 my $incs = join("", map { " /I ".$_ } @{$args{incs}});
277 my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
279 if ($target !~ /\.asm$/) {
281 $target: $args{generator}->[0] $deps
282 \$(PERL)$generator_incs $generator > \$@
285 if ($args{generator}->[0] =~ /\.pl$/) {
286 $generator = '$(PERL)'.$generator_incs.' '.$generator;
287 } elsif ($args{generator}->[0] =~ /\.S$/) {
290 die "Generator type for $src unknown: $generator\n";
293 if (defined($generator)) {
294 # If the target is named foo.S in build.info, we want to
295 # end up generating foo.s in two steps.
296 if ($args{src} =~ /\.S$/) {
298 $target: $args{generator}->[0] $deps
301 \$(CC) \$(CFLAGS) $incs /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
307 $target: $args{generator}->[0] $deps
313 $target: $args{generator}->[0] $deps
314 \$(CC) \$(CFLAGS) $incs /EP /C $args{generator}->[0] > \$@.i && move /Y \$@.i \$@
321 my $obj = $args{obj};
322 my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
323 } ( @{$args{srcs}} );
324 my $srcs = join(" ", @srcs);
325 my $deps = join(" ", @srcs, @{$args{deps}});
326 my $incs = join("", map { " /I ".$_ } @{$args{incs}});
327 unless ($disabled{zlib}) {
328 if ($withargs{zlib_include}) {
329 $incs .= " /I ".$withargs{zlib_include};
332 my $ecflags = { lib => '$(LIB_CFLAGS)',
333 dso => '$(DSO_CFLAGS)',
334 bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
335 my $makedepprog = $config{makedepprog};
336 if ($srcs[0] =~ /\.asm$/) {
339 \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
342 return <<"EOF" if (!$disabled{makedepend});
344 \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
345 \$(PERL) -n << > $obj$depext
347 s/^Note: including file: *//;
348 \$\$collect{\$\$_} = 1;
349 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
351 $obj$objext: $obj$depext
352 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ @<<
356 return <<"EOF" if ($disabled{makedepend});
358 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ $srcs
362 # On Unix, we build shlibs from static libs, so we're ignoring the
363 # object file array. We *know* this routine is only called when we've
364 # configure 'shared'.
367 my $lib = $args{lib};
368 my $shlib = $args{shlib};
369 (my $mkdef_key = $lib) =~ s/^lib//i;
370 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
371 my $linklibs = join("",
372 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
374 (map { $_.$objext } @{$args{objs}}),
375 compute_lib_depends(@{$args{deps}}));
376 my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
377 my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
378 "util", "mkdef.pl")),
379 rel2abs($config{builddir}));
380 my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
382 rel2abs($config{builddir}));
383 my $target = shlib_import($lib);
385 $target: $deps $ordinalsfile $mkdef_pl
386 \$(PERL) $mkdef_pl "$mkdef_key" 32 > $shlib.def
387 \$(PERL) -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
389 \$(PERL) $mkrc_pl $shlib$shlibext > $shlib.rc
390 \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
391 \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
392 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
393 $objs $shlib.res$linklibs \$(EX_LIBS)
395 DEL /Q /F apps\\$shlib$shlibext
396 DEL /Q /F test\\$shlib$shlibext
397 COPY $shlib$shlibext apps
398 COPY $shlib$shlibext test
403 my $dso = $args{lib};
404 my $dso_n = basename($dso);
405 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
406 my $linklibs = join("",
407 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
409 (map { $_.$objext } @{$args{objs}}),
410 compute_lib_depends(@{$args{deps}}));
413 \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
419 $objs$linklibs \$(EX_LIBS)
424 # Because static libs and import libs are both named the same in native
425 # Windows, we can't have both. We skip the static lib in that case,
426 # as the shared libs are what we use anyway.
427 return "" unless $disabled{"shared"};
430 my $lib = $args{lib};
431 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
432 my $deps = join(" ", map { $_.$objext } @{$args{objs}});
435 \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
442 my $bin = $args{bin};
443 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
444 my $linklibs = join("",
445 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
447 (map { $_.$objext } @{$args{objs}}),
448 compute_lib_depends(@{$args{deps}}));
451 \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
452 $objs setargv.obj$linklibs \$(EX_LIBS)
458 my $script = $args{script};
459 my $sources = join(" ", @{$args{sources}});
460 my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
461 "util", "dofile.pl")),
462 rel2abs($config{builddir}));
465 \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
466 "-o$target{build_file}" $sources > "$script"
469 "" # Important! This becomes part of the template result.