Configurations/windows-makefile.tmpl: HTMLDOCS are files, not directories
[openssl.git] / Configurations / windows-makefile.tmpl
1 ##
2 ## Makefile for OpenSSL
3 ##
4 ## {- join("\n## ", @autowarntext) -}
5 {-
6  use File::Basename;
7
8  our $sover_dirname = platform->shlib_version_as_filename();
9
10  my $build_scheme = $target{build_scheme};
11  my $install_flavour = $build_scheme->[$#$build_scheme]; # last element
12  my $win_installenv =
13      $install_flavour eq "VC-WOW" ? "ProgramFiles(x86)"
14                                   : "ProgramW6432";
15  my $win_commonenv =
16      $install_flavour eq "VC-WOW" ? "CommonProgramFiles(x86)"
17                                   : "CommonProgramW6432";
18  our $win_installroot =
19      defined($ENV{$win_installenv}) ? $win_installenv : 'ProgramFiles';
20  our $win_commonroot =
21      defined($ENV{$win_commonenv}) ? $win_commonenv : 'CommonProgramFiles';
22
23  # expand variables early
24  $win_installroot = $ENV{$win_installroot};
25  $win_commonroot = $ENV{$win_commonroot};
26
27  # This makes sure things get built in the order they need
28  # to. You're welcome.
29  sub dependmagic {
30      my $target = shift;
31
32      return "$target: build_generated\n\t\$(MAKE) /\$(MAKEFLAGS) depend && \$(MAKE) /\$(MAKEFLAGS) _$target\n_$target";
33  }
34  '';
35 -}
36
37 PLATFORM={- $config{target} -}
38 SRCDIR={- $config{sourcedir} -}
39 BLDDIR={- $config{builddir} -}
40
41 VERSION={- "$config{full_version}" -}
42 MAJOR={- $config{major} -}
43 MINOR={- $config{minor} -}
44
45 SHLIB_VERSION_NUMBER={- $config{shlib_version} -}
46
47 LIBS={- join(" ", map { ( platform->sharedlib_import($_), platform->staticlib($_) ) } @{$unified_info{libraries}}) -}
48 SHLIBS={- join(" ", map { platform->sharedlib($_) // () } @{$unified_info{libraries}}) -}
49 SHLIBPDBS={- join(" ", map { platform->sharedlibpdb($_) // () } @{$unified_info{libraries}}) -}
50 MODULES={- join(" ", map { platform->dso($_) } @{$unified_info{modules}}) -}
51 MODULEPDBS={- join(" ", map { platform->dsopdb($_) } @{$unified_info{modules}}) -}
52 PROGRAMS={- our @PROGRAMS = map { platform->bin($_) } @{$unified_info{programs}}; join(" ", @PROGRAMS) -}
53 PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -}
54 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
55 {- output_off() if $disabled{makedepend}; "" -}
56 DEPS={- join(" ", map { platform->isobj($_) ? platform->dep($_) : () }
57                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
58                   keys %{$unified_info{sources}}); -}
59 {- output_on() if $disabled{makedepend}; "" -}
60 GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
61 GENERATED={- # common0.tmpl provides @generated
62              join(" ", map { platform->convertext($_) } @generated) -}
63
64 INSTALL_LIBS={-
65         join(" ", map { quotify1(platform->sharedlib_import($_)
66                                  // platform->staticlib($_)) }
67                   grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
68                   @{$unified_info{libraries}})
69 -}
70 INSTALL_SHLIBS={-
71         join(" ", map { my $x = platform->sharedlib($_);
72                         $x ? quotify_l($x) : () }
73                   grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
74                   @{$unified_info{libraries}})
75 -}
76 INSTALL_SHLIBPDBS={-
77         join(" ", map { my $x = platform->sharedlibpdb($_);
78                         $x ? quotify_l($x) : () }
79                   grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
80                   @{$unified_info{libraries}})
81 -}
82 INSTALL_ENGINES={-
83         join(" ", map { quotify1(platform->dso($_)) }
84                   grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
85                          && $unified_info{attributes}->{modules}->{$_}->{engine} }
86                   @{$unified_info{modules}})
87 -}
88 INSTALL_ENGINEPDBS={-
89         join(" ", map { quotify1(platform->dsopdb($_)) }
90                   grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
91                          && $unified_info{attributes}->{modules}->{$_}->{engine} }
92                   @{$unified_info{modules}})
93 -}
94 INSTALL_PROGRAMS={-
95         join(" ", map { quotify1(platform->bin($_)) }
96                   grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
97                   @{$unified_info{programs}})
98 -}
99 INSTALL_PROGRAMPDBS={-
100         join(" ", map { quotify1(platform->binpdb($_)) }
101                   grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
102                   @{$unified_info{programs}})
103 -}
104 BIN_SCRIPTS={-
105         join(" ", map { quotify1($_) }
106                   grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
107                          && !$unified_info{attributes}->{scripts}->{$_}->{misc} }
108                   @{$unified_info{scripts}})
109 -}
110 MISC_SCRIPTS={-
111         join(" ", map { quotify1($_) }
112                   grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
113                          && $unified_info{attributes}->{scripts}->{$_}->{misc} }
114                   @{$unified_info{scripts}})
115 -}
116 HTMLDOCS1={- our @HTMLDOCS1 = @{$unified_info{htmldocs}->{man1}};
117              join(" ", @HTMLDOCS1) -}
118 HTMLDOCS3={- our @HTMLDOCS3 = @{$unified_info{htmldocs}->{man3}};
119              join(" ", @HTMLDOCS3) -}
120 HTMLDOCS5={- our @HTMLDOCS5 = @{$unified_info{htmldocs}->{man5}};
121              join(" ", @HTMLDOCS5) -}
122 HTMLDOCS7={- our @HTMLDOCS7 = @{$unified_info{htmldocs}->{man7}};
123              join(" ", @HTMLDOCS7) -}
124 HTMLDOCS1_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS1;
125                      join(' ', sort keys %dirs) -}
126 HTMLDOCS3_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS3;
127                      join(' ', sort keys %dirs) -}
128 HTMLDOCS5_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS5;
129                      join(' ', sort keys %dirs) -}
130 HTMLDOCS7_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS7;
131                      join(' ', sort keys %dirs) -}
132
133 APPS_OPENSSL={- use File::Spec::Functions;
134                 "\"".catfile("apps","openssl")."\"" -}
135
136 # Do not edit these manually. Use Configure with --prefix or --openssldir
137 # to change this!  Short explanation in the top comment in Configure
138 INSTALLTOP_dev={- # $prefix is used in the OPENSSLDIR perl snippet
139                   #
140                   use File::Spec::Functions qw(:DEFAULT splitpath);
141                   our $prefix = canonpath($config{prefix}
142                                           || "$win_installroot\\OpenSSL");
143                   our ($prefix_dev, $prefix_dir, $prefix_file) =
144                       splitpath($prefix, 1);
145                   $prefix_dev -}
146 INSTALLTOP_dir={- canonpath($prefix_dir) -}
147 OPENSSLDIR_dev={- #
148                   # The logic here is that if no --openssldir was given,
149                   # OPENSSLDIR will get the value "$win_commonroot\\SSL".
150                   # If --openssldir was given and the value is an absolute
151                   # path, OPENSSLDIR will get its value without change.
152                   # If the value from --openssldir is a relative path,
153                   # OPENSSLDIR will get $prefix with the --openssldir
154                   # value appended as a subdirectory.
155                   #
156                   use File::Spec::Functions qw(:DEFAULT splitpath);
157                   our $openssldir =
158                       $config{openssldir} ?
159                           (file_name_is_absolute($config{openssldir}) ?
160                                canonpath($config{openssldir})
161                                : catdir($prefix, $config{openssldir}))
162                           : canonpath("$win_commonroot\\SSL");
163                   our ($openssldir_dev, $openssldir_dir, $openssldir_file) =
164                       splitpath($openssldir, 1);
165                   $openssldir_dev -}
166 OPENSSLDIR_dir={- canonpath($openssldir_dir) -}
167 LIBDIR={- our $libdir = $config{libdir} || "lib";
168           file_name_is_absolute($libdir) ? "" : $libdir -}
169 MODULESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath catpath);
170                   our $modulesprefix = catdir($prefix,$libdir);
171                   our ($modulesprefix_dev, $modulesprefix_dir,
172                        $modulesprefix_file) =
173                       splitpath($modulesprefix, 1);
174                   our $modulesdir_dev = $modulesprefix_dev;
175                   our $modulesdir_dir =
176                       catdir($modulesprefix_dir, "ossl-modules");
177                   our $modulesdir = catpath($modulesdir_dev, $modulesdir_dir);
178                   our $enginesdir_dev = $modulesprefix_dev;
179                   our $enginesdir_dir =
180                       catdir($modulesprefix_dir, "engines-$sover_dirname");
181                   our $enginesdir = catpath($enginesdir_dev, $enginesdir_dir);
182                   $modulesdir_dev -}
183 MODULESDIR_dir={- canonpath($modulesdir_dir) -}
184 ENGINESDIR_dev={- $enginesdir_dev -}
185 ENGINESDIR_dir={- canonpath($enginesdir_dir) -}
186 !IF "$(DESTDIR)" != ""
187 INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir)
188 OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir)
189 ENGINESDIR=$(DESTDIR)$(ENGINESDIR_dir)
190 MODULESDIR=$(DESTDIR)$(MODULESDIR_dir)
191 !ELSE
192 INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
193 OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
194 ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
195 MODULESDIR=$(MODULESDIR_dev)$(MODULESDIR_dir)
196 !ENDIF
197
198 # $(libdir) is chosen to be compatible with the GNU coding standards
199 libdir={- file_name_is_absolute($libdir)
200           ? $libdir : '$(INSTALLTOP)\$(LIBDIR)' -}
201
202 ##### User defined commands and flags ################################
203
204 CC="{- $config{CC} -}"
205 CPP="{- $config{CPP} -}"
206 CPPFLAGS={- our $cppflags1 = join(" ",
207                                   (map { "-D".$_} @{$config{CPPDEFINES}}),
208                                   (map { " -I ".$_} @{$config{CPPINCLUDES}}),
209                                   @{$config{CPPFLAGS}}) -}
210 CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
211 LD="{- $config{LD} -}"
212 LDFLAGS={- join(' ', @{$config{LDFLAGS}}) -}
213 EX_LIBS={- join(' ', @{$config{LDLIBS}}) -}
214
215 PERL={- $config{PERL} -}
216
217 AR="{- $config{AR} -}"
218 ARFLAGS= {- join(' ', @{$config{ARFLAGS}}) -}
219
220 MT="{- $config{MT} -}"
221 MTFLAGS= {- join(' ', @{$config{MTFLAGS}}) -}
222
223 AS="{- $config{AS} -}"
224 ASFLAGS={- join(' ', @{$config{ASFLAGS}}) -}
225
226 RC="{- $config{RC} -}"
227 RCFLAGS={- join(' ', @{$config{RCFLAGS}}) -}
228
229 ECHO="$(PERL)" "$(SRCDIR)\util\echo.pl"
230
231 ##### Special command flags ##########################################
232
233 COUTFLAG={- $target{coutflag} -}$(OSSL_EMPTY)
234 LDOUTFLAG={- $target{ldoutflag} -}$(OSSL_EMPTY)
235 AROUTFLAG={- $target{aroutflag} -}$(OSSL_EMPTY)
236 MTINFLAG={- $target{mtinflag} -}$(OSSL_EMPTY)
237 MTOUTFLAG={- $target{mtoutflag} -}$(OSSL_EMPTY)
238 ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
239 RCOUTFLAG={- $target{rcoutflag} -}$(OSSL_EMPTY)
240
241 ##### Project flags ##################################################
242
243 # Variables starting with CNF_ are common variables for all product types
244
245 CNF_ASFLAGS={- join(' ', $target{asflags} || (),
246                          @{$config{asflags}}) -}
247 CNF_CPPFLAGS={- our $cppfags2 =
248                     join(' ', $target{cppflags} || (),
249                               (map { '-D'.quotify1($_) } @{$target{defines}},
250                                                          @{$config{defines}}),
251                               (map { '-I'.quotify1($_) } @{$target{includes}},
252                                                          @{$config{includes}}),
253                               @{$config{cppflags}}) -}
254 CNF_CFLAGS={- join(' ', $target{cflags} || (),
255                         @{$config{cflags}}) -}
256 CNF_CXXFLAGS={- join(' ', $target{cxxflags} || (),
257                           @{$config{cxxflags}}) -}
258 CNF_LDFLAGS={- join(' ', $target{lflags} || (),
259                          @{$config{lflags}}) -}
260 CNF_EX_LIBS={- join(' ', $target{ex_libs} || (),
261                          @{$config{ex_libs}}) -}
262
263 # Variables starting with LIB_ are used to build library object files
264 # and shared libraries.
265 # Variables starting with DSO_ are used to build DSOs and their object files.
266 # Variables starting with BIN_ are used to build programs and their object
267 # files.
268
269 LIB_ASFLAGS={- join(' ', $target{lib_asflags} || (),
270                          @{$config{lib_asflags}},
271                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
272 LIB_CPPFLAGS={- our $lib_cppflags =
273                 join(' ', $target{lib_cppflags} || (),
274                           $target{shared_cppflag} || (),
275                           (map { '-D'.quotify1($_) }
276                                @{$target{lib_defines}},
277                                @{$target{shared_defines}},
278                                @{$config{lib_defines}},
279                                @{$config{shared_defines}}),
280                           (map { '-I'.quotify1($_) }
281                                @{$target{lib_includes}},
282                                @{$target{shared_includes}},
283                                @{$config{lib_includes}},
284                                @{$config{shared_includes}}),
285                           @{$config{lib_cppflags}},
286                           @{$config{shared_cppflag}});
287                 join(' ', $lib_cppflags,
288                           (map { '-D'.quotify1($_) }
289                                "OPENSSLDIR=\"$openssldir\"",
290                                "ENGINESDIR=\"$enginesdir\"",
291                                "MODULESDIR=\"$modulesdir\""),
292                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
293 LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
294                         $target{shared_cflag} || (),
295                         @{$config{lib_cflags}},
296                         @{$config{shared_cflag}},
297                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
298 LIB_LDFLAGS={- join(' ', $target{shared_ldflag} || (),
299                          $config{shared_ldflag} || (),
300                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
301 LIB_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
302 DSO_ASFLAGS={- join(' ', $target{dso_asflags} || (),
303                          $target{module_asflags} || (),
304                          @{$config{dso_asflags}},
305                          @{$config{module_asflags}},
306                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
307 DSO_CPPFLAGS={- join(' ', $target{dso_cppflags} || (),
308                           $target{module_cppflag} || (),
309                           (map { '-D'.quotify1($_) }
310                                @{$target{dso_defines}},
311                                @{$target{module_defines}},
312                                @{$config{dso_defines}},
313                                @{$config{module_defines}}),
314                           (map { '-I'.quotify1($_) }
315                                @{$target{dso_includes}},
316                                @{$target{module_includes}},
317                                @{$config{dso_includes}},
318                                @{$config{module_includes}}),
319                           @{$config{dso_cppflags}},
320                           @{$config{module_cppflags}},
321                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
322 DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
323                         $target{module_cflags} || (),
324                         @{$config{dso_cflags}},
325                         @{$config{module_cflags}},
326                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
327 DSO_LDFLAGS={- join(' ', $target{dso_lflags} || (),
328                          $target{module_ldflags} || (),
329                          @{$config{dso_lflags}},
330                          @{$config{module_ldflags}},
331                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
332 DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
333 BIN_ASFLAGS={- join(' ', $target{bin_asflags} || (),
334                          @{$config{bin_asflags}},
335                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
336 BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
337                           @{$config{bin_cppflags}},
338                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
339 BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
340                         @{$config{bin_cflags}},
341                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
342 BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
343                          @{$config{bin_lflags}},
344                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
345 BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
346
347 # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
348 CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
349               $cppflags2 =~ s|([\\"])|\\$1|g;
350               join(' ', $lib_cppflags || (), $cppflags2 || (),
351                         $cppflags1 || ()) -}
352
353 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
354
355 PROCESSOR= {- $config{processor} -}
356
357 # The main targets ###################################################
358
359 {- dependmagic('build_sw'); -}: build_libs_nodep build_modules_nodep build_programs_nodep
360 {- dependmagic('build_libs'); -}: build_libs_nodep
361 {- dependmagic('build_modules'); -}: build_modules_nodep
362 {- dependmagic('build_programs'); -}: build_programs_nodep
363
364 build_docs: build_html_docs
365 build_html_docs: $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
366
367 build_generated: $(GENERATED_MANDATORY)
368 build_libs_nodep: $(LIBS) {- join(" ",map { platform->sharedlib_import($_) // () } @{$unified_info{libraries}}) -}
369 build_modules_nodep: $(MODULES)
370 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
371
372 # Kept around for backward compatibility
373 build_apps build_tests: build_programs
374
375 # Convenience target to prebuild all generated files, not just the mandatory
376 # ones
377 build_all_generated: $(GENERATED_MANDATORY) $(GENERATED) build_docs
378         @{- output_off() if $disabled{makedepend}; "" -}
379         @$(ECHO) "Warning: consider configuring with no-makedepend, because if"
380         @$(ECHO) "         target system doesn't have $(PERL),"
381         @$(ECHO) "         then make will fail..."
382         @{- output_on() if $disabled{makedepend}; "" -}
383
384 all: build_sw build_docs
385
386 test: tests
387 {- dependmagic('tests'); -}: build_programs_nodep build_modules_nodep
388         @{- output_off() if $disabled{tests}; "" -}
389         -mkdir $(BLDDIR)\test\test-runs
390         set SRCTOP=$(SRCDIR)
391         set BLDTOP=$(BLDDIR)
392         set RESULT_D=$(BLDDIR)\test\test-runs
393         set PERL=$(PERL)
394         set OPENSSL_ENGINES=$(MAKEDIR)\engines
395         set OPENSSL_MODULES=$(MAKEDIR)\providers
396         "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
397         @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
398         @$(ECHO) "Tests are not supported with your chosen Configure options"
399         @{- output_on() if !$disabled{tests}; "" -}
400
401 list-tests:
402         @{- output_off() if $disabled{tests}; "" -}
403         @set SRCTOP=$(SRCDIR)
404         @"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
405         @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
406         @$(ECHO) "Tests are not supported with your chosen Configure options"
407         @{- output_on() if !$disabled{tests}; "" -}
408
409 install: install_sw install_ssldirs install_docs
410
411 uninstall: uninstall_docs uninstall_sw
412
413 libclean:
414         "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """{.,apps,test,fuzz}/$$1.*"""; } @ARGV" $(SHLIBS)
415         -del /Q /F $(LIBS) libcrypto.* libssl.* ossl_static.pdb
416
417 clean: libclean
418         -rmdir /Q /S $(HTMLDOCS1_BLDDIRS)
419         -rmdir /Q /S $(HTMLDOCS3_BLDDIRS)
420         -rmdir /Q /S $(HTMLDOCS5_BLDDIRS)
421         -rmdir /Q /S $(HTMLDOCS7_BLDDIRS)
422         {- join("\n\t", map { "-del /Q /F $_" } @PROGRAMS) -}
423         -del /Q /F $(MODULES)
424         -del /Q /F $(SCRIPTS)
425         -del /Q /F $(GENERATED_MANDATORY)
426         -del /Q /F $(GENERATED)
427         -del /Q /S /F *.d *.obj *.pdb *.ilk *.manifest
428         -del /Q /S /F engines\*.lib engines\*.exp
429         -del /Q /S /F apps\*.lib apps\*.rc apps\*.res apps\*.exp
430         -del /Q /S /F test\*.exp
431         -rmdir /Q /S test\test-runs
432
433 distclean: clean
434         -del /Q /F configdata.pm
435         -del /Q /F makefile
436
437 depend:
438         @ {- output_off() if $disabled{makedepend}; "" -}
439         @ "$(PERL)" "$(SRCDIR)\util\add-depends.pl" "VC"
440         @ {- output_on() if $disabled{makedepend}; "" -}
441
442 # Install helper targets #############################################
443
444 install_sw: install_dev install_engines install_runtime
445
446 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
447
448 install_docs: install_html_docs
449
450 uninstall_docs: uninstall_html_docs
451
452 install_ssldirs:
453         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\certs"
454         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\private"
455         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\misc"
456         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
457                                         "$(OPENSSLDIR)\openssl.cnf.dist"
458         @IF NOT EXIST "$(OPENSSLDIR)\openssl.cnf" \
459          "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
460                                         "$(OPENSSLDIR)\openssl.cnf"
461         @if not "$(MISC_SCRIPTS)"=="" \
462          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
463                                         "$(OPENSSLDIR)\misc"
464         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
465                                         "$(OPENSSLDIR)\ct_log_list.cnf.dist"
466         @IF NOT EXIST "$(OPENSSLDIR)\ct_log_list.cnf" \
467          "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
468                                         "$(OPENSSLDIR)\ct_log_list.cnf"
469
470 install_dev: install_runtime_libs
471         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
472         @$(ECHO) "*** Installing development files"
473         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\include\openssl"
474         @{- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
475         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\ms\applink.c" \
476                                        "$(INSTALLTOP)\include\openssl"
477         @{- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
478         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "-exclude_re=/__DECC_" \
479                                        "$(SRCDIR)\include\openssl\*.h" \
480                                        "$(INSTALLTOP)\include\openssl"
481         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(BLDDIR)\include\openssl\*.h" \
482                                        "$(INSTALLTOP)\include\openssl"
483         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(libdir)"
484         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) "$(libdir)"
485         @if "$(SHLIBS)"=="" \
486          "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb "$(libdir)"
487
488 uninstall_dev:
489
490 install_engines: install_runtime_libs build_modules
491         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
492         @$(ECHO) "*** Installing ENGINE modules"
493         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(ENGINESDIR)"
494         @if not "$(INSTALL_ENGINES)"=="" \
495          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINES) "$(ENGINESDIR)"
496         @if not "$(INSTALL_ENGINES)"=="" \
497          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINEPDBS) "$(ENGINESDIR)"
498
499 uninstall_engines:
500
501 install_runtime: install_programs
502
503 install_runtime_libs: build_libs
504         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
505         @$(ECHO) "*** Installing runtime libraries"
506         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
507         @if not "$(SHLIBS)"=="" \
508          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBS) "$(INSTALLTOP)\bin"
509         @if not "$(SHLIBS)"=="" \
510          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBPDBS) \
511                                         "$(INSTALLTOP)\bin"
512
513 install_programs: install_runtime_libs build_programs
514         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
515         @$(ECHO) "*** Installing runtime programs"
516         @if not "$(INSTALL_PROGRAMS)"=="" \
517          "$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
518         @if not "$(INSTALL_PROGRAMS)"=="" \
519          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \
520                                         "$(INSTALLTOP)\bin"
521         @if not "$(INSTALL_PROGRAMS)"=="" \
522          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \
523                                         "$(INSTALLTOP)\bin"
524         @if not "$(INSTALL_PROGRAMS)"=="" \
525          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
526                                         "$(INSTALLTOP)\bin"
527
528 uninstall_runtime:
529
530 install_html_docs: build_html_docs
531         @if "$(INSTALLTOP)"=="" ( echo INSTALLTOP should not be empty & exit 1 )
532         @echo *** Installing HTML docs
533         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man1"
534         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man3"
535         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man5"
536         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\html\man7"
537         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man1\*.html \
538                                         "$(INSTALLTOP)\html\man1"
539         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man3\*.html \
540                                         "$(INSTALLTOP)\html\man3"
541         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man5\*.html \
542                                         "$(INSTALLTOP)\html\man5"
543         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BLDDIR)\doc\html\man7\*.html \
544                                         "$(INSTALLTOP)\html\man7"
545
546 uninstall_html_docs:
547
548 # Building targets ###################################################
549
550 configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
551         @$(ECHO) "Detected changed: $?"
552         "$(PERL)" configdata.pm -r
553         @$(ECHO) "**************************************************"
554         @$(ECHO) "***                                            ***"
555         @$(ECHO) "***   Please run the same make command again   ***"
556         @$(ECHO) "***                                            ***"
557         @$(ECHO) "**************************************************"
558         @exit 1
559
560 reconfigure reconf:
561         "$(PERL)" configdata.pm -r
562
563 {-
564  use File::Basename;
565  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
566
567  # Helper function to figure out dependencies on libraries
568  # It takes a list of library names and outputs a list of dependencies
569  sub compute_lib_depends {
570      if ($disabled{shared}) {
571          return map { platform->staticlib($_) } @_;
572      }
573      return map { platform->sharedlib_import($_) // platform->staticlib($_) } @_;
574  }
575
576   sub generatesrc {
577       my %args = @_;
578       my ($gen0, @gens) = @{$args{generator}};
579       my $generator = '"'.$gen0.'"'.join('', map { " $_" } @gens);
580       my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
581       my $incs = join("", map { " -I \"$_\"" } @{$args{incs}});
582       my $defs = join("", map { " -D".$_ } @{$args{defs}});
583       my $deps = @{$args{deps}} ?
584           '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
585
586       if ($args{src} =~ /\.html$/) {
587           my $title = basename($args{src}, ".html");
588           return <<"EOF";
589 $args{src}: $args{generator}->[0]
590         pod2html "--podroot=\$(SRCDIR)/doc" --htmldir=.. \\
591                  --podpath=man1:man3:man5:man7 "--infile=\$<" "--title=$title" \\
592         | \$(PERL) -pe "s|href=\\"http://man\\.he\\.net/(man\d/[^\\"]+)(?:\\.html)?\\"|href=\\"../\$1.html|g;" \\
593         > \$\@
594 EOF
595       } elsif (platform->isdef($args{src})) {
596           my $target = platform->def($args{src});
597           my $mkdef = abs2rel(rel2abs(catfile($config{sourcedir},
598                                               "util", "mkdef.pl")),
599                               rel2abs($config{builddir}));
600           my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION)' : '';
601           my $ord_name =
602               $args{generator}->[1] || platform->dsoname($args{product});
603           return <<"EOF";
604 $target: $args{generator}->[0] $deps $mkdef
605         "\$(PERL)" $mkdef$ord_ver --ordinals $args{generator}->[0] --name $ord_name --OS windows > $target
606 EOF
607       } elsif (!platform->isasm($args{src})) {
608           my $target = $args{src};
609           if ($args{generator}->[0] =~ m|^.*\.in$|) {
610               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
611                                                    "util", "dofile.pl")),
612                                    rel2abs($config{builddir}));
613               my @modules = ( 'configdata.pm',
614                               grep { $_ =~ m|\.pm$| } @{$args{deps}} );
615               my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules;
616               @modules = map { "-M".basename($_, '.pm') } @modules;
617               my $modules = join(' ', '', sort keys %moduleincs, @modules);
618               return <<"EOF";
619 $target: "$args{generator}->[0]" $deps
620         "\$(PERL)"$modules "$dofile" "-o$target{build_file}" $generator > \$@
621 EOF
622           } else {
623               return <<"EOF";
624 $target: "$args{generator}->[0]" $deps
625         "\$(PERL)"$generator_incs $generator > \$@
626 EOF
627           }
628       } else {
629           my $cppflags = {
630               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
631               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
632               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
633               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
634           } -> {$args{intent}};
635           my $target = platform->asm($args{src});
636
637           if ($args{generator}->[0] =~ /\.pl$/) {
638               $generator = '"$(PERL)"'.$generator_incs.' '.$generator
639                   .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSSOR)';
640           } elsif ($args{generator}->[0] =~ /\.S$/) {
641               $generator = undef;
642           } else {
643               die "Generator type for $src unknown: $generator\n";
644           }
645
646           if (defined($generator)) {
647               # If the target is named foo.S in build.info, we want to
648               # end up generating foo.s in two steps.
649               if ($args{src} =~ /\.S$/) {
650                    return <<"EOF";
651 $target: "$args{generator}->[0]" $deps
652         set ASM=\$(AS)
653         $generator \$@.S
654         \$(CPP) $incs $cppflags $defs \$@.S > \$@.i && move /Y \$@.i \$@
655         del /Q \$@.S
656 EOF
657               }
658               # Otherwise....
659               return <<"EOF";
660 $target: "$args{generator}->[0]" $deps
661         set ASM=\$(AS)
662         $generator \$@
663 EOF
664           }
665           return <<"EOF";
666 $target: "$args{generator}->[0]" $deps
667         \$(CPP) $incs $cppflags $defs "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
668 EOF
669       }
670   }
671
672  sub src2obj {
673      my $asmext = platform->asmext();
674      my %args = @_;
675      my @srcs =
676          map { my $x = $_;
677                (platform->isasm($x) && grep { $x eq $_ } @generated)
678                ? platform->asm($x) : $x }
679          ( @{$args{srcs}} );
680      my $srcs = '"'.join('" "',  @srcs).'"';
681      my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
682      my $incs = join("", map { ' -I "'.$_.'"' } @{$args{incs}});
683      my $defs = join("", map { " -D".$_ } @{$args{defs}});
684      my $cflags = { shlib => ' $(LIB_CFLAGS)',
685                     lib => ' $(LIB_CFLAGS)',
686                     dso => ' $(DSO_CFLAGS)',
687                     bin => ' $(BIN_CFLAGS)' } -> {$args{intent}};
688      $cflags .= $incs;
689      $cflags .= { shlib => ' $(LIB_CPPFLAGS)',
690                   lib => ' $(LIB_CPPFLAGS)',
691                   dso => ' $(DSO_CPPFLAGS)',
692                   bin => ' $(BIN_CPPFLAGS)' } -> {$args{intent}};
693      my $asflags = { shlib => ' $(LIB_ASFLAGS)',
694                      lib => ' $(LIB_ASFLAGS)',
695                      dso => ' $(DSO_ASFLAGS)',
696                      bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}};
697      my $makedepprog = $config{makedepprog};
698      if ($srcs[0] =~ /\.rc$/) {
699          my $res = platform->res($args{obj});
700          return <<"EOF";
701 $res: $deps
702         \$(RC) \$(RCFLAGS) \$(RCOUTFLAG)\$\@ $srcs
703 EOF
704      }
705      my $obj = platform->obj($args{obj});
706      my $dep = platform->dep($args{obj});
707      if ($srcs[0] =~ /\Q${asmext}\E$/) {
708          return <<"EOF";
709 $obj: $deps
710         \$(AS) $asflags \$(ASOUTFLAG)\$\@ $srcs
711 EOF
712      } elsif ($srcs[0] =~ /.S$/) {
713          return <<"EOF";
714 $obj: $deps
715         \$(CC) /EP -D__ASSEMBLER__ $cflags $defs $srcs > \$@.asm && \$(AS) $asflags \$(ASOUTFLAG)\$\@ \$@.asm
716 EOF
717      }
718      my $recipe = <<"EOF";
719 $obj: $deps
720         \$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
721 EOF
722      $recipe .= <<"EOF" unless $disabled{makedepend};
723         \$(CC) $cflags $defs /Zs /showIncludes $srcs 2>&1 > $dep
724 EOF
725      return $recipe;
726  }
727
728  # We *know* this routine is only called when we've configure 'shared'.
729  # Also, note that even though the import library built here looks like
730  # a static library, it really isn't.
731  sub obj2shlib {
732      my %args = @_;
733      my $lib = $args{lib};
734      my @objs = map { platform->convertext($_) }
735                 grep { platform->isobj($_) || platform->isres($_) }
736                 @{$args{objs}};
737      my @defs = map { platform->def($_) }
738                 grep { platform->isdef($_) }
739                 @{$args{objs}};
740      my @deps = compute_lib_depends(@{$args{deps}});
741      die "More than one exported symbols list" if scalar @defs > 1;
742      my $linklibs = join("", map { "$_\n" } @deps);
743      my $objs = join("\n", @objs);
744      my $deps = join(" ", @objs, @defs, @deps);
745      my $import = platform->sharedlib_import($lib);
746      my $dll =  platform->sharedlib($lib);
747      my $shared_def = join("", map { " /def:$_" } @defs);
748      return <<"EOF"
749 # The import library may look like a static library, but it is not.
750 # We MUST make the import library depend on the DLL, in case someone
751 # mistakenly removes the latter.
752 $import: $dll
753 $dll: $deps
754         IF EXIST $full.manifest DEL /F /Q $full.manifest
755         IF EXIST \$@ DEL /F /Q \$@
756         \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
757                 /implib:$import \$(LDOUTFLAG)$dll$shared_def @<< || (DEL /Q \$(\@B).* $import && EXIT 1)
758 $objs
759 $linklibs\$(LIB_EX_LIBS)
760 <<
761         IF EXIST $dll.manifest \\
762            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dll.manifest \$(MTOUTFLAG)$dll
763         IF EXIST apps\\$dll DEL /Q /F apps\\$dll
764         IF EXIST test\\$dll DEL /Q /F test\\$dll
765         IF EXIST fuzz\\$dll DEL /Q /F fuzz\\$dll
766         COPY $dll apps
767         COPY $dll test
768         COPY $dll fuzz
769 EOF
770  }
771  sub obj2dso {
772      my %args = @_;
773      my $dso = platform->dso($args{module});
774      my $dso_n = platform->dsoname($args{module});
775      my @objs = map { platform->convertext($_) }
776                 grep { platform->isobj($_) || platform->isres($_) }
777                 @{$args{objs}};
778      my @defs = map { platform->def($_) }
779                 grep { platform->isdef($_) }
780                 @{$args{objs}};
781      my @deps = compute_lib_depends(@{$args{deps}});
782      my $objs = join("\n", @objs);
783      my $linklibs = join("", map { "$_\n" } @deps);
784      my $deps = join(" ", @objs, @defs, @deps);
785      my $shared_def = join("", map { " /def:$_" } @defs);
786      return <<"EOF";
787 $dso: $deps
788         IF EXIST $dso.manifest DEL /F /Q $dso.manifest
789         \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \\
790                 \$(LDOUTFLAG)$dso$shared_def @<< || (DEL /Q \$(\@B).* $dso_n.* && EXIT 1)
791 $objs
792 $linklibs \$(DSO_EX_LIBS)
793 <<
794         IF EXIST $dso.manifest \\
795            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso.manifest \$(MTOUTFLAG)$dso
796 EOF
797  }
798  sub obj2lib {
799      my %args = @_;
800      my $lib = platform->staticlib($args{lib});
801      my @objs = map { platform->obj($_) } @{$args{objs}};
802      my $objs = join("\n", @objs);
803      my $deps = join(" ", @objs);
804      return <<"EOF";
805 $lib: $deps
806         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib @<<
807 $objs
808 <<
809 EOF
810  }
811  sub obj2bin {
812      my %args = @_;
813      my $bin = platform->bin($args{bin});
814      my @objs = map { platform->convertext($_) }
815                 grep { platform->isobj($_) || platform->isres($_) }
816                 @{$args{objs}};
817      my @deps = compute_lib_depends(@{$args{deps}});
818      my $objs = join("\n", @objs);
819      my $linklibs = join("", map { "$_\n" } @deps);
820      my $deps = join(" ", @objs, @deps);
821      return <<"EOF";
822 $bin: $deps
823         IF EXIST $bin.manifest DEL /F /Q $bin.manifest
824         \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin @<<
825 $objs
826 setargv.obj
827 $linklibs\$(BIN_EX_LIBS)
828 <<
829         IF EXIST $bin.manifest \\
830            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin.manifest \$(MTOUTFLAG)$bin
831 EOF
832   }
833   sub in2script {
834       my %args = @_;
835       my $script = $args{script};
836       my $sources = '"'.join('" "', @{$args{sources}}).'"';
837       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
838                                            "util", "dofile.pl")),
839                            rel2abs($config{builddir}));
840       return <<"EOF";
841 $script: $sources
842         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
843             "-o$target{build_file}" $sources > "$script"
844 EOF
845   }
846   sub generatedir {
847       my %args = @_;
848       my $dir = $args{dir};
849       my @deps = map { platform->convertext($_) } @{$args{deps}};
850       my @actions = ();
851       my %extinfo = ( dso => platform->dsoext(),
852                       lib => platform->libext(),
853                       bin => platform->binext() );
854
855       # We already have a 'test' target, and the top directory is just plain
856       # silly
857       return if $dir eq "test" || $dir eq ".";
858
859       foreach my $type (("dso", "lib", "bin", "script")) {
860           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
861           # For lib object files, we could update the library.  However,
862           # LIB on Windows doesn't work that way, so we won't create any
863           # actions for it, and the dependencies are already taken care of.
864           if ($type ne "lib") {
865               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
866                   if (dirname($prod) eq $dir) {
867                       push @deps, $prod.$extinfo{$type};
868                   }
869               }
870           }
871       }
872
873       my $deps = join(" ", @deps);
874       my $actions = join("\n", "", @actions);
875       return <<"EOF";
876 $dir $dir\\ : $deps$actions
877 EOF
878   }
879   ""    # Important!  This becomes part of the template result.
880 -}