Remove the source directory .num targets
[openssl.git] / Configurations / descrip.mms.tmpl
1 ## descrip.mms to build OpenSSL on OpenVMS
2 ##
3 ## {- join("\n## ", @autowarntext) -}
4 {-
5   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
6   use File::Basename;
7   use OpenSSL::Util;
8
9   (our $osslprefix_q = platform->osslprefix()) =~ s/\$/\\\$/;
10
11   our $sover_dirname = platform->shlib_version_as_filename();
12   our $osslver = sprintf "%02d", split(/\./, $config{version});
13
14   our $sourcedir = $config{sourcedir};
15   our $builddir = $config{builddir};
16   sub make_unix_path {
17       # Split the native path
18       (my $vol, my $dirs, my $file) = File::Spec->splitpath($_[0]);
19       my @dirs = File::Spec->splitdir($dirs);
20
21       # Reassemble it as a Unix path
22       $vol =~ s|:$||;
23       return File::Spec::Unix->catpath(
24           '', File::Spec::Unix->catdir('', $vol ? $vol : (), @dirs), $file);
25   }
26   sub sourcefile {
27       catfile($sourcedir, @_);
28   }
29   sub buildfile {
30       catfile($builddir, @_);
31   }
32   sub sourcedir {
33       catdir($sourcedir, @_);
34   }
35   sub builddir {
36       catdir($builddir, @_);
37   }
38   sub tree {
39       (my $x = shift) =~ s|\]$|...]|;
40       $x
41   }
42
43   # Because we need to make two computations of these data,
44   # we store them in arrays for reuse
45   our @libs =
46       map { platform->staticname($_) }
47       @{$unified_info{libraries}};
48   our @shlibs =
49       map { platform->sharedname($_) // () }
50       @{$unified_info{libraries}};
51   our @install_libs =
52       map { platform->staticname($_) }
53       grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
54       @{$unified_info{libraries}};
55   our @install_shlibs =
56       map { platform->sharedname($_) // () }
57       grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
58       @{$unified_info{libraries}};
59   our @install_engines =
60       grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
61              && $unified_info{attributes}->{modules}->{$_}->{engine} }
62       @{$unified_info{modules}};
63   our @install_modules =
64       grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
65              && !$unified_info{attributes}->{modules}->{$_}->{engine}
66              && !$unified_info{attributes}->{modules}->{$_}->{fips} }
67       @{$unified_info{modules}};
68   our @install_fipsmodules =
69       grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
70              && $unified_info{attributes}->{modules}->{$_}->{fips} }
71       @{$unified_info{modules}};
72   our @install_programs =
73       grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
74       @{$unified_info{programs}};
75   our @install_bin_scripts =
76       grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
77              && !$unified_info{attributes}->{scripts}->{$_}->{misc} }
78       @{$unified_info{scripts}};
79   our @install_misc_scripts =
80       grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
81              && $unified_info{attributes}->{scripts}->{$_}->{misc} }
82       @{$unified_info{scripts}};
83
84   # Configured flags
85
86   our @cnf_asflags = ($target{asflags} || (), @{$config{asflags}});
87   our @cnf_defines = (@{$target{defines}}, @{$config{defines}});
88   our @cnf_includes = (@{$target{includes}}, @{$config{includes}});
89   our @cnf_cppflags = ($target{cppflags} || (), @{$config{cppflags}});
90   our @cnf_cflags = ($target{cflags} || (), @{$config{cflags}});
91   our @cnf_cxxflags = ($target{cxxflags} || (), @{$config{cxxflags}});
92   our @cnf_ldflags = ($target{lflags} || (), @{$config{lflags}});
93   our @cnf_ex_libs = (map{ ",$_" } @{$target{ex_libs}}, @{$config{ex_libs}});
94
95   # Variables starting with $lib_ are used to build library object files
96   # and shared libraries.
97   # Variables starting with $dso_ are used to build DSOs and their object files.
98   # Variables starting with $bin_ are used to build programs and their object
99   # files.
100
101   # The following array is special and is treated separately from the rest of
102   # the lib_ variables.
103   our @lib_cppincludes = (@{$target{lib_includes}}, @{$target{shared_includes}},
104                           @{$config{lib_includes}}, @{$config{shared_includes}},
105                           @cnf_includes);
106
107   our $lib_cppdefines =
108       join(',', @{$target{lib_defines}}, @{$target{shared_defines}},
109                 @{$config{lib_defines}}, @{$config{shared_defines}},
110                 @cnf_defines,
111                 'OPENSSLDIR="""$(OPENSSLDIR_C)"""',
112                 'ENGINESDIR="""$(ENGINESDIR_C)"""',
113                 'MODULESDIR="""$(MODULESDIR_C)"""'
114                 )
115       . '$(DEFINES)'
116       . "'extradefines'";
117   our $lib_asflags =
118       join(' ', $target{lib_asflags} || (), @{$config{lib_asflags}},
119                 @cnf_asflags, '$(ASFLAGS)');
120   our $lib_cppflags =
121       join('', $target{lib_cppflags} || (), $target{shared_cppflags} || (),
122                @{$config{lib_cppflags}}, @{$config{shared_cppflag}},
123                @cnf_cppflags, '/DEFINE=('.$lib_cppdefines.')', '$(CPPFLAGS)');
124   my @lib_cflags = ( $target{lib_cflags} // () );
125   my @lib_cflags_no_inst = ( $target{no_inst_lib_cflags} // @lib_cflags );
126   my @lib_cflags_cont = ( $target{shared_cflag} || (),
127                           @{$config{lib_cflags}}, @{$config{shared_cflag}},
128                           @cnf_cflags, '$(CFLAGS)');
129   our $lib_cflags = join('', @lib_cflags, @lib_cflags_cont );
130   our $lib_cflags_no_inst = join('', @lib_cflags_no_inst, @lib_cflags_cont );
131   our $lib_ldflags =
132       join('', $target{lib_lflags} || (), $target{shared_ldflag} || (),
133                @{$config{lib_lflags}}, @{$config{shared_ldflag}},
134                @cnf_ldflags, '$(LDFLAGS)');
135   our $lib_ex_libs = join('', @cnf_ex_libs, '$(EX_LIBS)');
136
137   # The following array is special and is treated separately from the rest of
138   # the dso_ variables.
139   our @dso_cppincludes = (@{$target{dso_includes}}, @{$target{module_includes}},
140                           @{$config{dso_includes}}, @{$config{module_includes}},
141                           @cnf_includes);
142
143   our $dso_cppdefines =
144       join(',', @{$target{dso_defines}}, @{$target{module_defines}},
145                 @{$config{dso_defines}}, @{$config{module_defines}},
146                 @cnf_defines,
147                 )
148       . '$(DEFINES)'
149       . "'extradefines'";
150   our $dso_asflags =
151       join(' ', $target{dso_asflags} || (), $target{module_asflags} || (),
152                 @{$config{dso_asflags}}, @{$config{module_asflags}},
153                 @cnf_asflags, '$(ASFLAGS)');
154   our $dso_cppflags =
155       join('', $target{dso_cppflags} || (), $target{module_cppflags} || (),
156                @{$config{dso_cppflags}}, @{$config{module_cppflag}},
157                @cnf_cppflags,
158                '/DEFINE=('.$dso_cppdefines.')',
159                '$(CPPFLAGS)');
160   my @dso_cflags = ( $target{dso_cflags} // () );
161   my @dso_cflags_no_inst = ( $target{no_inst_dso_cflags} // @dso_cflags );
162   my @dso_cflags_cont = ( $target{module_cflag} || (),
163                           @{$config{dso_cflags}}, @{$config{module_cflag}},
164                           @cnf_cflags, '$(CFLAGS)');
165   our $dso_cflags = join('', @dso_cflags, @dso_cflags_cont );
166   our $dso_cflags_no_inst = join('', @dso_cflags_no_inst, @dso_cflags_cont );
167   our $dso_ldflags =
168       join('', $target{dso_lflags} || (), $target{module_ldflag} || (),
169                @{$config{dso_lflags}}, @{$config{module_ldflag}},
170                @cnf_ldflags, '$(LDFLAGS)');
171   our $dso_ex_libs = join('', @cnf_ex_libs, '$(EX_LIBS)');
172
173   # The following array is special and is treated separately from the rest of
174   # the bin_ variables.
175   our @bin_cppincludes = (@{$target{bin_includes}},
176                           @{$config{bin_includes}},
177                           @cnf_includes);
178
179   our $bin_cppdefines =
180       join(',', @{$target{bin_defines}},
181                 @{$config{bin_defines}},
182                 @cnf_defines,
183                 )
184       . '$(DEFINES)'
185       . "'extradefines'";
186   our $bin_asflags =
187       join(' ', $target{bin_asflags} || (),
188                 @{$config{bin_asflags}},
189                 @cnf_asflags, '$(ASFLAGS)');
190   our $bin_cppflags =
191       join('', $target{bin_cppflags} || (),
192                @{$config{bin_cppflags}},
193                @cnf_cppflags,
194                '/DEFINE=('.$bin_cppdefines.')',
195                '$(CPPFLAGS)');
196   my @bin_cflags = ( $target{bin_cflags} // () );
197   my @bin_cflags_no_inst = ( $target{no_inst_bin_cflags} // @bin_cflags );
198   my @bin_cflags_cont = ( @{$config{bin_cflags}},
199                           @cnf_cflags, '$(CFLAGS)');
200   our $bin_cflags = join('', @bin_cflags, @bin_cflags_cont );
201   our $bin_cflags_no_inst = join('', @bin_cflags_no_inst, @bin_cflags_cont );
202   our $bin_ldflags =
203       join('', $target{bin_lflags} || (),
204                @{$config{bin_lflags}},
205                @cnf_ldflags, '$(LDFLAGS)');
206   our $bin_ex_libs = join('', @cnf_ex_libs, '$(EX_LIBS)');
207
208   # These are horrible hacks, but are needed because recursive inclusion of
209   # files in different directories does not work well with VMS C.  We try to
210   # help by specifying extra relative directories.  They must always be in Unix
211   # format, relative to the directory where the .c file is located.  The logic
212   # is that any inclusion, merged with one of these relative directories, will
213   # find the requested inclusion file.
214   # In the regexps, it's advisable to always start the file name with .*?, as
215   # the C source to OBJ file translation adds stuff at the beginning of the,
216   # name, such as [.ssl]bio_ssl.c -> [.ssl]libssl-shlib-bio_ssl.OBJ
217   foreach (grep /\[\.crypto\.async\.arch\].*?\.o$/, keys %{$unified_info{sources}}) {
218       my $obj = platform->obj($_);
219       push @{$unified_info{includes_extra}->{$obj}}, qw(../);
220   }
221   foreach (grep /\[\.crypto\.ec\.curve448\].*?\.o$/, keys %{$unified_info{sources}}) {
222       my $obj = platform->obj($_);
223       push @{$unified_info{includes_extra}->{$obj}}, qw(./arch_32 ./arch64);
224   }
225   foreach (grep /\[\.crypto\.ec\.curve448.arch_(?:32|64)\].*?\.o$/, keys %{$unified_info{sources}}) {
226       my $obj = platform->obj($_);
227       push @{$unified_info{includes_extra}->{$obj}}, qw(../);
228   }
229   foreach (grep /\[\.ssl\].*?\.o$/, keys %{$unified_info{sources}}) {
230       my $obj = platform->obj($_);
231       # Most of the files in [.ssl] include "ssl_local.h" which includes things
232       # like "record/record.h".  Adding "./" as an inclusion directory helps
233       # making this sort of header from these directories.
234       push @{$unified_info{includes_extra}->{$obj}}, qw(./);
235
236       # Additionally, an increasing amount of files in [.ssl] include
237       # "quic/quic_local.h", which in turn includes "../ssl_local.h".  Adding
238       # "./quic" as an inclusion directory helps making this sort of header
239       # from these directories.
240       push @{$unified_info{includes_extra}->{$obj}}, qw(./quic);
241   }
242   foreach (grep /\[\.ssl\.(?:quic|record|statem)\].*?\.o$/, keys %{$unified_info{sources}}) {
243       my $obj = platform->obj($_);
244       # Most of the files in [.ssl.record] and [.ssl.statem] include
245       # "../ssl_local.h", which includes things like "record/record.h".
246       # Adding "../" as an inclusion directory helps making this sort of header
247       # from these directories.
248       push @{$unified_info{includes_extra}->{$obj}}, qw(../);
249
250   }
251   foreach (grep /\[\.ssl\.record\.methods\].*?\.o$/, keys %{$unified_info{sources}}) {
252       my $obj = platform->obj($_);
253       # Most of the files in [.ssl.record.methods] include "../../ssl_local.h"
254       # which includes things like "record/record.h".  Adding "../../" as an
255       # inclusion directory helps making this sort of header from these
256       # directories.  But this gets worse; through a series of inclusions,
257       # all of them based on the relative directory of the object file, there's
258       # a need to deal with an inclusion of "../ssl_local.h" as well.
259       push @{$unified_info{includes_extra}->{$obj}}, qw(../../), qw(../);
260   }
261   foreach (grep /\[\.test\].*?\.o$/, keys %{$unified_info{sources}}) {
262       my $obj = platform->obj($_);
263       push @{$unified_info{includes_extra}->{$obj}}, qw(../ssl ./helpers);
264       # Some of the sources in [.test] also include headers like
265       # "../ssl/record/methods/recmethod_local.h", which in turn might include
266       # "../../ssl_local.h", so these object files need yet another hack.
267       # We could make this specific to just the object files that are affected
268       # directly, but that would end up with more whack-a-mole of this sort, so
269       # nah, we do it broadly.
270       push @{$unified_info{includes_extra}->{$obj}}, qw(../ssl/record/methods);
271       # Similarly, some include "../ssl/ssl_local.h", and somewhere down the
272       # line, "quic/quic_local.h" gets included, which includes "../ssl_local.h"
273       # The problem is fixed by adding ../ssl/quic too.
274       push @{$unified_info{includes_extra}->{$obj}}, qw(../ssl/quic);
275   }
276   foreach (grep /\[\.test\.helpers\].*?\.o$/, keys %{$unified_info{sources}}) {
277       my $obj = platform->obj($_);
278       push @{$unified_info{includes_extra}->{$obj}},
279           qw(../../ssl ../../ssl/quic);
280   }
281
282   # This makes sure things get built in the order they need
283   # to. You're welcome.
284   sub dependmagic {
285       my $target = shift;
286
287       return "$target : build_generated\n\t\pipe \$(MMS) \$(MMSQUALIFIERS) depend && \$(MMS) \$(MMSQUALIFIERS) _$target\n_$target";
288   }
289   "";
290 -}
291 PLATFORM={- $config{target} -}
292 OPTIONS={- $config{options} -}
293 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
294 SRCDIR={- $config{sourcedir} -}
295 BLDDIR={- $config{builddir} -}
296 FIPSKEY={- $config{FIPSKEY} -}
297
298 # Allow both V and VERBOSE to indicate verbosity.  This only applies
299 # to testing.
300 VERBOSE=$(V)
301 VERBOSE_FAILURE=$(VF)
302
303 VERSION={- "$config{full_version}" -}
304 VERSION_NUMBER={- "$config{version}" -}
305 MAJOR={- $config{major} -}
306 MINOR={- $config{minor} -}
307 SHLIB_VERSION_NUMBER={- $config{shlib_version} -}
308 SHLIB_TARGET={- $target{shared_target} -}
309
310 LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @libs) -}
311 SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @shlibs) -}
312 MODULES={- join(", ", map { "-\n\t".$_.".EXE" }
313                       # Drop all modules that are dependencies, they will
314                       # be processed through their dependents
315                       grep { my $x = $_;
316                              !grep { grep { $_ eq $x } @$_ }
317                                    values %{$unified_info{depends}} }
318                       @{$unified_info{modules}}) -}
319 FIPSMODULE={- # We do some extra checking here, as there should be only one
320               use File::Basename;
321               our @fipsmodules =
322                   grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
323                          && $unified_info{attributes}->{modules}->{$_}->{fips} }
324                   @{$unified_info{modules}};
325               die "More that one FIPS module" if scalar @fipsmodules > 1;
326               join(" ", map { platform->dso($_) } @fipsmodules) -}
327 FIPSMODULENAME={- die "More that one FIPS module" if scalar @fipsmodules > 1;
328                   join(", ", map { basename(platform->dso($_)) } @fipsmodules) -}
329 PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{programs}}) -}
330 SCRIPTS={- join(", ", map { "-\n\t".$_ } @{$unified_info{scripts}}) -}
331 {- output_off() if $disabled{makedepend}; "" -}
332 DEPS={- our @deps = map { platform->isobj($_) ? platform->dep($_) : $_ }
333                     grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
334                     keys %{$unified_info{sources}};
335         join(", ", map { "-\n\t".$_ } @deps); -}
336 {- output_on() if $disabled{makedepend}; "" -}
337 GENERATED_MANDATORY={- join(", ",
338                             map { "-\n\t".$_ } @{$unified_info{depends}->{""}} ) -}
339 GENERATED_PODS={- # common0.tmpl provides @generated
340                   join(", ",
341                        map { my $x = $_;
342                              (
343                                grep { 
344                                       $unified_info{attributes}->{depends}
345                                       ->{$x}->{$_}->{pod} // 0
346                                     }
347                                    keys %{$unified_info{attributes}->{depends}->{$x}}
348                              ) ? "-\n\t".$x : ();
349                            }
350                            @generated) -}
351 GENERATED={- # common0.tmpl provides @generated
352              join(", ", map { platform->convertext($_) } @generated) -}
353
354 INSTALL_LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @install_libs) -}
355 INSTALL_SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @install_shlibs) -}
356 INSTALL_ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @install_engines) -}
357 INSTALL_MODULES={- join(", ", map { "-\n\t".$_.".EXE" } @install_modules) -}
358 INSTALL_FIPSMODULE={- join(", ", map { "-\n\t".$_.".EXE" } @install_fipsmodules) -}
359 INSTALL_FIPSMODULECONF=[.providers]fipsmodule.cnf
360 INSTALL_PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @install_programs) -}
361 BIN_SCRIPTS={- join(", ", @install_bin_scripts) -}
362 MISC_SCRIPTS={- join(", ", @install_misc_scripts) -}
363 HTMLDOCS1={- join(", ", map { "-\n\t".$_ } @{$unified_info{htmldocs}->{man1}}) -}
364 HTMLDOCS3={- join(", ", map { "-\n\t".$_ } @{$unified_info{htmldocs}->{man3}}) -}
365 HTMLDOCS5={- join(", ", map { "-\n\t".$_ } @{$unified_info{htmldocs}->{man5}}) -}
366 HTMLDOCS7={- join(", ", map { "-\n\t".$_ } @{$unified_info{htmldocs}->{man7}}) -}
367
368 APPS_OPENSSL="{- use File::Spec::Functions;
369                  catfile("apps","openssl") -}"
370
371 # DESTDIR is for package builders so that they can configure for, say,
372 # SYS$COMMON:[OPENSSL] and yet have everything installed in STAGING:[USER].
373 # In that case, configure with --prefix=SYS$COMMON:[OPENSSL] and then run
374 # MMS with /MACROS=(DESTDIR=STAGING:[USER]).  The result will end up in
375 # STAGING:[USER.OPENSSL].
376 # Normally it is left empty.
377 DESTDIR=
378
379 # Do not edit this manually. Use Configure --prefix=DIR to change this!
380 INSTALLTOP={- our $installtop =
381                   catdir($config{prefix}) || "SYS\$COMMON:[OPENSSL]";
382               $installtop -}
383 SYSTARTUP={- catdir($installtop, '[.SYS$STARTUP]'); -}
384 # This is the standard central area to store certificates, private keys...
385 OPENSSLDIR={- catdir($config{openssldir}) or
386               $config{prefix} ? catdir($config{prefix},"COMMON")
387                               : "SYS\$COMMON:[OPENSSL-COMMON]" -}
388 # The same, but for C
389 OPENSSLDIR_C={- platform->osslprefix() -}DATAROOT:[000000]
390 # Where installed ENGINE modules reside, for C
391 ENGINESDIR_C={- platform->osslprefix() -}ENGINES{- $sover_dirname.$target{pointer_size} -}:
392 # Where modules reside, for C
393 MODULESDIR_C={- platform->osslprefix() -}MODULES{- $target{pointer_size} -}:
394
395 ##### User defined commands and flags ################################
396
397 CC={- $config{CC} -}
398 CPP={- $config{CPP} -}
399 DEFINES={- our $defines = join('', map { ",$_" } @{$config{CPPDEFINES}}) -}
400 #INCLUDES={- our $includes = join(',', @{$config{CPPINCLUDES}}) -}
401 CPPFLAGS={- our $cppflags = join('', @{$config{CPPFLAGS}}) -}
402 CFLAGS={- join('', @{$config{CFLAGS}}) -}
403 LDFLAGS={- join('', @{$config{LFLAGS}}) -}
404 EX_LIBS={- join('', map { ",$_" } @{$config{LDLIBS}}) -}
405
406 PERL={- $config{PERL} -}
407
408 AS={- $config{AS} -}
409 ASFLAGS={- join(' ', @{$config{ASFLAGS}}) -}
410
411 ##### Special command flags ##########################################
412
413 ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
414
415 PERLASM_SCHEME={- $target{perlasm_scheme} -}
416
417 # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
418 CPPFLAGS_Q={- (my $c = $lib_cppflags.$cppflags) =~ s|"|""|g;
419               (my $d = $lib_cppdefines) =~ s|"|""|g;
420               my $i = join(',', @lib_cppincludes || (), '$(INCLUDES)');
421               my $x = $c;
422               $x .= "/INCLUDE=($i)" if $i;
423               $x .= "/DEFINE=($d)" if $d;
424               $x; -}
425
426 # .FIRST and .LAST are special targets with MMS and MMK.
427 NODEBUG=@
428 .FIRST :
429         {- join( "\n        \$(NODEBUG) ", @{ $target{setup_commands} // [] },
430                                            '!' ) -}
431         $(NODEBUG) sourcetop = F$PARSE("$(SRCDIR)","[]A.;",,,"SYNTAX_ONLY,NO_CONCEAL") - ".][000000" - "[000000." - "][" - "]A.;" + ".]"
432         $(NODEBUG) DEFINE ossl_sourceroot 'sourcetop'
433         $(NODEBUG) !
434         $(NODEBUG) staging_dir = "$(DESTDIR)"
435         $(NODEBUG) staging_instdir = ""
436         $(NODEBUG) staging_datadir = ""
437         $(NODEBUG) IF staging_dir .NES. "" THEN -
438                 staging_instdir = F$PARSE("A.;",staging_dir,"[]",,"SYNTAX_ONLY")
439         $(NODEBUG) IF staging_instdir - "]A.;" .NES. staging_instdir THEN -
440                 staging_instdir = staging_instdir - "]A.;" + ".OPENSSL-INSTALL]"
441         $(NODEBUG) IF staging_instdir - "A.;" .NES. staging_instdir THEN -
442                 staging_instdir = staging_instdir - "A.;" + "[OPENSSL-INSTALL]"
443         $(NODEBUG) IF staging_dir .NES. "" THEN -
444                 staging_datadir = F$PARSE("A.;",staging_dir,"[]",,"SYNTAX_ONLY")
445         $(NODEBUG) IF staging_datadir - "]A.;" .NES. staging_datadir THEN -
446                 staging_datadir = staging_datadir - "]A.;" + ".OPENSSL-COMMON]"
447         $(NODEBUG) IF staging_datadir - "A.;" .NES. staging_datadir THEN -
448                 staging_datadir = staging_datadir - "A.;" + "[OPENSSL-COMMON]"
449         $(NODEBUG) !
450         $(NODEBUG) ! Installation logical names
451         $(NODEBUG) !
452         $(NODEBUG) ! This also creates a few DCL variables that are used for
453         $(NODEBUG) ! the "install_msg" target.
454         $(NODEBUG) !
455         $(NODEBUG) installroot = F$PARSE(staging_instdir,"$(INSTALLTOP)","[]A.;",,"SYNTAX_ONLY,NO_CONCEAL") - ".][000000" - "[000000." - "][" - "]A.;"
456         $(NODEBUG) installtop = installroot + ".]"
457         $(NODEBUG) dataroot = F$PARSE(staging_datadir,"$(OPENSSLDIR)","[]A.;",,"SYNTAX_ONLY,NO_CONCEAL") - ".][000000" - "[000000." - "][" - "]A.;"
458         $(NODEBUG) datatop = dataroot + ".]"
459         $(NODEBUG) DEFINE ossl_installroot 'installtop'
460         $(NODEBUG) DEFINE ossl_dataroot 'datatop'
461         $(NODEBUG) !
462         $(NODEBUG) ! Override disturbing system logicals.  We can't deassign
463         $(NODEBUG) ! them, so we create it instead.  This is an unfortunate
464         $(NODEBUG) ! necessity.
465         $(NODEBUG) !
466         $(NODEBUG) openssl_inc1 = F$PARSE("[.include.openssl]","A.;",,,"syntax_only") - "A.;"
467         $(NODEBUG) openssl_inc2 = F$PARSE("sourcetop:[include.openssl]","A.;",,,"SYNTAX_ONLY") - "A.;"
468         $(NODEBUG) DEFINE openssl 'openssl_inc1','openssl_inc2'
469         $(NODEBUG) !
470         $(NODEBUG) ! Figure out the architecture
471         $(NODEBUG) !
472         $(NODEBUG) arch = f$edit( f$getsyi( "arch_name"), "upcase")
473         $(NODEBUG) !
474         $(NODEBUG) ! Set up logical names for the libraries, so LINK and
475         $(NODEBUG) ! running programs can use them.
476         $(NODEBUG) !
477         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEFINE ".uc($_)." 'F\$ENV(\"DEFAULT\")'".uc($_).".EXE" } @shlibs) || "!" -}
478
479 .LAST :
480         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEASSIGN ".uc($_) } @shlibs) || "!" -}
481         $(NODEBUG) DEASSIGN openssl
482         $(NODEBUG) DEASSIGN ossl_dataroot
483         $(NODEBUG) DEASSIGN ossl_installroot
484         $(NODEBUG) DEASSIGN ossl_sourceroot
485 .DEFAULT :
486         @ ! MMS cannot handle no actions...
487
488 # The main targets ###################################################
489
490 {- dependmagic('build_sw'); -} : build_libs_nodep, build_modules_nodep, build_programs_nodep
491 {- dependmagic('build_libs'); -} : build_libs_nodep
492 {- dependmagic('build_modules'); -} : build_modules_nodep
493 {- dependmagic('build_programs'); -} : build_programs_nodep
494
495 build_generated_pods : $(GENERATED_PODS)
496 build_docs : build_html_docs
497 build_html_docs : $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
498
499 build_generated : $(GENERATED_MANDATORY)
500 build_libs_nodep : $(LIBS), $(SHLIBS)
501 build_modules_nodep : $(MODULES)
502 build_programs_nodep : $(PROGRAMS), $(SCRIPTS)
503
504 # Kept around for backward compatibility
505 build_apps build_tests : build_programs
506
507 # Convenience target to prebuild all generated files, not just the mandatory
508 # ones
509 build_all_generated : $(GENERATED_MANDATORY) $(GENERATED) build_docs
510         @ ! {- output_off() if $disabled{makedepend}; "" -}
511         @ WRITE SYS$OUTPUT "Warning: consider configuring with no-makedepend, because if"
512         @ WRITE SYS$OUTPUT "         target system doesn't have $(PERL),"
513         @ WRITE SYS$OUTPUT "         then make will fail..."
514         @ ! {- output_on() if $disabled{makedepend}; "" -}
515
516 all : build_sw build_docs
517
518 test : tests
519 {- dependmagic('tests'); -} : build_programs_nodep, build_modules_nodep run_tests
520 run_tests :
521         @ ! {- output_off() if $disabled{tests}; "" -}
522         DEFINE SRCTOP "$(SRCDIR)"
523         DEFINE BLDTOP "$(BLDDIR)"
524         DEFINE FIPSKEY "$(FIPSKEY)"
525         IF "$(VERBOSE)" .NES. "" THEN DEFINE VERBOSE "$(VERBOSE)"
526         $(PERL) {- sourcefile("test", "run_tests.pl") -} $(TESTS)
527         DEASSIGN BLDTOP
528         DEASSIGN SRCTOP
529         DEASSIGN FIPSKEY
530         @ ! {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
531         @ WRITE SYS$OUTPUT "Tests are not supported with your chosen Configure options"
532         @ ! {- output_on() if !$disabled{tests}; "" -}
533
534 list-tests :
535         @ ! {- output_off() if $disabled{tests}; "" -}
536         @ DEFINE SRCTOP "$(SRCDIR)"
537         @ $(PERL) {- sourcefile("test", "run_tests.pl") -} list
538         @ DEASSIGN SRCTOP
539         @ ! {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
540         @ WRITE SYS$OUTPUT "Tests are not supported with your chosen Configure options"
541         @ ! {- output_on() if !$disabled{tests}; "" -}
542
543 install : install_sw install_ssldirs install_docs {- $disabled{fips} ? "" : "install_fips" -} install_msg
544
545 install_msg :
546         @ WRITE SYS$OUTPUT ""
547         @ WRITE SYS$OUTPUT "######################################################################"
548         @ WRITE SYS$OUTPUT ""
549         @ IF "$(DESTDIR)" .EQS. "" THEN -
550              @{- sourcefile("VMS", "msg_install.com") -} "$(SYSTARTUP)" "{- $osslver -}"
551         @ IF "$(DESTDIR)" .NES. "" THEN -
552              @{- sourcefile("VMS", "msg_staging.com") -} -
553              "''installroot']" "''dataroot']" "$(INSTALLTOP)" "$(OPENSSLDIR)" -
554              "$(SYSTARTUP)" "{- $osslver -}"
555
556 check_install :
557         spawn/nolog @ossl_installroot:[SYSTEST]openssl_ivp{- $osslver -}.com
558
559 uninstall : uninstall_docs uninstall_sw {- $disabled{fips} ? "" : "uninstall_fips" -}
560
561 # Because VMS wants the generation number (or *) to delete files, we can't
562 # use $(LIBS), $(PROGRAMS), $(GENERATED) and $(MODULES) directly.
563 libclean :
564         {- join("\n\t", map { "- DELETE $_.OLB;*" } @libs) || "@ !" -}
565         {- join("\n\t", map { "- DELETE $_.EXE;*,$_.MAP;*" } @shlibs) || "@ !" -}
566
567 clean : libclean
568         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{htmldocs}->{man1}}) || "@ !" -}
569         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{htmldocs}->{man3}}) || "@ !" -}
570         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{htmldocs}->{man5}}) || "@ !" -}
571         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{htmldocs}->{man7}}) || "@ !" -}
572         {- join("\n\t", map { "- DELETE $_.EXE;*,$_.OPT;*" } @{$unified_info{programs}}) || "@ !" -}
573         {- join("\n\t", map { "- DELETE $_.EXE;*,$_.OPT;*" } @{$unified_info{modules}}) || "@ !" -}
574         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{scripts}}) || "@ !" -}
575         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{depends}->{""}}) || "@ !" -}
576         {- join("\n\t", map { "- DELETE $_;*" } @generated) || "@ !" -}
577         - DELETE [...]*.MAP;*
578         - DELETE [...]*.D;*
579         - DELETE [...]*.OBJ;*,*.LIS;*
580         - DELETE []CXX$DEMANGLER_DB.;*
581         - DELETE [.VMS]openssl_startup.com;*
582         - DELETE [.VMS]openssl_shutdown.com;*
583         - DELETE []vmsconfig.pm;*
584
585 distclean : clean
586         - DELETE [.include.openssl]configuration.h;*
587         - DELETE configdata.pm;*
588         - DELETE descrip.mms;*
589
590 depend : descrip.mms
591         @ ! {- output_off() if $disabled{makedepend}; "" -}
592         @ $(PERL) {- sourcefile("util", "add-depends.pl") -} "{- $config{makedep_scheme} -}"
593         @ ! {- output_on() if $disabled{makedepend}; "" -}
594
595 # Install helper targets #############################################
596
597 install_sw : install_dev install_engines install_modules -
598              install_runtime install_startup install_ivp
599
600 uninstall_sw : uninstall_dev uninstall_modules uninstall_engines -
601                uninstall_runtime uninstall_startup uninstall_ivp
602
603 install_docs : install_html_docs
604
605 uninstall_docs : uninstall_html_docs
606
607 {- output_off() if $disabled{fips}; "" -}
608 install_fips : build_sw $(INSTALL_FIPSMODULECONF)
609         @ WRITE SYS$OUTPUT "*** Installing FIPS module"
610         - CREATE/DIR ossl_installroot:[MODULES{- $target{pointer_size} -}.'arch']
611         - CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[000000]
612         COPY/PROT=W:RE $(INSTALL_FIPSMODULES) -
613                 ossl_installroot:[MODULES{- $target{pointer_size} -}.'arch']$(FIPSMODULENAME)
614         @ WRITE SYS$OUTPUT "*** Installing FIPS module configuration"
615         COPY/PROT=W:RE $(INSTALL_FIPSMODULECONF) OSSL_DATAROOT:[000000]
616
617 uninstall_fips :
618         @ WRITE SYS$OUTPUT "*** Uninstalling FIPS module configuration"
619         DELETE OSSL_DATAROOT:[000000]fipsmodule.cnf;*
620         @ WRITE SYS$OUTPUT "*** Uninstalling FIPS module"
621         DELETE ossl_installroot:[MODULES{- $target{pointer_size} -}.'arch']$(FIPSMODULENAME);*
622 {- output_on() if $disabled{fips}; "" -}
623
624 install_ssldirs : check_INSTALLTOP
625         - CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[000000]
626         IF F$SEARCH("OSSL_DATAROOT:[000000]CERTS.DIR;1") .EQS. "" THEN -
627                 CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[CERTS]
628         IF F$SEARCH("OSSL_DATAROOT:[000000]PRIVATE.DIR;1") .EQS. "" THEN -
629                 CREATE/DIR/PROT=(S:RWED,O:RWE,G,W) OSSL_DATAROOT:[PRIVATE]
630         IF F$SEARCH("OSSL_DATAROOT:[000000]MISC.DIR;1") .EQS. "" THEN -
631                 CREATE/DIR/PROT=(S:RWED,O:RWE,G,W) OSSL_DATAROOT:[MISC]
632         COPY/PROT=W:RE $(MISC_SCRIPTS) OSSL_DATAROOT:[MISC]
633         @ ! Install configuration file
634         COPY/PROT=W:R {- sourcefile("apps", "openssl-vms.cnf") -} -
635                 ossl_dataroot:[000000]openssl.cnf-dist
636         IF F$SEARCH("OSSL_DATAROOT:[000000]openssl.cnf") .EQS. "" THEN -
637                 COPY/PROT=W:R {- sourcefile("apps", "openssl-vms.cnf") -} -
638                         ossl_dataroot:[000000]openssl.cnf
639         @ ! Install CTLOG configuration file
640         COPY/PROT=W:R {- sourcefile("apps", "ct_log_list.cnf") -} -
641                 ossl_dataroot:[000000]ct_log_list.cnf-dist
642         IF F$SEARCH("OSSL_DATAROOT:[000000]ct_log_list.cnf") .EQS. "" THEN -
643                 COPY/PROT=W:R {- sourcefile("apps", "ct_log_list.cnf") -} -
644                         ossl_dataroot:[000000]ct_log_list.cnf
645
646 install_dev : check_INSTALLTOP install_runtime_libs
647         @ WRITE SYS$OUTPUT "*** Installing development files"
648         @ ! Install header files
649         - CREATE/DIR ossl_installroot:[include.openssl]
650         COPY/PROT=W:R ossl_sourceroot:[include.openssl]*.h -
651                 ossl_installroot:[include.openssl]
652         COPY/PROT=W:R [.include.openssl]*.h ossl_installroot:[include.openssl]
653         @ ! Install static (development) libraries
654         - CREATE/DIR ossl_installroot:[LIB.'arch']
655         {- join("\n        ",
656                 map { "COPY/PROT=W:R $_.OLB ossl_installroot:[LIB.'arch']" }
657                 @install_libs) -}
658
659 install_engines : check_INSTALLTOP install_runtime_libs build_modules
660         @ {- output_off() unless scalar @install_engines; "" -} !
661         @ WRITE SYS$OUTPUT "*** Installing engines"
662         - CREATE/DIR ossl_installroot:[ENGINES{- $sover_dirname.$target{pointer_size} -}.'arch']
663         {- join("\n        ",
664                 map { "COPY/PROT=W:RE $_.EXE ossl_installroot:[ENGINES$sover_dirname$target{pointer_size}.'arch']" }
665                 @install_engines) -}
666         @ {- output_on() unless scalar @install_engines; "" -} !
667
668 install_modules : check_INSTALLTOP install_runtime_libs build_modules
669         @ {- output_off() unless scalar @install_modules; "" -} !
670         @ WRITE SYS$OUTPUT "*** Installing modules"
671         - CREATE/DIR ossl_installroot:[MODULES{- $target{pointer_size} -}.'arch']
672         {- join("\n        ",
673                 map { "COPY/PROT=W:RE $_.EXE ossl_installroot:[MODULES$target{pointer_size}.'arch']" }
674                 @install_modules) -}
675         @ {- output_on() unless scalar @install_modules; "" -} !
676
677 install_runtime : install_programs
678
679 install_runtime_libs : check_INSTALLTOP build_libs
680         @ {- output_off() if $disabled{shared}; "" -} !
681         @ WRITE SYS$OUTPUT "*** Installing shareable images"
682         @ ! Install shared (runtime) libraries
683         - CREATE/DIR ossl_installroot:[LIB.'arch']
684         {- join("\n        ",
685                 map { "COPY/PROT=W:R $_.EXE ossl_installroot:[LIB.'arch']" }
686                 @install_shlibs) -}
687         @ {- output_on() if $disabled{shared}; "" -} !
688
689 install_programs : check_INSTALLTOP install_runtime_libs build_programs
690         @ {- output_off() if $disabled{apps}; "" -} !
691         @ ! Install the main program
692         - CREATE/DIR ossl_installroot:[EXE.'arch']
693         COPY/PROT=W:RE [.APPS]openssl.EXE -
694                 ossl_installroot:[EXE.'arch']openssl{- $osslver -}.EXE
695         @ ! Install scripts
696         COPY/PROT=W:RE $(BIN_SCRIPTS) ossl_installroot:[EXE]
697         @ ! {- output_on() if $disabled{apps}; "" -}
698
699 install_startup : [.VMS]openssl_startup.com [.VMS]openssl_shutdown.com -
700                  [.VMS]openssl_utils.com, check_INSTALLTOP
701         - CREATE/DIR ossl_installroot:[SYS$STARTUP]
702         COPY/PROT=W:RE [.VMS]openssl_startup.com -
703                 ossl_installroot:[SYS$STARTUP]openssl_startup{- $osslver -}.com
704         COPY/PROT=W:RE [.VMS]openssl_shutdown.com -
705                 ossl_installroot:[SYS$STARTUP]openssl_shutdown{- $osslver -}.com
706         COPY/PROT=W:RE [.VMS]openssl_utils.com -
707                 ossl_installroot:[SYS$STARTUP]openssl_utils{- $osslver -}.com
708
709 install_ivp : [.VMS]openssl_ivp.com check_INSTALLTOP
710         - CREATE/DIR ossl_installroot:[SYSTEST]
711         COPY/PROT=W:RE [.VMS]openssl_ivp.com -
712                 ossl_installroot:[SYSTEST]openssl_ivp{- $osslver -}.com
713
714 [.VMS]openssl_startup.com : vmsconfig.pm {- sourcefile("VMS", "openssl_startup.com.in") -}
715         - CREATE/DIR [.VMS]
716         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
717                 {- sourcefile("VMS", "openssl_startup.com.in") -} -
718                 > [.VMS]openssl_startup.com
719
720 [.VMS]openssl_utils.com : vmsconfig.pm {- sourcefile("VMS", "openssl_utils.com.in") -}
721         - CREATE/DIR [.VMS]
722         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
723                 {- sourcefile("VMS", "openssl_utils.com.in") -} -
724                 > [.VMS]openssl_utils.com
725
726 [.VMS]openssl_shutdown.com : vmsconfig.pm {- sourcefile("VMS", "openssl_shutdown.com.in") -}
727         - CREATE/DIR [.VMS]
728         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
729                 {- sourcefile("VMS", "openssl_shutdown.com.in") -} -
730                 > [.VMS]openssl_shutdown.com
731
732 [.VMS]openssl_ivp.com : vmsconfig.pm {- sourcefile("VMS", "openssl_ivp.com.in") -}
733         - CREATE/DIR [.VMS]
734         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
735                 {- sourcefile("VMS", "openssl_ivp.com.in") -} -
736                 > [.VMS]openssl_ivp.com
737
738 vmsconfig.pm : configdata.pm
739         OPEN/WRITE/SHARE=READ CONFIG []vmsconfig.pm
740         WRITE CONFIG "package vmsconfig;"
741         WRITE CONFIG "use strict; use warnings;"
742         WRITE CONFIG "use Exporter;"
743         WRITE CONFIG "our @ISA = qw(Exporter);"
744         WRITE CONFIG "our @EXPORT = qw(%config %target %withargs %unified_info %disabled);"
745         WRITE CONFIG "our %config = ("
746         WRITE CONFIG "  target => '","{- $config{target} -}","',"
747         WRITE CONFIG "  version => '","{- $config{version} -}","',"
748         WRITE CONFIG "  shlib_version => '","{- $config{shlib_version} -}","',"
749         WRITE CONFIG "  shlib_major => '","{- $config{shlib_major} -}","',"
750         WRITE CONFIG "  shlib_minor => '","{- $config{shlib_minor} -}","',"
751         WRITE CONFIG "  no_shared => '","{- $disabled{shared} -}","',"
752         WRITE CONFIG "  INSTALLTOP => '$(INSTALLTOP)',"
753         WRITE CONFIG "  OPENSSLDIR => '$(OPENSSLDIR)',"
754         WRITE CONFIG "  pointer_size => '","{- $target{pointer_size} -}","',"
755         WRITE CONFIG ");"
756         WRITE CONFIG "our %target = ();"
757         WRITE CONFIG "our %disabled = ();"
758         WRITE CONFIG "our %withargs = ();"
759         WRITE CONFIG "our %unified_info = ();"
760         WRITE CONFIG "1;"
761         CLOSE CONFIG
762
763 install_html_docs : check_INSTALLTOP build_html_docs
764         @ WRITE SYS$OUTPUT "*** Installing HTML docs"
765         - CREATE/DIR ossl_installroot:[HTML.MAN1]
766         - CREATE/DIR ossl_installroot:[HTML.MAN3]
767         - CREATE/DIR ossl_installroot:[HTML.MAN5]
768         - CREATE/DIR ossl_installroot:[HTML.MAN7]
769         {- join("\n        ",
770                 ( map { "COPY/PROT=W:RE $_ ossl_installroot:[HTML.MAN1]" }
771                   @{$unified_info{htmldocs}->{man1}} ),
772                 ( map { "COPY/PROT=W:RE $_ ossl_installroot:[HTML.MAN3]" }
773                   @{$unified_info{htmldocs}->{man3}} ),
774                 ( map { "COPY/PROT=W:RE $_ ossl_installroot:[HTML.MAN5]" }
775                   @{$unified_info{htmldocs}->{man5}} ),
776                 ( map { "COPY/PROT=W:RE $_ ossl_installroot:[HTML.MAN7]" }
777                   @{$unified_info{htmldocs}->{man7}} )) -}
778
779 check_INSTALLTOP :
780         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
781                 WRITE SYS$ERROR "INSTALLTOP should not be empty"
782         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
783                 EXIT %x10000002
784
785 # Developer targets ##################################################
786
787 debug_logicals :
788         SH LOGICAL/PROC openssl,internal,ossl_installroot,ossl_dataroot
789
790 # Building targets ###################################################
791
792 descrip.mms : configdata.pm {- join(" ", @{$config{build_file_templates}}) -}
793         perl configdata.pm
794         @ WRITE SYS$OUTPUT "*************************************************"
795         @ WRITE SYS$OUTPUT "***                                           ***"
796         @ WRITE SYS$OUTPUT "***   Please run the same mms command again   ***"
797         @ WRITE SYS$OUTPUT "***                                           ***"
798         @ WRITE SYS$OUTPUT "*************************************************"
799         @ PIPE ( EXIT %X10000000 )
800
801 configdata.pm : $(SRCDIR)Configure $(SRCDIR)config.com {- join(" ", @{$config{build_infos}}, @{$config{conf_files}}) -}
802         perl configdata.pm -r
803         @ WRITE SYS$OUTPUT "*************************************************"
804         @ WRITE SYS$OUTPUT "***                                           ***"
805         @ WRITE SYS$OUTPUT "***   Please run the same mms command again   ***"
806         @ WRITE SYS$OUTPUT "***                                           ***"
807         @ WRITE SYS$OUTPUT "*************************************************"
808         @ PIPE ( EXIT %X10000000 )
809
810 reconfigure reconf :
811         perl configdata.pm -r
812
813 {-
814   use File::Basename;
815   use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/;
816   use File::Spec::Unix;
817
818   # Helper function to convert dependencies in platform agnostic form to
819   # dependencies in platform form.
820   sub compute_platform_depends {
821       map { my $x = $_;
822
823             grep { $x eq $_ } @{$unified_info{programs}} and platform->bin($x)
824             or grep { $x eq $_ } @{$unified_info{modules}} and platform->dso($x)
825             or grep { $x eq $_ } @{$unified_info{libraries}} and platform->lib($x)
826             or platform->convertext($x); } @_;
827   }
828
829   # Helper function to figure out dependencies on libraries
830   # It takes a list of library names and outputs a list of dependencies
831   sub compute_lib_depends {
832       # Depending on shared libraries:
833       # On Windows POSIX layers, we depend on {libname}.dll.a
834       # On Unix platforms, we depend on {shlibname}.so
835       return map {
836           { lib   => platform->sharedlib($_) // platform->staticlib($_),
837             attrs => $unified_info{attributes}->{libraries}->{$_} }
838       } @_;
839   }
840
841   # Helper function to deal with inclusion directory specs.
842   # We're dealing with two issues:
843   # 1. A lot of include directory specs take up a lot of command line real
844   #    estate, and the DCL command line is very limited (2KiB).
845   # 2. For optimal usage, include directory paths must be in Unix form,
846   #    that's the only way the C compiler can merge multiple include paths
847   #    in a sane way (we can stop worrying about 1.h including foo/2.h
848   #    including ../3.h).
849   #
850   # To resolve 1, we need to create a file with include directory pragmas,
851   # and let the compiler use it with /FIRST_INCLUDE=.
852   # To resolve 2, we convert all include directory specs we get to Unix,
853   # with available File::Spec functions.
854   #
855   # We use CRC-24 from https://tools.ietf.org/html/rfc4880#section-6,
856   # reimplemented in Perl to get a workable and constant file name for each
857   # combination of include directory specs.  It is assumed that the order of
858   # these directories don't matter.
859   #
860   # This function takes as input a list of include directories
861   # This function returns a list two things:
862   # 1. The file name to use with /FIRST_INCLUDE=
863   # 2. Text to insert into descrip.mms (may be the empty string)
864   sub crc24 {
865       my $input = shift;
866
867       my $init_value = 0x00B704CE;
868       my $poly_value = 0x01864CFB;
869
870       my $crc = $init_value;
871
872       foreach my $x (unpack ('C*', $input)) {
873           $crc ^= $x << 16;
874
875           for (my $i; $i < 8; $i++) {
876               $crc <<= 1;
877               if ($crc & 0x01000000) {
878                   $crc ^= $poly_value;
879               }
880           }
881       }
882       $crc &= 0xFFFFFF;
883
884       return $crc;
885   }
886   my %includefile_cache;
887   sub make_includefile {
888       my %dirs = map {
889           my $udir = make_unix_path(rel2abs($_));
890
891           $udir => 1;
892       } @_;
893       my @dirs = sort keys %dirs;
894       my $filename = sprintf 'incdirs_%x.h', crc24(join(',', @dirs));
895
896       if ($includefile_cache{$filename}) {
897           return ($filename, "");
898       }
899
900       my $scripture = <<"EOF";
901 $filename :
902         open/write inc_output $filename
903 EOF
904       foreach (@dirs) {
905           $scripture .= <<"EOF";
906         write inc_output "#pragma include_directory ""$_"""
907 EOF
908       }
909       $scripture .= <<"EOF";
910         close inc_output
911 EOF
912       $includefile_cache{$filename} = $scripture;
913
914       return ($filename, $scripture);
915   }
916
917   # On VMS, (some) header file directories include the files
918   # __DECC_INCLUDE_EPILOGUE.H and __DECC_INCLUDE_PROLOGUE.H.
919   # When header files are generated, and the build directory
920   # isn't the same as the source directory, these files must
921   # be copied alongside the generated header file, or their
922   # effect will be lost.
923   # We use the same include file cache as make_includefile
924   # to check if the scripture to copy these files has already
925   # been generated.
926   sub make_decc_include_files {
927       my $outd = shift;
928       my $ind = shift;
929
930       # If the build directory and the source directory are the
931       # same, there's no need to copy the prologue and epilogue
932       # files.
933       return ('') if $outd eq $ind;
934
935       my $outprologue = catfile($outd, '__DECC_INCLUDE_PROLOGUE.H');
936       my $outepilogue = catfile($outd, '__DECC_INCLUDE_EPILOGUE.H');
937       my $inprologue = catfile($ind, '__DECC_INCLUDE_PROLOGUE.H');
938       my $inepilogue = catfile($ind, '__DECC_INCLUDE_EPILOGUE.H');
939       my @filenames = ();
940       my $scripture = '';
941
942       if ($includefile_cache{$outprologue}) {
943           push @filenames, $outprologue;
944       } elsif (-f $inprologue) {
945           my $local_scripture .= <<"EOF";
946 $outprologue : $inprologue
947         COPY $inprologue $outprologue
948 EOF
949           $includefile_cache{$outprologue} = $local_scripture;
950
951           push @filenames, $outprologue;
952           $scripture .= $local_scripture;
953       }
954       if ($includefile_cache{$outepilogue}) {
955           push @filenames, $outepilogue;
956       } elsif (-f $inepilogue) {
957           my $local_scripture .= <<"EOF";
958 $outepilogue : $inepilogue
959         COPY $inepilogue $outepilogue
960 EOF
961           $includefile_cache{$outepilogue} = $local_scripture;
962
963           push @filenames, $outepilogue;
964           $scripture .= $local_scripture;
965       }
966
967       return (@filenames, $scripture);
968   }
969
970   sub generatetarget {
971       my %args = @_;
972       my $deps = join(" ", compute_platform_depends(@{$args{deps}}));
973       return <<"EOF";
974 $args{target} : $deps
975 EOF
976   }
977
978   sub generatesrc {
979       my %args = @_;
980       my $gen0 = $args{generator}->[0];
981       my $gen_args = join('', map { " $_" }
982                               @{$args{generator}}[1..$#{$args{generator}}]);
983       my $gen_incs = join("", map { ' "-I'.$_.'"' } @{$args{generator_incs}});
984       my $deps = join(", -\n\t\t",
985                       compute_platform_depends(@{$args{generator_deps}},
986                                                @{$args{deps}}));
987
988       if ($args{src} =~ /\.html$/) {
989           #
990           # HTML generator
991           #
992           my $title = basename($args{src}, ".html");
993           my $pod = $gen0;
994           my $mkpod2html = sourcefile('util', 'mkpod2html.pl');
995           my $srcdoc = sourcedir('doc');
996           return <<"EOF";
997 $args{src} : $pod
998         \$(PERL) $mkpod2html -i $pod -o \$\@ -t "$title" -r "$srcdoc"
999 EOF
1000       } elsif ($args{src} =~ /\.(\d)$/) {
1001           #
1002           # Man-page generator, on VMS we simply ignore man-pages
1003           #
1004           return "";
1005       } elsif (platform->isdef($args{src})) {
1006           #
1007           # Linker script-ish generator
1008           #
1009           my $target = platform->def($args{src});
1010           my $mkdef = sourcefile('util', 'mkdef.pl');
1011           my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION_NUMBER)' : '';
1012           my $ord_name =
1013               $args{generator}->[1] || basename($args{product}, '.EXE');
1014           my $case_insensitive =
1015               $target{$args{intent}.'_cflags'} =~ m|/NAMES=[^/]*AS_IS|i
1016               ? '' : ' --case-insensitive';
1017           return <<"EOF";
1018 $target : $gen0 $deps $mkdef
1019         \$(PERL) $mkdef$ord_ver --type $args{intent} --ordinals $gen0 --name $ord_name "--OS" "VMS"$case_insensitive > $target
1020 EOF
1021       } elsif (platform->isasm($args{src})
1022                || platform->iscppasm($args{src})) {
1023           #
1024           # Assembler generator
1025           #
1026           my $cppflags =
1027               { shlib => "$lib_cflags $lib_cppflags",
1028                 lib => "$lib_cflags $lib_cppflags",
1029                 dso => "$dso_cflags $dso_cppflags",
1030                 bin => "$bin_cflags $bin_cppflags" } -> {$args{intent}};
1031           my $defs = join("", map { ",".$_ } @{$args{defs}});
1032           my $target = platform->isasm($args{src})
1033                        ? platform->asm($args{src})
1034                        : $args{src};
1035
1036           my $generator;
1037           if ($gen0 =~ /\.pl$/) {
1038               $generator = '$(PERL)'.$gen_incs.' '.$gen0.$gen_args
1039                   .' '.$cppflags;
1040           } elsif ($gen0 =~ /\.S$/) {
1041               $generator = undef;
1042           } else {
1043               die "Generator type for $src unknown: $gen0.$gen_args\n";
1044           }
1045
1046           if (defined($generator)) {
1047               return <<"EOF";
1048 $target : $gen0 $deps
1049         \@ extradefines = "$defs"
1050         $generator \$\@
1051         \@ DELETE/SYMBOL/LOCAL extradefines
1052 EOF
1053           }
1054           return <<"EOF";
1055 $target : $gen0 $deps
1056         \@ extradefines = "$defs"
1057         PIPE \$(CPP) $cppflags $gen0 | -
1058         \$(PERL) "-ne" "/^#(\\s*line)?\\s*[0-9]+\\s+""/ or print" > \$\@
1059         \@ DELETE/SYMBOL/LOCAL extradefines
1060 EOF
1061       } elsif ($gen0 =~ m|^.*\.in$|) {
1062           #
1063           # "dofile" generator (file.in -> file)
1064           #
1065           my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1066                                                "util", "dofile.pl")),
1067                                rel2abs($config{builddir}));
1068           my @perlmodules = ();
1069           my %perlmoduleincs = ();
1070           my %perlmoduledeps = ();
1071           foreach my $x (('configdata.pm', @{$args{deps}})) {
1072               # Compute (i)nclusion directory, (m)odule name and (d)ependency
1073               my $i, $m, $d;
1074               if ($x =~ /\|/) {
1075                   $i = $`;
1076                   $d = $';
1077
1078                   # Massage the module part to become a real perl module spec
1079                   $m = $d;
1080                   $m =~ s|\.pm$||;
1081                   # Directory specs are :: in perl package names
1082                   $m =~ s|/|::|g;
1083
1084                   # Full file name of the dependency
1085                   $d = catfile($i, $d) if $i;
1086               } elsif ($x =~ /\.pm$/) {
1087                   $i = dirname($x);
1088                   $m = basename($x, '.pm');
1089                   $d = $x;
1090               } else {
1091                   # All other dependencies are simply collected
1092                   $d = $x;
1093               }
1094               push @perlmodules, '"-M'.$m.'"' if $m;
1095               $perlmoduledeps{$d} = 1;
1096               $perlmoduleincs{'"-I'.$i.'"'} = 1 if $i;
1097           }
1098
1099           my @decc_include_data
1100               = make_decc_include_files(dirname($args{src}), dirname($gen0));
1101           my $decc_include_scripture = pop @decc_include_data;
1102           # Because of the special treatment of dependencies, we need to
1103           # recompute $deps completely
1104           my $deps
1105               = join(" ", @decc_include_data,
1106                           compute_platform_depends(@{$args{generator_deps}},
1107                                                    sort keys %perlmoduledeps));
1108           my $perlmodules = join(' ', '', ( sort keys %perlmoduleincs ), @perlmodules);
1109
1110
1111           return <<"EOF";
1112 $args{src} : $gen0 $deps
1113         \$(PERL)$perlmodules $dofile "-o$target{build_file}" $gen0$gen_args > \$\@
1114 $decc_include_scripture
1115 EOF
1116       } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) {
1117           #
1118           # Generic generator using OpenSSL programs
1119           #
1120
1121           # Redo $gen0, to ensure that we have the proper extension
1122           $gen0 = platform->bin($gen0);
1123           return <<"EOF";
1124 $args{src} : $gen0 $deps
1125         PIPE MCR $gen0$gen_args > \$@
1126 EOF
1127       } else {
1128           #
1129           # Generic generator using Perl
1130           #
1131           return <<"EOF";
1132 $args{src} : $gen0 $deps
1133         \$(PERL)$gen_incs $gen0$gen_args > \$\@
1134 EOF
1135       }
1136   }
1137
1138   sub src2obj {
1139       my $asmext = platform->asmext();
1140       my %args = @_;
1141       my @srcs =
1142           map { my $x = $_;
1143                 (platform->isasm($x) && grep { $x eq $_ } @generated)
1144                 ? platform->asm($x) : $x }
1145           ( @{$args{srcs}} );
1146       my $obj = platform->obj($args{obj});
1147       my $dep = platform->dep($args{obj});
1148       my $deps = join(", -\n\t\t", @srcs, @{$args{deps}});
1149
1150       # Because VMS C isn't very good at combining a /INCLUDE path with
1151       # #includes having a relative directory (like '#include "../foo.h"),
1152       # the best choice is to move to the first source file's intended
1153       # directory before compiling, and make sure to write the object file
1154       # in the correct position (important when the object tree is other
1155       # than the source tree).
1156       my $forward = dirname($args{srcs}->[0]);
1157       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
1158       my $objd = abs2rel(rel2abs(dirname($obj)), rel2abs($forward));
1159       my $objn = basename($obj);
1160       my $depd = abs2rel(rel2abs(dirname($dep)), rel2abs($forward));
1161       my $depn = basename($dep);
1162       my $srcs =
1163           join(", ", map { abs2rel(rel2abs($_), rel2abs($forward)) } @srcs);
1164       my $incextra = join(',', map { "\"$_\"" }
1165                                @{$unified_info{includes_extra}->{$obj}});
1166       $incextra = "/INCLUDE=($incextra)" if $incextra;
1167
1168       my $cflags;
1169       if ($args{attrs}->{noinst}) {
1170           $cflags .= { shlib => $lib_cflags_no_inst,
1171                        lib => $lib_cflags_no_inst,
1172                        dso => $dso_cflags_no_inst,
1173                        bin => $bin_cflags_no_inst } -> {$args{intent}};
1174       } else {
1175           $cflags .= { shlib => $lib_cflags,
1176                        lib => $lib_cflags,
1177                        dso => $dso_cflags,
1178                        bin => $bin_cflags } -> {$args{intent}};
1179       }
1180       $cflags .= { shlib => $lib_cppflags,
1181                    lib => $lib_cppflags,
1182                    dso => $dso_cppflags,
1183                    bin => $bin_cppflags } -> {$args{intent}};
1184       $cflags .= $incextra;
1185       my $defs = join("", map { ",".$_ } @{$args{defs}});
1186       my $asflags = { shlib => $lib_asflags,
1187                       lib => $lib_asflags,
1188                       dso => $dso_asflags,
1189                       bin => $bin_asflags } -> {$args{intent}};
1190
1191       if ($srcs[0] =~ /\Q${asmext}\E$/) {
1192           return <<"EOF";
1193 $obj : $deps
1194         SET DEFAULT $forward
1195         \$(AS) $asflags \$(ASOUTFLAG)${objd}${objn} $srcs
1196         SET DEFAULT $backward
1197         - PURGE $obj
1198 EOF
1199       } elsif ($srcs[0] =~ /.S$/) {
1200          return <<"EOF";
1201 $obj : $deps
1202         SET DEFAULT $forward
1203         \@ $incs_on
1204         \@ extradefines = "$defs"
1205         PIPE \$(CPP) ${cflags} $srcs | -
1206              \$(PERL) -ne "/^#(\\s*line)?\\s*[0-9]+\\s+""/ or print" -
1207              > ${objd}${objn}-asm
1208         \@ DELETE/SYMBOL/LOCAL extradefines
1209         \@ $incs_off
1210         SET DEFAULT $backward
1211         \$(AS) $asflags \$(ASOUTFLAG)$obj $obj-asm
1212         - PURGE $obj
1213 EOF
1214       }
1215
1216       my ($incdir_filename, $incdir_scripture) =
1217           make_includefile(@{ { shlib => [ @lib_cppincludes ],
1218                                 lib => [ @lib_cppincludes ],
1219                                 dso => [ @dso_cppincludes ],
1220                                 bin => [ @bin_cppincludes ] } -> {$args{intent}} },
1221                            @{$args{incs}});
1222       $deps .= ", -\n\t\t$incdir_filename";
1223       $cflags =
1224           $target{cflag_incfirst}
1225           . '"'.make_unix_path(rel2abs($incdir_filename)).'"'
1226           . $cflags;
1227
1228       my $depbuild = $disabled{makedepend} ? ""
1229           : " /MMS=(FILE=${depd}${depn},TARGET=$obj)";
1230
1231       return <<"EOF";
1232 $obj : $deps
1233         SET DEFAULT $forward
1234         \@ $incs_on
1235         \@ extradefines = "$defs"
1236         \$(CC) ${cflags}${depbuild} /OBJECT=${objd}${objn} /REPOSITORY=$backward $srcs
1237         \@ DELETE/SYMBOL/LOCAL extradefines
1238         \@ $incs_off
1239         SET DEFAULT $backward
1240         - PURGE $obj
1241 $incdir_scripture
1242 EOF
1243   }
1244   sub obj2shlib {
1245       my %args = @_;
1246       my $shlibname = platform->sharedname($args{lib});
1247       my $shlib = platform->sharedlib($args{lib});
1248       my @objs = map { platform->convertext($_) }
1249                  grep { platform->isobj($_) }
1250                  @{$args{objs}};
1251       my @defs = map { platform->convertext($_) }
1252                  grep { platform->isdef($_) }
1253                  @{$args{objs}};
1254       my @deps = compute_lib_depends(@{$args{deps}});
1255       die "More than one symbol vector" if scalar @defs > 1;
1256       my $deps = join(", -\n\t\t", @objs, @defs, map { $_->{lib} } @deps);
1257       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
1258       my $translatesyms_pl = abs2rel(rel2abs(catfile($config{sourcedir},
1259                                                      "VMS", "translatesyms.pl")),
1260                                      rel2abs($config{builddir}));
1261       # The "[]" hack is because in .OPT files, each line inherits the
1262       # previous line's file spec as default, so if no directory spec
1263       # is present in the current line and the previous line has one that
1264       # doesn't apply, you're in for a surprise.
1265       my $write_opt1 =
1266           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
1267                                  "WRITE OPT_FILE \"$x" } @objs).
1268           "\"";
1269       my $write_opt2 =
1270           join("\n\t", map { my $x = $_->{lib} =~ /\[/
1271                                  ? $_->{lib} : "[]".$_->{lib};
1272                              $x =~ s|(\.EXE)|$1/SHARE|;
1273                              $x =~ s|(\.OLB)|$1/LIB|;
1274                              "WRITE OPT_FILE \"$x\"" } @deps)
1275           || "\@ !";
1276       return <<"EOF"
1277 $shlib : $deps
1278         \$(PERL) $translatesyms_pl \$(BLDDIR)CXX\$DEMANGLER_DB. < $defs[0] > $defs[0]-translated
1279         OPEN/WRITE/SHARE=READ OPT_FILE $shlibname-components.OPT
1280         $write_opt1
1281         $write_opt2
1282         CLOSE OPT_FILE
1283         LINK ${lib_ldflags}/SHARE=\$\@ $defs[0]-translated/OPT,-
1284                 $shlibname-components.OPT/OPT \$(LIB_EX_LIBS)
1285         DELETE $defs[0]-translated;*,$shlibname-components.OPT;*
1286         PURGE $shlibname.EXE,$shlibname.MAP
1287 EOF
1288         . ($config{target} =~ m|alpha| ? "" : <<"EOF"
1289         SET IMAGE/FLAGS=(NOCALL_DEBUG) \$\@
1290 EOF
1291         );
1292   }
1293   sub obj2dso {
1294       my %args = @_;
1295       my $dsoname = platform->dsoname($args{module});
1296       my $dso = platform->dso($args{module});
1297       my @objs = map { platform->convertext($_) }
1298                  grep { platform->isobj($_) }
1299                  @{$args{objs}};
1300       my @defs = map { platform->convertext($_) }
1301                  grep { platform->isdef($_) }
1302                  @{$args{objs}};
1303       my @deps = compute_lib_depends(@{$args{deps}});
1304       my $deps = join(", -\n\t\t", @objs, @defs, map { $_->{lib} } @deps);
1305       die "More than one symbol vector" if scalar @defs > 1;
1306       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
1307       # The "[]" hack is because in .OPT files, each line inherits the
1308       # previous line's file spec as default, so if no directory spec
1309       # is present in the current line and the previous line has one that
1310       # doesn't apply, you're in for a surprise.
1311       # Furthermore, we collect all object files and static libraries in
1312       # an explicit cluster, to make it clear to the linker that these files
1313       # shall be processed before shareable images.
1314       # The shareable images are used with /SELECTIVE, to avoid warnings of
1315       # multiply defined symbols when the module object files override some
1316       # symbols that are present in the shareable image.
1317       my $write_opt1 =
1318           join(",-\"\n\t",
1319                "\@ WRITE OPT_FILE \"CLUSTER=_,,",
1320                (map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
1321                       "\@ WRITE OPT_FILE \"$x" } @objs),
1322                (map { my $x = ($_->{lib} =~ /\[/) ? $_->{lib} : "[]".$_->{lib};
1323                       "\@ WRITE OPT_FILE \"$x/LIB" }
1324                 grep { $_->{lib} =~ m|\.OLB$| }
1325                 @deps))
1326           ."\"";
1327       my $write_opt2 =
1328           join("\n\t",
1329                (map { my $x = ($_->{lib} =~ /\[/) ? $_->{lib} : "[]".$_->{lib};
1330                       "\@ WRITE OPT_FILE \"$x/SHARE/SELECTIVE\"" }
1331                 grep { $_->{lib} =~ m|\.EXE$| }
1332                 @deps))
1333           || "\@ !";
1334       return <<"EOF"
1335 $dso : $deps
1336         OPEN/WRITE/SHARE=READ OPT_FILE $dsoname-components.OPT
1337         $write_opt1
1338         $write_opt2
1339         CLOSE OPT_FILE
1340         LINK ${dso_ldflags}/SHARE=\$\@ $defs[0]/OPT,-
1341                 $dsoname-components.OPT/OPT \$(DSO_EX_LIBS)
1342         - PURGE $dsoname.EXE,$dsoname.OPT,$dsoname.MAP
1343 EOF
1344         . ($config{target} =~ m|alpha| ? "" : <<"EOF"
1345         SET IMAGE/FLAGS=(NOCALL_DEBUG) \$\@
1346 EOF
1347         );
1348   }
1349   sub obj2lib {
1350       my %args = @_;
1351       my $lib = platform->staticlib($args{lib});
1352       my @objs = map { platform->convertext($_) }
1353                  grep { platform->isobj($_) }
1354                  @{$args{objs}};
1355       my $objs = join(", -\n\t\t", @objs);
1356       my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib $_" } @objs));
1357       return <<"EOF";
1358 $lib : $objs
1359         LIBRARY/CREATE/OBJECT $lib
1360         $fill_lib
1361         - PURGE $lib
1362 EOF
1363   }
1364   sub obj2bin {
1365       my %args = @_;
1366       my $bin = platform->bin($args{bin});
1367       my $binname = platform->binname($args{bin});
1368       my @objs = map { platform->convertext($_) }
1369                  grep { platform->isobj($_) }
1370                  @{$args{objs}};
1371       my $objs = join(",", @objs);
1372       my @deps = compute_lib_depends(@{$args{deps}});
1373       my $deps = join(", -\n\t\t", @objs, map { $_->{lib} } @deps);
1374
1375       my $olb_count = scalar grep(m|\.OLB$|, map { $_->{lib} } @deps);
1376       my $analyse_objs = "@ !";
1377       if ($olb_count > 0) {
1378           my $analyse_quals =
1379               $config{target} =~ m|alpha| ? "/GSD" : "/SECTIONS=SYMTAB";
1380           $analyse_objs = "- pipe ANALYSE/OBJECT$analyse_quals $objs | SEARCH SYS\$INPUT \"\"\"main\"\"\" ; nomain = \$severity .NE. 1"
1381       }
1382       # The "[]" hack is because in .OPT files, each line inherits the
1383       # previous line's file spec as default, so if no directory spec
1384       # is present in the current line and the previous line has one that
1385       # doesn't apply, you're in for a surprise.
1386       my $write_opt1 =
1387           "\@ WRITE OPT_FILE \"CASE_SENSITIVE=YES\"\n\t"
1388           .join(",-\"\n\t",
1389                 "\@ WRITE OPT_FILE \"CLUSTER=_,,",
1390                 (map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
1391                        "\@ WRITE OPT_FILE \"$x" } @objs),
1392                 (map { my $x = ($_->{lib} =~ /\[/) ? $_->{lib} : "[]".$_->{lib};
1393                        # Special hack to include the MAIN object module
1394                        # explicitly, if it's known that there is one.
1395                        # |incmain| is defined in the rule generation further
1396                        # down, with the necessary /INCLUDE=main option unless
1397                        # the program has been determined to have a main function
1398                        # already.
1399                        $_->{attrs}->{has_main}
1400                        ? "\@ WRITE OPT_FILE \"$x/LIB''incmain'"
1401                        : "\@ WRITE OPT_FILE \"$x/LIB" }
1402                  grep { $_->{lib} =~ m|\.OLB$| }
1403                  @deps))
1404           ."\"";
1405       my $write_opt2 =
1406           join("\n\t",
1407                (map { my $x = $_->{lib} =~ /\[/ ? $_->{lib} : "[]".$_->{lib};
1408                       "\@ WRITE OPT_FILE \"$x/SHARE/SELECTIVE\"" }
1409                 grep { $_->{lib} =~ m|\.EXE$| }
1410                 @deps))
1411           || "\@ !";
1412       # The linking commands looks a bit complex, but it's for good reason.
1413       # When you link, say, foo.obj, bar.obj and libsomething.exe/share, and
1414       # bar.obj happens to have a symbol that also exists in libsomething.exe,
1415       # the linker will warn about it, loudly, and will then choose to pick
1416       # the first copy encountered (the one in bar.obj in this example).
1417       # On Unix and on Windows, the corresponding maneuver goes through
1418       # silently with the same effect.
1419       # With some test programs, made for checking the internals of OpenSSL,
1420       # we do this kind of linking deliberately, picking a few specific object
1421       # files from within [.crypto] or [.ssl] so we can reach symbols that are
1422       # otherwise unreachable (since the shareable images only exports the
1423       # symbols listed in [.util]*.num), and then with the shared libraries
1424       # themselves.  So we need to silence the warning about multiply defined
1425       # symbols, to mimic the way linking work on Unix and Windows, and so
1426       # the build isn't interrupted (MMS stops when warnings are signaled,
1427       # by default), and so someone building doesn't have to worry where it
1428       # isn't necessary.  If there are other warnings, however, we show them
1429       # and let it break the build.
1430       return <<"EOF"
1431 $bin : $deps
1432         $analyse_objs
1433         @ incmain = "/INCLUDE=main"
1434         @ IF .NOT. nomain THEN incmain = ""
1435         @ OPEN/WRITE/SHARE=READ OPT_FILE $binname.OPT
1436         $write_opt1
1437         $write_opt2
1438         @ CLOSE OPT_FILE
1439         TYPE $binname.OPT ! For debugging
1440         - pipe SPAWN/WAIT/NOLOG/OUT=$binname.LINKLOG -
1441                     LINK ${bin_ldflags}/EXEC=\$\@ $binname.OPT/OPT \$(BIN_EX_LIBS) ; -
1442                link_status = \$status ; link_severity = link_status .AND. 7
1443         @ search_severity = 1
1444         -@ IF link_severity .EQ. 0 THEN -
1445                 pipe SEARCH $binname.LINKLOG "%","-"/MATCH=AND | -
1446                      SPAWN/WAIT/NOLOG/OUT=NLA0: -
1447                           SEARCH SYS\$INPUT: "-W-MULDEF,"/MATCH=NOR ; -
1448                      search_severity = \$severity
1449         @ ! search_severity is 3 when the last search didn't find any matching
1450         @ ! string: %SEARCH-I-NOMATCHES, no strings matched
1451         @ ! If that was the result, we pretend linking got through without
1452         @ ! fault or warning.
1453         @ IF search_severity .EQ. 3 THEN link_severity = 1
1454         @ ! At this point, if link_severity shows that there was a fault
1455         @ ! or warning, make sure to restore the linking status.
1456         -@ IF .NOT. link_severity THEN TYPE $binname.LINKLOG
1457         -@ DELETE $binname.LINKLOG;*
1458         @ IF .NOT. link_severity THEN SPAWN/WAIT/NOLOG EXIT 'link_status'
1459         - PURGE $bin,$binname.OPT
1460 EOF
1461       . ($config{target} =~ m|alpha| ? "" : <<"EOF"
1462         SET IMAGE/FLAGS=(NOCALL_DEBUG) \$\@
1463 EOF
1464         );
1465   }
1466   sub in2script {
1467       my %args = @_;
1468       my $script = $args{script};
1469       return "" if grep { $_ eq $script } @{$args{sources}}; # No overwrite!
1470       my $sources = join(" ", @{$args{sources}});
1471       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1472                                            "util", "dofile.pl")),
1473                            rel2abs($config{builddir}));
1474       return <<"EOF";
1475 $script : $sources configdata.pm
1476         \$(PERL) "-I\$(BLDDIR)" "-Mconfigdata" $dofile -
1477             "-o$target{build_file}" $sources > $script
1478         SET FILE/PROT=(S:RWED,O:RWED,G:RE,W:RE) $script
1479         PURGE $script
1480 EOF
1481   }
1482   ""    # Important!  This becomes part of the template result.
1483 -}