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