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