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