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 ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
64 PROGRAMS={- join(" ", map { $_.$exeext } grep { !m|^test\\| } @{$unified_info{programs}}) -}
65 TESTPROGS={- join(" ", map { $_.$exeext } grep { m|^test\\| } @{$unified_info{programs}}) -}
66 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
68 {- output_off() if $disabled{makedepend}; "" -}
69 DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
70 grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
71 keys %{$unified_info{sources}}); -}
72 {- output_on() if $disabled{makedepend}; "" -}
74 # Do not edit these manually. Use Configure with --prefix or --openssldir
75 # to change this! Short explanation in the top comment in Configure
76 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
78 our $prefix = $config{prefix} || "$win_installroot\\OpenSSL";
81 # The logic here is that if no --openssldir was given,
82 # OPENSSLDIR will get the value from $prefix plus "/ssl".
83 # If --openssldir was given and the value is an absolute
84 # path, OPENSSLDIR will get its value without change.
85 # If the value from --openssldir is a relative path,
86 # OPENSSLDIR will get $prefix with the --openssldir
87 # value appended as a subdirectory.
89 use File::Spec::Functions;
92 (file_name_is_absolute($config{openssldir}) ?
94 : catdir($prefix, $config{openssldir}))
95 : "$win_commonroot\\SSL";
97 LIBDIR={- our $libdir = $config{libdir} || "lib";
99 ENGINESDIR={- use File::Spec::Functions;
100 our $enginesdir = catdir($prefix,$libdir,"engines");
104 CFLAGS={- join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}})) -} {- join(" ", quotify_l("-DENGINESDIR=\"$enginesdir\"", "-DOPENSSLDIR=\"$openssldir\"")) -} {- $target{cflags} -} {- $config{cflags} -}
105 COUTFLAG={- $target{coutflag} || "/Fo" -}
106 RC={- $target{rc} || "rc" -}
107 RCOUTFLAG={- $target{rcoutflag} || "/fo" -}
108 LD={- $target{ld} || "link" -}
109 LDFLAGS={- $target{lflags} -}
110 LDOUTFLAG={- $target{loutflag} || "/out:" -}
111 EX_LIBS={- $target{ex_libs} -}
112 LIB_CFLAGS={- join(" ", $target{lib_cflags}, $target{shared_cflag}) || "" -}
113 LIB_LDFLAGS={- $target{shared_ldflag} || "" -}
114 DSO_CFLAGS={- join(" ", $target{dso_cflags}, $target{shared_cflag}) || "" -}
115 DSO_LDFLAGS={- join(" ", $target{dso_lflags}, $target{shared_ldflag}) || "" -}
116 BIN_CFLAGS={- $target{bin_cflags} -}
117 BIN_LDFLAGS={- $target{bin_lflags} -}
119 PERL={- $config{perl} -}
122 ARFLAGS= {- $target{arflags} -}
123 AROUTFLAG={- $target{aroutflag} || "/out:" -}
126 ASFLAGS={- $target{asflags} -}
127 ASOUTFLAG={- $target{asoutflag} -}
128 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
130 PROCESSOR= {- $config{processor} -}
132 # The main targets ###################################################
134 all: configdata.pm build_libs_nodep build_engines_nodep build_apps_nodep depend
136 build_libs: configdata.pm build_libs_nodep depend
137 build_libs_nodep: $(LIBS)
138 build_engines: configdata.pm build_engines_nodep depend
139 build_engines_nodep: $(ENGINES)
140 build_apps: configdata.pm build_apps_nodep depend
141 build_apps_nodep: $(PROGRAMS) $(SCRIPTS)
142 build_tests: configdata.pm build_tests_nodep depend
143 build_tests_nodep: $(TESTPROGS)
146 tests: build_tests_nodep build_apps_nodep build_engines_nodep depend
147 @rem {- output_off() if $disabled{tests}; "" -}
151 $(PERL) $(SRCDIR)\test\run_tests.pl $(TESTS)
152 @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
153 @echo "Tests are not supported with your chosen Configure options"
154 @rem {- output_on() if !$disabled{tests}; "" -}
159 @$(PERL) $(SRCDIR)\test\run_tests.pl list
161 install: install_sw install_ssldirs install_docs
163 uninstall: uninstall_docs uninstall_sw
166 $(PERL) -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
171 -del /Q /F $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
177 -del /Q /S /F engines\*.ilk
178 -del /Q /S /F engines\*.lib
182 # Install helper targets #############################################
184 install_sw: all install_dev install_engines install_runtime
186 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
193 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\certs"
194 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\private"
197 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
198 @echo *** Installing development files
199 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\include\openssl"
200 @$(PERL) $(SRCDIR)\util\copy.pl $(SRCDIR)\include\openssl\*.h \
201 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
202 @$(PERL) $(SRCDIR)\util\copy.pl $(BLDDIR)\include\openssl\*.h \
203 "$(DESTDIR)$(INSTALLTOP)\include\openssl"
204 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
205 @$(PERL) $(SRCDIR)\util\copy.pl $(LIBS) \
206 "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
211 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
212 @echo *** Installing engines
213 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(ENGINESDIR)"
214 @if not "$(ENGINES)"=="" \
215 $(PERL) $(SRCDIR)\util\copy.pl $(ENGINES) "$(DESTDIR)$(ENGINESDIR)"
220 @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
221 @echo *** Installing runtime files
222 @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\bin"
223 @if not "$(SHLIBS)"=="" \
224 $(PERL) $(SRCDIR)\util\copy.pl $(SHLIBS) "$(DESTDIR)$(INSTALLTOP)\bin"
225 @$(PERL) $(SRCDIR)\util\copy.pl $(PROGRAMS) "$(DESTDIR)$(INSTALLTOP)\bin"
229 # Building targets ###################################################
231 configdata.pm: {- $config{build_file_template} -} $(SRCDIR)\Configure
232 @echo "Detected changed: $?"
233 @echo "Reconfiguring..."
234 $(PERL) $(SRCDIR)\Configure reconf
235 @echo "**************************************************"
237 @echo "*** Please run the same make command again ***"
239 @echo "**************************************************"
244 use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
246 # Helper function to figure out dependencies on libraries
247 # It takes a list of library names and outputs a list of dependencies
248 sub compute_lib_depends {
249 if ($disabled{shared}) {
250 return map { $_.$libext } @_;
252 return map { shlib_import($_) } @_;
257 (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
258 my $generator = join(" ", @{$args{generator}});
259 my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
260 my $incs = join("", map { " /I ".$_ } @{$args{incs}});
261 my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
263 if ($target !~ /\.asm$/) {
265 $target: $args{generator}->[0] $deps
266 \$(PERL)$generator_incs $generator > \$@
269 if ($args{generator}->[0] =~ /\.pl$/) {
270 $generator = '$(PERL)'.$generator_incs.' '.$generator;
271 } elsif ($args{generator}->[0] =~ /\.S$/) {
274 die "Generator type for $src unknown: $generator\n";
277 if (defined($generator)) {
278 # If the target is named foo.S in build.info, we want to
279 # end up generating foo.s in two steps.
280 if ($args{src} =~ /\.S$/) {
282 $target: $args{generator}->[0] $deps
285 \$(CC) \$(CFLAGS) $incs /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
291 $target: $args{generator}->[0] $deps
297 $target: $args{generator}->[0] $deps
298 \$(CC) \$(CFLAGS) $incs /EP /C $args{generator}->[0] > \$@.i && move /Y \$@.i \$@
305 my $obj = $args{obj};
306 my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
307 } ( @{$args{srcs}} );
308 my $srcs = join(" ", @srcs);
309 my $deps = join(" ", @srcs, @{$args{deps}});
310 my $incs = join("", map { " /I ".$_ } @{$args{incs}});
311 unless ($disabled{zlib}) {
312 if ($withargs{zlib_include}) {
313 $incs .= " /I ".$withargs{zlib_include};
316 my $ecflags = { lib => '$(LIB_CFLAGS)',
317 dso => '$(DSO_CFLAGS)',
318 bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
319 my $makedepprog = $config{makedepprog};
320 if ($srcs[0] =~ /\.asm$/) {
323 \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
326 return <<"EOF" if (!$disabled{makedepend});
328 \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
329 \$(PERL) -n << > $obj$depext
331 s/^Note: including file: *//;
332 \$\$collect{\$\$_} = 1;
333 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
335 $obj$objext: $obj$depext
336 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ @<<
340 return <<"EOF" if ($disabled{makedepend});
342 \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ $srcs
346 # On Unix, we build shlibs from static libs, so we're ignoring the
347 # object file array. We *know* this routine is only called when we've
348 # configure 'shared'.
351 my $lib = $args{lib};
352 my $shlib = $args{shlib};
353 (my $mkdef_key = $lib) =~ s/^lib//i;
354 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
355 my $linklibs = join("",
356 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
358 (map { $_.$objext } @{$args{objs}}),
359 compute_lib_depends(@{$args{deps}}));
360 my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
361 my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
362 "util", "mkdef.pl")),
363 rel2abs($config{builddir}));
364 my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
366 rel2abs($config{builddir}));
367 my $target = shlib_import($lib);
369 $target: $deps $ordinalsfile $mkdef_pl
370 \$(PERL) $mkdef_pl "$mkdef_key" 32 > $shlib.def
371 \$(PERL) -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
373 \$(PERL) $mkrc_pl $shlib$shlibext > $shlib.rc
374 \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
375 \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
376 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
377 $objs $shlib.res$linklibs \$(EX_LIBS)
379 DEL /F apps\\$shlib$shlibext
380 DEL /F test\\$shlib$shlibext
381 COPY $shlib$shlibext apps
382 COPY $shlib$shlibext test
387 my $dso = $args{lib};
388 my $dso_n = basename($dso);
389 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
390 my $linklibs = join("",
391 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
393 (map { $_.$objext } @{$args{objs}}),
394 compute_lib_depends(@{$args{deps}}));
397 \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
403 $objs$linklibs \$(EX_LIBS)
408 # Because static libs and import libs are both named the same in native
409 # Windows, we can't have both. We skip the static lib in that case,
410 # as the shared libs are what we use anyway.
411 return "" unless $disabled{"shared"};
414 my $lib = $args{lib};
415 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
416 my $deps = join(" ", map { $_.$objext } @{$args{objs}});
419 \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
426 my $bin = $args{bin};
427 my $objs = join("\n", map { $_.$objext } @{$args{objs}});
428 my $linklibs = join("",
429 map { "\n$_" } compute_lib_depends(@{$args{deps}}));
431 (map { $_.$objext } @{$args{objs}}),
432 compute_lib_depends(@{$args{deps}}));
435 \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
436 $objs setargv.obj$linklibs \$(EX_LIBS)
442 my $script = $args{script};
443 my $sources = join(" ", @{$args{sources}});
444 my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
445 "util", "dofile.pl")),
446 rel2abs($config{builddir}));
449 \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
450 "-o$target{build_file}" $sources > "$script"
453 "" # Important! This becomes part of the template result.