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