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