1c5f58af2513202726685835a217ab2e5bffa7d6
[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() if $config{no_shared}; "" -} !
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() if $config{no_shared}; "" -} !
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       my $deps = join(", -\n\t\t", @{$args{srcs}}, @{$args{deps}});
412
413       # Because VMS C isn't very good at combining a /INCLUDE path with
414       # #includes having a relative directory (like '#include "../foo.h"),
415       # the best choice is to move to the first source file's intended
416       # directory before compiling, and make sure to write the object file
417       # in the correct position (important when the object tree is other
418       # than the source tree).
419       my $forward = dirname($args{srcs}->[0]);
420       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
421       my $depd = abs2rel(rel2abs(dirname($dep)), rel2abs($forward));
422       my $depn = basename($dep);
423       my $srcs =
424           join(", ",
425                map { abs2rel(rel2abs($_), rel2abs($forward)) } @{$args{srcs}});
426       my $incs =
427           "/INCLUDE=(".join(",",
428                             map {
429                                file_name_is_absolute($_)
430                                ? $_ : catdir($backward,$_)
431                             } @{$args{incs}}).")";
432       my $before = $unified_info{before}->{$dep.".OBJ"} || "\@ !";
433       my $after = $unified_info{after}->{$dep.".OBJ"} || "\@ !";
434
435       return <<"EOF";
436 $dep.MMS : $deps
437         ${before}
438         SET DEFAULT $forward
439         \$(CC) \$(CFLAGS)${incs} /MMS=(TARGET=.OBJ)/OBJECT=${depd}${depn}.MMS $srcs
440         SET DEFAULT $backward
441         ${after}
442         - PURGE $dep.MMS
443 EOF
444   }
445   sub src2obj {
446       my %args = @_;
447       my $obj = $args{obj};
448       my $deps = join(", -\n\t\t", @{$args{srcs}}, @{$args{deps}});
449
450       # Because VMS C isn't very good at combining a /INCLUDE path with
451       # #includes having a relative directory (like '#include "../foo.h"),
452       # the best choice is to move to the first source file's intended
453       # directory before compiling, and make sure to write the object file
454       # in the correct position (important when the object tree is other
455       # than the source tree).
456       my $forward = dirname($args{srcs}->[0]);
457       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
458       my $objd = abs2rel(rel2abs(dirname($obj)), rel2abs($forward));
459       my $objn = basename($obj);
460       my $srcs =
461           join(", ",
462                map { abs2rel(rel2abs($_), rel2abs($forward)) } @{$args{srcs}});
463       my $incs =
464           "/INCLUDE=(".join(",",
465                             map {
466                                file_name_is_absolute($_)
467                                ? $_ : catdir($backward,$_)
468                             } @{$args{incs}}).")";
469       my $before = $unified_info{before}->{$obj.".OBJ"} || "\@ !";
470       my $after = $unified_info{after}->{$obj.".OBJ"} || "\@ !";
471
472       return <<"EOF";
473 $obj.OBJ : $deps
474         ${before}
475         SET DEFAULT $forward
476         \$(CC) \$(CFLAGS)${incs} /OBJECT=${objd}${objn}.OBJ /REPOSITORY=$backward $srcs
477         SET DEFAULT $backward
478         ${after}
479         - PURGE $obj.OBJ
480 EOF
481   }
482   sub libobj2shlib {
483       my %args = @_;
484       my $lib = $args{lib};
485       my $shlib = $args{shlib};
486       my $libd = dirname($lib);
487       my $libn = basename($lib);
488       (my $mkdef_key = $libn) =~ s/^${osslprefix_q}lib//i;
489       my @deps = map {
490           $config{no_shared} ? $_.".OLB"
491               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
492       my $deps = join(", -\n\t\t", @deps);
493       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
494       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
495       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
496                                                "VMS", "engine.opt")),
497                                rel2abs($config{builddir}));
498       my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
499                                              "util", "mkdef.pl")),
500                              rel2abs($config{builddir}));
501       my $translatesyms_pl = abs2rel(rel2abs(catfile($config{sourcedir},
502                                                      "VMS", "translatesyms.pl")),
503                                      rel2abs($config{builddir}));
504       # The "[]" hack is because in .OPT files, each line inherits the
505       # previous line's file spec as default, so if no directory spec
506       # is present in the current line and the previous line has one that
507       # doesn't apply, you're in for a surprise.
508       my $write_opt =
509           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
510                              $x =~ s|(\.EXE)|$1/SHARE|;
511                              $x =~ s|(\.LIB)|$1/LIB|;
512                              "WRITE OPT_FILE \"$x\"" } @deps)
513           || "\@ !";
514       return <<"EOF";
515 $shlib.EXE : $lib.OLB $deps $ordinalsfile
516         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
517            \$(PERL) $mkdef_pl "$mkdef_key" "VMS" > $shlib.SYMVEC-tmp
518         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
519            \$(PERL) $translatesyms_pl \$(BUILDDIR)CXX\$DEMANGLER_DB. < $shlib.SYMVEC-tmp > $shlib.SYMVEC
520         OPEN/WRITE/SHARE=READ OPT_FILE $shlib.OPT
521         WRITE OPT_FILE "IDENTIFICATION=""V$config{version}"""
522         IF "$mkdef_key" .NES. "ssl" .AND. "$mkdef_key" .NES. "crypto" THEN -
523            TYPE $engine_opt /OUTPUT=OPT_FILE:
524         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
525            TYPE $shlib.SYMVEC /OUTPUT=OPT_FILE:
526         WRITE OPT_FILE "$lib.OLB/LIBRARY"
527         $write_opt ! Comment to protect from empty line
528         CLOSE OPT_FILE
529         LINK /MAP=$shlib.MAP /FULL/SHARE=$shlib.EXE $shlib.OPT/OPT \$(EX_LIBS)
530         - DELETE $shlib.SYMVEC;*
531         - PURGE $shlib.EXE,$shlib.OPT,$shlib.MAP
532 EOF
533   }
534   sub obj2dynlib {
535       my %args = @_;
536       my $lib = $args{lib};
537       my $libd = dirname($lib);
538       my $libn = basename($lib);
539       (my $libn_nolib = $libn) =~ s/^lib//;
540       my @objs = map { "$_.OBJ" } @{$args{objs}};
541       my @deps = map {
542           $config{no_shared} ? $_.".OLB"
543               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
544       my $deps = join(", -\n\t\t", @objs, @deps);
545       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
546       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
547                                                "VMS", "engine.opt")),
548                                rel2abs($config{builddir}));
549       # The "[]" hack is because in .OPT files, each line inherits the
550       # previous line's file spec as default, so if no directory spec
551       # is present in the current line and the previous line has one that
552       # doesn't apply, you're in for a surprise.
553       my $write_opt =
554           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
555                                  "WRITE OPT_FILE \"$x" } @objs).
556           "\"\n\t".
557           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
558                              $x =~ s|(\.EXE)|$1/SHARE|;
559                              $x =~ s|(\.LIB)|$1/LIB|;
560                              "WRITE OPT_FILE \"$x\"" } @deps)
561           || "\@ !";
562       return <<"EOF";
563 $lib.EXE : $deps
564         OPEN/WRITE/SHARE=READ OPT_FILE $lib.OPT
565         TYPE $engine_opt /OUTPUT=OPT_FILE:
566         $write_opt
567         CLOSE OPT_FILE
568         LINK /MAP=$lib.MAP /FULL/SHARE=$lib.EXE $lib.OPT/OPT \$(EX_LIBS)
569         - PURGE $lib.EXE,$lib.OPT,$lib.MAP
570 EOF
571   }
572   sub obj2lib {
573       my %args = @_;
574       my $lib = $args{lib};
575       my $objs = join(", -\n\t\t", map { $_.".OBJ" } (@{$args{objs}}));
576       my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib.OLB $_.OBJ" }
577                                     @{$args{objs}}));
578       return <<"EOF";
579 $lib.OLB : $objs
580         LIBRARY/CREATE/OBJECT $lib
581         $fill_lib
582         - PURGE $lib.OLB
583 EOF
584   }
585   sub obj2bin {
586       my %args = @_;
587       my $bin = $args{bin};
588       my $bind = dirname($bin);
589       my $binn = basename($bin);
590       my @objs = map { "$_.OBJ" } @{$args{objs}};
591       my @deps = map {
592           $config{no_shared} ? $_.".OLB"
593               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
594       my $deps = join(", -\n\t\t", @objs, @deps);
595       # The "[]" hack is because in .OPT files, each line inherits the
596       # previous line's file spec as default, so if no directory spec
597       # is present in the current line and the previous line has one that
598       # doesn't apply, you're in for a surprise.
599       my $write_opt =
600           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
601                                  "WRITE OPT_FILE \"$x" } @objs).
602           "\"\n\t".
603           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
604                              $x =~ s|(\.EXE)|$1/SHARE|;
605                              $x =~ s|(\.OLB)|$1/LIB|;
606                              "WRITE OPT_FILE \"$x\"" } @deps)
607           || "\@ !";
608       return <<"EOF";
609 $bin.EXE : $deps
610         OPEN/WRITE/SHARE=READ OPT_FILE $bin.OPT
611         $write_opt
612         CLOSE OPT_FILE
613         LINK/EXEC=$bin.EXE \$(LDFLAGS) $bin.OPT/OPT \$(EX_LIBS)
614         - PURGE $bin.EXE,$bin.OPT
615 EOF
616   }
617   sub in2script {
618       my %args = @_;
619       my $script = $args{script};
620       return "" if grep { $_ eq $script } @{$args{sources}}; # No overwrite!
621       my $sources = join(" ", @{$args{sources}});
622       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
623                                            "util", "dofile.pl")),
624                            rel2abs($config{builddir}));
625       return <<"EOF";
626 $script : $sources
627         \$(PERL) "-I\$(BUILDDIR)" "-Mconfigdata" $dofile $sources > $script
628         SET FILE/PROT=(S:RWED,O:RWED,G:RE,W:RE) $script
629         PURGE $script
630 EOF
631   }
632   ""    # Important!  This becomes part of the template result.
633 -}