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