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