4732782072529d0d3ed1a35afd57707f08b6dc1c
[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
7   # Our prefix, claimed when speaking with the VSI folks Tuesday
8   # January 26th 2016
9   our $osslprefix = 'OSSL$';
10   (our $osslprefix_q = $osslprefix) =~ s/\$/\\\$/;
11
12   our $sourcedir = $config{sourcedir};
13   our $builddir = $config{builddir};
14   sub sourcefile {
15       catfile($sourcedir, @_);
16   }
17   sub buildfile {
18       catfile($builddir, @_);
19   }
20   sub sourcedir {
21       catdir($sourcedir, @_);
22   }
23   sub builddir {
24       catdir($builddir, @_);
25   }
26   sub tree {
27       (my $x = shift) =~ s|\]$|...]|;
28       $x
29   }
30   sub move {
31       my $f = catdir(@_);
32       my $b = abs2rel(rel2abs("."),rel2abs($f));
33       $sourcedir = catdir($b,$sourcedir)
34           if !file_name_is_absolute($sourcedir);
35       $builddir = catdir($b,$builddir)
36           if !file_name_is_absolute($builddir);
37       "";
38   }
39
40   # This is a horrible hack, but is needed because recursive inclusion of files
41   # in different directories does not work well with HP C.
42   my $sd = sourcedir("crypto", "async", "arch");
43   foreach (grep /\[\.crypto\.async\.arch\].*\.o$/, keys %{$unified_info{sources}}) {
44       (my $x = $_) =~ s|\.o$|.OBJ|;
45       $unified_info{before}->{$x}
46           = qq(arch = F\$PARSE("$sd","A.;",,,"SYNTAX_ONLY") - "A.;"
47         define arch 'arch');
48       $unified_info{after}->{$x}
49           = qq(deassign arch);
50   }
51   my $sd1 = sourcedir("ssl","record");
52   my $sd2 = sourcedir("ssl","statem");
53   $unified_info{before}->{"[.crypto.ct]ct_lib.OBJ"}
54       = $unified_info{before}->{"[.test]heartbeat_test.OBJ"}
55       = $unified_info{before}->{"[.test]ssltest.OBJ"}
56       = qq(record = F\$PARSE("$sd1","A.;",,,"SYNTAX_ONLY") - "A.;"
57         define record 'record'
58         statem = F\$PARSE("$sd2","A.;",,,"SYNTAX_ONLY") - "A.;"
59         define statem 'statem');
60   $unified_info{after}->{"[.crypto.ct]ct_lib.OBJ"}
61       = $unified_info{after}->{"[.test]heartbeat_test.OBJ"}
62       = $unified_info{after}->{"[.test]ssltest.OBJ"}
63       = qq(deassign statem
64         deassign record);
65   foreach (grep /^\[\.ssl\.(?:record|statem)\].*\.o$/, keys %{$unified_info{sources}}) {
66       (my $x = $_) =~ s|\.o$|.OBJ|;
67       $unified_info{before}->{$x}
68           = qq(record = F\$PARSE("$sd1","A.;",,,"SYNTAX_ONLY") - "A.;"
69         define record 'record'
70         statem = F\$PARSE("$sd2","A.;",,,"SYNTAX_ONLY") - "A.;"
71         define statem 'statem');
72       $unified_info{after}->{$x}
73           = qq(deassign statem
74         deassign record);
75   }
76   #use Data::Dumper;
77   #print STDERR "DEBUG: before:\n", Dumper($unified_info{before});
78   #print STDERR "DEBUG: after:\n", Dumper($unified_info{after});
79   "";
80 -}
81 PLATFORM={- $config{target} -}
82 OPTIONS={- $config{options} -}
83 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
84 SRCDIR={- $config{sourcedir} -}
85 BUILDDIR={- $config{builddir} -}
86
87 VERSION={- $config{version} -}
88 MAJOR={- $config{major} -}
89 MINOR={- $config{minor} -}
90 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
91 SHLIB_VERSION_HISTORY={- $config{shlib_version_history} -}
92 SHLIB_MAJOR={- $config{shlib_major} -}
93 SHLIB_MINOR={- $config{shlib_minor} -}
94 SHLIB_TARGET={- $target{shared_target} -}
95
96 EXE_EXT=.EXE
97 LIB_EXT=.OLB
98 SHLIB_EXT=.EXE
99 OBJ_EXT=.OBJ
100 DEP_EXT=.MMS
101
102 LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @{$unified_info{libraries}}) -}
103 SHLIBS={- join(" ", map { $_."\$(SHLIB_EXT)" } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) -}
104 ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{engines}}) -}
105 PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } grep { !m|^\[\.test\]| } @{$unified_info{programs}}) -}
106 TESTPROGS={- join(", ", map { "-\n\t".$_.".EXE" } grep { m|^\[\.test\]| } @{$unified_info{programs}}) -}
107 SCRIPTS={- join(", ", map { "-\n\t".$_ } @{$unified_info{scripts}}) -}
108
109 # DESTDIR is for package builders so that they can configure for, say,
110 # SYS$COMMON:[OPENSSL] and yet have everything installed in STAGING:[USER].
111 # In that case, configure with --prefix=SYS$COMMON:[OPENSSL] and then run
112 # MMS with /MACROS=(DESTDIR=STAGING:[USER]).  The result will end up in
113 # STAGING:[USER.OPENSSL].
114 # Normally it is left empty.
115 DESTDIR=
116
117 # Do not edit this manually. Use Configure --prefix=DIR to change this!
118 INSTALLTOP={- catdir($config{prefix}) || "SYS\$COMMON:[OPENSSL-\$(MAJOR).\$(MINOR)]" -}
119 # This is the standard central area to store certificates, private keys...
120 OPENSSLDIR={- catdir($config{openssldir}) ||
121               $config{prefix} ? catdir($config{prefix},"SSL")
122                               : "SYS\$COMMON:[SSL]" -}
123 # Where installed engines reside
124 ENGINESDIR={- $osslprefix -}ENGINES:
125
126 CC= {- $target{cc} -}
127 CFLAGS= /DEFINE=({- join(",", @{$config{defines}},"OPENSSLDIR=\"\"\"\$(OPENSSLDIR)\"\"\"","ENGINESDIR=\"\"\"\$(ENGINESDIR)\"\"\"") -}) {- $config{cflags} -}
128 DEPFLAG= /DEFINE=({- join(",", @{$config{depdefines}}) -})
129 LDFLAGS= {- $config{lflags} -}
130 EX_LIBS= {- $config{ex_libs} ? ",".$config{ex_libs} : "" -}
131
132 PERL={- $config{perl} -}
133
134 # We let the C compiler driver to take care of .s files. This is done in
135 # order to be excused from maintaining a separate set of architecture
136 # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
137 # gcc, then the driver will automatically translate it to -xarch=v8plus
138 # and pass it down to assembler.
139 AS={- $target{as} -}
140 ASFLAG={- $target{asflags} -}
141
142 # .FIRST and .LAST are special targets with MMS and MMK.
143 # The defines in there are for C.  includes that look like
144 # this:
145 #
146 #    #include <openssl/foo.h>
147 #    #include "internal/bar.h"
148 #
149 # will use the logical names to find the files.  Expecting
150 # DECompHP C to find files in subdirectories of whatever was
151 # given with /INCLUDE is a fantasy, unfortunately.
152 NODEBUG=@
153 .FIRST :
154         $(NODEBUG) openssl_inc1 = F$PARSE("[.include.openssl]","A.;",,,"syntax_only") - "A.;"
155         $(NODEBUG) openssl_inc2 = F$PARSE("{- catdir($config{sourcedir},"[.include.openssl]") -}","a.;",,,"SYNTAX_ONLY") - "A.;"
156         $(NODEBUG) internal_inc1 = F$PARSE("[.crypto.include.internal]","A.;",,,"SYNTAX_ONLY") - "A.;"
157         $(NODEBUG) internal_inc2 = F$PARSE("{- catdir($config{sourcedir},"[.include.internal]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
158         $(NODEBUG) internal_inc3 = F$PARSE("{- catdir($config{sourcedir},"[.crypto.include.internal]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
159         $(NODEBUG) DEFINE openssl 'openssl_inc1','openssl_inc2'
160         $(NODEBUG) DEFINE internal 'internal_inc1','internal_inc2','internal_inc3'
161         $(NODEBUG) staging_dir = "$(DESTDIR)"
162         $(NODEBUG) IF staging_dir .NES. "" THEN -
163                 staging_dir = F$PARSE("A.;",staging_dir,"[]",,"SYNTAX_ONLY") - "A.;"
164         $(NODEBUG) !
165         $(NODEBUG) ! Installation logical names
166         $(NODEBUG) !
167         $(NODEBUG) installtop_dev = F$PARSE(staging_dir,"$(INSTALLTOP)",,"DEVICE","SYNTAX_ONLY")
168         $(NODEBUG) ! Because there are no routines to merge directories, we have to
169         $(NODEBUG) ! do it ourselves
170         $(NODEBUG) IF staging_dir .NES. "" THEN -
171                 staging_dir = F$PARSE(staging_dir,"[000000]",,"DIRECTORY","SYNTAX_ONLY")
172         $(NODEBUG) installtop_dir = F$PARSE("$(INSTALLTOP)","[000000]",,"DIRECTORY","SYNTAX_ONLY")
173         $(NODEBUG) IF staging_dir .NES. "" .AND. staging_dir .NES. "[000000]" THEN -
174                 installtop_dir = staging_dir - "]" + "." + (installtop_dir - "[")
175         $(NODEBUG) installtop_dir = installtop_dir - "]" + ".]"
176         $(NODEBUG) DEFINE ossl_installroot 'installtop_dev''installtop_dir'
177         $(NODEBUG) !
178         $(NODEBUG) datatop = F$PARSE("$(OPENSSLDIR)","[000000]A.;",,,"SYNTAX_ONLY") -
179                 - "]A.;" + ".]"
180         $(NODEBUG) IF "$(DESTDIR)" .EQS. "" THEN -
181                 DEFINE ossl_dataroot 'datatop'
182         $(NODEBUG) !
183         $(NODEBUG) ! Figure out the architecture
184         $(NODEBUG) !
185         $(NODEBUG) arch == f$edit( f$getsyi( "arch_name"), "upcase")
186         $(NODEBUG) !
187         $(NODEBUG) ! Set up logical names for the libraries, so LINK and
188         $(NODEBUG) ! running programs can use them.
189         $(NODEBUG) !
190         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEFINE ".uc($_)." 'F\$ENV(\"DEFAULT\")'".uc($_)."\$(SHLIB_EXT)" } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) || "!" -}
191
192 .LAST :
193         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEASSIGN ".uc($_) } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) || "!" -}
194         $(NODEBUG) IF "$(DESTDIR)" .EQS. "" THEN DEASSIGN ossl_dataroot
195         $(NODEBUG) DEASSIGN ossl_installroot
196         $(NODEBUG) DEASSIGN internal
197         $(NODEBUG) DEASSIGN openssl
198 .DEFAULT :
199         @ ! MMS cannot handle no actions...
200
201 # The main targets ###################################################
202
203 all : descrip.mms, $(LIBS), $(ENGINES), $(PROGRAMS), $(SCRIPTS), $(TESTPROGS)
204
205 test tests : $(TESTPROGS), rehash
206         SET DEFAULT [.test]{- move("test") -}
207         DEFINE SRCTOP {- sourcedir() -}
208         DEFINE BLDTOP {- builddir() -}
209         $(PERL) {- sourcefile("test", "run_tests.pl") -} $(TESTS)
210         DEASSIGN BLDTOP
211         DEASSIGN SRCTOP
212         SET DEFAULT [-]{- move("..") -}
213
214 list-tests :
215         @ TOP=$(SRCDIR) PERL=$(PERL) $(PERL) {- catfile($config{sourcedir},"test", "run_tests.pl") -} list
216
217 # Because VMS wants the generation number (or *) to delete files, we can't
218 # use $(LIBS), $(PROGRAMS) and $(TESTPROGS) directly.
219 libclean :
220         - DELETE []OSSL$LIB*.OLB;*,OSSL$LIB*.LIS;*
221         - DELETE [.crypto...]*.OBJ;*,*.LIS;*
222         - DELETE [.ssl...]*.OBJ;*,*.LIS;*
223         - DELETE [.engines...]*.OBJ;*,*.LIS;*
224         - DELETE []CXX$DEMANGLER_DB.;*
225
226 install : install_sw install_docs
227
228 uninstall : uninstall_docs uninstall_sw
229
230 clean : libclean
231         - DELETE []OSSL$LIB*.EXE;*,OSSL$LIB*.MAP;*,OSSL$LIB*.OPT;*
232         - DELETE [.engines...]LIB*.EXE;*,LIB*.MAP;*,LIB*.OPT;*
233         - DELETE [.apps]*.EXE;*,*.MAP;*,*.OPT;*
234         - DELETE [.apps]*.OBJ;*,*.LIS;*
235         - DELETE [.test]*.EXE;*,*.MAP;*,*.OPT;*
236         - DELETE [.test]*.OBJ;*,*.LIS;*
237         - DELETE [.test]*.LOG;*
238         - DELETE []*.MAP;*
239
240 DCLEAN_CMD=$(PERL) -pe "if (/^# DO NOT DELETE.*/) { exit(0); }"
241 dclean :
242         $(DCLEAN_CMD) < descrip.mms > descrip.mms.new
243         RENAME descrip.mms.new descrip.mms
244         PURGE descrip.mms
245
246 {- our @deps = map { (my $x = $_) =~ s|\.o$|\$(DEP_EXT)|; $x; }
247                grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
248                keys %{$unified_info{sources}};
249    ""; -}
250 depend : {- join(",-\n\t", @deps); -}
251         $(DCLEAN_CMD) < descrip.mms > descrip.mms.new
252         OPEN/APPEND DESCRIP descrip.mms.new
253         WRITE DESCRIP "# DO NOT DELETE THIS LINE -- make depend depends on it."
254         {- join("\n\t", map { "TYPE $_ /OUTPUT=DESCRIP:" } @deps); -}
255         CLOSE DESCRIP
256         RENAME descrip.mms.new descrip.mms
257         PURGE descrip.mms
258
259 # Install helper targets #############################################
260
261 install_sw : all install_dev install_engines install_runtime install_config
262         @ WRITE SYS$OUTPUT ""
263         @ WRITE SYS$OUTPUT "######################################################################"
264         @ WRITE SYS$OUTPUT ""
265         @ WRITE SYS$OUTPUT "Installation complete"
266         @ WRITE SYS$OUTPUT ""
267         @ IF "$(DESTDIR)" .NES. "" THEN EXIT 1
268         @ WRITE SYS$OUTPUT "Run @$(INSTALLTOP)openssl_startup to set up logical names"
269         @ WRITE SYS$OUTPUT "then run @$(INSTALLTOP)openssl_setup to define commands"
270         @ WRITE SYS$OUTPUT ""
271
272 uninstall_sw : uninstall_dev uninstall_engines uninstall_runtime uninstall_config
273
274 install_docs : install_man_docs install_html_docs
275
276 uninstall_docs : uninstall_man_docs uninstall_html_docs
277
278 install_dev : check_INSTALLTOP
279         @ WRITE SYS$OUTPUT "*** Installing development files"
280         @ ! Install header files
281         CREATE/DIR ossl_installroot:[include.openssl]
282         COPY/PROT=W:R openssl:*.h ossl_installroot:[include.openssl]
283         @ ! Install libraries
284         CREATE/DIR ossl_installroot:['arch'.LIB]
285         {- join("\n        ",
286                 map { "COPY/PROT=W:R $_.OLB ossl_installroot:['arch'.LIB]" }
287                 @{$unified_info{libraries}}) -}
288         @ {- output_off() if $config{no_shared}; "" -} !
289         {- join("\n        ",
290                 map { "COPY/PROT=W:RE $_.EXE ossl_installroot:['arch'.LIB]" }
291                 map { $unified_info{sharednames}->{$_} || () } 
292                 @{$unified_info{libraries}}) -}
293         @ {- output_on() -} !
294
295 install_runtime : check_INSTALLTOP
296         @ WRITE SYS$OUTPUT "*** Installing runtime files"
297         @ ! Install the main program
298         CREATE/DIR ossl_installroot:['arch'.EXE]
299         COPY/PROT=W:RE [.APPS]openssl.EXE ossl_installroot:['arch'.EXE]
300         @ ! Install scripts
301         CREATE/DIR ossl_installroot:[EXE]
302         COPY/PROT=W:RE [.APPS]CA.pl ossl_installroot:[EXE]
303         COPY/PROT=W:RE [.TOOLS]c_rehash. ossl_installroot:[EXE]c_rehash.pl
304         @ ! Install configuration file
305         COPY/PROT=W:RE {- sourcefile("apps", "openssl-vms.cnf") -} -
306                 ossl_installroot:[000000]openssl.cnf
307
308 install_engines : check_INSTALLTOP
309         @ {- output_off() if $config{no_shared}; "" -} !
310         @ WRITE SYS$OUTPUT "*** Installing engines"
311         CREATE/DIR ossl_installroot:['arch'.ENGINES]
312         COPY/PROT=W:RE [.ENGINES]*.EXE ossl_installroot:['arch'.ENGINES]
313         @ {- output_on() -} !
314
315 install_config : [.VMS]openssl_startup.com [.VMS]openssl_shutdown.com -
316                  check_INSTALLTOP
317         IF "$(DESTDIR)" .EQS. "" THEN -
318                 IF F$SEARCH("OSSL_DATAROOT:[000000]CERTS.DIR;1") .EQS. "" THEN -
319                 CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[CERTS]
320         IF "$(DESTDIR)" .EQS. "" THEN -
321                 IF F$SEARCH("OSSL_DATAROOT:[000000]PRIVATE.DIR;1") .EQS. "" THEN -
322                 CREATE/DIR/PROT=(S:RWED,O:RWE,G:,W:) OSSL_DATAROOT:[PRIVATE]
323         CREATE/DIR ossl_installroot:[SYS$STARTUP]
324         COPY/PROT=W:RE -
325                 [.VMS]openssl_startup.com,openssl_shutdown.com -
326                 ossl_installroot:[SYS$STARTUP]
327         COPY/PROT=W:RE -
328                 {- sourcefile("VMS", "openssl_utils.com") -} -
329                 ossl_installroot:[SYS$STARTUP]
330
331 [.VMS]openssl_startup.com : vmsconfig.pm
332         CREATE/DIR [.VMS]
333         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
334                 {- sourcefile("VMS", "openssl_startup.com.in") -} -
335                 > [.VMS]openssl_startup.com
336
337 [.VMS]openssl_shutdown.com : vmsconfig.pm
338         CREATE/DIR [.VMS]
339         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
340                 {- sourcefile("VMS", "openssl_shutdown.com.in") -} -
341                 > [.VMS]openssl_shutdown.com
342
343 vmsconfig.pm : descrip.mms
344         OPEN/WRITE/SHARE=READ CONFIG []vmsconfig.pm
345         WRITE CONFIG "package vmsconfig;"
346         WRITE CONFIG "use strict; use warnings;"
347         WRITE CONFIG "use Exporter;"
348         WRITE CONFIG "our @ISA = qw(Exporter);"
349         WRITE CONFIG "our @EXPORT = qw(%config %target %withargs %unified_info);"
350         WRITE CONFIG "our %config = ("
351         WRITE CONFIG "  target => '{- $config{target} -}',"
352         WRITE CONFIG "  version => '$(MAJOR).$(MINOR)',"
353         WRITE CONFIG "  no_shared => '","{- $config{no_shared} -}","',"
354         WRITE CONFIG "  INSTALLTOP => '$(INSTALLTOP)',"
355         WRITE CONFIG "  OPENSSLDIR => '$(OPENSSLDIR)',"
356         WRITE CONFIG "  pointersize => '","{- $target{pointersize} -}","',"
357         WRITE CONFIG "  shared_libs => ["
358         {- join("\n        ", map { "WRITE CONFIG \"    '$_'," } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) || "\@ !" -}
359         WRITE CONFIG "  ],"
360         WRITE CONFIG ");"
361         WRITE CONFIG "our %target = ();"
362         WRITE CONFIG "our %withargs = ();"
363         WRITE CONFIG "our %unified_info = ();"
364         WRITE CONFIG "1;"
365         CLOSE CONFIG
366
367 check_INSTALLTOP :
368         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
369                 WRITE SYS$ERROR "INSTALLTOP should not be empty"
370         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
371                 EXIT %x10000002
372
373 # Helper targets #####################################################
374
375 rehash : [.apps]openssl.exe, copy-certs
376         !MCR [.apps]openssl.exe rehash {- builddir("certs", "demo") -}
377         $(PERL) [.tools]c_rehash. [.certs.demo]
378
379 copy-certs :
380         @ IF F$SEARCH("{- buildfile("certs.dir") -}") .EQS. "" THEN -
381              CREATE/DIR {- builddir("certs") -}
382         -@ IF "{- sourcedir("certs") -}" .NES. "{- builddir("certs") -}" THEN -
383              COPY {- tree(sourcedir("certs")) -}*.* {- tree(builddir("certs")) -}
384
385 # Developer targets ##################################################
386
387 debug_logicals :
388         SH LOGICAL/PROC openssl,internal,ossl_installroot
389         IF "$(DESTDIR)" .EQS. "" THEN -
390                 SH LOGICAL/PROC ossl_dataroot
391
392 # Building targets ###################################################
393
394 descrip.mms : {- sourcefile("Configurations", "descrip.mms.tmpl") -} $(SRCDIR)Configure ! $(SRCDIR)config.com
395         @ WRITE SYS$OUTPUT "descrip.mms is older than $?."
396         @ WRITE SYS$OUTPUT "Reconfiguring..."
397         perl $(SRCDIR)Configure reconf
398         @ WRITE SYS$OUTPUT "*************************************************"
399         @ WRITE SYS$OUTPUT "***                                           ***"
400         @ WRITE SYS$OUTPUT "***   Please run the same mms command again   ***"
401         @ WRITE SYS$OUTPUT "***                                           ***"
402         @ WRITE SYS$OUTPUT "*************************************************"
403         @ exit %10000000
404
405 {-
406   use File::Basename;
407   use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/;
408   sub src2dep {
409       my %args = @_;
410       my $dep = $args{obj};
411
412       # Because VMS C isn't very good at combining a /INCLUDE path with
413       # #includes having a relative directory (like '#include "../foo.h"),
414       # the best choice is to move to the first source file's intended
415       # directory before compiling, and make sure to write the object file
416       # in the correct position (important when the object tree is other
417       # than the source tree).
418       my $forward = dirname($args{srcs}->[0]);
419       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
420       my $depd = abs2rel(rel2abs(dirname($dep)), rel2abs($forward));
421       my $depn = basename($dep);
422       my $srcs =
423           join(", ",
424                map { abs2rel(rel2abs($_), rel2abs($forward)) } @{$args{srcs}});
425       my $incs =
426           "/INCLUDE=(".join(",",
427                             map {
428                                file_name_is_absolute($_)
429                                ? $_ : catdir($backward,$_)
430                             } @{$args{incs}}).")";
431       my $before = $unified_info{before}->{$dep.".OBJ"} || "\@ !";
432       my $after = $unified_info{after}->{$dep.".OBJ"} || "\@ !";
433
434       return <<"EOF";
435 $dep.MMS : $srcs
436         ${before}
437         SET DEFAULT $forward
438         \$(CC) \$(CFLAGS)${incs} /MMS=(TARGET=.OBJ)/OBJECT=${depd}${depn}.MMS $srcs
439         SET DEFAULT $backward
440         ${after}
441         - PURGE $dep.MMS
442 EOF
443   }
444   sub src2obj {
445       my %args = @_;
446       my $obj = $args{obj};
447       my $deps = join(", -\n\t\t", @{$args{srcs}}, @{$args{deps}});
448
449       # Because VMS C isn't very good at combining a /INCLUDE path with
450       # #includes having a relative directory (like '#include "../foo.h"),
451       # the best choice is to move to the first source file's intended
452       # directory before compiling, and make sure to write the object file
453       # in the correct position (important when the object tree is other
454       # than the source tree).
455       my $forward = dirname($args{srcs}->[0]);
456       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
457       my $objd = abs2rel(rel2abs(dirname($obj)), rel2abs($forward));
458       my $objn = basename($obj);
459       my $srcs =
460           join(", ",
461                map { abs2rel(rel2abs($_), rel2abs($forward)) } @{$args{srcs}});
462       my $incs =
463           "/INCLUDE=(".join(",",
464                             map {
465                                file_name_is_absolute($_)
466                                ? $_ : catdir($backward,$_)
467                             } @{$args{incs}}).")";
468       my $before = $unified_info{before}->{$obj.".OBJ"} || "\@ !";
469       my $after = $unified_info{after}->{$obj.".OBJ"} || "\@ !";
470
471       return <<"EOF";
472 $obj.OBJ : $deps
473         ${before}
474         SET DEFAULT $forward
475         \$(CC) \$(CFLAGS)${incs} /OBJECT=${objd}${objn}.OBJ /REPOSITORY=$backward $srcs
476         SET DEFAULT $backward
477         ${after}
478         - PURGE $obj.OBJ
479 EOF
480   }
481   sub libobj2shlib {
482       my %args = @_;
483       my $lib = $args{lib};
484       my $shlib = $args{shlib};
485       my $libd = dirname($lib);
486       my $libn = basename($lib);
487       (my $mkdef_key = $libn) =~ s/^${osslprefix_q}lib//i;
488       my @deps = map {
489           $config{no_shared} ? $_.".OLB"
490               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
491       my $deps = join(", -\n\t\t", @deps);
492       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
493       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
494       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
495                                                "VMS", "engine.opt")),
496                                rel2abs($config{builddir}));
497       my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
498                                              "util", "mkdef.pl")),
499                              rel2abs($config{builddir}));
500       my $translatesyms_pl = abs2rel(rel2abs(catfile($config{sourcedir},
501                                                      "VMS", "translatesyms.pl")),
502                                      rel2abs($config{builddir}));
503       # The "[]" hack is because in .OPT files, each line inherits the
504       # previous line's file spec as default, so if no directory spec
505       # is present in the current line and the previous line has one that
506       # doesn't apply, you're in for a surprise.
507       my $write_opt =
508           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
509                              $x =~ s|(\.EXE)|$1/SHARE|;
510                              $x =~ s|(\.LIB)|$1/LIB|;
511                              "WRITE OPT_FILE \"$x\"" } @deps)
512           || "\@ !";
513       return <<"EOF";
514 $shlib.EXE : $lib.OLB $deps $ordinalsfile
515         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
516            \$(PERL) $mkdef_pl "$mkdef_key" "VMS" > $shlib.SYMVEC-tmp
517         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
518            \$(PERL) $translatesyms_pl \$(BUILDDIR)CXX\$DEMANGLER_DB. < $shlib.SYMVEC-tmp > $shlib.SYMVEC
519         OPEN/WRITE/SHARE=READ OPT_FILE $shlib.OPT
520         WRITE OPT_FILE "IDENTIFICATION=""V$config{version}"""
521         IF "$mkdef_key" .NES. "ssl" .AND. "$mkdef_key" .NES. "crypto" THEN -
522            TYPE $engine_opt /OUTPUT=OPT_FILE:
523         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
524            TYPE $shlib.SYMVEC /OUTPUT=OPT_FILE:
525         WRITE OPT_FILE "$lib.OLB/LIBRARY"
526         $write_opt ! Comment to protect from empty line
527         CLOSE OPT_FILE
528         LINK /MAP=$shlib.MAP /FULL/SHARE=$shlib.EXE $shlib.OPT/OPT \$(EX_LIBS)
529         - DELETE $shlib.SYMVEC;*
530         - PURGE $shlib.EXE,$shlib.OPT,$shlib.MAP
531 EOF
532   }
533   sub obj2dynlib {
534       my %args = @_;
535       my $lib = $args{lib};
536       my $libd = dirname($lib);
537       my $libn = basename($lib);
538       (my $libn_nolib = $libn) =~ s/^lib//;
539       my @objs = map { "$_.OBJ" } @{$args{objs}};
540       my @deps = map {
541           $config{no_shared} ? $_.".OLB"
542               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
543       my $deps = join(", -\n\t\t", @objs, @deps);
544       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
545       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
546                                                "VMS", "engine.opt")),
547                                rel2abs($config{builddir}));
548       # The "[]" hack is because in .OPT files, each line inherits the
549       # previous line's file spec as default, so if no directory spec
550       # is present in the current line and the previous line has one that
551       # doesn't apply, you're in for a surprise.
552       my $write_opt =
553           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
554                                  "WRITE OPT_FILE \"$x" } @objs).
555           "\"\n\t".
556           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
557                              $x =~ s|(\.EXE)|$1/SHARE|;
558                              $x =~ s|(\.LIB)|$1/LIB|;
559                              "WRITE OPT_FILE \"$x\"" } @deps)
560           || "\@ !";
561       return <<"EOF";
562 $lib.EXE : $deps
563         OPEN/WRITE/SHARE=READ OPT_FILE $lib.OPT
564         TYPE $engine_opt /OUTPUT=OPT_FILE:
565         $write_opt
566         CLOSE OPT_FILE
567         LINK /MAP=$lib.MAP /FULL/SHARE=$lib.EXE $lib.OPT/OPT \$(EX_LIBS)
568         - PURGE $lib.EXE,$lib.OPT,$lib.MAP
569 EOF
570   }
571   sub obj2lib {
572       my %args = @_;
573       my $lib = $args{lib};
574       my $objs = join(", -\n\t\t", map { $_.".OBJ" } (@{$args{objs}}));
575       my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib.OLB $_.OBJ" }
576                                     @{$args{objs}}));
577       return <<"EOF";
578 $lib.OLB : $objs
579         LIBRARY/CREATE/OBJECT $lib
580         $fill_lib
581         - PURGE $lib.OLB
582 EOF
583   }
584   sub obj2bin {
585       my %args = @_;
586       my $bin = $args{bin};
587       my $bind = dirname($bin);
588       my $binn = basename($bin);
589       my @objs = map { "$_.OBJ" } @{$args{objs}};
590       my @deps = map {
591           $config{no_shared} ? $_.".OLB"
592               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
593       my $deps = join(", -\n\t\t", @objs, @deps);
594       # The "[]" hack is because in .OPT files, each line inherits the
595       # previous line's file spec as default, so if no directory spec
596       # is present in the current line and the previous line has one that
597       # doesn't apply, you're in for a surprise.
598       my $write_opt =
599           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
600                                  "WRITE OPT_FILE \"$x" } @objs).
601           "\"\n\t".
602           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
603                              $x =~ s|(\.EXE)|$1/SHARE|;
604                              $x =~ s|(\.OLB)|$1/LIB|;
605                              "WRITE OPT_FILE \"$x\"" } @deps)
606           || "\@ !";
607       return <<"EOF";
608 $bin.EXE : $deps
609         OPEN/WRITE/SHARE=READ OPT_FILE $bin.OPT
610         $write_opt
611         CLOSE OPT_FILE
612         LINK/EXEC=$bin.EXE \$(LDFLAGS) $bin.OPT/OPT \$(EX_LIBS)
613         - PURGE $bin.EXE,$bin.OPT
614 EOF
615   }
616   sub in2script {
617       my %args = @_;
618       my $script = $args{script};
619       return "" if grep { $_ eq $script } @{$args{sources}}; # No overwrite!
620       my $sources = join(" ", @{$args{sources}});
621       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
622                                            "util", "dofile.pl")),
623                            rel2abs($config{builddir}));
624       return <<"EOF";
625 $script : $sources
626         \$(PERL) "-I\$(BUILDDIR)" "-Mconfigdata" $dofile $sources > $script
627         SET FILE/PROT=(S:RWED,O:RWED,G:RE,W:RE) $script
628         PURGE $script
629 EOF
630   }
631   ""    # Important!  This becomes part of the template result.
632 -}