Introduce a no-pinshared option
[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
191 ECHO="$(PERL)" "$(SRCDIR)\util\echo.pl"
192
193 ##### Special command flags ##########################################
194
195 COUTFLAG={- $target{coutflag} -}$(OSSL_EMPTY)
196 LDOUTFLAG={- $target{ldoutflag} -}$(OSSL_EMPTY)
197 AROUTFLAG={- $target{aroutflag} -}$(OSSL_EMPTY)
198 MTINFLAG={- $target{mtinflag} -}$(OSSL_EMPTY)
199 MTOUTFLAG={- $target{mtoutflag} -}$(OSSL_EMPTY)
200 ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
201 RCOUTFLAG={- $target{rcoutflag} -}$(OSSL_EMPTY)
202
203 ##### Project flags ##################################################
204
205 # Variables starting with CNF_ are common variables for all product types
206
207 CNF_ASFLAGS={- join(' ', $target{asflags} || (),
208                          @{$config{asflags}}) -}
209 CNF_CPPFLAGS={- our $cppfags2 =
210                     join(' ', $target{cppflags} || (),
211                               (map { '-D'.quotify1($_) } @{$target{defines}},
212                                                          @{$config{defines}}),
213                               (map { '-I'.quotify1($_) } @{$target{includes}},
214                                                          @{$config{includes}}),
215                               @{$config{cppflags}}) -}
216 CNF_CFLAGS={- join(' ', $target{cflags} || (),
217                         @{$config{cflags}}) -}
218 CNF_CXXFLAGS={- join(' ', $target{cxxflags} || (),
219                           @{$config{cxxflags}}) -}
220 CNF_LDFLAGS={- join(' ', $target{lflags} || (),
221                          @{$config{lflags}}) -}
222 CNF_EX_LIBS={- join(' ', $target{ex_libs} || (),
223                          @{$config{ex_libs}}) -}
224
225 # Variables starting with LIB_ are used to build library object files
226 # and shared libraries.
227 # Variables starting with DSO_ are used to build DSOs and their object files.
228 # Variables starting with BIN_ are used to build programs and their object
229 # files.
230
231 LIB_ASFLAGS={- join(' ', $target{lib_asflags} || (),
232                          @{$config{lib_asflags}},
233                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
234 LIB_CPPFLAGS={- our $lib_cppflags =
235                 join(' ', $target{lib_cppflags} || (),
236                           $target{shared_cppflag} || (),
237                           (map { '-D'.quotify1($_) }
238                                @{$target{lib_defines}},
239                                @{$target{shared_defines}},
240                                @{$config{lib_defines}},
241                                @{$config{shared_defines}}),
242                           (map { '-I'.quotify1($_) }
243                                @{$target{lib_includes}},
244                                @{$target{shared_includes}},
245                                @{$config{lib_includes}},
246                                @{$config{shared_includes}}),
247                           @{$config{lib_cppflags}},
248                           @{$config{shared_cppflag}});
249                 join(' ', $lib_cppflags,
250                           (map { '-D'.quotify1($_) }
251                                "OPENSSLDIR=\"$openssldir\"",
252                                "ENGINESDIR=\"$enginesdir\""),
253                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
254 LIB_CFLAGS={- join(' ', $target{lib_cflags} || (),
255                         $target{shared_cflag} || (),
256                         @{$config{lib_cflags}},
257                         @{$config{shared_cflag}},
258                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
259 LIB_LDFLAGS={- join(' ', $target{shared_ldflag} || (),
260                          $config{shared_ldflag} || (),
261                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
262 LIB_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
263 DSO_ASFLAGS={- join(' ', $target{dso_asflags} || (),
264                          $target{module_asflags} || (),
265                          @{$config{dso_asflags}},
266                          @{$config{module_asflags}},
267                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
268 DSO_CPPFLAGS={- join(' ', $target{dso_cppflags} || (),
269                           $target{module_cppflags} || (),
270                           @{$config{dso_cppflags}},
271                           @{$config{module_cppflags}},
272                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
273 DSO_CFLAGS={- join(' ', $target{dso_cflags} || (),
274                         $target{module_cflags} || (),
275                         @{$config{dso_cflags}},
276                         @{$config{module_cflags}},
277                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
278 DSO_LDFLAGS={- join(' ', $target{dso_lflags} || (),
279                          $target{module_ldflags} || (),
280                          @{$config{dso_lflags}},
281                          @{$config{module_ldflags}},
282                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
283 DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
284 BIN_ASFLAGS={- join(' ', $target{bin_asflags} || (),
285                          @{$config{bin_asflags}},
286                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
287 BIN_CPPFLAGS={- join(' ', $target{bin_cppflags} || (),
288                           @{$config{bin_cppflags}},
289                           '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
290 BIN_CFLAGS={- join(' ', $target{bin_cflags} || (),
291                         @{$config{bin_cflags}},
292                         '$(CNF_CFLAGS)', '$(CFLAGS)') -}
293 BIN_LDFLAGS={- join(' ', $target{bin_lflags} || (),
294                          @{$config{bin_lflags}},
295                          '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
296 BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
297
298 # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
299 CPPFLAGS_Q={- $cppflags1 =~ s|([\\"])|\\$1|g;
300               $cppflags2 =~ s|([\\"])|\\$1|g;
301               join(' ', $lib_cppflags || (), $cppflags2 || (),
302                         $cppflags1 || ()) -}
303
304 PERLASM_SCHEME= {- $target{perlasm_scheme} -}
305
306 PROCESSOR= {- $config{processor} -}
307
308 # The main targets ###################################################
309
310 {- dependmagic('all'); -}: build_libs_nodep build_engines_nodep build_programs_nodep
311 {- dependmagic('build_libs'); -}: build_libs_nodep
312 {- dependmagic('build_engines'); -}: build_engines_nodep
313 {- dependmagic('build_programs'); -}: build_programs_nodep
314
315 build_generated: $(GENERATED_MANDATORY)
316 build_libs_nodep: $(LIBS) {- join(" ",map { shlib_import($_) } @{$unified_info{libraries}}) -}
317 build_engines_nodep: $(ENGINES)
318 build_programs_nodep: $(PROGRAMS) $(SCRIPTS)
319
320 # Kept around for backward compatibility
321 build_apps build_tests: build_programs
322
323 # Convenience target to prebuild all generated files, not just the mandatory
324 # ones
325 build_all_generated: $(GENERATED_MANDATORY) $(GENERATED)
326         @{- output_off() if $disabled{makedepend}; "" -}
327         @$(ECHO) "Warning: consider configuring with no-makedepend, because if"
328         @$(ECHO) "         target system doesn't have $(PERL),"
329         @$(ECHO) "         then make will fail..."
330         @{- output_on() if $disabled{makedepend}; "" -}
331
332 test: tests
333 {- dependmagic('tests'); -}: build_programs_nodep build_engines_nodep
334         @{- output_off() if $disabled{tests}; "" -}
335         -mkdir $(BLDDIR)\test\test-runs
336         set SRCTOP=$(SRCDIR)
337         set BLDTOP=$(BLDDIR)
338         set RESULT_D=$(BLDDIR)\test\test-runs
339         set PERL=$(PERL)
340         set OPENSSL_ENGINES=$(MAKEDIR)\engines
341         set OPENSSL_DEBUG_MEMORY=on
342         "$(PERL)" "$(SRCDIR)\test\run_tests.pl" $(TESTS)
343         @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
344         @$(ECHO) "Tests are not supported with your chosen Configure options"
345         @{- output_on() if !$disabled{tests}; "" -}
346
347 list-tests:
348         @{- output_off() if $disabled{tests}; "" -}
349         @set SRCTOP=$(SRCDIR)
350         @"$(PERL)" "$(SRCDIR)\test\run_tests.pl" list
351         @{- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
352         @$(ECHO) "Tests are not supported with your chosen Configure options"
353         @{- output_on() if !$disabled{tests}; "" -}
354
355 install: install_sw install_ssldirs install_docs
356
357 uninstall: uninstall_docs uninstall_sw
358
359 libclean:
360         "$(PERL)" -e "map { m/(.*)\.dll$$/; unlink glob """{.,apps,test,fuzz}/$$1.*"""; } @ARGV" $(SHLIBS)
361         -del /Q /F $(LIBS) libcrypto.* libssl.* ossl_static.pdb
362
363 clean: libclean
364         {- join("\n\t", map { "-del /Q /F $_" } @PROGRAMS) -}
365         -del /Q /F $(ENGINES)
366         -del /Q /F $(SCRIPTS)
367         -del /Q /F $(GENERATED_MANDATORY)
368         -del /Q /F $(GENERATED)
369         -del /Q /S /F *.d *.obj *.pdb *.ilk *.manifest
370         -del /Q /S /F engines\*.lib engines\*.exp
371         -del /Q /S /F apps\*.lib apps\*.rc apps\*.res apps\*.exp
372         -del /Q /S /F test\*.exp
373         -rmdir /Q /S test\test-runs
374
375 distclean: clean
376         -del /Q /F configdata.pm
377         -del /Q /F makefile
378
379 depend:
380         @ {- output_off() if $disabled{makedepend}; "" -}
381         @ "$(PERL)" "$(SRCDIR)\util\add-depends.pl" "VC"
382         @ {- output_on() if $disabled{makedepend}; "" -}
383
384 # Install helper targets #############################################
385
386 install_sw: install_dev install_engines install_runtime
387
388 uninstall_sw: uninstall_runtime uninstall_engines uninstall_dev
389
390 install_docs: install_html_docs
391
392 uninstall_docs: uninstall_html_docs
393
394 install_ssldirs:
395         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\certs"
396         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\private"
397         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(OPENSSLDIR)\misc"
398         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
399                                         "$(OPENSSLDIR)\openssl.cnf.dist"
400         @IF NOT EXIST "$(OPENSSLDIR)\openssl.cnf" \
401          "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\openssl.cnf" \
402                                         "$(OPENSSLDIR)\openssl.cnf"
403         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(MISC_SCRIPTS) \
404                                         "$(OPENSSLDIR)\misc"
405         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
406                                         "$(OPENSSLDIR)\ct_log_list.cnf.dist"
407         @IF NOT EXIST "$(OPENSSLDIR)\ct_log_list.cnf" \
408          "$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\apps\ct_log_list.cnf" \
409                                         "$(OPENSSLDIR)\ct_log_list.cnf"
410
411 install_dev: install_runtime_libs
412         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
413         @$(ECHO) "*** Installing development files"
414         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\include\openssl"
415         @{- output_off() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
416         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(SRCDIR)\ms\applink.c" \
417                                        "$(INSTALLTOP)\include\openssl"
418         @{- output_on() unless grep { $_ eq "OPENSSL_USE_APPLINK" } (@{$target{defines}}, @{$config{defines}}); "" -}
419         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "-exclude_re=/__DECC_" \
420                                        "$(SRCDIR)\include\openssl\*.h" \
421                                        "$(INSTALLTOP)\include\openssl"
422         @"$(PERL)" "$(SRCDIR)\util\copy.pl" "$(BLDDIR)\include\openssl\*.h" \
423                                        "$(INSTALLTOP)\include\openssl"
424         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(libdir)"
425         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) "$(libdir)"
426         @if "$(SHLIBS)"=="" \
427          "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb "$(libdir)"
428
429 uninstall_dev:
430
431 install_engines: install_runtime_libs build_engines
432         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
433         @$(ECHO) "*** Installing engines"
434         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(ENGINESDIR)"
435         @if not "$(ENGINES)"=="" \
436          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINES) "$(ENGINESDIR)"
437         @if not "$(ENGINES)"=="" \
438          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINEPDBS) "$(ENGINESDIR)"
439
440 uninstall_engines:
441
442 install_runtime: install_programs
443
444 install_runtime_libs: build_libs
445         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
446         @$(ECHO) "*** Installing runtime libraries"
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
454 install_programs: install_runtime_libs build_programs
455         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
456         @$(ECHO) "*** Installing runtime programs"
457         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
458         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \
459                                         "$(INSTALLTOP)\bin"
460         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \
461                                         "$(INSTALLTOP)\bin"
462         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
463                                         "$(INSTALLTOP)\bin"
464
465 uninstall_runtime:
466
467 install_html_docs:
468         "$(PERL)" "$(SRCDIR)\util\process_docs.pl" \
469                 "--destdir=$(INSTALLTOP)\html" --type=html
470
471 uninstall_html_docs:
472
473 # Building targets ###################################################
474
475 configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
476         @$(ECHO) "Detected changed: $?"
477         "$(PERL)" configdata.pm -r
478         @$(ECHO) "**************************************************"
479         @$(ECHO) "***                                            ***"
480         @$(ECHO) "***   Please run the same make command again   ***"
481         @$(ECHO) "***                                            ***"
482         @$(ECHO) "**************************************************"
483         @exit 1
484
485 reconfigure reconf:
486         "$(PERL)" configdata.pm -r
487
488 {-
489  use File::Basename;
490  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
491
492  # Helper function to figure out dependencies on libraries
493  # It takes a list of library names and outputs a list of dependencies
494  sub compute_lib_depends {
495      if ($disabled{shared}) {
496          return map { lib($_) } @_;
497      }
498      return map { shlib_import($_) or lib($_) } @_;
499  }
500
501   sub generatesrc {
502       my %args = @_;
503       (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
504       my ($gen0, @gens) = @{$args{generator}};
505       my $generator = '"'.$gen0.'"'.join('', map { " $_" } @gens);
506       my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
507       my $incs = join("", map { " /I \"$_\"" } @{$args{incs}});
508       my $deps = @{$args{deps}} ?
509           '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
510
511       if ($target !~ /\.asm$/) {
512           if ($args{generator}->[0] =~ m|^.*\.in$|) {
513               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
514                                                    "util", "dofile.pl")),
515                                    rel2abs($config{builddir}));
516               return <<"EOF";
517 $target: "$args{generator}->[0]" $deps
518         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
519             "-o$target{build_file}" $generator > \$@
520 EOF
521           } else {
522               return <<"EOF";
523 $target: "$args{generator}->[0]" $deps
524         "\$(PERL)"$generator_incs $generator > \$@
525 EOF
526           }
527       } else {
528           if ($args{generator}->[0] =~ /\.pl$/) {
529               $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
530           } elsif ($args{generator}->[0] =~ /\.S$/) {
531               $generator = undef;
532           } else {
533               die "Generator type for $src unknown: $generator\n";
534           }
535
536           my $cppflags = $incs;
537           $cppflags .= {
538               lib => ' $(LIB_CFLAGS) $(LIB_CPPFLAGS)',
539               dso => ' $(DSO_CFLAGS) $(DSO_CPPFLAGS)',
540               bin => ' $(BIN_CFLAGS) $(BIN_CPPFLAGS)'
541           } -> {$args{intent}};
542           if (defined($generator)) {
543               # If the target is named foo.S in build.info, we want to
544               # end up generating foo.s in two steps.
545               if ($args{src} =~ /\.S$/) {
546                    return <<"EOF";
547 $target: "$args{generator}->[0]" $deps
548         set ASM=\$(AS)
549         $generator \$@.S
550         \$(CPP) $cppflags \$@.S > \$@.i && move /Y \$@.i \$@
551         del /Q \$@.S
552 EOF
553               }
554               # Otherwise....
555               return <<"EOF";
556 $target: "$args{generator}->[0]" $deps
557         set ASM=\$(AS)
558         $generator \$@
559 EOF
560           }
561           return <<"EOF";
562 $target: "$args{generator}->[0]" $deps
563         \$(CPP) $incs $cppflags "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
564 EOF
565       }
566   }
567
568  sub src2obj {
569      my %args = @_;
570      my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
571                     } ( @{$args{srcs}} );
572      my $srcs = '"'.join('" "',  @srcs).'"';
573      my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
574      my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
575      my $cflags = { lib => ' $(LIB_CFLAGS)',
576                     dso => ' $(DSO_CFLAGS)',
577                     bin => ' $(BIN_CFLAGS)' } -> {$args{intent}};
578      $cflags .= $incs;
579      $cflags .= { lib => ' $(LIB_CPPFLAGS)',
580                   dso => ' $(DSO_CPPFLAGS)',
581                   bin => ' $(BIN_CPPFLAGS)' } -> {$args{intent}};
582      my $asflags = { lib => ' $(LIB_ASFLAGS)',
583                      dso => ' $(DSO_ASFLAGS)',
584                      bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}};
585      my $makedepprog = $config{makedepprog};
586      if ($srcs[0] =~ /\.rc$/) {
587          return <<"EOF";
588 $args{obj}: $deps
589         \$(RC) \$(RCOUTFLAG)\$\@ $srcs
590 EOF
591      }
592      (my $obj = $args{obj}) =~ s|\.o$||;
593      if ($srcs[0] =~ /\.asm$/) {
594          return <<"EOF";
595 $obj$objext: $deps
596         \$(AS) $asflags \$(ASOUTFLAG)\$\@ $srcs
597 EOF
598      } elsif ($srcs[0] =~ /.S$/) {
599          return <<"EOF";
600 $obj$objext: $deps
601         \$(CC) /EP /D__ASSEMBLER__ $cflags $srcs > \$@.asm && \$(AS) $asflags \$(ASOUTFLAG)\$\@ \$@.asm
602 EOF
603      }
604      my $recipe = <<"EOF";
605 $obj$objext: $deps
606         \$(CC) $cflags -c \$(COUTFLAG)\$\@ $srcs
607 EOF
608      $recipe .= <<"EOF" unless $disabled{makedepend};
609         \$(CC) $cflags /Zs /showIncludes $srcs 2>&1 > $obj$depext
610 EOF
611      return $recipe;
612  }
613
614  # We *know* this routine is only called when we've configure 'shared'.
615  # Also, note that even though the import library built here looks like
616  # a static library, it really isn't.
617  sub libobj2shlib {
618      my %args = @_;
619      my $lib = $args{lib};
620      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x }
621                 grep { $_ =~ m/\.(?:o|res)$/ }
622                 @{$args{objs}};
623      my @defs = grep { $_ =~ /\.def$/ } @{$args{objs}};
624      my @deps = compute_lib_depends(@{$args{deps}});
625      die "More than one exported symbols list" if scalar @defs > 1;
626      my $linklibs = join("", map { "$_\n" } @deps);
627      my $objs = join("\n", @objs);
628      my $deps = join(" ", @objs, @defs, @deps);
629      my $import = shlib_import($lib);
630      my $dll =  shlib($lib);
631      my $shared_def = join("", map { " /def:$_" } @defs);
632      return <<"EOF"
633 # The import library may look like a static library, but it is not.
634 # We MUST make the import library depend on the DLL, in case someone
635 # mistakenly removes the latter.
636 $import: $dll
637 $dll: $deps
638         IF EXIST $full.manifest DEL /F /Q $full.manifest
639         IF EXIST \$@ DEL /F /Q \$@
640         \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
641                 /implib:$import \$(LDOUTFLAG)$dll$shared_def @<< || (DEL /Q \$(\@B).* $import && EXIT 1)
642 $objs
643 $linklibs\$(LIB_EX_LIBS)
644 <<
645         IF EXIST $dll.manifest \\
646            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dll.manifest \$(MTOUTFLAG)$dll
647         IF EXIST apps\\$dll DEL /Q /F apps\\$dll
648         IF EXIST test\\$dll DEL /Q /F test\\$dll
649         IF EXIST fuzz\\$dll DEL /Q /F fuzz\\$dll
650         COPY $dll apps
651         COPY $dll test
652         COPY $dll fuzz
653 EOF
654  }
655  sub obj2dso {
656      my %args = @_;
657      my $dso = $args{lib};
658      my $dso_n = basename($dso);
659      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
660      my @deps = compute_lib_depends(@{$args{deps}});
661      my $objs = join("\n", @objs);
662      my $linklibs = join("", map { "$_\n" } @deps);
663      my $deps = join(" ", @objs, @deps);
664      return <<"EOF";
665 $dso$dsoext: $deps
666         IF EXIST $dso$dsoext.manifest DEL /F /Q $dso$dsoext.manifest
667         \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \$(LDOUTFLAG)$dso$dsoext /def:<< @<<
668 LIBRARY         $dso_n
669 EXPORTS
670     bind_engine         @1
671     v_check             @2
672 <<
673 $objs
674 $linklibs \$(DSO_EX_LIBS)
675 <<
676         IF EXIST $dso$dsoext.manifest \\
677            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso$dsoext.manifest \$(MTOUTFLAG)$dso$dsoext
678 EOF
679  }
680  sub obj2lib {
681      my %args = @_;
682      my $lib = lib($args{lib});
683      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
684      my $objs = join("\n", @objs);
685      my $deps = join(" ", @objs);
686      return <<"EOF";
687 $lib: $deps
688         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib @<<
689 $objs
690 <<
691 EOF
692  }
693  sub obj2bin {
694      my %args = @_;
695      my $bin = $args{bin};
696      my @objs = map { (my $x = $_) =~ s|\.o$|$objext|; $x } @{$args{objs}};
697      my @deps = compute_lib_depends(@{$args{deps}});
698      my $objs = join("\n", @objs);
699      my $linklibs = join("", map { "$_\n" } @deps);
700      my $deps = join(" ", @objs, @deps);
701      return <<"EOF";
702 $bin$exeext: $deps
703         IF EXIST $bin$exeext.manifest DEL /F /Q $bin$exeext.manifest
704         \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<<
705 $objs
706 setargv.obj
707 $linklibs\$(BIN_EX_LIBS)
708 <<
709         IF EXIST $bin$exeext.manifest \\
710            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin$exeext.manifest \$(MTOUTFLAG)$bin$exeext
711 EOF
712   }
713   sub in2script {
714       my %args = @_;
715       my $script = $args{script};
716       my $sources = '"'.join('" "', @{$args{sources}}).'"';
717       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
718                                            "util", "dofile.pl")),
719                            rel2abs($config{builddir}));
720       return <<"EOF";
721 $script: $sources
722         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
723             "-o$target{build_file}" $sources > "$script"
724 EOF
725   }
726   sub generatedir {
727       my %args = @_;
728       my $dir = $args{dir};
729       my @deps = map { s|\.o$|$objext|; $_ } @{$args{deps}};
730       my @actions = ();
731       my %extinfo = ( dso => $dsoext,
732                       lib => $libext,
733                       bin => $exeext );
734
735       # We already have a 'test' target, and the top directory is just plain
736       # silly
737       return if $dir eq "test" || $dir eq ".";
738
739       foreach my $type (("dso", "lib", "bin", "script")) {
740           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
741           # For lib object files, we could update the library.  However,
742           # LIB on Windows doesn't work that way, so we won't create any
743           # actions for it, and the dependencies are already taken care of.
744           if ($type ne "lib") {
745               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
746                   if (dirname($prod) eq $dir) {
747                       push @deps, $prod.$extinfo{$type};
748                   }
749               }
750           }
751       }
752
753       my $deps = join(" ", @deps);
754       my $actions = join("\n", "", @actions);
755       return <<"EOF";
756 $dir $dir\\ : $deps$actions
757 EOF
758   }
759   ""    # Important!  This becomes part of the template result.
760 -}