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