Communicate Configure generated header files to build files
[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  my $win_installenv =
15      $target{build_scheme}->[2] eq "VC-W32" ?
16      "ProgramFiles(x86)" : "ProgramW6432";
17  my $win_commonenv =
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';
23  our $win_commonroot =
24      defined($ENV{$win_commonenv})
25      ? $win_commonenv : 'CommonProgramFiles';
26
27  # expand variables early
28  $win_installroot = $ENV{$win_installroot};
29  $win_commonroot = $ENV{$win_commonroot};
30
31  sub shlib {
32      return () if $disabled{shared};
33      my $lib = shift;
34      return $unified_info{sharednames}->{$lib} . $shlibext;
35  }
36
37  sub shlib_import {
38      return () if $disabled{shared};
39      my $lib = shift;
40      return $lib . $shlibextimport;
41  }
42
43  sub dso {
44      my $dso = shift;
45
46      return $dso . $dsoext;
47  }
48  '';
49 -}
50
51 PLATFORM={- $config{target} -}
52 SRCDIR={- $config{sourcedir} -}
53 BLDDIR={- $config{builddir} -}
54
55 VERSION={- $config{version} -}
56 MAJOR={- $config{major} -}
57 MINOR={- $config{minor} -}
58
59 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
60
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}; "" -}
74
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}} )) -}
86
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
90               #
91               our $prefix = $config{prefix} || "$win_installroot\\OpenSSL";
92               $prefix -}
93 OPENSSLDIR={- #
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.
101               #
102               use File::Spec::Functions;
103               our $openssldir =
104                   $config{openssldir} ?
105                       (file_name_is_absolute($config{openssldir}) ?
106                            $config{openssldir}
107                            : catdir($prefix, $config{openssldir}))
108                       : "$win_commonroot\\SSL";
109               $openssldir -}
110 LIBDIR={- our $libdir = $config{libdir} || "lib";
111           $libdir -}
112 ENGINESDIR={- use File::Spec::Functions;
113               our $enginesdir = catdir($prefix,$libdir,"engines");
114               $enginesdir -}
115
116 CC={- $target{cc} -}
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} -}
131
132 PERL={- $config{perl} -}
133
134 AR={- $target{ar} -}
135 ARFLAGS= {- $target{arflags} -}
136 AROUTFLAG={- $target{aroutflag} || "/out:" -}
137
138 AS={- $target{as} -}
139 ASFLAGS={- $target{asflags} -}
140 ASOUTFLAG={- $target{asoutflag} -}
141 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
142
143 PROCESSOR= {- $config{processor} -}
144
145 # The main targets ###################################################
146
147 all: configdata.pm build_libs_nodep build_engines_nodep build_apps_nodep depend
148
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)
157
158 test: tests
159 tests: build_tests_nodep build_apps_nodep build_engines_nodep depend
160         @rem {- output_off() if $disabled{tests}; "" -}
161         set SRCTOP=$(SRCDIR)
162         set BLDTOP=$(BLDDIR)
163         set PERL=$(PERL)
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}; "" -}
168
169 list-tests:
170         @set TOP=$(SRCDIR)
171         @set PERL=$(PERL)
172         @$(PERL) $(SRCDIR)\test\run_tests.pl list
173
174 install: install_sw install_ssldirs install_docs
175
176 uninstall: uninstall_docs uninstall_sw
177
178 libclean:
179         $(PERL) -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*"""; } @ARGV" $(SHLIBS)
180         -del /Q /F $(LIBS)
181         -del /Q ossl_static.pdb
182
183 clean: libclean
184         -del /Q /F $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
185         -del /Q /S /F $(GENERATED)
186         -del /Q /S /F *.d
187         -del /Q /S /F *.obj
188         -del /Q /S /F *.pdb
189         -del /Q /S /F *.exp
190         -del /Q /S /F engines\*.ilk
191         -del /Q /S /F engines\*.lib
192
193 depend:
194
195 # Install helper targets #############################################
196
197 install_sw: all install_dev install_engines install_runtime
198
199 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
200
201 install_docs:
202         $(PERL) $(SRCDIR)\util\process_docs.pl \
203                 "--destdir=$(DESTDIR)$(INSTALLTOP)\html" --type=html
204
205 uninstall_docs:
206
207 install_ssldirs:
208         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\certs"
209         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\private"
210         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\misc"
211         @$(PERL) $(SRCDIR)\util\copy.pl $(SRCDIR)\apps\openssl.cnf \
212                                        "$(DESTDIR)$(OPENSSLDIR)"
213         @$(PERL) $(SRCDIR)\util\copy.pl $(MISC_SCRIPTS) \
214                                         "$(DESTDIR)$(OPENSSLDIR)\misc"
215
216 install_dev:
217         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
218         @echo *** Installing development files
219         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\include\openssl"
220         @$(PERL) $(SRCDIR)\util\copy.pl $(SRCDIR)\include\openssl\*.h \
221                                        "$(DESTDIR)$(INSTALLTOP)\include\openssl"
222         @$(PERL) $(SRCDIR)\util\copy.pl $(BLDDIR)\include\openssl\*.h \
223                                        "$(DESTDIR)$(INSTALLTOP)\include\openssl"
224         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
225         @$(PERL) $(SRCDIR)\util\copy.pl $(LIBS) \
226                                        "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
227         @if "$(SHLIBS)"=="" \
228          $(PERL) $(SRCDIR)\util\copy.pl ossl_static.pdb \
229                                        "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
230
231 uninstall_dev:
232
233 install_engines:
234         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
235         @echo *** Installing engines
236         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(ENGINESDIR)"
237         @if not "$(ENGINES)"=="" \
238          $(PERL) $(SRCDIR)\util\copy.pl $(ENGINES) "$(DESTDIR)$(ENGINESDIR)"
239         @if not "$(ENGINES)"=="" \
240          $(PERL) $(SRCDIR)\util\copy.pl $(ENGINEPDBS) "$(DESTDIR)$(ENGINESDIR)"
241
242 uninstall_engines:
243
244 install_runtime:
245         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
246         @echo *** Installing runtime files
247         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\bin"
248         @if not "$(SHLIBS)"=="" \
249          $(PERL) $(SRCDIR)\util\copy.pl $(SHLIBS) "$(DESTDIR)$(INSTALLTOP)\bin"
250         @if not "$(SHLIBS)"=="" \
251          $(PERL) $(SRCDIR)\util\copy.pl $(SHLIBPDBS) \
252                                         "$(DESTDIR)$(INSTALLTOP)\bin"
253         @$(PERL) $(SRCDIR)\util\copy.pl $(PROGRAMS) \
254                                         "$(DESTDIR)$(INSTALLTOP)\bin"
255         @$(PERL) $(SRCDIR)\util\copy.pl $(PROGRAMPDBS) \
256                                         "$(DESTDIR)$(INSTALLTOP)\bin"
257         @$(PERL) $(SRCDIR)\util\copy.pl $(BIN_SCRIPTS) \
258                                         "$(DESTDIR)$(INSTALLTOP)\bin"
259
260 uninstall_runtime:
261
262 # Building targets ###################################################
263
264 configdata.pm: {- $config{build_file_template} -} $(SRCDIR)\Configure
265         @echo "Detected changed: $?"
266         @echo "Reconfiguring..."
267         $(PERL) $(SRCDIR)\Configure reconf
268         @echo "**************************************************"
269         @echo "***                                            ***"
270         @echo "***   Please run the same make command again   ***"
271         @echo "***                                            ***"
272         @echo "**************************************************"
273         @exit 1
274
275 {-
276  use File::Basename;
277  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
278
279  # Helper function to figure out dependencies on libraries
280  # It takes a list of library names and outputs a list of dependencies
281  sub compute_lib_depends {
282      if ($disabled{shared}) {
283          return map { $_.$libext } @_;
284      }
285      return map { shlib_import($_) } @_;
286  }
287
288   sub generatesrc {
289       my %args = @_;
290       (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
291       my $generator = join(" ", @{$args{generator}});
292       my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
293       my $incs = join("", map { " /I ".$_ } @{$args{incs}});
294       my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
295
296       if ($target !~ /\.asm$/) {
297           return <<"EOF";
298 $target: $args{generator}->[0] $deps
299         \$(PERL)$generator_incs $generator > \$@
300 EOF
301       } else {
302           if ($args{generator}->[0] =~ /\.pl$/) {
303               $generator = '$(PERL)'.$generator_incs.' '.$generator;
304           } elsif ($args{generator}->[0] =~ /\.S$/) {
305               $generator = undef;
306           } else {
307               die "Generator type for $src unknown: $generator\n";
308           }
309
310           if (defined($generator)) {
311               # If the target is named foo.S in build.info, we want to
312               # end up generating foo.s in two steps.
313               if ($args{src} =~ /\.S$/) {
314                    return <<"EOF";
315 $target: $args{generator}->[0] $deps
316         set ASM=\$(AS)
317         $generator \$@.S
318         \$(CC) \$(CFLAGS) $incs /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
319         del /Q \$@.S
320 EOF
321               }
322               # Otherwise....
323               return <<"EOF";
324 $target: $args{generator}->[0] $deps
325         set ASM=\$(AS)
326         $generator \$@
327 EOF
328           }
329           return <<"EOF";
330 $target: $args{generator}->[0] $deps
331         \$(CC) \$(CFLAGS) $incs /EP /C $args{generator}->[0] > \$@.i && move /Y \$@.i \$@
332 EOF
333       }
334   }
335
336  sub src2obj {
337      my %args = @_;
338      my $obj = $args{obj};
339      my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
340                     } ( @{$args{srcs}} );
341      my $srcs = join(" ",  @srcs);
342      my $deps = join(" ", @srcs, @{$args{deps}});
343      my $incs = join("", map { " /I ".$_ } @{$args{incs}});
344      unless ($disabled{zlib}) {
345          if ($withargs{zlib_include}) {
346              $incs .= " /I ".$withargs{zlib_include};
347          }
348      }
349      my $ecflags = { lib => '$(LIB_CFLAGS)',
350                      dso => '$(DSO_CFLAGS)',
351                      bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
352      my $makedepprog = $config{makedepprog};
353      if ($srcs[0] =~ /\.asm$/) {
354          return <<"EOF";
355 $obj$objext: $deps
356         \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
357 EOF
358      }
359      return <<"EOF"     if (!$disabled{makedepend});
360 $obj$depext: $deps
361         \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
362             \$(PERL) -n << > $obj$depext
363 chomp;
364 s/^Note: including file: *//;
365 \$\$collect{\$\$_} = 1;
366 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
367 <<
368 $obj$objext: $obj$depext
369         \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ @<<
370 $srcs
371 <<
372 EOF
373     return <<"EOF"      if ($disabled{makedepend});
374 $obj$objext: $deps
375         \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ $srcs
376 EOF
377  }
378
379  # On Unix, we build shlibs from static libs, so we're ignoring the
380  # object file array.  We *know* this routine is only called when we've
381  # configure 'shared'.
382  sub libobj2shlib {
383      my %args = @_;
384      my $lib = $args{lib};
385      my $shlib = $args{shlib};
386      (my $mkdef_key = $lib) =~ s/^lib//i;
387      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
388      my $linklibs = join("",
389                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
390      my $deps = join(" ",
391                      (map { $_.$objext } @{$args{objs}}),
392                      compute_lib_depends(@{$args{deps}}));
393      my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
394      my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
395                                             "util", "mkdef.pl")),
396                             rel2abs($config{builddir}));
397      my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
398                                            "util", "mkrc.pl")),
399                            rel2abs($config{builddir}));
400      my $target = shlib_import($lib);
401      return <<"EOF"
402 $target: $deps $ordinalsfile $mkdef_pl
403         \$(PERL) $mkdef_pl "$mkdef_key" 32 > $shlib.def
404         \$(PERL) -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
405         DEL $shlib.def.tmp
406         \$(PERL) $mkrc_pl $shlib$shlibext > $shlib.rc
407         \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
408         \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
409                 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
410 $objs $shlib.res$linklibs \$(EX_LIBS)
411 <<
412         IF EXIST apps\\$shlib$shlibext DEL /Q /F apps\\$shlib$shlibext
413         IF EXIST test\\$shlib$shlibext DEL /Q /F test\\$shlib$shlibext
414         COPY $shlib$shlibext apps
415         COPY $shlib$shlibext test
416 EOF
417  }
418  sub obj2dso {
419      my %args = @_;
420      my $dso = $args{lib};
421      my $dso_n = basename($dso);
422      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
423      my $linklibs = join("",
424                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
425      my $deps = join(" ",
426                      (map { $_.$objext } @{$args{objs}}),
427                      compute_lib_depends(@{$args{deps}}));
428      return <<"EOF";
429 $dso$dsoext: $deps
430         \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
431 LIBRARY         $dso_n
432 EXPORTS
433     bind_engine         @1
434     v_check             @2
435 <<
436 $objs$linklibs \$(EX_LIBS)
437 <<
438 EOF
439  }
440  sub obj2lib {
441      # Because static libs and import libs are both named the same in native
442      # Windows, we can't have both.  We skip the static lib in that case,
443      # as the shared libs are what we use anyway.
444      return "" unless $disabled{"shared"};
445
446      my %args = @_;
447      my $lib = $args{lib};
448      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
449      my $deps = join(" ", map { $_.$objext } @{$args{objs}});
450      return <<"EOF";
451 $lib$libext: $deps
452         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
453 \$\?
454 <<
455 EOF
456  }
457  sub obj2bin {
458      my %args = @_;
459      my $bin = $args{bin};
460      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
461      my $linklibs = join("",
462                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
463      my $deps = join(" ",
464                      (map { $_.$objext } @{$args{objs}}),
465                      compute_lib_depends(@{$args{deps}}));
466      return <<"EOF";
467 $bin$exeext: $deps
468         \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
469 $objs setargv.obj$linklibs \$(EX_LIBS)
470 <<
471 EOF
472   }
473   sub in2script {
474       my %args = @_;
475       my $script = $args{script};
476       my $sources = join(" ", @{$args{sources}});
477       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
478                                            "util", "dofile.pl")),
479                            rel2abs($config{builddir}));
480       return <<"EOF";
481 $script: $sources
482         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
483             "-o$target{build_file}" $sources > "$script"
484 EOF
485   }
486   ""    # Important!  This becomes part of the template result.
487 -}