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