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