0cd1e863d3acd484e582838f362461f5e5e335af
[openssl.git] / Configurations / windows-makefile.tmpl
1 ##
2 ## Makefile for OpenSSL
3 ##
4 ## {- join("\n## ", @autowarntext) -}
5 {-
6  our $sover_dirname = platform->shlib_version_as_filename();
7
8  my $build_scheme = $target{build_scheme};
9  my $install_flavour = $build_scheme->[$#$build_scheme]; # last element
10  my $win_installenv =
11      $install_flavour eq "VC-WOW" ? "ProgramFiles(x86)"
12                                   : "ProgramW6432";
13  my $win_commonenv =
14      $install_flavour eq "VC-WOW" ? "CommonProgramFiles(x86)"
15                                   : "CommonProgramW6432";
16  our $win_installroot =
17      defined($ENV{$win_installenv}) ? $win_installenv : 'ProgramFiles';
18  our $win_commonroot =
19      defined($ENV{$win_commonenv}) ? $win_commonenv : 'CommonProgramFiles';
20
21  # expand variables early
22  $win_installroot = $ENV{$win_installroot};
23  $win_commonroot = $ENV{$win_commonroot};
24
25  # This makes sure things get built in the order they need
26  # to. You're welcome.
27  sub dependmagic {
28      my $target = shift;
29
30      return "$target: build_generated\n\t\$(MAKE) /\$(MAKEFLAGS) depend && \$(MAKE) /\$(MAKEFLAGS) _$target\n_$target";
31  }
32  '';
33 -}
34
35 PLATFORM={- $config{target} -}
36 SRCDIR={- $config{sourcedir} -}
37 BLDDIR={- $config{builddir} -}
38
39 VERSION={- "$config{full_version}" -}
40 MAJOR={- $config{major} -}
41 MINOR={- $config{minor} -}
42
43 SHLIB_VERSION_NUMBER={- $config{shlib_version} -}
44
45 LIBS={- join(" ", map { ( platform->sharedlib_import($_), platform->staticlib($_) ) } @{$unified_info{libraries}}) -}
46 SHLIBS={- join(" ", map { platform->sharedlib($_) // () } @{$unified_info{libraries}}) -}
47 SHLIBPDBS={- join(" ", map { platform->sharedlibpdb($_) // () } @{$unified_info{libraries}}) -}
48 ENGINES={- join(" ", map { platform->dso($_) } @{$unified_info{engines}}) -}
49 ENGINEPDBS={- join(" ", map { platform->dsopdb($_) } @{$unified_info{engines}}) -}
50 PROGRAMS={- our @PROGRAMS = map { platform->bin($_) } @{$unified_info{programs}}; join(" ", @PROGRAMS) -}
51 PROGRAMPDBS={- join(" ", map { $_.".pdb" } @{$unified_info{programs}}) -}
52 SCRIPTS={- join(" ", @{$unified_info{scripts}}) -}
53 {- output_off() if $disabled{makedepend}; "" -}
54 DEPS={- join(" ", map { platform->isobj($_) ? platform->dep($_) : () }
55                   grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
56                   keys %{$unified_info{sources}}); -}
57 {- output_on() if $disabled{makedepend}; "" -}
58 GENERATED_MANDATORY={- join(" ", @{$unified_info{depends}->{""}} ) -}
59 GENERATED={- # common0.tmpl provides @generated
60              join(" ", map { platform->convertext($_) } @generated) -}
61
62 INSTALL_LIBS={-
63         join(" ", map { quotify1(platform->sharedlib_import($_)
64                                  // platform->staticlib($_)) }
65                   grep { !$unified_info{attributes}->{$_}->{noinst} }
66                   @{$unified_info{libraries}})
67 -}
68 INSTALL_SHLIBS={-
69         join(" ", map { my $x = platform->sharedlib($_);
70                         $x ? quotify_l($x) : () }
71                   grep { !$unified_info{attributes}->{$_}->{noinst} }
72                   @{$unified_info{libraries}})
73 -}
74 INSTALL_SHLIBPDBS={-
75         join(" ", map { my $x = platform->sharedlibpdb($_);
76                         $x ? quotify_l($x) : () }
77                   grep { !$unified_info{attributes}->{$_}->{noinst} }
78                   @{$unified_info{libraries}})
79 -}
80 INSTALL_ENGINES={-
81         join(" ", map { quotify1(platform->dso($_)) }
82                   grep { !$unified_info{attributes}->{$_}->{noinst} }
83                   @{$unified_info{engines}})
84 -}
85 INSTALL_ENGINEPDBS={-
86         join(" ", map { quotify1(platform->dsopdb($_)) }
87                   grep { !$unified_info{attributes}->{$_}->{noinst} }
88                   @{$unified_info{engines}})
89 -}
90 INSTALL_PROGRAMS={-
91         join(" ", map { quotify1(platform->bin($_)) }
92                   grep { !$unified_info{attributes}->{$_}->{noinst} }
93                   @{$unified_info{programs}})
94 -}
95 INSTALL_PROGRAMPDBS={-
96         join(" ", map { quotify1(platform->binpdb($_)) }
97                   grep { !$unified_info{attributes}->{$_}->{noinst} }
98                   @{$unified_info{programs}})
99 -}
100 BIN_SCRIPTS={-
101         join(" ", map { quotify1($_) }
102                   grep { !$unified_info{attributes}->{$_}->{noinst}
103                          && !$unified_info{attributes}->{$_}->{misc} }
104                   @{$unified_info{scripts}})
105 -}
106 MISC_SCRIPTS={-
107         join(" ", map { quotify1($_) }
108                   grep { !$unified_info{attributes}->{$_}->{noinst}
109                          && $unified_info{attributes}->{$_}->{misc} }
110                   @{$unified_info{scripts}})
111 -}
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 { platform->sharedlib_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: 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: install_runtime_libs
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: install_runtime_libs build_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: install_programs
447
448 install_runtime_libs: build_libs
449         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
450         @$(ECHO) "*** Installing runtime libraries"
451         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
452         @if not "$(SHLIBS)"=="" \
453          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBS) "$(INSTALLTOP)\bin"
454         @if not "$(SHLIBS)"=="" \
455          "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBPDBS) \
456                                         "$(INSTALLTOP)\bin"
457
458 install_programs: install_runtime_libs build_programs
459         @if "$(INSTALLTOP)"=="" ( $(ECHO) "INSTALLTOP should not be empty" & exit 1 )
460         @$(ECHO) "*** Installing runtime programs"
461         @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(INSTALLTOP)\bin"
462         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \
463                                         "$(INSTALLTOP)\bin"
464         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \
465                                         "$(INSTALLTOP)\bin"
466         @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(BIN_SCRIPTS) \
467                                         "$(INSTALLTOP)\bin"
468
469 uninstall_runtime:
470
471 install_html_docs:
472         "$(PERL)" "$(SRCDIR)\util\process_docs.pl" \
473                 "--destdir=$(INSTALLTOP)\html" --type=html
474
475 uninstall_html_docs:
476
477 # Building targets ###################################################
478
479 configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
480         @$(ECHO) "Detected changed: $?"
481         "$(PERL)" configdata.pm -r
482         @$(ECHO) "**************************************************"
483         @$(ECHO) "***                                            ***"
484         @$(ECHO) "***   Please run the same make command again   ***"
485         @$(ECHO) "***                                            ***"
486         @$(ECHO) "**************************************************"
487         @exit 1
488
489 reconfigure reconf:
490         "$(PERL)" configdata.pm -r
491
492 {-
493  use File::Basename;
494  use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
495
496  # Helper function to figure out dependencies on libraries
497  # It takes a list of library names and outputs a list of dependencies
498  sub compute_lib_depends {
499      if ($disabled{shared}) {
500          return map { platform->staticlib($_) } @_;
501      }
502      return map { platform->sharedlib_import($_) // platform->staticlib($_) } @_;
503  }
504
505   sub generatesrc {
506       my %args = @_;
507       my ($gen0, @gens) = @{$args{generator}};
508       my $generator = '"'.$gen0.'"'.join('', map { " $_" } @gens);
509       my $generator_incs = join("", map { " -I \"$_\"" } @{$args{generator_incs}});
510       my $incs = join("", map { " /I \"$_\"" } @{$args{incs}});
511       my $defs = join("", map { " /D".$_ } @{$args{defs}});
512       my $deps = @{$args{deps}} ?
513           '"'.join('" "', @{$args{generator_deps}}, @{$args{deps}}).'"' : '';
514
515       if (platform->isdef($args{src})) {
516           my $target = platform->def($args{src});
517           my $mkdef = abs2rel(rel2abs(catfile($config{sourcedir},
518                                               "util", "mkdef.pl")),
519                               rel2abs($config{builddir}));
520           my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION)' : '';
521           my $ord_name =
522               $args{generator}->[1] || platform->dsoname($args{product});
523           return <<"EOF";
524 $target: $args{generator}->[0] $deps $mkdef
525         \$(PERL) $mkdef$ord_ver --ordinals $args{generator}->[0] --name $ord_name --OS windows > $target
526 EOF
527       } elsif (!platform->isasm($args{src})) {
528           my $target = $args{src};
529           if ($args{generator}->[0] =~ m|^.*\.in$|) {
530               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
531                                                    "util", "dofile.pl")),
532                                    rel2abs($config{builddir}));
533               return <<"EOF";
534 $target: "$args{generator}->[0]" $deps
535         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
536             "-o$target{build_file}" $generator > \$@
537 EOF
538           } else {
539               return <<"EOF";
540 $target: "$args{generator}->[0]" $deps
541         "\$(PERL)"$generator_incs $generator > \$@
542 EOF
543           }
544       } else {
545           my $target = platform->asm($args{src});
546           if ($args{generator}->[0] =~ /\.pl$/) {
547               $generator = '"$(PERL)"'.$generator_incs.' '.$generator;
548           } elsif ($args{generator}->[0] =~ /\.S$/) {
549               $generator = undef;
550           } else {
551               die "Generator type for $src unknown: $generator\n";
552           }
553
554           my $cppflags = $incs;
555           $cppflags .= {
556               shlib => ' $(LIB_CFLAGS) $(LIB_CPPFLAGS)',
557               lib => ' $(LIB_CFLAGS) $(LIB_CPPFLAGS)',
558               dso => ' $(DSO_CFLAGS) $(DSO_CPPFLAGS)',
559               bin => ' $(BIN_CFLAGS) $(BIN_CPPFLAGS)'
560           } -> {$args{intent}};
561           if (defined($generator)) {
562               # If the target is named foo.S in build.info, we want to
563               # end up generating foo.s in two steps.
564               if ($args{src} =~ /\.S$/) {
565                    return <<"EOF";
566 $target: "$args{generator}->[0]" $deps
567         set ASM=\$(AS)
568         $generator \$@.S
569         \$(CPP) $cppflags $defs \$@.S > \$@.i && move /Y \$@.i \$@
570         del /Q \$@.S
571 EOF
572               }
573               # Otherwise....
574               return <<"EOF";
575 $target: "$args{generator}->[0]" $deps
576         set ASM=\$(AS)
577         $generator \$@
578 EOF
579           }
580           return <<"EOF";
581 $target: "$args{generator}->[0]" $deps
582         \$(CPP) $incs $cppflags $defs "$args{generator}->[0]" > \$@.i && move /Y \$@.i \$@
583 EOF
584       }
585   }
586
587  sub src2obj {
588      my %args = @_;
589      my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x } ( @{$args{srcs}} );
590      my $srcs = '"'.join('" "',  @srcs).'"';
591      my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"';
592      my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}});
593      my $defs = join("", map { " /D".$_ } @{$args{defs}});
594      my $cflags = { shlib => ' $(LIB_CFLAGS)',
595                     lib => ' $(LIB_CFLAGS)',
596                     dso => ' $(DSO_CFLAGS)',
597                     bin => ' $(BIN_CFLAGS)' } -> {$args{intent}};
598      $cflags .= $incs;
599      $cflags .= { shlib => ' $(LIB_CPPFLAGS)',
600                   lib => ' $(LIB_CPPFLAGS)',
601                   dso => ' $(DSO_CPPFLAGS)',
602                   bin => ' $(BIN_CPPFLAGS)' } -> {$args{intent}};
603      my $asflags = { shlib => ' $(LIB_ASFLAGS)',
604                      lib => ' $(LIB_ASFLAGS)',
605                      dso => ' $(DSO_ASFLAGS)',
606                      bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}};
607      my $makedepprog = $config{makedepprog};
608      if ($srcs[0] =~ /\.rc$/) {
609          my $res = platform->res($args{obj});
610          return <<"EOF";
611 $res: $deps
612         \$(RC) \$(RCOUTFLAG)\$\@ $srcs
613 EOF
614      }
615      my $obj = platform->obj($args{obj});
616      my $dep = platform->dep($args{obj});
617      if ($srcs[0] =~ /\.asm$/) {
618          return <<"EOF";
619 $obj: $deps
620         \$(AS) $asflags \$(ASOUTFLAG)\$\@ $srcs
621 EOF
622      } elsif ($srcs[0] =~ /.S$/) {
623          return <<"EOF";
624 $obj: $deps
625         \$(CC) /EP /D__ASSEMBLER__ $cflags $defs $srcs > \$@.asm && \$(AS) $asflags \$(ASOUTFLAG)\$\@ \$@.asm
626 EOF
627      }
628      my $recipe = <<"EOF";
629 $obj: $deps
630         \$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
631 EOF
632      $recipe .= <<"EOF" unless $disabled{makedepend};
633         \$(CC) $cflags $defs /Zs /showIncludes $srcs 2>&1 > $dep
634 EOF
635      return $recipe;
636  }
637
638  # We *know* this routine is only called when we've configure 'shared'.
639  # Also, note that even though the import library built here looks like
640  # a static library, it really isn't.
641  sub obj2shlib {
642      my %args = @_;
643      my $lib = $args{lib};
644      my @objs = map { platform->convertext($_) }
645                 grep { platform->isobj($_) || platform->isres($_) }
646                 @{$args{objs}};
647      my @defs = map { platform->def($_) }
648                 grep { platform->isdef($_) }
649                 @{$args{objs}};
650      my @deps = compute_lib_depends(@{$args{deps}});
651      die "More than one exported symbols list" if scalar @defs > 1;
652      my $linklibs = join("", map { "$_\n" } @deps);
653      my $objs = join("\n", @objs);
654      my $deps = join(" ", @objs, @defs, @deps);
655      my $import = platform->sharedlib_import($lib);
656      my $dll =  platform->sharedlib($lib);
657      my $shared_def = join("", map { " /def:$_" } @defs);
658      return <<"EOF"
659 # The import library may look like a static library, but it is not.
660 # We MUST make the import library depend on the DLL, in case someone
661 # mistakenly removes the latter.
662 $import: $dll
663 $dll: $deps
664         IF EXIST $full.manifest DEL /F /Q $full.manifest
665         IF EXIST \$@ DEL /F /Q \$@
666         \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
667                 /implib:$import \$(LDOUTFLAG)$dll$shared_def @<< || (DEL /Q \$(\@B).* $import && EXIT 1)
668 $objs
669 $linklibs\$(LIB_EX_LIBS)
670 <<
671         IF EXIST $dll.manifest \\
672            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dll.manifest \$(MTOUTFLAG)$dll
673         IF EXIST apps\\$dll DEL /Q /F apps\\$dll
674         IF EXIST test\\$dll DEL /Q /F test\\$dll
675         IF EXIST fuzz\\$dll DEL /Q /F fuzz\\$dll
676         COPY $dll apps
677         COPY $dll test
678         COPY $dll fuzz
679 EOF
680  }
681  sub obj2dso {
682      my %args = @_;
683      my $dso = platform->dso($args{lib});
684      my $dso_n = platform->dsoname($args{lib});
685      my @objs = map { platform->convertext($_) }
686                 grep { platform->isobj($_) || platform->isres($_) }
687                 @{$args{objs}};
688      my @defs = map { platform->def($_) }
689                 grep { platform->isdef($_) }
690                 @{$args{objs}};
691      my @deps = compute_lib_depends(@{$args{deps}});
692      my $objs = join("\n", @objs);
693      my $linklibs = join("", map { "$_\n" } @deps);
694      my $deps = join(" ", @objs, @defs, @deps);
695      my $shared_def = join("", map { " /def:$_" } @defs);
696      return <<"EOF";
697 $dso: $deps
698         IF EXIST $dso.manifest DEL /F /Q $dso.manifest
699         \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \\
700                 \$(LDOUTFLAG)$dso$shared_def @<< || (DEL /Q \$(\@B).* $dso_n.* && EXIT 1)
701 $objs
702 $linklibs \$(DSO_EX_LIBS)
703 <<
704         IF EXIST $dso.manifest \\
705            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso.manifest \$(MTOUTFLAG)$dso
706 EOF
707  }
708  sub obj2lib {
709      my %args = @_;
710      my $lib = platform->staticlib($args{lib});
711      my @objs = map { platform->obj($_) } @{$args{objs}};
712      my $objs = join("\n", @objs);
713      my $deps = join(" ", @objs);
714      return <<"EOF";
715 $lib: $deps
716         \$(AR) \$(ARFLAGS) \$(AROUTFLAG)$lib @<<
717 $objs
718 <<
719 EOF
720  }
721  sub obj2bin {
722      my %args = @_;
723      my $bin = platform->bin($args{bin});
724      my @objs = map { platform->convertext($_) }
725                 grep { platform->isobj($_) || platform->isres($_) }
726                 @{$args{objs}};
727      my @deps = compute_lib_depends(@{$args{deps}});
728      my $objs = join("\n", @objs);
729      my $linklibs = join("", map { "$_\n" } @deps);
730      my $deps = join(" ", @objs, @deps);
731      return <<"EOF";
732 $bin: $deps
733         IF EXIST $bin.manifest DEL /F /Q $bin.manifest
734         \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin @<<
735 $objs
736 setargv.obj
737 $linklibs\$(BIN_EX_LIBS)
738 <<
739         IF EXIST $bin.manifest \\
740            \$(MT) \$(MTFLAGS) \$(MTINFLAG)$bin.manifest \$(MTOUTFLAG)$bin
741 EOF
742   }
743   sub in2script {
744       my %args = @_;
745       my $script = $args{script};
746       my $sources = '"'.join('" "', @{$args{sources}}).'"';
747       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
748                                            "util", "dofile.pl")),
749                            rel2abs($config{builddir}));
750       return <<"EOF";
751 $script: $sources
752         "\$(PERL)" "-I\$(BLDDIR)" -Mconfigdata "$dofile" \\
753             "-o$target{build_file}" $sources > "$script"
754 EOF
755   }
756   sub generatedir {
757       my %args = @_;
758       my $dir = $args{dir};
759       my @deps = map { platform->convertext($_) } @{$args{deps}};
760       my @actions = ();
761       my %extinfo = ( dso => platform->dsoext(),
762                       lib => platform->libext(),
763                       bin => platform->binext() );
764
765       # We already have a 'test' target, and the top directory is just plain
766       # silly
767       return if $dir eq "test" || $dir eq ".";
768
769       foreach my $type (("dso", "lib", "bin", "script")) {
770           next unless defined($unified_info{dirinfo}->{$dir}->{products}->{$type});
771           # For lib object files, we could update the library.  However,
772           # LIB on Windows doesn't work that way, so we won't create any
773           # actions for it, and the dependencies are already taken care of.
774           if ($type ne "lib") {
775               foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) {
776                   if (dirname($prod) eq $dir) {
777                       push @deps, $prod.$extinfo{$type};
778                   }
779               }
780           }
781       }
782
783       my $deps = join(" ", @deps);
784       my $actions = join("\n", "", @actions);
785       return <<"EOF";
786 $dir $dir\\ : $deps$actions
787 EOF
788   }
789   ""    # Important!  This becomes part of the template result.
790 -}