Pass down inclusion directories to source file generators
[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={- $target{ex_libs} -}
98 LIB_CFLAGS={- join(" ", $target{lib_cflags}, $target{shared_cflag}) || "" -}
99 SHARED_LDFLAGS={- $target{shared_ldflag} || "" -}
100 DSO_CFLAGS={- join(" ", $target{dso_cflags}, $target{shared_cflag}) || "" -}
101 DSO_LDFLAGS={- join(" ", $target{dso_lflags}, $target{shared_ldflag}) || "" -}
102 BIN_CFLAGS={- $target{bin_cflags} -}
103 BIN_LDFLAGS={- $target{bin_lflags} -}
104
105 PERL={- $config{perl} -}
106
107 AR={- $target{ar} -}
108 ARFLAGS= {- $target{arflags} -}
109 AROUTFLAG={- $target{aroutflag} || "/out:" -}
110
111 AS={- $target{as} -}
112 ASFLAGS={- $target{asflags} -}
113 ASOUTFLAG={- $target{asoutflag} -}
114 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
115
116 PROCESSOR= {- $config{processor} -}
117
118 # The main targets ###################################################
119
120 all: configdata.pm build_libs_nodep build_engines_nodep build_apps_nodep depend
121
122 build_libs: configdata.pm build_libs_nodep depend
123 build_libs_nodep: $(LIBS)
124 build_engines: configdata.pm build_engines_nodep depend
125 build_engines_nodep: $(ENGINES)
126 build_apps: configdata.pm build_apps_nodep depend
127 build_apps_nodep: $(PROGRAMS) $(SCRIPTS)
128 build_tests: configdata.pm build_tests_nodep depend
129 build_tests_nodep: $(TESTPROGS)
130
131 test tests: build_tests_nodep build_apps_nodep build_engines_nodep depend
132         set SRCTOP=$(SRCDIR)
133         set BLDTOP=$(BLDDIR)
134         set PERL=$(PERL)
135         $(PERL) $(SRCDIR)\test\run_tests.pl $(TESTS)
136
137 list-tests:
138         @set TOP=$(SRCDIR)
139         @set PERL=$(PERL)
140         @$(PERL) $(SRCDIR)\test\run_tests.pl list
141
142 depend:
143
144 # Building targets ###################################################
145
146 configdata.pm: {- $config{build_file_template} -} $(SRCDIR)\Configure
147         @echo "Detected changed: $?"
148         @echo "Reconfiguring..."
149         $(PERL) $(SRCDIR)\Configure reconf
150         @echo "**************************************************"
151         @echo "***                                            ***"
152         @echo "***   Please run the same make command again   ***"
153         @echo "***                                            ***"
154         @echo "**************************************************"
155         @( exit 1 )
156
157 {-
158  use File::Basename;
159  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
160
161  # Helper function to figure out dependencies on libraries
162  # It takes a list of library names and outputs a list of dependencies
163  sub compute_lib_depends {
164      if ($disabled{shared}) {
165          return map { $_.$libext } @_;
166      }
167      return map { shlib_import($_) } @_;
168  }
169
170   sub generatesrc {
171       my %args = @_;
172       (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
173       my $generator = join(" ", @{$args{generator}});
174       my $incs = join("", map { " /I ".$_ } @{$args{incs}});
175
176       if ($target !~ /\.asm$/) {
177           return <<"EOF";
178 $target: $args{generator}->[0]
179         \$(PERL) $generator > \$@
180 EOF
181       } else {
182           if ($args{generator}->[0] =~ /\.pl$/) {
183               $generator = '$(PERL) '.$generator;
184           } elsif ($args{generator}->[0] =~ /\.S$/) {
185               $generator = undef;
186           } else {
187               die "Generator type for $src unknown: $generator\n";
188           }
189
190           if (defined($generator)) {
191               # If the target is named foo.S in build.info, we want to
192               # end up generating foo.s in two steps.
193               if ($args{src} =~ /\.S$/) {
194                    return <<"EOF";
195 $target: $args{generator}->[0]
196         set ASM=\$(AS)
197         set CC=\$(CC)
198         $generator \$@.S
199         \$(CC) \$(CFLAGS) $incs /EP /C \$@.S > \$@
200         del /Q \$@.S
201 EOF
202               }
203               # Otherwise....
204               return <<"EOF";
205 $target: $args{generator}->[0]
206         set ASM=\$(AS)
207         set CC=\$(CC)
208         $generator \$@
209 EOF
210           }
211           return <<"EOF";
212 $target: $args{generator}->[0]
213         \$(CC) \$(CFLAGS) $incs /EP /C \$< > \$@
214 EOF
215       }
216   }
217
218  sub src2obj {
219      my %args = @_;
220      my $obj = $args{obj};
221      my @srcs = map { (my $x = $_) =~ s/\.[sS]$/.asm/; $x } ( @{$args{srcs}} );
222      my $srcs = join(" ",  @srcs);
223      my $deps = join(" ", @srcs, @{$args{deps}});
224      my $incs = join("", map { " /I ".$_ } @{$args{incs}});
225      my $ecflags = { lib => '$(LIB_CFLAGS)',
226                      dso => '$(DSO_CFLAGS)',
227                      bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
228      my $makedepprog = $config{makedepprog};
229      if ($srcs[0] =~ /\.asm$/) {
230          return <<"EOF";
231 $obj$objext: $deps
232         \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
233 EOF
234      }
235      return <<"EOF";
236 $obj$depext: $deps
237         \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
238             \$(PERL) -n << > $obj$depext
239 chomp;
240 s/^Note: including file: *//;
241 \$\$collect{\$\$_} = 1;
242 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
243 <<KEEP
244 $obj$objext: $obj$depext
245         \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ @<<
246 $srcs
247 <<KEEP
248 EOF
249  }
250
251  # On Unix, we build shlibs from static libs, so we're ignoring the
252  # object file array.  We *know* this routine is only called when we've
253  # configure 'shared'.
254  sub libobj2shlib {
255      my %args = @_;
256      my $lib = $args{lib};
257      my $shlib = $args{shlib};
258      (my $mkdef_key = $lib) =~ s/^lib//i;
259      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
260      my $linklibs = join("",
261                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
262      my $deps = join(" ",
263                      (map { $_.$objext } @{$args{objs}}),
264                      compute_lib_depends(@{$args{deps}}));
265      my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
266      my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
267                                             "util", "mkdef.pl")),
268                             rel2abs($config{builddir}));
269      my $target = shlib_import($lib);
270      return <<"EOF"
271 $target: $deps $ordinalsfile
272         \$(PERL) $mkdef_pl "$mkdef_key" 32 > $shlib.def
273         \$(LD) \$(LDFLAGS) \$(SHARED_LDFLAGS) \\
274                 /implib:$target \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<<
275 $objs$linklibs \$(EX_LIBS)
276 <<
277 EOF
278  }
279  sub obj2dso {
280      my %args = @_;
281      my $dso = $args{lib};
282      my $dso_n = basename($dso);
283      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
284      my $linklibs = join("",
285                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
286      my $deps = join(" ",
287                      (map { $_.$objext } @{$args{objs}}),
288                      compute_lib_depends(@{$args{deps}}));
289      return <<"EOF";
290 $dso$dsoext: $deps
291         \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
292 LIBRARY         $dso_n
293 EXPORTS
294     bind_engine         @1
295     v_check             @2
296 <<
297 $objs$linklibs \$(EX_LIBS)
298 <<
299 EOF
300  }
301  sub obj2lib {
302      # Because static libs and import libs are both named the same in native
303      # Windows, we can't have both.  We skip the static lib in that case,
304      # as the shared libs are what we use anyway.
305      return "" unless $disabled{"shared"};
306
307      my %args = @_;
308      my $lib = $args{lib};
309      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
310      my $deps = join(" ", map { $_.$objext } @{$args{objs}});
311      return <<"EOF";
312 $lib$libext: $deps
313         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
314 $objs
315 <<
316 EOF
317  }
318  sub obj2bin {
319      my %args = @_;
320      my $bin = $args{bin};
321      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
322      my $linklibs = join("",
323                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
324      my $deps = join(" ",
325                      (map { $_.$objext } @{$args{objs}}),
326                      compute_lib_depends(@{$args{deps}}));
327      return <<"EOF";
328 $bin$exeext: $deps
329         \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
330 $objs setargv.obj$linklibs \$(EX_LIBS)
331 <<
332 EOF
333   }
334   sub in2script {
335       my %args = @_;
336       my $script = $args{script};
337       my $sources = join(" ", @{$args{sources}});
338       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
339                                            "util", "dofile.pl")),
340                            rel2abs($config{builddir}));
341       return <<"EOF";
342 $script: $sources
343         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
344             "-o$target{build_file}" $sources > "$script"
345 EOF
346   }
347   ""    # Important!  This becomes part of the template result.
348 -}