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