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