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