rand_lib.c: fix null pointer dereferences after RAND_get_rand_method() failure
[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
8   (our $osslprefix_q = platform->osslprefix()) =~ s/\$/\\\$/;
9
10   our $sover_dirname = platform->shlib_version_as_filename();
11   our $osslver = sprintf "%02d%02d", split(/\./, $config{version});
12
13   our $sourcedir = $config{sourcedir};
14   our $builddir = $config{builddir};
15   sub sourcefile {
16       catfile($sourcedir, @_);
17   }
18   sub buildfile {
19       catfile($builddir, @_);
20   }
21   sub sourcedir {
22       catdir($sourcedir, @_);
23   }
24   sub builddir {
25       catdir($builddir, @_);
26   }
27   sub tree {
28       (my $x = shift) =~ s|\]$|...]|;
29       $x
30   }
31   sub move {
32       my $f = catdir(@_);
33       my $b = abs2rel(rel2abs("."),rel2abs($f));
34       $sourcedir = catdir($b,$sourcedir)
35           if !file_name_is_absolute($sourcedir);
36       $builddir = catdir($b,$builddir)
37           if !file_name_is_absolute($builddir);
38       "";
39   }
40
41   # Because we need to make two computations of these data,
42   # we store them in arrays for reuse
43   our @libs =
44       map { platform->staticname($_) }
45       @{$unified_info{libraries}};
46   our @shlibs =
47       map { platform->sharedname($_) // () }
48       @{$unified_info{libraries}};
49   our @install_libs =
50       map { platform->staticname($_) }
51       grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
52       @{$unified_info{libraries}};
53   our @install_shlibs =
54       map { platform->sharedname($_) // () }
55       grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
56       @{$unified_info{libraries}};
57   our @install_engines =
58       grep { !$unified_info{attributes}->{modules}->{$_}->{noinst}
59              && $unified_info{attributes}->{modules}->{$_}->{engine} }
60       @{$unified_info{modules}};
61   our @install_programs =
62       grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} }
63       @{$unified_info{programs}};
64   our @install_bin_scripts =
65       grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
66              && !$unified_info{attributes}->{scripts}->{$_}->{misc} }
67       @{$unified_info{scripts}};
68   our @install_misc_scripts =
69       grep { !$unified_info{attributes}->{scripts}->{$_}->{noinst}
70              && $unified_info{attributes}->{scripts}->{$_}->{misc} }
71       @{$unified_info{scripts}};
72
73   # This is a horrible hack, but is needed because recursive inclusion of files
74   # in different directories does not work well with HP C.
75   my $sd = sourcedir("crypto", "async", "arch");
76   foreach (grep /\[\.crypto\.async\.arch\].*\.o$/, keys %{$unified_info{sources}}) {
77       my $obj = platform->obj($_);
78       $unified_info{before}->{$obj}
79           = qq(arch_include = F\$PARSE("$sd","A.;",,,"SYNTAX_ONLY") - "A.;"
80         define arch 'arch_include');
81       $unified_info{after}->{$obj}
82           = qq(deassign arch);
83   }
84   my $sd1 = sourcedir("ssl","record");
85   my $sd2 = sourcedir("ssl","statem");
86   my @ssl_locl_users = grep(/^\[\.(?:ssl\.(?:record|statem)|test)\].*\.o$/,
87                             keys %{$unified_info{sources}});
88   foreach (@ssl_locl_users) {
89       my $obj = platform->obj($_);
90       $unified_info{before}->{$obj}
91           = qq(record_include = F\$PARSE("$sd1","A.;",,,"SYNTAX_ONLY") - "A.;"
92         define record 'record_include'
93         statem_include = F\$PARSE("$sd2","A.;",,,"SYNTAX_ONLY") - "A.;"
94         define statem 'statem_include');
95       $unified_info{after}->{$obj}
96           = qq(deassign statem
97         deassign record);
98   }
99   # This makes sure things get built in the order they need
100   # to. You're welcome.
101   sub dependmagic {
102       my $target = shift;
103
104       return "$target : build_generated\n\t\pipe \$(MMS) \$(MMSQUALIFIERS) depend && \$(MMS) \$(MMSQUALIFIERS) _$target\n_$target";
105   }
106   "";
107 -}
108 PLATFORM={- $config{target} -}
109 OPTIONS={- $config{options} -}
110 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
111 SRCDIR={- $config{sourcedir} -}
112 BLDDIR={- $config{builddir} -}
113
114 # Allow both V and VERBOSE to indicate verbosity.  This only applies
115 # to testing.
116 VERBOSE=$(V)
117 VERBOSE_FAILURE=$(VF)
118
119 VERSION={- "$config{full_version}" -}
120 MAJOR={- $config{major} -}
121 MINOR={- $config{minor} -}
122 SHLIB_VERSION_NUMBER={- $config{shlib_version} -}
123 SHLIB_TARGET={- $target{shared_target} -}
124
125 LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @libs) -}
126 SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @shlibs) -}
127 MODULES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{modules}}) -}
128 PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{programs}}) -}
129 SCRIPTS={- join(", ", map { "-\n\t".$_ } @{$unified_info{scripts}}) -}
130 {- output_off() if $disabled{makedepend}; "" -}
131 DEPS={- our @deps = map { platform->isobj($_) ? platform->dep($_) : $_ }
132                     grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
133                     keys %{$unified_info{sources}};
134         join(", ", map { "-\n\t".$_ } @deps); -}
135 {- output_on() if $disabled{makedepend}; "" -}
136 GENERATED_MANDATORY={- join(", ", map { "-\n\t".$_ } @{$unified_info{depends}->{""}} ) -}
137 GENERATED={- # common0.tmpl provides @generated
138              join(", ", map { platform->convertext($_) } @generated) -}
139
140 INSTALL_LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @install_libs) -}
141 INSTALL_SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @install_shlibs) -}
142 INSTALL_ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @install_engines) -}
143 INSTALL_PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @install_programs) -}
144 BIN_SCRIPTS={- join(", ", @install_bin_scripts) -}
145 MISC_SCRIPTS={- join(", ", @install_misc_scripts) -}
146 HTMLDOCS1={- join(", ", map { "-\n\t".$_ } @{$unified_info{htmldocs}->{man1}}) -}
147 HTMLDOCS3={- join(", ", map { "-\n\t".$_ } @{$unified_info{htmldocs}->{man3}}) -}
148 HTMLDOCS5={- join(", ", map { "-\n\t".$_ } @{$unified_info{htmldocs}->{man5}}) -}
149 HTMLDOCS7={- join(", ", map { "-\n\t".$_ } @{$unified_info{htmldocs}->{man7}}) -}
150
151 APPS_OPENSSL={- use File::Spec::Functions;
152                 catfile("apps","openssl") -}
153
154 # DESTDIR is for package builders so that they can configure for, say,
155 # SYS$COMMON:[OPENSSL] and yet have everything installed in STAGING:[USER].
156 # In that case, configure with --prefix=SYS$COMMON:[OPENSSL] and then run
157 # MMS with /MACROS=(DESTDIR=STAGING:[USER]).  The result will end up in
158 # STAGING:[USER.OPENSSL].
159 # Normally it is left empty.
160 DESTDIR=
161
162 # Do not edit this manually. Use Configure --prefix=DIR to change this!
163 INSTALLTOP={- our $installtop =
164                   catdir($config{prefix}) || "SYS\$COMMON:[OPENSSL]";
165               $installtop -}
166 SYSTARTUP={- catdir($installtop, '[.SYS$STARTUP]'); -}
167 # This is the standard central area to store certificates, private keys...
168 OPENSSLDIR={- catdir($config{openssldir}) or
169               $config{prefix} ? catdir($config{prefix},"COMMON")
170                               : "SYS\$COMMON:[OPENSSL-COMMON]" -}
171 # The same, but for C
172 OPENSSLDIR_C={- platform->osslprefix() -}DATAROOT:[000000]
173 # Where installed ENGINE modules reside, for C
174 ENGINESDIR_C={- platform->osslprefix() -}ENGINES{- $sover_dirname.$target{pointer_size} -}:
175 # Where modules reside, for C
176 MODULESDIR_C={- platform->osslprefix() -}MODULES{- $sover_dirname.$target{pointer_size} -}:
177
178 ##### User defined commands and flags ################################
179
180 CC={- $config{CC} -}
181 CPP={- $config{CPP} -}
182 DEFINES={- our $defines1 = join('', map { ",$_" } @{$config{CPPDEFINES}}) -}
183 INCLUDES={- our $includes1 = join(',', @{$config{CPPINCLUDES}}) -}
184 CPPFLAGS={- our $cppflags1 = join('', @{$config{CPPFLAGS}}) -}
185 CFLAGS={- join('', @{$config{CFLAGS}}) -}
186 LDFLAGS={- join('', @{$config{LFLAGS}}) -}
187 EX_LIBS={- join('', map { ",$_" } @{$config{LDLIBS}}) -}
188
189 PERL={- $config{PERL} -}
190
191 AS={- $config{AS} -}
192 ASFLAGS={- join(' ', @{$config{ASFLAGS}}) -}
193
194 ##### Special command flags ##########################################
195
196 ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
197
198 ##### Project flags ##################################################
199
200 # Variables starting with CNF_ are common variables for all product types
201
202 CNF_ASFLAGS={- join('', $target{asflags} || (),
203                         @{$config{asflags}}) -}
204 CNF_DEFINES={- our $defines2 = join('', (map { ",$_" } @{$target{defines}},
205                                                        @{$config{defines}}),
206                                         "'extradefines'") -}
207 CNF_INCLUDES={- our $includes2 = join(',', @{$target{includes}},
208                                            @{$config{includes}}) -}
209 CNF_CPPFLAGS={- our $cppflags2 = join('', $target{cppflags} || (),
210                                           @{$config{cppflags}}) -}
211 CNF_CFLAGS={- join('', $target{cflags} || (),
212                        @{$config{cflags}}) -}
213 CNF_CXXFLAGS={- join('', $target{cxxflags} || (),
214                          @{$config{cxxflags}}) -}
215 CNF_LDFLAGS={- join('', $target{lflags} || (),
216                         @{$config{lflags}}) -}
217 CNF_EX_LIBS={- join('', map{ ",$_" } @{$target{ex_libs}},
218                                      @{$config{ex_libs}}) -}
219
220 # Variables starting with LIB_ are used to build library object files
221 # and shared libraries.
222 # Variables starting with DSO_ are used to build DSOs and their object files.
223 # Variables starting with BIN_ are used to build programs and their object
224 # files.
225
226 LIB_ASFLAGS={- join(' ', $target{lib_asflags} || (),
227                          @{$config{lib_asflags}},
228                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
229 LIB_DEFINES={- our $lib_defines =
230                join('', (map { ",$_" } @{$target{lib_defines}},
231                                        @{$target{shared_defines}},
232                                        @{$config{lib_defines}},
233                                        @{$config{shared_defines}}));
234                join('', $lib_defines,
235                         (map { ",$_" } 'OPENSSLDIR="""$(OPENSSLDIR_C)"""',
236                                        'ENGINESDIR="""$(ENGINESDIR_C)"""',
237                                        'MODULESDIR="""$(MODULESDIR_C)"""'),
238                         '$(CNF_DEFINES)', '$(DEFINES)') -}
239 LIB_INCLUDES={- our $lib_includes =
240                 join(',', @{$target{lib_includes}},
241                           @{$target{shared_includes}},
242                           @{$config{lib_includes}},
243                           @{$config{shared_includes}}) -}
244 LIB_CPPFLAGS={- our $lib_cppflags =
245                 join('', $target{lib_cppflags} || (),
246                          $target{shared_cppflags} || (),
247                          @{$config{lib_cppflags}},
248                          @{$config{shared_cppflag}});
249                 join('', "'qual_includes'",
250                          '/DEFINE=(__dummy$(LIB_DEFINES))',
251                          $lib_cppflags,
252                          '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
253 LIB_CFLAGS={- join('', $target{lib_cflags} || (),
254                        $target{shared_cflag} || (),
255                        @{$config{lib_cflags}},
256                        @{$config{shared_cflag}},
257                        '$(CNF_CFLAGS)', '$(CFLAGS)') -}
258 LIB_LDFLAGS={- join('', $target{lib_lflags} || (),
259                         $target{shared_ldflag} || (),
260                         @{$config{lib_lflags}},
261                         @{$config{shared_ldflag}},
262                         '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
263 LIB_EX_LIBS=$(CNF_EX_LIBS)$(EX_LIBS)
264 DSO_ASFLAGS={- join(' ', $target{dso_asflags} || (),
265                          $target{module_asflags} || (),
266                          @{$config{dso_asflags}},
267                          @{$config{module_asflags}},
268                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
269 DSO_DEFINES={- join('', (map { ",$_" } @{$target{dso_defines}},
270                                        @{$target{module_defines}},
271                                        @{$config{dso_defines}},
272                                        @{$config{module_defines}}),
273                         '$(CNF_DEFINES)', '$(DEFINES)') -}
274 DSO_INCLUDES={- join(',', @{$target{dso_includes}},
275                           @{$target{module_includes}},
276                           @{$config{dso_includes}},
277                           @{$config{module_includes}}) -}
278 DSO_CPPFLAGS={- join('', "'qual_includes'",
279                          '/DEFINE=(__dummy$(DSO_DEFINES))',
280                          $target{dso_cppflags} || (),
281                          $target{module_cppflags} || (),
282                          @{$config{dso_cppflags}},
283                          @{$config{module_cppflags}},
284                          '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
285 DSO_CFLAGS={- join('', $target{dso_cflags} || (),
286                        $target{module_cflags} || (),
287                        @{$config{dso_cflags}},
288                        @{$config{module_cflags}},
289                        '$(CNF_CFLAGS)', '$(CFLAGS)') -}
290 DSO_LDFLAGS={- join('', $target{dso_lflags} || (),
291                         $target{module_ldflags} || (),
292                         @{$config{dso_lflags}},
293                         @{$config{module_ldflags}},
294                         '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
295 DSO_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
296 BIN_ASFLAGS={- join(' ', $target{bin_asflags} || (),
297                          @{$config{bin_asflags}},
298                          '$(CNF_ASFLAGS)', '$(ASFLAGS)') -}
299 BIN_DEFINES={- join('', (map { ",$_" } @{$target{bin_defines}},
300                                        @{$config{bin_defines}}),
301                         '$(CNF_DEFINES)', '$(DEFINES)') -}
302 BIN_INCLUDES={- join(',', @{$target{bin_includes}},
303                           @{$config{bin_includes}}) -}
304 BIN_CPPFLAGS={- join('', "'qual_includes'",
305                          '/DEFINE=(__dummy$(DSO_DEFINES))',
306                          $target{bin_cppflags} || (),
307                          @{$config{bin_cppflag}},
308                          '$(CNF_CPPFLAGS)', '$(CPPFLAGS)') -}
309 BIN_CFLAGS={- join('', $target{bin_cflags} || (),
310                        @{$config{bin_cflags}},
311                        '$(CNF_CFLAGS)', '$(CFLAGS)') -}
312 BIN_LDFLAGS={- join('', $target{bin_lflags} || (),
313                         @{$config{bin_lflags}} || (),
314                         '$(CNF_LDFLAGS)', '$(LDFLAGS)') -}
315 BIN_EX_LIBS=$(CNF_EX_LIBS) $(EX_LIBS)
316 NO_INST_LIB_CFLAGS={- join('', $target{no_inst_lib_cflags}
317                                // $target{lib_cflags}
318                                // (),
319                                $target{shared_cflag} || (),
320                                @{$config{lib_cflags}},
321                                @{$config{shared_cflag}},
322                                '$(CNF_CFLAGS)', '$(CFLAGS)') -}
323 NO_INST_DSO_CFLAGS={- join('', $target{no_inst_dso_cflags}
324                                // $target{dso_cflags}
325                                // (),
326                                $target{no_inst_module_cflags}
327                                // $target{module_cflags}
328                                // (),
329                                @{$config{dso_cflags}},
330                                @{$config{module_cflags}},
331                                '$(CNF_CFLAGS)', '$(CFLAGS)') -}
332 NO_INST_BIN_CFLAGS={- join('', $target{no_inst_bin_cflags}
333                                // $target{bin_cflags}
334                                // (),
335                                @{$config{bin_cflags}},
336                                '$(CNF_CFLAGS)', '$(CFLAGS)') -}
337
338 PERLASM_SCHEME={- $target{perlasm_scheme} -}
339
340 # CPPFLAGS_Q is used for one thing only: to build up buildinf.h
341 CPPFLAGS_Q={- (my $c = $lib_cppflags.$cppflags2.$cppflags1) =~ s|"|""|g;
342               (my $d = $lib_defines.$defines2.$defines1) =~ s|"|""|g;
343               my $i = join(',', $lib_includes || (), $includes2 || (),
344                                 $includes1 || ());
345               my $x = $c;
346               $x .= "/INCLUDE=($i)" if $i;
347               $x .= "/DEFINE=($d)" if $d;
348               $x; -}
349
350 # .FIRST and .LAST are special targets with MMS and MMK.
351 # The defines in there are for C.  includes that look like
352 # this:
353 #
354 #    #include <openssl/foo.h>
355 #    #include "internal/bar.h"
356 #
357 # will use the logical names to find the files.  Expecting
358 # DECompHP C to find files in subdirectories of whatever was
359 # given with /INCLUDE is a fantasy, unfortunately.
360 NODEBUG=@
361 .FIRST :
362         $(NODEBUG) openssl_inc1 = F$PARSE("[.include.openssl]","A.;",,,"syntax_only") - "A.;"
363         $(NODEBUG) openssl_inc2 = F$PARSE("{- catdir($config{sourcedir},"[.include.openssl]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
364         $(NODEBUG) internal_inc1 = F$PARSE("[.crypto.include.internal]","A.;",,,"SYNTAX_ONLY") - "A.;"
365         $(NODEBUG) internal_inc2 = F$PARSE("{- catdir($config{sourcedir},"[.include.internal]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
366         $(NODEBUG) internal_inc3 = F$PARSE("{- catdir($config{sourcedir},"[.crypto.include.internal]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
367         $(NODEBUG) DEFINE openssl 'openssl_inc1','openssl_inc2'
368         $(NODEBUG) DEFINE internal 'internal_inc1','internal_inc2','internal_inc3'
369         $(NODEBUG) staging_dir = "$(DESTDIR)"
370         $(NODEBUG) staging_instdir = ""
371         $(NODEBUG) staging_datadir = ""
372         $(NODEBUG) IF staging_dir .NES. "" THEN -
373                 staging_instdir = F$PARSE("A.;",staging_dir,"[]",,"SYNTAX_ONLY")
374         $(NODEBUG) IF staging_instdir - "]A.;" .NES. staging_instdir THEN -
375                 staging_instdir = staging_instdir - "]A.;" + ".OPENSSL-INSTALL]"
376         $(NODEBUG) IF staging_instdir - "A.;" .NES. staging_instdir THEN -
377                 staging_instdir = staging_instdir - "A.;" + "[OPENSSL-INSTALL]"
378         $(NODEBUG) IF staging_dir .NES. "" THEN -
379                 staging_datadir = F$PARSE("A.;",staging_dir,"[]",,"SYNTAX_ONLY")
380         $(NODEBUG) IF staging_datadir - "]A.;" .NES. staging_datadir THEN -
381                 staging_datadir = staging_datadir - "]A.;" + ".OPENSSL-COMMON]"
382         $(NODEBUG) IF staging_datadir - "A.;" .NES. staging_datadir THEN -
383                 staging_datadir = staging_datadir - "A.;" + "[OPENSSL-COMMON]"
384         $(NODEBUG) !
385         $(NODEBUG) ! Installation logical names
386         $(NODEBUG) !
387         $(NODEBUG) installtop = F$PARSE(staging_instdir,"$(INSTALLTOP)","[]A.;",,"SYNTAX_ONLY,NO_CONCEAL") - ".][000000" - "[000000." - "][" - "]A.;" + ".]"
388         $(NODEBUG) datatop = F$PARSE(staging_datadir,"$(OPENSSLDIR)","[]A.;",,"SYNTAX_ONLY,NO_CONCEAL") - ".][000000" - "[000000." - "][" - "]A.;" + ".]"
389         $(NODEBUG) DEFINE ossl_installroot 'installtop'
390         $(NODEBUG) DEFINE ossl_dataroot 'datatop'
391         $(NODEBUG) !
392         $(NODEBUG) ! Figure out the architecture
393         $(NODEBUG) !
394         $(NODEBUG) arch = f$edit( f$getsyi( "arch_name"), "upcase")
395         $(NODEBUG) !
396         $(NODEBUG) ! Set up logical names for the libraries, so LINK and
397         $(NODEBUG) ! running programs can use them.
398         $(NODEBUG) !
399         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEFINE ".uc($_)." 'F\$ENV(\"DEFAULT\")'".uc($_)."\$(SHLIB_EXT)" } @shlibs) || "!" -}
400
401 .LAST :
402         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEASSIGN ".uc($_) } @shlibs) || "!" -}
403         $(NODEBUG) DEASSIGN ossl_dataroot
404         $(NODEBUG) DEASSIGN ossl_installroot
405         $(NODEBUG) DEASSIGN internal
406         $(NODEBUG) DEASSIGN openssl
407 .DEFAULT :
408         @ ! MMS cannot handle no actions...
409
410 # The main targets ###################################################
411
412 {- dependmagic('build_sw'); -} : build_libs_nodep, build_modules_nodep, build_programs_nodep
413 {- dependmagic('build_libs'); -} : build_libs_nodep
414 {- dependmagic('build_modules'); -} : build_modules_nodep
415 {- dependmagic('build_programs'); -} : build_programs_nodep
416
417 build_generated : $(GENERATED_MANDATORY)
418 build_libs_nodep : $(LIBS), $(SHLIBS)
419 build_modules_nodep : $(MODULES)
420 build_programs_nodep : $(PROGRAMS), $(SCRIPTS)
421
422 build_docs: build_html_docs
423 build_html_docs: $(HTMLDOCS1) $(HTMLDOCS3) $(HTMLDOCS5) $(HTMLDOCS7)
424
425 # Kept around for backward compatibility
426 build_apps build_tests : build_programs
427
428 # Convenience target to prebuild all generated files, not just the mandatory
429 # ones
430 build_all_generated : $(GENERATED_MANDATORY) $(GENERATED) build_docs
431         @ ! {- output_off() if $disabled{makedepend}; "" -}
432         @ WRITE SYS$OUTPUT "Warning: consider configuring with no-makedepend, because if"
433         @ WRITE SYS$OUTPUT "         target system doesn't have $(PERL),"
434         @ WRITE SYS$OUTPUT "         then make will fail..."
435         @ ! {- output_on() if $disabled{makedepend}; "" -}
436
437 all : build_sw build_docs
438
439 test : tests
440 {- dependmagic('tests'); -} : build_programs_nodep, build_modules_nodep
441         @ ! {- output_off() if $disabled{tests}; "" -}
442         SET DEFAULT [.test]{- move("test") -}
443         CREATE/DIR [.test-runs]
444         DEFINE SRCTOP {- sourcedir() -}
445         DEFINE BLDTOP {- builddir() -}
446         DEFINE RESULT_D {- builddir(qw(test test-runs)) -}
447         DEFINE OPENSSL_ENGINES {- builddir("engines") -}
448         DEFINE OPENSSL_MODULES {- builddir("providers") -}
449         DEFINE OPENSSL_DEBUG_MEMORY "on"
450         IF "$(VERBOSE)" .NES. "" THEN DEFINE VERBOSE "$(VERBOSE)"
451         $(PERL) {- sourcefile("test", "run_tests.pl") -} $(TESTS)
452         DEASSIGN OPENSSL_DEBUG_MEMORY
453         DEASSIGN OPENSSL_MODULES
454         DEASSIGN OPENSSL_ENGINES
455         DEASSIGN BLDTOP
456         DEASSIGN SRCTOP
457         SET DEFAULT [-]{- move("..") -}
458         @ ! {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
459         @ WRITE SYS$OUTPUT "Tests are not supported with your chosen Configure options"
460         @ ! {- output_on() if !$disabled{tests}; "" -}
461
462 list-tests :
463         @ ! {- output_off() if $disabled{tests}; "" -}
464         @ DEFINE SRCTOP {- sourcedir() -}
465         @ $(PERL) {- sourcefile("test", "run_tests.pl") -} list
466         @ DEASSIGN SRCTOP
467         @ ! {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
468         @ WRITE SYS$OUTPUT "Tests are not supported with your chosen Configure options"
469         @ ! {- output_on() if !$disabled{tests}; "" -}
470
471 install : install_sw install_ssldirs install_docs install_final
472
473 install_final :
474         @ WRITE SYS$OUTPUT ""
475         @ WRITE SYS$OUTPUT "######################################################################"
476         @ WRITE SYS$OUTPUT ""
477         @ IF "$(DESTDIR)" .EQS. "" THEN -
478              PIPE ( WRITE SYS$OUTPUT "Installation complete" ; -
479                     WRITE SYS$OUTPUT "" ; -
480                     WRITE SYS$OUTPUT "Run @$(SYSTARTUP)openssl_startup{- $osslver -} to set up logical names" ; -
481                     WRITE SYS$OUTPUT "then run @$(SYSTARTUP)openssl_utils{- $osslver -} to define commands" ; -
482                     WRITE SYS$OUTPUT "" )
483         @ IF "$(DESTDIR)" .NES. "" THEN -
484              PIPE ( WRITE SYS$OUTPUT "Staging installation complete" ; -
485                     WRITE SYS$OUTPUT "" ; -
486                     WRITE SYS$OUTPUT "Finish or package in such a way that the contents of the directory tree" ; -
487                     WRITE SYS$OUTPUT staging_instdir ; -
488                     WRITE SYS$OUTPUT "ends up in $(INSTALLTOP)," ; -
489                     WRITE SYS$OUTPUT "and that the contents of the contents of the directory tree" ; -
490                     WRITE SYS$OUTPUT staging_datadir ; -
491                     WRITE SYS$OUTPUT "ends up in $(OPENSSLDIR)" ; -
492                     WRITE SYS$OUTPUT "" ; -
493                     WRITE SYS$OUTPUT "When in its final destination," ; -
494                     WRITE SYS$OUTPUT "Run @$(SYSTARTUP)openssl_startup{- $osslver -} to set up logical names" ; -
495                     WRITE SYS$OUTPUT "then run @$(SYSTARTUP)openssl_utils{- $osslver -} to define commands" ; -
496                     WRITE SYS$OUTPUT "" )
497
498 check_install :
499         spawn/nolog @ossl_installroot:[SYSTEST]openssl_ivp{- $osslver -}.com
500
501 uninstall : uninstall_docs uninstall_sw
502
503 # Because VMS wants the generation number (or *) to delete files, we can't
504 # use $(LIBS), $(PROGRAMS), $(GENERATED) and $(MODULES) directly.
505 libclean :
506         {- join("\n\t", map { "- DELETE $_.OLB;*" } @libs) || "@ !" -}
507         {- join("\n\t", map { "- DELETE $_.EXE;*,$_.MAP;*" } @shlibs) || "@ !" -}
508
509 clean : libclean
510         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{htmldocs}->{man1}}) || "@ !" -}
511         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{htmldocs}->{man3}}) || "@ !" -}
512         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{htmldocs}->{man5}}) || "@ !" -}
513         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{htmldocs}->{man7}}) || "@ !" -}
514         {- join("\n\t", map { "- DELETE $_.EXE;*,$_.OPT;*" } @{$unified_info{programs}}) || "@ !" -}
515         {- join("\n\t", map { "- DELETE $_.EXE;*,$_.OPT;*" } @{$unified_info{modules}}) || "@ !" -}
516         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{scripts}}) || "@ !" -}
517         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{depends}->{""}}) || "@ !" -}
518         {- join("\n\t", map { "- DELETE $_;*" } @generated) || "@ !" -}
519         - DELETE [...]*.MAP;*
520         - DELETE [...]*.D;*
521         - DELETE [...]*.OBJ;*,*.LIS;*
522         - DELETE []CXX$DEMANGLER_DB.;*
523         - DELETE [.VMS]openssl_startup.com;*
524         - DELETE [.VMS]openssl_shutdown.com;*
525         - DELETE []vmsconfig.pm;*
526
527 distclean : clean
528         - DELETE configdata.pm;*
529         - DELETE descrip.mms;*
530
531 depend : descrip.mms
532 descrip.mms : FORCE
533         @ ! {- output_off() if $disabled{makedepend}; "" -}
534         @ $(PERL) {- sourcefile("util", "add-depends.pl") -} "VMS C"
535         @ ! {- output_on() if $disabled{makedepend}; "" -}
536
537 # Install helper targets #############################################
538
539 install_sw : install_dev install_engines install_runtime -
540              install_startup install_ivp
541
542 uninstall_sw : uninstall_dev uninstall_engines uninstall_runtime -
543                uninstall_startup uninstall_ivp
544
545 install_docs : install_html_docs
546
547 uninstall_docs : uninstall_html_docs
548
549 install_ssldirs : check_INSTALLTOP
550         - CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[000000]
551         IF F$SEARCH("OSSL_DATAROOT:[000000]CERTS.DIR;1") .EQS. "" THEN -
552                 CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[CERTS]
553         IF F$SEARCH("OSSL_DATAROOT:[000000]PRIVATE.DIR;1") .EQS. "" THEN -
554                 CREATE/DIR/PROT=(S:RWED,O:RWE,G,W) OSSL_DATAROOT:[PRIVATE]
555         IF F$SEARCH("OSSL_DATAROOT:[000000]MISC.DIR;1") .EQS. "" THEN -
556                 CREATE/DIR/PROT=(S:RWED,O:RWE,G,W) OSSL_DATAROOT:[MISC]
557         COPY/PROT=W:RE $(MISC_SCRIPTS) OSSL_DATAROOT:[MISC]
558         @ ! Install configuration file
559         COPY/PROT=W:R {- sourcefile("apps", "openssl-vms.cnf") -} -
560                 ossl_dataroot:[000000]openssl.cnf-dist
561         IF F$SEARCH("OSSL_DATAROOT:[000000]openssl.cnf") .EQS. "" THEN -
562                 COPY/PROT=W:R {- sourcefile("apps", "openssl-vms.cnf") -} -
563                         ossl_dataroot:[000000]openssl.cnf
564         @ ! Install CTLOG configuration file
565         COPY/PROT=W:R {- sourcefile("apps", "ct_log_list.cnf") -} -
566                 ossl_dataroot:[000000]ct_log_list.cnf-dist
567         IF F$SEARCH("OSSL_DATAROOT:[000000]ct_log_list.cnf") .EQS. "" THEN -
568                 COPY/PROT=W:R {- sourcefile("apps", "ct_log_list.cnf") -} -
569                         ossl_dataroot:[000000]ct_log_list.cnf
570
571 install_dev : check_INSTALLTOP install_runtime_libs
572         @ WRITE SYS$OUTPUT "*** Installing development files"
573         @ ! Install header files
574         - CREATE/DIR ossl_installroot:[include.openssl]
575         COPY/PROT=W:R openssl:*.h ossl_installroot:[include.openssl]
576         @ ! Install static (development) libraries
577         - CREATE/DIR ossl_installroot:[LIB.'arch']
578         {- join("\n        ",
579                 map { "COPY/PROT=W:R $_.OLB ossl_installroot:[LIB.'arch']" }
580                 @install_libs) -}
581
582 install_engines : check_INSTALLTOP install_runtime_libs build_modules
583         @ {- output_off() unless scalar @install_engines; "" -} !
584         @ WRITE SYS$OUTPUT "*** Installing ENGINE modules"
585         - CREATE/DIR ossl_installroot:[ENGINES{- $sover_dirname.$target{pointer_size} -}.'arch']
586         {- join("\n        ",
587                 map { "COPY/PROT=W:RE $_.EXE ossl_installroot:[ENGINES$sover_dirname$target{pointer_size}.'arch']" }
588                 @install_engines) -}
589         @ {- output_on() unless scalar @install_engines; "" -} !
590
591 install_runtime : install_programs
592
593 install_runtime_libs : check_INSTALLTOP build_libs
594         @ {- output_off() if $disabled{shared}; "" -} !
595         @ WRITE SYS$OUTPUT "*** Installing shareable images"
596         @ ! Install shared (runtime) libraries
597         - CREATE/DIR ossl_installroot:[LIB.'arch']
598         {- join("\n        ",
599                 map { "COPY/PROT=W:R $_.EXE ossl_installroot:[LIB.'arch']" }
600                 @install_shlibs) -}
601         @ {- output_on() if $disabled{shared}; "" -} !
602
603 install_programs : check_INSTALLTOP install_runtime_libs build_programs
604         @ {- output_off() if $disabled{apps}; "" -} !
605         @ ! Install the main program
606         - CREATE/DIR ossl_installroot:[EXE.'arch']
607         COPY/PROT=W:RE [.APPS]openssl.EXE -
608                 ossl_installroot:[EXE.'arch']openssl{- $osslver -}.EXE
609         @ ! Install scripts
610         COPY/PROT=W:RE $(BIN_SCRIPTS) ossl_installroot:[EXE]
611         @ ! {- output_on() if $disabled{apps}; "" -}
612
613 install_startup : [.VMS]openssl_startup.com [.VMS]openssl_shutdown.com -
614                  [.VMS]openssl_utils.com, check_INSTALLTOP
615         - CREATE/DIR ossl_installroot:[SYS$STARTUP]
616         COPY/PROT=W:RE [.VMS]openssl_startup.com -
617                 ossl_installroot:[SYS$STARTUP]openssl_startup{- $osslver -}.com
618         COPY/PROT=W:RE [.VMS]openssl_shutdown.com -
619                 ossl_installroot:[SYS$STARTUP]openssl_shutdown{- $osslver -}.com
620         COPY/PROT=W:RE [.VMS]openssl_utils.com -
621                 ossl_installroot:[SYS$STARTUP]openssl_utils{- $osslver -}.com
622
623 install_ivp : [.VMS]openssl_ivp.com check_INSTALLTOP
624         - CREATE/DIR ossl_installroot:[SYSTEST]
625         COPY/PROT=W:RE [.VMS]openssl_ivp.com -
626                 ossl_installroot:[SYSTEST]openssl_ivp{- $osslver -}.com
627
628 [.VMS]openssl_startup.com : vmsconfig.pm {- sourcefile("VMS", "openssl_startup.com.in") -}
629         - CREATE/DIR [.VMS]
630         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
631                 {- sourcefile("VMS", "openssl_startup.com.in") -} -
632                 > [.VMS]openssl_startup.com
633
634 [.VMS]openssl_utils.com : vmsconfig.pm {- sourcefile("VMS", "openssl_utils.com.in") -}
635         - CREATE/DIR [.VMS]
636         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
637                 {- sourcefile("VMS", "openssl_utils.com.in") -} -
638                 > [.VMS]openssl_utils.com
639
640 [.VMS]openssl_shutdown.com : vmsconfig.pm {- sourcefile("VMS", "openssl_shutdown.com.in") -}
641         - CREATE/DIR [.VMS]
642         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
643                 {- sourcefile("VMS", "openssl_shutdown.com.in") -} -
644                 > [.VMS]openssl_shutdown.com
645
646 [.VMS]openssl_ivp.com : vmsconfig.pm {- sourcefile("VMS", "openssl_ivp.com.in") -}
647         - CREATE/DIR [.VMS]
648         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
649                 {- sourcefile("VMS", "openssl_ivp.com.in") -} -
650                 > [.VMS]openssl_ivp.com
651
652 vmsconfig.pm : configdata.pm
653         OPEN/WRITE/SHARE=READ CONFIG []vmsconfig.pm
654         WRITE CONFIG "package vmsconfig;"
655         WRITE CONFIG "use strict; use warnings;"
656         WRITE CONFIG "use Exporter;"
657         WRITE CONFIG "our @ISA = qw(Exporter);"
658         WRITE CONFIG "our @EXPORT = qw(%config %target %withargs %unified_info %disabled);"
659         WRITE CONFIG "our %config = ("
660         WRITE CONFIG "  target => '","{- $config{target} -}","',"
661         WRITE CONFIG "  version => '","{- $config{version} -}","',"
662         WRITE CONFIG "  shlib_version => '","{- $config{shlib_version} -}","',"
663         WRITE CONFIG "  shlib_major => '","{- $config{shlib_major} -}","',"
664         WRITE CONFIG "  shlib_minor => '","{- $config{shlib_minor} -}","',"
665         WRITE CONFIG "  no_shared => '","{- $disabled{shared} -}","',"
666         WRITE CONFIG "  INSTALLTOP => '$(INSTALLTOP)',"
667         WRITE CONFIG "  OPENSSLDIR => '$(OPENSSLDIR)',"
668         WRITE CONFIG "  pointer_size => '","{- $target{pointer_size} -}","',"
669         WRITE CONFIG ");"
670         WRITE CONFIG "our %target = ();"
671         WRITE CONFIG "our %disabled = ();"
672         WRITE CONFIG "our %withargs = ();"
673         WRITE CONFIG "our %unified_info = ();"
674         WRITE CONFIG "1;"
675         CLOSE CONFIG
676
677 install_html_docs : check_INSTALLTOP build_html_docs
678         @ WRITE SYS$OUTPUT "*** Installing HTML docs"
679         - CREATE/DIR ossl_installroot:[HTML.MAN1]
680         - CREATE/DIR ossl_installroot:[HTML.MAN3]
681         - CREATE/DIR ossl_installroot:[HTML.MAN5]
682         - CREATE/DIR ossl_installroot:[HTML.MAN7]
683         {- join("\n        ",
684                 ( map { "COPY/PROT=W:RE $_ ossl_installroot:[HTML.MAN1]" }
685                   @{$unified_info{htmldocs}->{man1}} ),
686                 ( map { "COPY/PROT=W:RE $_ ossl_installroot:[HTML.MAN3]" }
687                   @{$unified_info{htmldocs}->{man3}} ),
688                 ( map { "COPY/PROT=W:RE $_ ossl_installroot:[HTML.MAN5]" }
689                   @{$unified_info{htmldocs}->{man5}} ),
690                 ( map { "COPY/PROT=W:RE $_ ossl_installroot:[HTML.MAN7]" }
691                   @{$unified_info{htmldocs}->{man7}} )) -}
692
693 check_INSTALLTOP :
694         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
695                 WRITE SYS$ERROR "INSTALLTOP should not be empty"
696         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
697                 EXIT %x10000002
698
699 # Helper targets #####################################################
700
701 # Developer targets ##################################################
702
703 debug_logicals :
704         SH LOGICAL/PROC openssl,internal,ossl_installroot,ossl_dataroot
705
706 # Building targets ###################################################
707
708 configdata.pm : $(SRCDIR)Configure $(SRCDIR)config.com {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
709         perl configdata.pm -r
710         @ WRITE SYS$OUTPUT "*************************************************"
711         @ WRITE SYS$OUTPUT "***                                           ***"
712         @ WRITE SYS$OUTPUT "***   Please run the same mms command again   ***"
713         @ WRITE SYS$OUTPUT "***                                           ***"
714         @ WRITE SYS$OUTPUT "*************************************************"
715         @ PIPE ( EXIT %X10000000 )
716
717 reconfigure reconf :
718         perl configdata.pm -r
719
720 {-
721   use File::Basename;
722   use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/;
723
724   # Helper function to figure out dependencies on libraries
725   # It takes a list of library names and outputs a list of dependencies
726   sub compute_lib_depends {
727       # Depending on shared libraries:
728       # On Windows POSIX layers, we depend on {libname}.dll.a
729       # On Unix platforms, we depend on {shlibname}.so
730       return map {
731           { lib   => platform->sharedlib($_) // platform->staticlib($_),
732             attrs => $unified_info{attributes}->{libraries}->{$_} }
733       } @_;
734   }
735
736   # Helper function to deal with inclusion directory specs.
737   # We have to deal with two things:
738   # 1. comma separation and no possibility of trailing comma
739   # 2. no inclusion directories given at all
740   # 3. long compiler command lines
741   # To resolve 1, we need to iterate through the sources of inclusion
742   # directories, and only add a comma when needed.
743   # To resolve 2, we need to have a variable that will hold the whole
744   # inclusion qualifier, or be the empty string if there are no inclusion
745   # directories.  That's the symbol 'qual_includes' that's used in CPPFLAGS
746   # To resolve 3, we creata a logical name TMP_INCLUDES: to hold the list
747   # of inclusion directories.
748   #
749   # This function returns a list of two lists, one being the collection of
750   # commands to execute before the compiler is called, and the other being
751   # the collection of commands to execute after.  It takes as arguments the
752   # collection of strings to include as directory specs.
753   sub includes {
754       my @stuff = ( @_ );
755       my @before = (
756           'qual_includes :=',
757       );
758       my @after = (
759           'DELETE/SYMBOL/LOCAL qual_includes',
760       );
761
762       if (scalar @stuff > 0) {
763           push @before, 'tmp_includes := '.shift(@stuff);
764           while (@stuff) {
765               push @before, 'tmp_add := '.shift(@stuff);
766               push @before, 'IF tmp_includes .NES. "" .AND. tmp_add .NES. "" THEN tmp_includes = tmp_includes + ","';
767               push @before, 'tmp_includes = tmp_includes + tmp_add';
768           }
769           push @before, "IF tmp_includes .NES. \"\" THEN DEFINE tmp_includes 'tmp_includes'";
770           push @before, 'IF tmp_includes .NES. "" THEN qual_includes := /INCLUDE=(tmp_includes:)';
771           push @before, 'DELETE/SYMBOL/LOCAL tmp_includes';
772           push @before, 'DELETE/SYMBOL/LOCAL tmp_add';
773           push @after, 'DEASSIGN tmp_includes:'
774       }
775       return ([ @before ], [ @after ]);
776   }
777
778   sub generatesrc {
779       my %args = @_;
780       my $generator = join(" ", @{$args{generator}});
781       my $generator_incs = join("", map { ' "-I'.$_.'"' } @{$args{generator_incs}});
782       my $deps = join(", -\n\t\t", @{$args{generator_deps}}, @{$args{deps}});
783
784       if ($args{src} =~ /\.html$/) {
785           my $title = basename($args{src}, ".html");
786           return <<"EOF";
787 $args{src}: $args{generator}->[0]
788         pipe pod2html "--podroot=\$(SRCDIR)/doc" --htmldir=.. -
789                        --podpath=man1:man3:man5:man7 "--infile=\$<" -
790                       "--title=$title" -
791         | \$(PERL) -pe "s|href=""http://man\\.he\\.net/(man\d/[^""]+)(?:\\.html)?""|href=""../\$1.html|g;" -
792         > \$\@
793 EOF
794       } elsif (platform->isdef($args{src})) {
795           my $target = platform->def($args{src});
796           my $mkdef = sourcefile('util', 'mkdef.pl');
797           my $ord_ver = $args{intent} eq 'lib' ? ' --version $(VERSION)' : '';
798           my $ord_name =
799               $args{generator}->[1] || basename($args{product}, '.EXE');
800           my $case_insensitive =
801               $target{$args{intent}.'_cflags'} =~ m|/NAMES=[^/]*AS_IS|i
802               ? '' : ' --case-insensitive';
803           return <<"EOF";
804 $target : $args{generator}->[0] $deps $mkdef
805         \$(PERL) $mkdef$ord_ver --ordinals $args{generator}->[0] --name $ord_name "--OS" "VMS"$case_insensitive > $target
806 EOF
807       } elsif (!platform->isasm($args{src})) {
808           my $target = $args{src};
809           if ($args{generator}->[0] =~ m|^.*\.in$|) {
810               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
811                                                    "util", "dofile.pl")),
812                                    rel2abs($config{builddir}));
813               my @modules = ( 'configdata.pm',
814                               grep { $_ =~ m|\.pm$| } @{$args{deps}} );
815               my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules;
816               @modules = map { '"-M'.basename($_, '.pm').'"' } @modules;
817               my $modules = join(' ', '', sort keys %moduleincs, @modules);
818               return <<"EOF";
819 $target : $args{generator}->[0] $deps
820         \$(PERL)$modules $dofile "-o$target{build_file}" $generator > \$\@
821 EOF
822           } else {
823               return <<"EOF";
824 $target : $args{generator}->[0] $deps
825         \$(PERL)$generator_incs $generator > \$\@
826 EOF
827           }
828       } else {
829           my $cppflags = {
830               shlib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
831               lib => '$(LIB_CFLAGS) $(LIB_CPPFLAGS)',
832               dso => '$(DSO_CFLAGS) $(DSO_CPPFLAGS)',
833               bin => '$(BIN_CFLAGS) $(BIN_CPPFLAGS)'
834           } -> {$args{intent}};
835           my @incs_cmds = includes({ shlib => '$(LIB_INCLUDES)',
836                                      lib => '$(LIB_INCLUDES)',
837                                      dso => '$(DSO_INCLUDES)',
838                                      bin => '$(BIN_INCLUDES)' } -> {$args{intent}},
839                                    '$(CNF_INCLUDES)',
840                                    '$(INCLUDES)',
841                                    @{$args{incs}});
842           my $incs_on = join("\n\t\@ ", @{$incs_cmds[0]}) || '!';
843           my $incs_off = join("\n\t\@ ", @{$incs_cmds[1]}) || '!';
844           my $defs = join("", map { ",".$_ } @{$args{defs}});
845           my $target = platform->asm($args{src});
846
847           if ($args{generator}->[0] =~ /\.pl$/) {
848               $generator = '$(PERL)'.$generator_incs.' '.$generator
849                   .' '.$cppflags;
850           } elsif ($args{generator}->[0] =~ /\.S$/) {
851               $generator = undef;
852           } else {
853               die "Generator type for $src unknown: $generator\n";
854           }
855
856           if (defined($generator)) {
857               # If the target is named foo.S in build.info, we want to
858               # end up generating foo.s in two steps.
859               if ($args{src} =~ /\.S$/) {
860                    return <<"EOF";
861 $target : $args{generator}->[0] $deps
862         $generator \$\@-S
863         \@ $incs_on
864         \@ extradefines = "$defs"
865         PIPE \$(CPP) $cppflags \$\@-S | -
866              \$(PERL) -ne "/^#(\\s*line)?\\s*[0-9]+\\s+""/ or print" > \$\@-i
867         \@ DELETE/SYMBOL/LOCAL extradefines
868         \@ $incs_off
869         RENAME \$\@-i \$\@
870         DELETE \$\@-S;
871 EOF
872               }
873               # Otherwise....
874               return <<"EOF";
875 $target : $args{generator}->[0] $deps
876         \@ $incs_on
877         \@ extradefines = "$defs"
878         $generator \$\@
879         \@ DELETE/SYMBOL/LOCAL extradefines
880         \@ $incs_off
881 EOF
882           }
883           return <<"EOF";
884 $target : $args{generator}->[0] $deps
885         \@ $incs_on
886         \@ extradefines = "$defs"
887         SHOW SYMBOL qual_includes
888         PIPE \$(CPP) $cppflags $args{generator}->[0] | -
889         \$(PERL) "-ne" "/^#(\\s*line)?\\s*[0-9]+\\s+""/ or print" > \$\@
890         \@ DELETE/SYMBOL/LOCAL extradefines
891         \@ $incs_off
892 EOF
893       }
894   }
895
896   sub src2obj {
897       my $asmext = platform->asmext();
898       my %args = @_;
899       my @srcs =
900           map { my $x = $_;
901                 (platform->isasm($x) && grep { $x eq $_ } @generated)
902                 ? platform->asm($x) : $x }
903           ( @{$args{srcs}} );
904       my $obj = platform->obj($args{obj});
905       my $dep = platform->dep($args{obj});
906       my $deps = join(", -\n\t\t", @srcs, @{$args{deps}});
907
908       # Because VMS C isn't very good at combining a /INCLUDE path with
909       # #includes having a relative directory (like '#include "../foo.h"),
910       # the best choice is to move to the first source file's intended
911       # directory before compiling, and make sure to write the object file
912       # in the correct position (important when the object tree is other
913       # than the source tree).
914       my $forward = dirname($args{srcs}->[0]);
915       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
916       my $objd = abs2rel(rel2abs(dirname($obj)), rel2abs($forward));
917       my $objn = basename($obj);
918       my $depd = abs2rel(rel2abs(dirname($dep)), rel2abs($forward));
919       my $depn = basename($dep);
920       my $srcs =
921           join(", ", map { abs2rel(rel2abs($_), rel2abs($forward)) } @srcs);
922       my $before = $unified_info{before}->{$obj} || "\@ !";
923       my $after = $unified_info{after}->{$obj} || "\@ !";
924
925       my $cflags;
926       if ($args{attrs}->{noinst}) {
927           $cflags = { shlib => '$(NO_INST_LIB_CFLAGS)',
928                       lib => '$(NO_INST_LIB_CFLAGS)',
929                       dso => '$(NO_INST_DSO_CFLAGS)',
930                       bin => '$(NO_INST_BIN_CFLAGS)' } -> {$args{intent}};
931       } else {
932           $cflags = { shlib => '$(LIB_CFLAGS)',
933                       lib => '$(LIB_CFLAGS)',
934                       dso => '$(DSO_CFLAGS)',
935                       bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
936       }
937       $cflags .= { shlib => '$(LIB_CPPFLAGS)',
938                    lib => '$(LIB_CPPFLAGS)',
939                    dso => '$(DSO_CPPFLAGS)',
940                    bin => '$(BIN_CPPFLAGS)' } -> {$args{intent}};
941       my $defs = join("", map { ",".$_ } @{$args{defs}});
942       my $asflags = { shlib => ' $(LIB_ASFLAGS)',
943                       lib => ' $(LIB_ASFLAGS)',
944                       dso => ' $(DSO_ASFLAGS)',
945                       bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}};
946
947       my @incs_cmds = includes({ shlib => '$(LIB_INCLUDES)',
948                                  lib => '$(LIB_INCLUDES)',
949                                  dso => '$(DSO_INCLUDES)',
950                                  bin => '$(BIN_INCLUDES)' } -> {$args{intent}},
951                                '$(INCLUDES)',
952                                map {
953                                    file_name_is_absolute($_)
954                                    ? $_ : catdir($backward,$_)
955                                } @{$args{incs}});
956       my $incs_on = join("\n\t\@ ", @{$incs_cmds[0]}) || '!';
957       my $incs_off = join("\n\t\@ ", @{$incs_cmds[1]}) || '!';
958
959       if ($srcs[0] =~ /\Q${asmext}\E$/) {
960           return <<"EOF";
961 $obj : $deps
962         ${before}
963         SET DEFAULT $forward
964         \$(AS) $asflags \$(ASOUTFLAG)${objd}${objn} $srcs
965         SET DEFAULT $backward
966         ${after}
967         - PURGE $obj
968 EOF
969       } elsif ($srcs[0] =~ /.S$/) {
970          return <<"EOF";
971 $obj : $deps
972         ${before}
973         SET DEFAULT $forward
974         \@ $incs_on
975         \@ extradefines = "$defs"
976         PIPE \$(CPP) ${cflags} $srcs | -
977              \$(PERL) -ne "/^#(\\s*line)?\\s*[0-9]+\\s+""/ or print" -
978              > ${objd}${objn}-asm
979         \@ DELETE/SYMBOL/LOCAL extradefines
980         \@ $incs_off
981         SET DEFAULT $backward
982         ${after}
983         \$(AS) $asflags \$(ASOUTFLAG)$obj $obj-asm
984         - PURGE $obj
985 EOF
986       }
987
988       my $depbuild = $disabled{makedepend} ? ""
989           : " /MMS=(FILE=${depd}${depn},TARGET=$obj)";
990
991       return <<"EOF";
992 $obj : $deps
993         ${before}
994         SET DEFAULT $forward
995         \@ $incs_on
996         \@ extradefines = "$defs"
997         \$(CC) ${cflags}${depbuild} /OBJECT=${objd}${objn} /REPOSITORY=$backward $srcs
998         \@ DELETE/SYMBOL/LOCAL extradefines
999         \@ $incs_off
1000         SET DEFAULT $backward
1001         ${after}
1002         - PURGE $obj
1003 EOF
1004   }
1005   sub obj2shlib {
1006       my %args = @_;
1007       my $shlibname = platform->sharedname($args{lib});
1008       my $shlib = platform->sharedlib($args{lib});
1009       my @objs = map { platform->convertext($_) }
1010                  grep { platform->isobj($_) }
1011                  @{$args{objs}};
1012       my @defs = map { platform->convertext($_) }
1013                  grep { platform->isdef($_) }
1014                  @{$args{objs}};
1015       my @deps = compute_lib_depends(@{$args{deps}});
1016       die "More than one symbol vector" if scalar @defs > 1;
1017       my $deps = join(", -\n\t\t", @objs, @defs, map { $_->{lib} } @deps);
1018       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
1019       my $translatesyms_pl = abs2rel(rel2abs(catfile($config{sourcedir},
1020                                                      "VMS", "translatesyms.pl")),
1021                                      rel2abs($config{builddir}));
1022       # The "[]" hack is because in .OPT files, each line inherits the
1023       # previous line's file spec as default, so if no directory spec
1024       # is present in the current line and the previous line has one that
1025       # doesn't apply, you're in for a surprise.
1026       my $write_opt1 =
1027           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
1028                                  "WRITE OPT_FILE \"$x" } @objs).
1029           "\"";
1030       my $write_opt2 =
1031           join("\n\t", map { my $x = $_->{lib} =~ /\[/
1032                                  ? $_->{lib} : "[]".$_->{lib};
1033                              $x =~ s|(\.EXE)|$1/SHARE|;
1034                              $x =~ s|(\.OLB)|$1/LIB|;
1035                              "WRITE OPT_FILE \"$x\"" } @deps)
1036           || "\@ !";
1037       return <<"EOF"
1038 $shlib : $deps
1039         \$(PERL) $translatesyms_pl \$(BLDDIR)CXX\$DEMANGLER_DB. < $defs[0] > $defs[0]-translated
1040         OPEN/WRITE/SHARE=READ OPT_FILE $shlibname-components.OPT
1041         $write_opt1
1042         $write_opt2
1043         CLOSE OPT_FILE
1044         LINK \$(LIB_LDFLAGS)/SHARE=\$\@ $defs[0]-translated/OPT,-
1045                 $shlibname-components.OPT/OPT \$(LIB_EX_LIBS)
1046         DELETE $defs[0]-translated;*,$shlibname-components.OPT;*
1047         PURGE $shlibname.EXE,$shlibname.MAP
1048 EOF
1049         . ($config{target} =~ m|alpha| ? "" : <<"EOF"
1050         SET IMAGE/FLAGS=(NOCALL_DEBUG) \$\@
1051 EOF
1052         );
1053   }
1054   sub obj2dso {
1055       my %args = @_;
1056       my $dsoname = platform->dsoname($args{module});
1057       my $dso = platform->dso($args{module});
1058       my @objs = map { platform->convertext($_) }
1059                  grep { platform->isobj($_) }
1060                  @{$args{objs}};
1061       my @defs = map { platform->convertext($_) }
1062                  grep { platform->isdef($_) }
1063                  @{$args{objs}};
1064       my @deps = compute_lib_depends(@{$args{deps}});
1065       my $deps = join(", -\n\t\t", @objs, @defs, map { $_->{lib} } @deps);
1066       die "More than one symbol vector" if scalar @defs > 1;
1067       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
1068       # The "[]" hack is because in .OPT files, each line inherits the
1069       # previous line's file spec as default, so if no directory spec
1070       # is present in the current line and the previous line has one that
1071       # doesn't apply, you're in for a surprise.
1072       my $write_opt1 =
1073           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
1074                                  "WRITE OPT_FILE \"$x" } @objs).
1075           "\"";
1076       my $write_opt2 =
1077           join("\n\t", map { my $x = $_->{lib} =~ /\[/
1078                                  ? $_->{lib} : "[]".$_->{lib};
1079                              $x =~ s|(\.EXE)|$1/SHARE|;
1080                              $x =~ s|(\.OLB)|$1/LIB|;
1081                              "WRITE OPT_FILE \"$x\"" } @deps)
1082           || "\@ !";
1083       return <<"EOF"
1084 $dso : $deps
1085         OPEN/WRITE/SHARE=READ OPT_FILE $dsoname-components.OPT
1086         $write_opt1
1087         $write_opt2
1088         CLOSE OPT_FILE
1089         LINK \$(DSO_LDFLAGS)/SHARE=\$\@ $defs[0]/OPT,-
1090                 $dsoname-components.OPT/OPT \$(DSO_EX_LIBS)
1091         - PURGE $dsoname.EXE,$dsoname.OPT,$dsoname.MAP
1092 EOF
1093         . ($config{target} =~ m|alpha| ? "" : <<"EOF"
1094         SET IMAGE/FLAGS=(NOCALL_DEBUG) \$\@
1095 EOF
1096         );
1097   }
1098   sub obj2lib {
1099       my %args = @_;
1100       my $lib = platform->staticlib($args{lib});
1101       my @objs = map { platform->convertext($_) }
1102                  grep { platform->isobj($_) }
1103                  @{$args{objs}};
1104       my $objs = join(", -\n\t\t", @objs);
1105       my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib $_" } @objs));
1106       return <<"EOF";
1107 $lib : $objs
1108         LIBRARY/CREATE/OBJECT $lib
1109         $fill_lib
1110         - PURGE $lib
1111 EOF
1112   }
1113   sub obj2bin {
1114       my %args = @_;
1115       my $bin = platform->bin($args{bin});
1116       my $binname = platform->binname($args{bin});
1117       my @objs = map { platform->convertext($_) }
1118                  grep { platform->isobj($_) }
1119                  @{$args{objs}};
1120       my $objs = join(",", @objs);
1121       my @deps = compute_lib_depends(@{$args{deps}});
1122       my $deps = join(", -\n\t\t", @objs, map { $_->{lib} } @deps);
1123
1124       my $olb_count = scalar grep(m|\.OLB$|, map { $_->{lib} } @deps);
1125       my $analyse_objs = "@ !";
1126       if ($olb_count > 0) {
1127           my $analyse_quals =
1128               $config{target} =~ m|alpha| ? "/GSD" : "/SECTIONS=SYMTAB";
1129           $analyse_objs = "- pipe ANALYSE/OBJECT$analyse_quals $objs | SEARCH SYS\$INPUT \"\"\"main\"\"\" ; nomain = \$severity .NE. 1"
1130       }
1131       # The "[]" hack is because in .OPT files, each line inherits the
1132       # previous line's file spec as default, so if no directory spec
1133       # is present in the current line and the previous line has one that
1134       # doesn't apply, you're in for a surprise.
1135       my $write_opt1 =
1136           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
1137                                  "\@ WRITE OPT_FILE \"$x" } @objs).
1138           "\"";
1139       my $write_opt2 =
1140           join("\n\t", "WRITE OPT_FILE \"CASE_SENSITIVE=YES\"",
1141                        map { my @lines = ();
1142                              use Data::Dumper;
1143                              my $x = $_->{lib} =~ /\[/
1144                                  ? $_->{lib} : "[]".$_->{lib};
1145                              if ($x =~ m|\.EXE$|) {
1146                                  push @lines, "\@ WRITE OPT_FILE \"$x/SHARE\"";
1147                              } elsif ($x =~ m|\.OLB$|) {
1148                                  # Special hack to include the MAIN object
1149                                  # module explicitly.  This will only be done
1150                                  # if there isn't a 'main' in the program's
1151                                  # object modules already.
1152                                  my $main = $_->{attrs}->{has_main}
1153                                      ? '/INCLUDE=main' : '';
1154                                  push @lines,
1155                                      "\@ IF nomain THEN WRITE OPT_FILE \"$x/LIB$main\"",
1156                                      "\@ IF .NOT. nomain THEN WRITE OPT_FILE \"$x/LIB\""
1157                              }
1158                              @lines
1159                            } @deps)
1160           || "\@ !";
1161       # The linking commands looks a bit complex, but it's for good reason.
1162       # When you link, say, foo.obj, bar.obj and libsomething.exe/share, and
1163       # bar.obj happens to have a symbol that also exists in libsomething.exe,
1164       # the linker will warn about it, loudly, and will then choose to pick
1165       # the first copy encountered (the one in bar.obj in this example).
1166       # On Unix and on Windows, the corresponding maneuvre goes through
1167       # silently with the same effect.
1168       # With some test programs, made for checking the internals of OpenSSL,
1169       # we do this kind of linking deliberately, picking a few specific object
1170       # files from within [.crypto] or [.ssl] so we can reach symbols that are
1171       # otherwise unreachable (since the shareable images only exports the
1172       # symbols listed in [.util]*.num), and then with the shared libraries
1173       # themselves.  So we need to silence the warning about multiply defined
1174       # symbols, to mimic the way linking work on Unix and Windows, and so
1175       # the build isn't interrupted (MMS stops when warnings are signaled,
1176       # by default), and so someone building doesn't have to worry where it
1177       # isn't necessary.  If there are other warnings, however, we show them
1178       # and let it break the build.
1179       return <<"EOF"
1180 $bin : $deps
1181         $analyse_objs
1182         @ OPEN/WRITE/SHARE=READ OPT_FILE $binname.OPT
1183         $write_opt1
1184         $write_opt2
1185         @ CLOSE OPT_FILE
1186         TYPE $binname.OPT ! For debugging
1187         - pipe SPAWN/WAIT/NOLOG/OUT=$binname.LINKLOG -
1188                     LINK \$(BIN_LDFLAGS)/EXEC=\$\@ $binname.OPT/OPT \$(BIN_EX_LIBS) ; -
1189                link_status = \$status ; link_severity = link_status .AND. 7
1190         @ search_severity = 1
1191         -@ IF link_severity .EQ. 0 THEN -
1192                 pipe SEARCH $binname.LINKLOG "%","-"/MATCH=AND | -
1193                      SPAWN/WAIT/NOLOG/OUT=NLA0: -
1194                           SEARCH SYS\$INPUT: "-W-MULDEF,"/MATCH=NOR ; -
1195                      search_severity = \$severity
1196         @ ! search_severity is 3 when the last search didn't find any matching
1197         @ ! string: %SEARCH-I-NOMATCHES, no strings matched
1198         @ ! If that was the result, we pretend linking got through without
1199         @ ! fault or warning.
1200         @ IF search_severity .EQ. 3 THEN link_severity = 1
1201         @ ! At this point, if link_severity shows that there was a fault
1202         @ ! or warning, make sure to restore the linking status.
1203         -@ IF .NOT. link_severity THEN TYPE $binname.LINKLOG
1204         -@ DELETE $binname.LINKLOG;*
1205         @ IF .NOT. link_severity THEN SPAWN/WAIT/NOLOG EXIT 'link_status'
1206         - PURGE $bin,$binname.OPT
1207 EOF
1208       . ($config{target} =~ m|alpha| ? "" : <<"EOF"
1209         SET IMAGE/FLAGS=(NOCALL_DEBUG) \$\@
1210 EOF
1211         );
1212   }
1213   sub in2script {
1214       my %args = @_;
1215       my $script = $args{script};
1216       return "" if grep { $_ eq $script } @{$args{sources}}; # No overwrite!
1217       my $sources = join(" ", @{$args{sources}});
1218       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
1219                                            "util", "dofile.pl")),
1220                            rel2abs($config{builddir}));
1221       return <<"EOF";
1222 $script : $sources
1223         \$(PERL) "-I\$(BLDDIR)" "-Mconfigdata" $dofile -
1224             "-o$target{build_file}" $sources > $script
1225         SET FILE/PROT=(S:RWED,O:RWED,G:RE,W:RE) $script
1226         PURGE $script
1227 EOF
1228   }
1229   ""    # Important!  This becomes part of the template result.
1230 -}