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