2f3e2442943823df6ab0eca8b51f887051693665
[openssl.git] / Configurations / windows-makefile.tmpl
1 ##
2 ## Makefile for OpenSSL
3 ##
4 ## {- join("\n## ", @autowarntext) -}
5 {-
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";
13
14  sub shlib {
15      return () if $disabled{shared};
16      my $lib = shift;
17      return $unified_info{sharednames}->{$lib} . $shlibext;
18  }
19
20  sub shlib_import {
21      return () if $disabled{shared};
22      my $lib = shift;
23      return $lib . $shlibextimport;
24  }
25
26  sub dso {
27      my $dso = shift;
28
29      return $dso . $dsoext;
30  }
31  '';
32 -}
33
34 PLATFORM={- $config{target} -}
35 SRCDIR={- $config{sourcedir} -}
36 BLDDIR={- $config{builddir} -}
37
38 VERSION={- $config{version} -}
39 MAJOR={- $config{major} -}
40 MINOR={- $config{minor} -}
41
42 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
43
44 LIBS={- join(" ", map { $_.$libext } @{$unified_info{libraries}}) -}
45 SHLIBS={- join(" ", map { shlib($_) } @{$unified_info{libraries}}) -}
46 ENGINES={- join(" ", map { dso($_) } @{$unified_info{engines}}) -}
47 PROGRAMS={- join(" ", map { $_.$exeext } grep { !m|^test\\| } @{$unified_info{programs}}) -}
48 TESTPROGS={- join(" ", map { $_.$exeext } grep { m|^test\\| } @{$unified_info{programs}}) -}
49 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
50
51 DEPS={- join(" ", map { (my $x = $_) =~ s|\.o$|$depext|; $x; }
52                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
53                   keys %{$unified_info{sources}}); -}
54
55 # Do not edit these manually. Use Configure with --prefix or --openssldir
56 # to change this!  Short explanation in the top comment in Configure
57 INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
58               #
59               our $prefix = $config{prefix} || "/usr/local";
60               $prefix -}
61 OPENSSLDIR={- #
62               # The logic here is that if no --openssldir was given,
63               # OPENSSLDIR will get the value from $prefix plus "/ssl".
64               # If --openssldir was given and the value is an absolute
65               # path, OPENSSLDIR will get its value without change.
66               # If the value from --openssldir is a relative path,
67               # OPENSSLDIR will get $prefix with the --openssldir
68               # value appended as a subdirectory.
69               #
70               use File::Spec::Functions;
71               our $openssldir =
72                   $config{openssldir} ?
73                       (file_name_is_absolute($config{openssldir}) ?
74                            $config{openssldir}
75                            : catdir($prefix, $config{openssldir}))
76                       : catdir($prefix, "ssl");
77               $openssldir -}
78 LIBDIR={- #
79           # if $prefix/lib$target{multilib} is not an existing
80           # directory, then assume that it's not searched by linker
81           # automatically, in which case adding $target{multilib} suffix
82           # causes more grief than we're ready to tolerate, so don't...
83           our $multilib =
84               -d "$prefix/lib$target{multilib}" ? $target{multilib} : "";
85           our $libdir = $config{libdir} || "lib$multilib";
86           $libdir -}
87 ENGINESDIR={- use File::Spec::Functions;
88               our $enginesdir = catdir($prefix,$libdir,"engines");
89               $enginesdir -}
90
91 CC={- $target{cc} -}
92 CFLAGS={- join(" ",(map { "-D".$_} @{$target{defines}}, @{$config{defines}})) -} {- join(" ", quotify_l("-DENGINESDIR=\"$enginesdir\"", "-DOPENSSLDIR=\"$openssldir\"")) -} {- $target{cflags} -} {- $config{cflags} -}
93 COUTFLAG={- $target{coutflag} || "/Fo" -}
94 LD={- $target{ld} || "link" -}
95 LDFLAGS={- $target{lflags} -}
96 LDOUTFLAG={- $target{loutflag} || "/out:" -}
97 EX_LIBS={- $config{ex_libs} -}
98 SHARED_CFLAGS={- $target{shared_cflag} || "" -}
99 SHARED_LDFLAGS={- $target{shared_ldflag} || "" -}
100 DSO_CFLAGS={- $target{shared_cflag} || "" -}
101 BIN_CFLAGS={- $target{bin_cflags} -}
102
103 PERL={- $config{perl} -}
104
105 AR={- $target{ar} -}
106 ARFLAGS= {- $target{arflags} -}
107 AROUTFLAG={- $target{aroutflag} || "/out:" -}
108
109 AS={- $target{as} -}
110 ASFLAGS={- $target{asflags} -}
111 ASOUTFLAG={- $target{asoutflag} -}
112 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
113
114 PROCESSOR= {- $config{processor} -}
115
116 # The main targets ###################################################
117
118 all: configdata.pm build_libs_nodep build_engines_nodep build_apps_nodep \
119      depend link-utils
120
121 build_libs: configdata.pm build_libs_nodep depend
122 build_libs_nodep: $(LIBS)
123 build_engines: configdata.pm build_engines_nodep depend
124 build_engines_nodep: $(ENGINES)
125 build_apps: configdata.pm build_apps_nodep depend
126 build_apps_nodep: $(PROGRAMS) $(SCRIPTS)
127 build_tests: configdata.pm build_tests_nodep depend
128 build_tests_nodep: $(TESTPROGS)
129
130 test tests: build_tests_nodep build_apps_nodep build_engines_nodep depend rehash
131         set SRCTOP=$(SRCDIR)
132         set BLDTOP=$(BLDDIR)
133         set PERL=$(PERL)
134         $(PERL) $(SRCDIR)\test\run_tests.pl $(TESTS)
135
136 list-tests:
137         @set TOP=$(SRCDIR)
138         @set PERL=$(PERL)
139         @$(PERL) $(SRCDIR)\test\run_tests.pl list
140
141 depend:
142
143 # Building targets ###################################################
144
145 configdata.pm: {- $config{build_file_template} -} $(SRCDIR)\Configure
146         @echo "Detected changed: $?"
147         @echo "Reconfiguring..."
148         $(PERL) $(SRCDIR)\Configure reconf
149         @echo "**************************************************"
150         @echo "***                                            ***"
151         @echo "***   Please run the same make command again   ***"
152         @echo "***                                            ***"
153         @echo "**************************************************"
154         @( exit 1 )
155
156 {-
157  use File::Basename;
158  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
159
160  # Helper function to figure out dependencies on libraries
161  # It takes a list of library names and outputs a list of dependencies
162  sub compute_lib_depends {
163      if ($disabled{shared}) {
164          return map { $_.$libext } @_;
165      }
166      return map { shlib_import($_) } @_;
167  }
168
169  sub src2obj {
170      my %args = @_;
171      my $obj = $args{obj};
172      my @srcs = map { (my $x = $_) =~ s/\.[sS]$/.asm/; $x } ( @{$args{srcs}} );
173      my $srcs = join(" ",  @srcs);
174      my $deps = join(" ", @srcs, @{$args{deps}});
175      my $incs = join("", map { " /I ".$_ } @{$args{incs}});
176      my $ecflags = { lib => '$(SHARED_CFLAGS)',
177                      dso => '$(DSO_CFLAGS)',
178                      bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
179      my $makedepprog = $config{makedepprog};
180      if ($srcs[0] =~ /\.asm$/) {
181          return <<"EOF";
182 $obj$objext: $deps
183         \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
184 EOF
185      }
186      return <<"EOF";
187 $obj$depext: $deps
188         \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
189             \$(PERL) -n << > $obj$depext
190 chomp;
191 s/^Note: including file: *//;
192 \$\$collect{\$\$_} = 1;
193 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
194 <<KEEP
195 $obj$objext: $obj$depext
196         \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ @<<
197 $srcs
198 <<KEEP
199 EOF
200  }
201
202  # On Unix, we build shlibs from static libs, so we're ignoring the
203  # object file array.  We *know* this routine is only called when we've
204  # configure 'shared'.
205  sub libobj2shlib {
206      my %args = @_;
207      my $lib = $args{lib};
208      my $shlib = $args{shlib};
209      (my $mkdef_key = $lib) =~ s/^lib//i;
210      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
211      my $linklibs = join("",
212                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
213      my $deps = join(" ",
214                      (map { $_.$objext } @{$args{objs}}),
215                      compute_lib_depends(@{$args{deps}}));
216      my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
217      my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
218                                             "util", "mkdef.pl")),
219                             rel2abs($config{builddir}));
220      my $target = shlib_import($lib);
221      return <<"EOF"
222 $target: $deps $ordinalsfile
223         \$(PERL) $mkdef_pl "$mkdef_key" 32 > $shlib.def
224         \$(LD) \$(LDFLAGS) \\
225                 /dll /implib:$target \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<<
226 $objs$linklibs \$(EX_LIBS)
227 <<
228 EOF
229  }
230  sub obj2dso {
231      my %args = @_;
232      my $dso = $args{lib};
233      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
234      my $linklibs = join("",
235                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
236      my $deps = join(" ",
237                      (map { $_.$objext } @{$args{objs}}),
238                      compute_lib_depends(@{$args{deps}}));
239      return <<"EOF";
240 $dso$dsoext: $deps
241         \$(LD) \$(LDFLAGS) /dll \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
242 LIBRARY         $dso
243 EXPORTS
244     bind_engine         @1
245     v_check             @2
246 <<
247 $objs$linklibs \$(EX_LIBS)
248 <<
249 EOF
250  }
251  sub obj2lib {
252      my %args = @_;
253      my $lib = $args{lib};
254      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
255      my $deps = join(" ", map { $_.$objext } @{$args{objs}});
256      return <<"EOF";
257 $lib$libext: $deps
258         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
259 $objs
260 <<
261 EOF
262  }
263  sub obj2bin {
264      my %args = @_;
265      my $bin = $args{bin};
266      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
267      my $linklibs = join("",
268                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
269      my $deps = join(" ",
270                      (map { $_.$objext } @{$args{objs}}),
271                      compute_lib_depends(@{$args{deps}}));
272      return <<"EOF";
273 $bin$exeext: $deps
274         \$(LD) \$(LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
275 $objs setargv.obj$linklibs \$(EX_LIBS)
276 <<
277 EOF
278   }
279   sub in2script {
280       my %args = @_;
281       my $script = $args{script};
282       my $sources = join(" ", @{$args{sources}});
283       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
284                                            "util", "dofile.pl")),
285                            rel2abs($config{builddir}));
286       return <<"EOF";
287 $script: $sources
288         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
289             "-o$target{build_file}" $sources > "$script"
290 EOF
291   }
292   ""    # Important!  This becomes part of the template result.
293 -}