Windows makefile generator: Don't delete long lists of files in one go
[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={- our @MODULES = map { platform->dso($_) } @{$unified_info{modules}};
51            join(" ", @MODULES) -}
52 MODULEPDBS={- join(" ", map { platform->dsopdb($_) } @{$unified_info{modules}}) -}
53 PROGRAMS={- our @PROGRAMS = map { platform->bin($_) } @{$unified_info{programs}}; join(" ", @PROGRAMS) -}
54 PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -}
55 SCRIPTS={- our @SCRIPTS = @{$unified_info{scripts}}; join(" ", @SCRIPTS) -}
56 {- output_off() if $disabled{makedepend}; "" -}
57 DEPS={- join(" ", map { platform->isobj($_) ? platform->dep($_) : () }
58                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
59                   keys %{$unified_info{sources}}); -}
60 {- output_on() if $disabled{makedepend}; "" -}
61 GENERATED_MANDATORY={- our @GENERATED_MANDATORY = @{$unified_info{depends}->{""}};
62                        join(" ", @GENERATED_MANDATORY) -}
63 GENERATED={- # common0.tmpl provides @generated
64              our @GENERATED = map { platform->convertext($_) } @generated;
65              join(" ", @GENERATED) -}
66
67 INSTALL_LIBS={-
68         join(" ", map { quotify1(platform->sharedlib_import($_)
69                                  // platform->staticlib($_)) }
70                   grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
71                   @{$unified_info{libraries}})
72 -}
73 INSTALL_SHLIBS={-
74         join(" ", map { my $x = platform->sharedlib($_);
75                         $x ? quotify_l($x) : () }
76                   grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
77                   @{$unified_info{libraries}})
78 -}
79 INSTALL_SHLIBPDBS={-
80         join(" ", map { my $x = platform->sharedlibpdb($_);
81                         $x ? quotify_l($x) : () }
82                   grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
83                   @{$unified_info{libraries}})
84 -}
85 INSTALL_ENGINES={-
86         join(" ", map { quotify1(platform->dso($_)) }
87                   grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
88                          && $unified_info{attributes}->{modules}->{$_}->{engine} }
89                   @{$unified_info{modules}})
90 -}
91 INSTALL_ENGINEPDBS={-
92         join(" ", map { quotify1(platform->dsopdb($_)) }
93                   grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
94                          && $unified_info{attributes}->{modules}->{$_}->{engine} }
95                   @{$unified_info{modules}})
96 -}
97 INSTALL_PROGRAMS={-
98         join(" ", map { quotify1(platform->bin($_)) }
99                   grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
100                   @{$unified_info{programs}})
101 -}
102 INSTALL_PROGRAMPDBS={-
103         join(" ", map { quotify1(platform->binpdb($_)) }
104                   grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
105                   @{$unified_info{programs}})
106 -}
107 BIN_SCRIPTS={-
108         join(" ", map { quotify1($_) }
109                   grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
110                          && !$unified_info{attributes}->{scripts}->{$_}->{misc} }
111                   @{$unified_info{scripts}})
112 -}
113 MISC_SCRIPTS={-
114         join(" ", map { quotify1($_) }
115                   grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
116                          && $unified_info{attributes}->{scripts}->{$_}->{misc} }
117                   @{$unified_info{scripts}})
118 -}
119 HTMLDOCS1={- our @HTMLDOCS1 = @{$unified_info{htmldocs}->{man1}};
120              join(" ", @HTMLDOCS1) -}
121 HTMLDOCS3={- our @HTMLDOCS3 = @{$unified_info{htmldocs}->{man3}};
122              join(" ", @HTMLDOCS3) -}
123 HTMLDOCS5={- our @HTMLDOCS5 = @{$unified_info{htmldocs}->{man5}};
124              join(" ", @HTMLDOCS5) -}
125 HTMLDOCS7={- our @HTMLDOCS7 = @{$unified_info{htmldocs}->{man7}};
126              join(" ", @HTMLDOCS7) -}
127 HTMLDOCS1_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS1;
128                      join(' ', sort keys %dirs) -}
129 HTMLDOCS3_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS3;
130                      join(' ', sort keys %dirs) -}
131 HTMLDOCS5_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS5;
132                      join(' ', sort keys %dirs) -}
133 HTMLDOCS7_BLDDIRS={- my %dirs = map { dirname($_) => 1 } @HTMLDOCS7;
134                      join(' ', sort keys %dirs) -}
135
136 APPS_OPENSSL="{- use File::Spec::Functions;
137                  catfile("apps","openssl") -}"
138
139 # Do not edit these manually. Use Configure with --prefix or --openssldir
140 # to change this!  Short explanation in the top comment in Configure
141 INSTALLTOP_dev={- # $prefix is used in the OPENSSLDIR perl snippet
142                   #
143                   use File::Spec::Functions qw(:DEFAULT splitpath);
144                   our $prefix = canonpath($config{prefix}
145                                           || "$win_installroot\\OpenSSL");
146                   our ($prefix_dev, $prefix_dir, $prefix_file) =
147                       splitpath($prefix, 1);
148                   $prefix_dev -}
149 INSTALLTOP_dir={- canonpath($prefix_dir) -}
150 OPENSSLDIR_dev={- #
151                   # The logic here is that if no --openssldir was given,
152                   # OPENSSLDIR will get the value "$win_commonroot\\SSL".
153                   # If --openssldir was given and the value is an absolute
154                   # path, OPENSSLDIR will get its value without change.
155                   # If the value from --openssldir is a relative path,
156                   # OPENSSLDIR will get $prefix with the --openssldir
157                   # value appended as a subdirectory.
158                   #
159                   use File::Spec::Functions qw(:DEFAULT splitpath);
160                   our $openssldir =
161                       $config{openssldir} ?
162                           (file_name_is_absolute($config{openssldir}) ?
163                                canonpath($config{openssldir})
164                                : catdir($prefix, $config{openssldir}))
165                           : canonpath("$win_commonroot\\SSL");
166                   our ($openssldir_dev, $openssldir_dir, $openssldir_file) =
167                       splitpath($openssldir, 1);
168                   $openssldir_dev -}
169 OPENSSLDIR_dir={- canonpath($openssldir_dir) -}
170 LIBDIR={- our $libdir = $config{libdir} || "lib";
171           file_name_is_absolute($libdir) ? "" : $libdir -}
172 MODULESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath catpath);
173                   our $modulesprefix = catdir($prefix,$libdir);
174                   our ($modulesprefix_dev, $modulesprefix_dir,
175                        $modulesprefix_file) =
176                       splitpath($modulesprefix, 1);
177                   our $modulesdir_dev = $modulesprefix_dev;
178                   our $modulesdir_dir =
179                       catdir($modulesprefix_dir, "ossl-modules");
180                   our $modulesdir = catpath($modulesdir_dev, $modulesdir_dir);
181                   our $enginesdir_dev = $modulesprefix_dev;
182                   our $enginesdir_dir =
183                       catdir($modulesprefix_dir, "engines-$sover_dirname");
184                   our $enginesdir = catpath($enginesdir_dev, $enginesdir_dir);
185                   $modulesdir_dev -}
186 MODULESDIR_dir={- canonpath($modulesdir_dir) -}
187 ENGINESDIR_dev={- $enginesdir_dev -}
188 ENGINESDIR_dir={- canonpath($enginesdir_dir) -}
189 !IF "$(DESTDIR)" != ""
190 INSTALLTOP=$(DESTDIR)$(INSTALLTOP_dir)
191 OPENSSLDIR=$(DESTDIR)$(OPENSSLDIR_dir)
192 ENGINESDIR=$(DESTDIR)$(ENGINESDIR_dir)
193 MODULESDIR=$(DESTDIR)$(MODULESDIR_dir)
194 !ELSE
195 INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
196 OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
197 ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
198 MODULESDIR=$(MODULESDIR_dev)$(MODULESDIR_dir)
199 !ENDIF
200
201 # $(libdir) is chosen to be compatible with the GNU coding standards
202 libdir={- file_name_is_absolute($libdir)
203           ? $libdir : '$(INSTALLTOP)\$(LIBDIR)' -}
204
205 ##### User defined commands and flags ################################
206
207 CC="{- $config{CC} -}"
208 CPP="{- $config{CPP} -}"
209 CPPFLAGS={- our $cppflags1 = join(" ",
210                                   (map { "-D".$_} @{$config{CPPDEFINES}}),
211                                   (map { " -I ".$_} @{$config{CPPINCLUDES}}),
212                                   @{$config{CPPFLAGS}}) -}
213 CFLAGS={- join(' ', @{$config{CFLAGS}}) -}
214 LD="{- $config{LD} -}"
215 LDFLAGS={- join(' ', @{$config{LDFLAGS}}) -}
216 EX_LIBS={- join(' ', @{$config{LDLIBS}}) -}
217
218 PERL={- $config{PERL} -}
219
220 AR="{- $config{AR} -}"
221 ARFLAGS= {- join(' ', @{$config{ARFLAGS}}) -}
222
223 MT="{- $config{MT} -}"
224 MTFLAGS= {- join(' ', @{$config{MTFLAGS}}) -}
225
226 AS="{- $config{AS} -}"
227 ASFLAGS={- join(' ', @{$config{ASFLAGS}}) -}
228
229 RC="{- $config{RC} -}"
230 RCFLAGS={- join(' ', @{$config{RCFLAGS}}) -}
231
232 ECHO="$(PERL)" "$(SRCDIR)\util\echo.pl"
233
234 ##### Special command flags ##########################################
235
236 COUTFLAG={- $target{coutflag} -}$(OSSL_EMPTY)
237 LDOUTFLAG={- $target{ldoutflag} -}$(OSSL_EMPTY)
238 AROUTFLAG={- $target{aroutflag} -}$(OSSL_EMPTY)
239 MTINFLAG={- $target{mtinflag} -}$(OSSL_EMPTY)
240 MTOUTFLAG={- $target{mtoutflag} -}$(OSSL_EMPTY)
241 ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
242 RCOUTFLAG={- $target{rcoutflag} -}$(OSSL_EMPTY)
243
244 ##### Project flags ##################################################
245
246 # Variables starting with CNF_ are common variables for all product types
247
248 CNF_ASFLAGS={- join(' ', $target{asflags} || (),
249                          @{$config{asflags}}) -}
250 CNF_CPPFLAGS={- our $cppfags2 =
251                     join(' ', $target{cppflags} || (),
252                               (map { '-D'.quotify1($_) } @{$target{defines}},
253                                                          @{$config{defines}}),
254                               (map { '-I'.quotify1($_) } @{$target{includes}},
255                                                          @{$config{includes}}),
256                               @{$config{cppflags}}) -}
257 CNF_CFLAGS={- join(' ', $target{cflags} || (),
258                         @{$config{cflags}}) -}
259 CNF_CXXFLAGS={- join(' ', $target{cxxflags} || (),
260                           @{$config{cxxflags}}) -}
261 CNF_LDFLAGS={- join(' ', $target{lflags} || (),
262                          @{$config{lflags}}) -}
263 CNF_EX_LIBS={- join(' ', $target{ex_libs} || (),
264                          @{$config{ex_libs}}) -}
265
266 # Variables starting with LIB_ are used to build library object files
267 # and shared libraries.
268 # Variables starting with DSO_ are used to build DSOs and their object files.
269 # Variables starting with BIN_ are used to build programs and their object
270 # files.
271
272 LIB_ASFLAGS={- join(' ', $target{lib_asflags} || (),
273                          @{$config{lib_asflags}},
274                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
275 LIB_CPPFLAGS={- our $lib_cppflags =
276                 join(' ', $target{lib_cppflags} || (),
277                           $target{shared_cppflag} || (),
278                           (map { '-D'.quotify1($_) }
279                                @{$target{lib_defines}},
280                                @{$target{shared_defines}},
281                                @{$config{lib_defines}},
282                                @{$config{shared_defines}}),
283                           (map { '-I'.quotify1($_) }
284                                @{$target{lib_includes}},
285                                @{$target{shared_includes}},
286                                @{$config{lib_includes}},
287                                @{$config{shared_includes}}),
288                           @{$config{lib_cppflags}},
289                           @{$config{shared_cppflag}});
290                 join(' ', $lib_cppflags,
291                           (map { '-D'.quotify1($_) }
292                                "OPENSSLDIR=\"$openssldir\"",
293                                "ENGINESDIR=\"$enginesdir\"",
294                                "MODULESDIR=\"$modulesdir\""),
295                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
296 LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
297                         $target{shared_cflag} || (),
298                         @{$config{lib_cflags}},
299                         @{$config{shared_cflag}},
300                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
301 LIB_LDFLAGS={- join(' ', $target{shared_ldflag} || (),
302                          $config{shared_ldflag} || (),
303                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
304 LIB_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
305 DSO_ASFLAGS={- join(' ', $target{dso_asflags} || (),
306                          $target{module_asflags} || (),
307                          @{$config{dso_asflags}},
308                          @{$config{module_asflags}},
309                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
310 DSO_CPPFLAGS={- join(' ', $target{dso_cppflags} || (),
311                           $target{module_cppflag} || (),
312                           (map { '-D'.quotify1($_) }
313                                @{$target{dso_defines}},
314                                @{$target{module_defines}},
315                                @{$config{dso_defines}},
316                                @{$config{module_defines}}),
317                           (map { '-I'.quotify1($_) }
318                                @{$target{dso_includes}},
319                                @{$target{module_includes}},
320                                @{$config{dso_includes}},
321                                @{$config{module_includes}}),
322                           @{$config{dso_cppflags}},
323                           @{$config{module_cppflags}},
324                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
325 DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
326                         $target{module_cflags} || (),
327                         @{$config{dso_cflags}},
328                         @{$config{module_cflags}},
329                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
330 DSO_LDFLAGS={- join(' ', $target{dso_lflags} || (),
331                          $target{module_ldflags} || (),
332                          @{$config{dso_lflags}},
333                          @{$config{module_ldflags}},
334                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
335 DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
336 BIN_ASFLAGS={- join(' ', $target{bin_asflags} || (),
337                          @{$config{bin_asflags}},
338                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
339 BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
340                           (map { '-D'.$_ } @{$config{bin_defines} || ()}),
341                           @{$config{bin_cppflags}},
342                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
343 BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
344                         @{$config{bin_cflags}},
345                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
346 BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
347                          @{$config{bin_lflags}},
348                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
349 BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
350
351 # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
352 CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
353               $cppflags2 =~ s|([\\"])|\\$1|g;
354               join(' ', $lib_cppflags || (), $cppflags2 || (),
355                         $cppflags1 || ()) -}
356
357 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
358
359 PROCESSOR= {- $config{processor} -}
360
361 # The main targets ###################################################
362
363 {- dependmagic('build_sw'); -}: build_libs_nodep build_modules_nodep build_programs_nodep copy-utils
364 {- dependmagic('build_libs'); -}: build_libs_nodep
365 {- dependmagic('build_modules'); -}: build_modules_nodep
366 {- dependmagic('build_programs'); -}: build_programs_nodep
367
368 build_docs: build_html_docs
369 build_html_docs: $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
370
371 build_generated: $(GENERATED_MANDATORY)
372 build_libs_nodep: $(LIBS) {- join(" ",map { platform->sharedlib_import($_) // () } @{$unified_info{libraries}}) -}
373 build_modules_nodep: $(MODULES)
374 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
375
376 # Kept around for backward compatibility
377 build_apps build_tests: build_programs
378
379 # Convenience target to prebuild all generated files, not just the mandatory
380 # ones
381 build_all_generated: $(GENERATED_MANDATORY) $(GENERATED) build_docs
382         @{- output_off() if $disabled{makedepend}; "" -}
383         @$(ECHO) "Warning: consider configuring with no-makedepend, because if"
384         @$(ECHO) "         target system doesn't have $(PERL),"
385         @$(ECHO) "         then make will fail..."
386         @{- output_on() if $disabled{makedepend}; "" -}
387
388 all: build_sw build_docs
389
390 test: tests
391 {- dependmagic('tests'); -}: build_programs_nodep build_modules_nodep copy-utils
392         @{- output_off() if $disabled{tests}; "" -}
393         set SRCTOP=$(SRCDIR)
394         set BLDTOP=$(BLDDIR)
395         set PERL=$(PERL)
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         {- join("\n\t", map { "-del /Q /F $_" } @MODULES) -}
424         {- join("\n\t", map { "-del /Q /F $_" } @SCRIPTS) -}
425         {- join("\n\t", map { "-del /Q /F $_" } @GENERATED_MANDATORY) -}
426         {- join("\n\t", map { "-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 # Helper targets #####################################################
549
550 copy-utils: $(BLDDIR)\util\wrap.pl
551
552 $(BLDDIR)\util\wrap.pl: configdata.pm
553         @if NOT EXIST "$(BLDDIR)\util" mkdir "$(BLDDIR)\util"
554         @if NOT "$(SRCDIR)"=="$(BLDDIR)" copy "$(SRCDIR)\util\$(@F)" "$(BLDDIR)\util"
555
556 # Building targets ###################################################
557
558 configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
559         @$(ECHO) "Detected changed: $?"
560         "$(PERL)" configdata.pm -r
561         @$(ECHO) "**************************************************"
562         @$(ECHO) "***                                            ***"
563         @$(ECHO) "***   Please run the same make command again   ***"
564         @$(ECHO) "***                                            ***"
565         @$(ECHO) "**************************************************"
566         @exit 1
567
568 reconfigure reconf:
569         "$(PERL)" configdata.pm -r
570
571 {-
572  use File::Basename;
573  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
574
575  # Helper function to figure out dependencies on libraries
576  # It takes a list of library names and outputs a list of dependencies
577  sub compute_lib_depends {
578      if ($disabled{shared}) {
579          return map { platform->staticlib($_) } @_;
580      }
581      return map { platform->sharedlib_import($_) // platform->staticlib($_) } @_;
582  }
583
584   sub generatesrc {
585       my %args = @_;
586       my ($gen0, @gens) = @{$args{generator}};
587       my $generator = '"'.$gen0.'"'.join('', map { " $_" } @gens);
588       my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
589       my $incs = join("", map { " -I \"$_\"" } @{$args{incs}});
590       my $defs = join("", map { " -D".$_ } @{$args{defs}});
591       my $deps = @{$args{deps}} ?
592           '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
593
594       if ($args{src} =~ /\.html$/) {
595           my $title = basename($args{src}, ".html");
596           my $pod = $args{generator}->[0];
597           return <<"EOF";
598 $args{src}: "$pod"
599         \$(PERL) \$(SRCDIR)/util/mkpod2html.pl -i "$pod" -o \$\@ -t "$title" -r "\$(SRCDIR)/doc"
600 EOF
601       } elsif (platform->isdef($args{src})) {
602           my $target = platform->def($args{src});
603           my $mkdef = abs2rel(rel2abs(catfile($config{sourcedir},
604                                               "util", "mkdef.pl")),
605                               rel2abs($config{builddir}));
606           my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION)' : '';
607           my $ord_name =
608               $args{generator}->[1] || platform->dsoname($args{product});
609           return <<"EOF";
610 $target: $args{generator}->[0] $deps $mkdef
611         "\$(PERL)" $mkdef$ord_ver --ordinals $args{generator}->[0] --name $ord_name --OS windows > $target
612 EOF
613       } elsif (!platform->isasm($args{src})) {
614           my $target = $args{src};
615           if ($args{generator}->[0] =~ m|^.*\.in$|) {
616               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
617                                                    "util", "dofile.pl")),
618                                    rel2abs($config{builddir}));
619               my @modules = ( 'configdata.pm',
620                               grep { $_ =~ m|\.pm$| } @{$args{deps}} );
621               my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules;
622               @modules = map { "-M".basename($_, '.pm') } @modules;
623               my $modules = join(' ', '', sort keys %moduleincs, @modules);
624               return <<"EOF";
625 $target: "$args{generator}->[0]" $deps
626         "\$(PERL)"$modules "$dofile" "-o$target{build_file}" $generator > \$@
627 EOF
628           } else {
629               return <<"EOF";
630 $target: "$args{generator}->[0]" $deps
631         "\$(PERL)"$generator_incs $generator > \$@
632 EOF
633           }
634       } else {
635           my $cppflags = {
636               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
637               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
638               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
639               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
640           } -> {$args{intent}};
641           my $target = platform->asm($args{src});
642
643           if ($args{generator}->[0] =~ /\.pl$/) {
644               $generator = '"$(PERL)"'.$generator_incs.' '.$generator
645                   .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSSOR)';
646           } elsif ($args{generator}->[0] =~ /\.S$/) {
647               $generator = undef;
648           } else {
649               die "Generator type for $src unknown: $generator\n";
650           }
651
652           if (defined($generator)) {
653               # If the target is named foo.S in build.info, we want to
654               # end up generating foo.s in two steps.
655               if ($args{src} =~ /\.S$/) {
656                    return <<"EOF";
657 $target: "$args{generator}->[0]" $deps
658         set ASM=\$(AS)
659         $generator \$@.S
660         \$(CPP) $incs $cppflags $defs \$@.S > \$@.i && move /Y \$@.i \$@
661         del /Q \$@.S
662 EOF
663               }
664               # Otherwise....
665               return <<"EOF";
666 $target: "$args{generator}->[0]" $deps
667         set ASM=\$(AS)
668         $generator \$@
669 EOF
670           }
671           return <<"EOF";
672 $target: "$args{generator}->[0]" $deps
673         \$(CPP) $incs $cppflags $defs "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
674 EOF
675       }
676   }
677
678  sub src2obj {
679      my $asmext = platform->asmext();
680      my %args = @_;
681      my @srcs =
682          map { my $x = $_;
683                (platform->isasm($x) && grep { $x eq $_ } @generated)
684                ? platform->asm($x) : $x }
685          ( @{$args{srcs}} );
686      my $srcs = '"'.join('" "',  @srcs).'"';
687      my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
688      my $incs = join("", map { ' -I "'.$_.'"' } @{$args{incs}});
689      my $defs = join("", map { " -D".$_ } @{$args{defs}});
690      my $cflags = { shlib => ' $(LIB_CFLAGS)',
691                     lib => ' $(LIB_CFLAGS)',
692                     dso => ' $(DSO_CFLAGS)',
693                     bin => ' $(BIN_CFLAGS)' } -> {$args{intent}};
694      $cflags .= $incs;
695      $cflags .= { shlib => ' $(LIB_CPPFLAGS)',
696                   lib => ' $(LIB_CPPFLAGS)',
697                   dso => ' $(DSO_CPPFLAGS)',
698                   bin => ' $(BIN_CPPFLAGS)' } -> {$args{intent}};
699      my $asflags = { shlib => ' $(LIB_ASFLAGS)',
700                      lib => ' $(LIB_ASFLAGS)',
701                      dso => ' $(DSO_ASFLAGS)',
702                      bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}};
703      my $makedepprog = $config{makedepprog};
704      if ($srcs[0] =~ /\.rc$/) {
705          my $res = platform->res($args{obj});
706          return <<"EOF";
707 $res: $deps
708         \$(RC) \$(RCFLAGS) \$(RCOUTFLAG)\$\@ $srcs
709 EOF
710      }
711      my $obj = platform->obj($args{obj});
712      my $dep = platform->dep($args{obj});
713      if ($srcs[0] =~ /\Q${asmext}\E$/) {
714          return <<"EOF";
715 $obj: $deps
716         \$(AS) $asflags \$(ASOUTFLAG)\$\@ $srcs
717 EOF
718      } elsif ($srcs[0] =~ /.S$/) {
719          return <<"EOF";
720 $obj: $deps
721         \$(CC) /EP -D__ASSEMBLER__ $cflags $defs $srcs > \$@.asm && \$(AS) $asflags \$(ASOUTFLAG)\$\@ \$@.asm
722 EOF
723      }
724      my $recipe = <<"EOF";
725 $obj: $deps
726         \$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
727 EOF
728      $recipe .= <<"EOF" unless $disabled{makedepend};
729         \$(CC) $cflags $defs /Zs /showIncludes $srcs 2>&1 > $dep
730 EOF
731      return $recipe;
732  }
733
734  # We *know* this routine is only called when we've configure 'shared'.
735  # Also, note that even though the import library built here looks like
736  # a static library, it really isn't.
737  sub obj2shlib {
738      my %args = @_;
739      my $lib = $args{lib};
740      my @objs = map { platform->convertext($_) }
741                 grep { platform->isobj($_) || platform->isres($_) }
742                 @{$args{objs}};
743      my @defs = map { platform->def($_) }
744                 grep { platform->isdef($_) }
745                 @{$args{objs}};
746      my @deps = compute_lib_depends(@{$args{deps}});
747      die "More than one exported symbols list" if scalar @defs > 1;
748      my $linklibs = join("", map { "$_\n" } @deps);
749      my $objs = join("\n", @objs);
750      my $deps = join(" ", @objs, @defs, @deps);
751      my $import = platform->sharedlib_import($lib);
752      my $dll =  platform->sharedlib($lib);
753      my $shared_def = join("", map { " /def:$_" } @defs);
754      return <<"EOF"
755 # The import library may look like a static library, but it is not.
756 # We MUST make the import library depend on the DLL, in case someone
757 # mistakenly removes the latter.
758 $import: $dll
759 $dll: $deps
760         IF EXIST $full.manifest DEL /F /Q $full.manifest
761         IF EXIST \$@ DEL /F /Q \$@
762         \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
763                 /implib:$import \$(LDOUTFLAG)$dll$shared_def @<< || (DEL /Q \$(\@B).* $import && EXIT 1)
764 $objs
765 $linklibs\$(LIB_EX_LIBS)
766 <<
767         IF EXIST $dll.manifest \\
768            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dll.manifest \$(MTOUTFLAG)$dll
769         IF EXIST apps\\$dll DEL /Q /F apps\\$dll
770         IF EXIST test\\$dll DEL /Q /F test\\$dll
771         IF EXIST fuzz\\$dll DEL /Q /F fuzz\\$dll
772         COPY $dll apps
773         COPY $dll test
774         COPY $dll fuzz
775 EOF
776  }
777  sub obj2dso {
778      my %args = @_;
779      my $dso = platform->dso($args{module});
780      my $dso_n = platform->dsoname($args{module});
781      my @objs = map { platform->convertext($_) }
782                 grep { platform->isobj($_) || platform->isres($_) }
783                 @{$args{objs}};
784      my @defs = map { platform->def($_) }
785                 grep { platform->isdef($_) }
786                 @{$args{objs}};
787      my @deps = compute_lib_depends(@{$args{deps}});
788      my $objs = join("\n", @objs);
789      my $linklibs = join("", map { "$_\n" } @deps);
790      my $deps = join(" ", @objs, @defs, @deps);
791      my $shared_def = join("", map { " /def:$_" } @defs);
792      return <<"EOF";
793 $dso: $deps
794         IF EXIST $dso.manifest DEL /F /Q $dso.manifest
795         \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \\
796                 \$(LDOUTFLAG)$dso$shared_def @<< || (DEL /Q \$(\@B).* $dso_n.* && EXIT 1)
797 $objs
798 $linklibs \$(DSO_EX_LIBS)
799 <<
800         IF EXIST $dso.manifest \\
801            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso.manifest \$(MTOUTFLAG)$dso
802 EOF
803  }
804  sub obj2lib {
805      my %args = @_;
806      my $lib = platform->staticlib($args{lib});
807      my @objs = map { platform->obj($_) } @{$args{objs}};
808      my $objs = join("\n", @objs);
809      my $deps = join(" ", @objs);
810      return <<"EOF";
811 $lib: $deps
812         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib @<<
813 $objs
814 <<
815 EOF
816  }
817  sub obj2bin {
818      my %args = @_;
819      my $bin = platform->bin($args{bin});
820      my @objs = map { platform->convertext($_) }
821                 grep { platform->isobj($_) || platform->isres($_) }
822                 @{$args{objs}};
823      my @deps = compute_lib_depends(@{$args{deps}});
824      my $objs = join("\n", @objs);
825      my $linklibs = join("", map { "$_\n" } @deps);
826      my $deps = join(" ", @objs, @deps);
827      return <<"EOF";
828 $bin: $deps
829         IF EXIST $bin.manifest DEL /F /Q $bin.manifest
830         \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin @<<
831 $objs
832 setargv.obj
833 $linklibs\$(BIN_EX_LIBS)
834 <<
835         IF EXIST $bin.manifest \\
836            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin.manifest \$(MTOUTFLAG)$bin
837 EOF
838   }
839   sub in2script {
840       my %args = @_;
841       my $script = $args{script};
842       my $sources = '"'.join('" "', @{$args{sources}}).'"';
843       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
844                                            "util", "dofile.pl")),
845                            rel2abs($config{builddir}));
846       return <<"EOF";
847 $script: $sources
848         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
849             "-o$target{build_file}" $sources > "$script"
850 EOF
851   }
852   sub generatedir {
853       my %args = @_;
854       my $dir = $args{dir};
855       my @deps = map { platform->convertext($_) } @{$args{deps}};
856       my @actions = ();
857       my %extinfo = ( dso => platform->dsoext(),
858                       lib => platform->libext(),
859                       bin => platform->binext() );
860
861       # We already have a 'test' target, and the top directory is just plain
862       # silly
863       return if $dir eq "test" || $dir eq ".";
864
865       foreach my $type (("dso", "lib", "bin", "script")) {
866           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
867           # For lib object files, we could update the library.  However,
868           # LIB on Windows doesn't work that way, so we won't create any
869           # actions for it, and the dependencies are already taken care of.
870           if ($type ne "lib") {
871               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
872                   if (dirname($prod) eq $dir) {
873                       push @deps, $prod.$extinfo{$type};
874                   }
875               }
876           }
877       }
878
879       my $deps = join(" ", @deps);
880       my $actions = join("\n", "", @actions);
881       return <<"EOF";
882 $dir $dir\\ : $deps$actions
883 EOF
884   }
885   ""    # Important!  This becomes part of the template result.
886 -}