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