make update
[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
142 tests: build_tests_nodep build_apps_nodep build_engines_nodep depend
143         @rem {- output_off() if $disabled{tests}; "" -}
144         set SRCTOP=$(SRCDIR)
145         set BLDTOP=$(BLDDIR)
146         set PERL=$(PERL)
147         $(PERL) $(SRCDIR)\test\run_tests.pl $(TESTS)
148         @rem {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
149         @echo "Tests are not supported with your chosen Configure options"
150         @rem {- output_on() if !$disabled{tests}; "" -}
151
152 list-tests:
153         @set TOP=$(SRCDIR)
154         @set PERL=$(PERL)
155         @$(PERL) $(SRCDIR)\test\run_tests.pl list
156
157 install: install_sw install_ssldirs install_docs
158
159 uninstall: uninstall_docs uninstall_sw
160
161 libclean:
162         $(PERL) -e "map { m/(.*)\.dll$$/; unlink glob """$$1.*""" } @ARGV" $(SHLIBS)
163         del /Q /F $(LIBS)
164         del lib.pdb
165
166 clean: libclean
167         del /Q /F $(PROGRAMS) $(TESTPROGS) $(ENGINES) $(SCRIPTS)
168         del /Q /S /F *.asm
169         del /Q /S /F *.d
170         del /Q /S /F *.obj
171         del /Q /S /F *.pdb
172         del /Q /S /F *.exp
173         del /Q /S /F engines\*.ilk
174         del /Q /S /F engines\*.lib
175
176 depend:
177
178 # Install helper targets #############################################
179
180 install_sw: all install_dev install_engines install_runtime
181
182 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
183
184 install_docs:
185
186 uninstall_docs:
187
188 install_ssldirs:
189         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\certs"
190         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(OPENSSLDIR)\private"
191
192 install_dev:
193         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
194         @echo *** Installing development files
195         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\include\openssl"
196         @$(PERL) $(SRCDIR)\util\copy.pl $(SRCDIR)\include\openssl\*.h \
197                                        "$(DESTDIR)$(INSTALLTOP)\include\openssl"
198         @$(PERL) $(SRCDIR)\util\copy.pl $(BLDDIR)\include\openssl\*.h \
199                                        "$(DESTDIR)$(INSTALLTOP)\include\openssl"
200         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
201         @$(PERL) $(SRCDIR)\util\copy.pl $(LIBS) \
202                                        "$(DESTDIR)$(INSTALLTOP)\$(LIBDIR)"
203
204 uninstall_dev:
205
206 install_engines:
207         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
208         @echo *** Installing engines
209         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(ENGINESDIR)"
210         @if not "$(ENGINES)"=="" \
211          $(PERL) $(SRCDIR)\util\copy.pl $(ENGINES) "$(DESTDIR)$(ENGINESDIR)"
212
213 uninstall_engines:
214
215 install_runtime:
216         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
217         @echo *** Installing runtime files
218         @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(INSTALLTOP)\bin"
219         @if not "$(SHLIBS)"=="" \
220          $(PERL) $(SRCDIR)\util\copy.pl $(SHLIBS) "$(DESTDIR)$(INSTALLTOP)\bin"
221         @$(PERL) $(SRCDIR)\util\copy.pl $(PROGRAMS) "$(DESTDIR)$(INSTALLTOP)\bin"
222
223 uninstall_runtime:
224
225 # Building targets ###################################################
226
227 configdata.pm: {- $config{build_file_template} -} $(SRCDIR)\Configure
228         @echo "Detected changed: $?"
229         @echo "Reconfiguring..."
230         $(PERL) $(SRCDIR)\Configure reconf
231         @echo "**************************************************"
232         @echo "***                                            ***"
233         @echo "***   Please run the same make command again   ***"
234         @echo "***                                            ***"
235         @echo "**************************************************"
236         @exit 1
237
238 {-
239  use File::Basename;
240  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
241
242  # Helper function to figure out dependencies on libraries
243  # It takes a list of library names and outputs a list of dependencies
244  sub compute_lib_depends {
245      if ($disabled{shared}) {
246          return map { $_.$libext } @_;
247      }
248      return map { shlib_import($_) } @_;
249  }
250
251   sub generatesrc {
252       my %args = @_;
253       (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
254       my $generator = join(" ", @{$args{generator}});
255       my $generator_incs = join("", map { " -I".$_ } @{$args{generator_incs}});
256       my $incs = join("", map { " /I ".$_ } @{$args{incs}});
257       my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}});
258
259       if ($target !~ /\.asm$/) {
260           return <<"EOF";
261 $target: $args{generator}->[0] $deps
262         \$(PERL)$generator_incs $generator > \$@
263 EOF
264       } else {
265           if ($args{generator}->[0] =~ /\.pl$/) {
266               $generator = '$(PERL)'.$generator_incs.' '.$generator;
267           } elsif ($args{generator}->[0] =~ /\.S$/) {
268               $generator = undef;
269           } else {
270               die "Generator type for $src unknown: $generator\n";
271           }
272
273           if (defined($generator)) {
274               # If the target is named foo.S in build.info, we want to
275               # end up generating foo.s in two steps.
276               if ($args{src} =~ /\.S$/) {
277                    return <<"EOF";
278 $target: $args{generator}->[0] $deps
279         set ASM=\$(AS)
280         set CC=\$(CC)
281         $generator \$@.S
282         \$(CC) \$(CFLAGS) $incs /EP /C \$@.S > \$@.i && move /Y \$@.i \$@
283         del /Q \$@.S
284 EOF
285               }
286               # Otherwise....
287               return <<"EOF";
288 $target: $args{generator}->[0] $deps
289         set ASM=\$(AS)
290         set CC=\$(CC)
291         $generator \$@
292 EOF
293           }
294           return <<"EOF";
295 $target: $args{generator}->[0] $deps
296         \$(CC) \$(CFLAGS) $incs /EP /C $args{generator}->[0] > \$@.i && move /Y \$@.i \$@
297 EOF
298       }
299   }
300
301  sub src2obj {
302      my %args = @_;
303      my $obj = $args{obj};
304      my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
305                     } ( @{$args{srcs}} );
306      my $srcs = join(" ",  @srcs);
307      my $deps = join(" ", @srcs, @{$args{deps}});
308      my $incs = join("", map { " /I ".$_ } @{$args{incs}});
309      unless ($disabled{zlib}) {
310          if ($withargs{zlib_include}) {
311              $incs .= " /I ".$withargs{zlib_include};
312          }
313      }
314      my $ecflags = { lib => '$(LIB_CFLAGS)',
315                      dso => '$(DSO_CFLAGS)',
316                      bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
317      my $makedepprog = $config{makedepprog};
318      if ($srcs[0] =~ /\.asm$/) {
319          return <<"EOF";
320 $obj$objext: $deps
321         \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)\$\@ $srcs
322 EOF
323      }
324      return <<"EOF"     if (!$disabled{makedepend});
325 $obj$depext: $deps
326         \$(CC) \$(CFLAGS) $ecflags$inc /Zs /showIncludes $srcs 2>&1 | \\
327             \$(PERL) -n << > $obj$depext
328 chomp;
329 s/^Note: including file: *//;
330 \$\$collect{\$\$_} = 1;
331 END { print '$obj$objext: ',join(" ", sort keys \%collect),"\\n" }
332 <<
333 $obj$objext: $obj$depext
334         \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ @<<
335 $srcs
336 <<
337 EOF
338     return <<"EOF"      if ($disabled{makedepend});
339 $obj$objext: $deps
340         \$(CC) \$(CFLAGS) $ecflags$incs -c \$(COUTFLAG)\$\@ $srcs
341 EOF
342  }
343
344  # On Unix, we build shlibs from static libs, so we're ignoring the
345  # object file array.  We *know* this routine is only called when we've
346  # configure 'shared'.
347  sub libobj2shlib {
348      my %args = @_;
349      my $lib = $args{lib};
350      my $shlib = $args{shlib};
351      (my $mkdef_key = $lib) =~ s/^lib//i;
352      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
353      my $linklibs = join("",
354                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
355      my $deps = join(" ",
356                      (map { $_.$objext } @{$args{objs}}),
357                      compute_lib_depends(@{$args{deps}}));
358      my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
359      my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
360                                             "util", "mkdef.pl")),
361                             rel2abs($config{builddir}));
362      my $mkrc_pl = abs2rel(rel2abs(catfile($config{sourcedir},
363                                            "util", "mkrc.pl")),
364                            rel2abs($config{builddir}));
365      my $target = shlib_import($lib);
366      return <<"EOF"
367 $target: $deps $ordinalsfile $mkdef_pl
368         \$(PERL) $mkdef_pl "$mkdef_key" 32 > $shlib.def
369         \$(PERL) -i.tmp -pe "s|^LIBRARY\\s+${mkdef_key}32|LIBRARY $shlib|;" $shlib.def
370         DEL $shlib.def.tmp
371         \$(PERL) $mkrc_pl $shlib$shlibext > $shlib.rc
372         \$(RC) \$(RCOUTFLAG)$shlib.res $shlib.rc
373         \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
374                 /implib:\$@ \$(LDOUTFLAG)$shlib$shlibext /def:$shlib.def @<< || (DEL /Q \$(\@B).* $shlib.* && EXIT 1)
375 $objs $shlib.res$linklibs \$(EX_LIBS)
376 <<
377         DEL /F apps\\$shlib$shlibext
378         DEL /F test\\$shlib$shlibext
379         COPY $shlib$shlibext apps
380         COPY $shlib$shlibext test
381 EOF
382  }
383  sub obj2dso {
384      my %args = @_;
385      my $dso = $args{lib};
386      my $dso_n = basename($dso);
387      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
388      my $linklibs = join("",
389                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
390      my $deps = join(" ",
391                      (map { $_.$objext } @{$args{objs}}),
392                      compute_lib_depends(@{$args{deps}}));
393      return <<"EOF";
394 $dso$dsoext: $deps
395         \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
396 LIBRARY         $dso_n
397 EXPORTS
398     bind_engine         @1
399     v_check             @2
400 <<
401 $objs$linklibs \$(EX_LIBS)
402 <<
403 EOF
404  }
405  sub obj2lib {
406      # Because static libs and import libs are both named the same in native
407      # Windows, we can't have both.  We skip the static lib in that case,
408      # as the shared libs are what we use anyway.
409      return "" unless $disabled{"shared"};
410
411      my %args = @_;
412      my $lib = $args{lib};
413      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
414      my $deps = join(" ", map { $_.$objext } @{$args{objs}});
415      return <<"EOF";
416 $lib$libext: $deps
417         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib$libext @<<
418 \$\?
419 <<
420 EOF
421  }
422  sub obj2bin {
423      my %args = @_;
424      my $bin = $args{bin};
425      my $objs = join("\n", map { $_.$objext } @{$args{objs}});
426      my $linklibs = join("",
427                          map { "\n$_" } compute_lib_depends(@{$args{deps}}));
428      my $deps = join(" ",
429                      (map { $_.$objext } @{$args{objs}}),
430                      compute_lib_depends(@{$args{deps}}));
431      return <<"EOF";
432 $bin$exeext: $deps
433         \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
434 $objs setargv.obj$linklibs \$(EX_LIBS)
435 <<
436 EOF
437   }
438   sub in2script {
439       my %args = @_;
440       my $script = $args{script};
441       my $sources = join(" ", @{$args{sources}});
442       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
443                                            "util", "dofile.pl")),
444                            rel2abs($config{builddir}));
445       return <<"EOF";
446 $script: $sources
447         \$(PERL) "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
448             "-o$target{build_file}" $sources > "$script"
449 EOF
450   }
451   ""    # Important!  This becomes part of the template result.
452 -}