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