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