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