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