1091952624459ead991dfdab9f56f636e3ebe010
[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, build_libs, build_engines, build_apps
204
205 build_libs : $(LIBS)
206 build_engines : $(ENGINES)
207 build_apps : $(PROGRAMS), $(SCRIPTS)
208 build_tests : $(TESTPROGS)
209
210 test tests : build_tests, rehash
211         SET DEFAULT [.test]{- move("test") -}
212         DEFINE SRCTOP {- sourcedir() -}
213         DEFINE BLDTOP {- builddir() -}
214         $(PERL) {- sourcefile("test", "run_tests.pl") -} $(TESTS)
215         DEASSIGN BLDTOP
216         DEASSIGN SRCTOP
217         SET DEFAULT [-]{- move("..") -}
218
219 list-tests :
220         @ TOP=$(SRCDIR) PERL=$(PERL) $(PERL) {- catfile($config{sourcedir},"test", "run_tests.pl") -} list
221
222 # Because VMS wants the generation number (or *) to delete files, we can't
223 # use $(LIBS), $(PROGRAMS) and $(TESTPROGS) directly.
224 libclean :
225         - DELETE []OSSL$LIB*.OLB;*,OSSL$LIB*.LIS;*
226         - DELETE [.crypto...]*.OBJ;*,*.LIS;*
227         - DELETE [.ssl...]*.OBJ;*,*.LIS;*
228         - DELETE [.engines...]*.OBJ;*,*.LIS;*
229         - DELETE []CXX$DEMANGLER_DB.;*
230
231 install : install_sw install_docs
232
233 uninstall : uninstall_docs uninstall_sw
234
235 clean : libclean
236         - DELETE []OSSL$LIB*.EXE;*,OSSL$LIB*.MAP;*,OSSL$LIB*.OPT;*
237         - DELETE [.engines...]LIB*.EXE;*,LIB*.MAP;*,LIB*.OPT;*
238         - DELETE [.apps]*.EXE;*,*.MAP;*,*.OPT;*
239         - DELETE [.apps]*.OBJ;*,*.LIS;*
240         - DELETE [.test]*.EXE;*,*.MAP;*,*.OPT;*
241         - DELETE [.test]*.OBJ;*,*.LIS;*
242         - DELETE [.test]*.LOG;*
243         - DELETE []*.MAP;*
244
245 DCLEAN_CMD=$(PERL) -pe "if (/^# DO NOT DELETE.*/) { exit(0); }"
246 dclean :
247         $(DCLEAN_CMD) < descrip.mms > descrip.mms.new
248         RENAME descrip.mms.new descrip.mms
249         PURGE descrip.mms
250
251 {- our @deps = map { (my $x = $_) =~ s|\.o$|\$(DEP_EXT)|; $x; }
252                grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
253                keys %{$unified_info{sources}};
254    ""; -}
255 depend : {- join(",-\n\t", @deps); -}
256         $(DCLEAN_CMD) < descrip.mms > descrip.mms.new
257         OPEN/APPEND DESCRIP descrip.mms.new
258         WRITE DESCRIP "# DO NOT DELETE THIS LINE -- make depend depends on it."
259         {- join("\n\t", map { "TYPE $_ /OUTPUT=DESCRIP:" } @deps); -}
260         CLOSE DESCRIP
261         RENAME descrip.mms.new descrip.mms
262         PURGE descrip.mms
263
264 # Install helper targets #############################################
265
266 install_sw : all install_dev install_engines install_runtime install_config
267         @ WRITE SYS$OUTPUT ""
268         @ WRITE SYS$OUTPUT "######################################################################"
269         @ WRITE SYS$OUTPUT ""
270         @ WRITE SYS$OUTPUT "Installation complete"
271         @ WRITE SYS$OUTPUT ""
272         @ IF "$(DESTDIR)" .NES. "" THEN EXIT 1
273         @ WRITE SYS$OUTPUT "Run @$(INSTALLTOP)openssl_startup to set up logical names"
274         @ WRITE SYS$OUTPUT "then run @$(INSTALLTOP)openssl_setup to define commands"
275         @ WRITE SYS$OUTPUT ""
276
277 uninstall_sw : uninstall_dev uninstall_engines uninstall_runtime uninstall_config
278
279 install_docs : install_man_docs install_html_docs
280
281 uninstall_docs : uninstall_man_docs uninstall_html_docs
282
283 install_dev : check_INSTALLTOP
284         @ WRITE SYS$OUTPUT "*** Installing development files"
285         @ ! Install header files
286         CREATE/DIR ossl_installroot:[include.openssl]
287         COPY/PROT=W:R openssl:*.h ossl_installroot:[include.openssl]
288         @ ! Install libraries
289         CREATE/DIR ossl_installroot:['arch'.LIB]
290         {- join("\n        ",
291                 map { "COPY/PROT=W:R $_.OLB ossl_installroot:['arch'.LIB]" }
292                 @{$unified_info{libraries}}) -}
293         @ {- output_off() if $config{no_shared}; "" -} !
294         {- join("\n        ",
295                 map { "COPY/PROT=W:RE $_.EXE ossl_installroot:['arch'.LIB]" }
296                 map { $unified_info{sharednames}->{$_} || () } 
297                 @{$unified_info{libraries}}) -}
298         @ {- output_on() if $config{no_shared}; "" -} !
299
300 install_runtime : check_INSTALLTOP
301         @ WRITE SYS$OUTPUT "*** Installing runtime files"
302         @ ! Install the main program
303         CREATE/DIR ossl_installroot:['arch'.EXE]
304         COPY/PROT=W:RE [.APPS]openssl.EXE ossl_installroot:['arch'.EXE]
305         @ ! Install scripts
306         CREATE/DIR ossl_installroot:[EXE]
307         COPY/PROT=W:RE [.APPS]CA.pl ossl_installroot:[EXE]
308         COPY/PROT=W:RE [.TOOLS]c_rehash. ossl_installroot:[EXE]c_rehash.pl
309         @ ! Install configuration file
310         COPY/PROT=W:RE {- sourcefile("apps", "openssl-vms.cnf") -} -
311                 ossl_installroot:[000000]openssl.cnf
312
313 install_engines : check_INSTALLTOP
314         @ {- output_off() if $config{no_shared}; "" -} !
315         @ WRITE SYS$OUTPUT "*** Installing engines"
316         CREATE/DIR ossl_installroot:['arch'.ENGINES]
317         COPY/PROT=W:RE [.ENGINES]*.EXE ossl_installroot:['arch'.ENGINES]
318         @ {- output_on() if $config{no_shared}; "" -} !
319
320 install_config : [.VMS]openssl_startup.com [.VMS]openssl_shutdown.com -
321                  check_INSTALLTOP
322         IF "$(DESTDIR)" .EQS. "" THEN -
323                 IF F$SEARCH("OSSL_DATAROOT:[000000]CERTS.DIR;1") .EQS. "" THEN -
324                 CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[CERTS]
325         IF "$(DESTDIR)" .EQS. "" THEN -
326                 IF F$SEARCH("OSSL_DATAROOT:[000000]PRIVATE.DIR;1") .EQS. "" THEN -
327                 CREATE/DIR/PROT=(S:RWED,O:RWE,G:,W:) OSSL_DATAROOT:[PRIVATE]
328         CREATE/DIR ossl_installroot:[SYS$STARTUP]
329         COPY/PROT=W:RE -
330                 [.VMS]openssl_startup.com,openssl_shutdown.com -
331                 ossl_installroot:[SYS$STARTUP]
332         COPY/PROT=W:RE -
333                 {- sourcefile("VMS", "openssl_utils.com") -} -
334                 ossl_installroot:[SYS$STARTUP]
335
336 [.VMS]openssl_startup.com : vmsconfig.pm
337         CREATE/DIR [.VMS]
338         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
339                 {- sourcefile("VMS", "openssl_startup.com.in") -} -
340                 > [.VMS]openssl_startup.com
341
342 [.VMS]openssl_shutdown.com : vmsconfig.pm
343         CREATE/DIR [.VMS]
344         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
345                 {- sourcefile("VMS", "openssl_shutdown.com.in") -} -
346                 > [.VMS]openssl_shutdown.com
347
348 vmsconfig.pm : descrip.mms
349         OPEN/WRITE/SHARE=READ CONFIG []vmsconfig.pm
350         WRITE CONFIG "package vmsconfig;"
351         WRITE CONFIG "use strict; use warnings;"
352         WRITE CONFIG "use Exporter;"
353         WRITE CONFIG "our @ISA = qw(Exporter);"
354         WRITE CONFIG "our @EXPORT = qw(%config %target %withargs %unified_info);"
355         WRITE CONFIG "our %config = ("
356         WRITE CONFIG "  target => '{- $config{target} -}',"
357         WRITE CONFIG "  version => '$(MAJOR).$(MINOR)',"
358         WRITE CONFIG "  no_shared => '","{- $config{no_shared} -}","',"
359         WRITE CONFIG "  INSTALLTOP => '$(INSTALLTOP)',"
360         WRITE CONFIG "  OPENSSLDIR => '$(OPENSSLDIR)',"
361         WRITE CONFIG "  pointersize => '","{- $target{pointersize} -}","',"
362         WRITE CONFIG "  shared_libs => ["
363         {- join("\n        ", map { "WRITE CONFIG \"    '$_'," } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) || "\@ !" -}
364         WRITE CONFIG "  ],"
365         WRITE CONFIG ");"
366         WRITE CONFIG "our %target = ();"
367         WRITE CONFIG "our %withargs = ();"
368         WRITE CONFIG "our %unified_info = ();"
369         WRITE CONFIG "1;"
370         CLOSE CONFIG
371
372 check_INSTALLTOP :
373         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
374                 WRITE SYS$ERROR "INSTALLTOP should not be empty"
375         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
376                 EXIT %x10000002
377
378 # Helper targets #####################################################
379
380 rehash : [.apps]openssl.exe, copy-certs
381         !MCR [.apps]openssl.exe rehash {- builddir("certs", "demo") -}
382         $(PERL) [.tools]c_rehash. [.certs.demo]
383
384 copy-certs :
385         @ IF F$SEARCH("{- buildfile("certs.dir") -}") .EQS. "" THEN -
386              CREATE/DIR {- builddir("certs") -}
387         -@ IF "{- sourcedir("certs") -}" .NES. "{- builddir("certs") -}" THEN -
388              COPY {- tree(sourcedir("certs")) -}*.* {- tree(builddir("certs")) -}
389
390 # Developer targets ##################################################
391
392 debug_logicals :
393         SH LOGICAL/PROC openssl,internal,ossl_installroot
394         IF "$(DESTDIR)" .EQS. "" THEN -
395                 SH LOGICAL/PROC ossl_dataroot
396
397 # Building targets ###################################################
398
399 descrip.mms : {- sourcefile("Configurations", "descrip.mms.tmpl") -} $(SRCDIR)Configure ! $(SRCDIR)config.com
400         @ WRITE SYS$OUTPUT "descrip.mms is older than $?."
401         @ WRITE SYS$OUTPUT "Reconfiguring..."
402         perl $(SRCDIR)Configure reconf
403         @ WRITE SYS$OUTPUT "*************************************************"
404         @ WRITE SYS$OUTPUT "***                                           ***"
405         @ WRITE SYS$OUTPUT "***   Please run the same mms command again   ***"
406         @ WRITE SYS$OUTPUT "***                                           ***"
407         @ WRITE SYS$OUTPUT "*************************************************"
408         @ exit %10000000
409
410 {-
411   use File::Basename;
412   use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/;
413   sub src2dep {
414       my %args = @_;
415       my $dep = $args{obj};
416       my $deps = join(", -\n\t\t", @{$args{srcs}}, @{$args{deps}});
417
418       # Because VMS C isn't very good at combining a /INCLUDE path with
419       # #includes having a relative directory (like '#include "../foo.h"),
420       # the best choice is to move to the first source file's intended
421       # directory before compiling, and make sure to write the object file
422       # in the correct position (important when the object tree is other
423       # than the source tree).
424       my $forward = dirname($args{srcs}->[0]);
425       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
426       my $depd = abs2rel(rel2abs(dirname($dep)), rel2abs($forward));
427       my $depn = basename($dep);
428       my $srcs =
429           join(", ",
430                map { abs2rel(rel2abs($_), rel2abs($forward)) } @{$args{srcs}});
431       my $incs =
432           "/INCLUDE=(".join(",",
433                             map {
434                                file_name_is_absolute($_)
435                                ? $_ : catdir($backward,$_)
436                             } @{$args{incs}}).")";
437       my $before = $unified_info{before}->{$dep.".OBJ"} || "\@ !";
438       my $after = $unified_info{after}->{$dep.".OBJ"} || "\@ !";
439
440       return <<"EOF";
441 $dep.MMS : $deps
442         ${before}
443         SET DEFAULT $forward
444         \$(CC) \$(CFLAGS)${incs} /MMS=(TARGET=.OBJ)/OBJECT=${depd}${depn}.MMS $srcs
445         SET DEFAULT $backward
446         ${after}
447         - PURGE $dep.MMS
448 EOF
449   }
450   sub src2obj {
451       my %args = @_;
452       my $obj = $args{obj};
453       my $deps = join(", -\n\t\t", @{$args{srcs}}, @{$args{deps}});
454
455       # Because VMS C isn't very good at combining a /INCLUDE path with
456       # #includes having a relative directory (like '#include "../foo.h"),
457       # the best choice is to move to the first source file's intended
458       # directory before compiling, and make sure to write the object file
459       # in the correct position (important when the object tree is other
460       # than the source tree).
461       my $forward = dirname($args{srcs}->[0]);
462       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
463       my $objd = abs2rel(rel2abs(dirname($obj)), rel2abs($forward));
464       my $objn = basename($obj);
465       my $srcs =
466           join(", ",
467                map { abs2rel(rel2abs($_), rel2abs($forward)) } @{$args{srcs}});
468       my $incs =
469           "/INCLUDE=(".join(",",
470                             map {
471                                file_name_is_absolute($_)
472                                ? $_ : catdir($backward,$_)
473                             } @{$args{incs}}).")";
474       my $before = $unified_info{before}->{$obj.".OBJ"} || "\@ !";
475       my $after = $unified_info{after}->{$obj.".OBJ"} || "\@ !";
476
477       return <<"EOF";
478 $obj.OBJ : $deps
479         ${before}
480         SET DEFAULT $forward
481         \$(CC) \$(CFLAGS)${incs} /OBJECT=${objd}${objn}.OBJ /REPOSITORY=$backward $srcs
482         SET DEFAULT $backward
483         ${after}
484         - PURGE $obj.OBJ
485 EOF
486   }
487   sub libobj2shlib {
488       my %args = @_;
489       my $lib = $args{lib};
490       my $shlib = $args{shlib};
491       my $libd = dirname($lib);
492       my $libn = basename($lib);
493       (my $mkdef_key = $libn) =~ s/^${osslprefix_q}lib//i;
494       my @deps = map {
495           $config{no_shared} ? $_.".OLB"
496               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
497       my $deps = join(", -\n\t\t", @deps);
498       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
499       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
500       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
501                                                "VMS", "engine.opt")),
502                                rel2abs($config{builddir}));
503       my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
504                                              "util", "mkdef.pl")),
505                              rel2abs($config{builddir}));
506       my $translatesyms_pl = abs2rel(rel2abs(catfile($config{sourcedir},
507                                                      "VMS", "translatesyms.pl")),
508                                      rel2abs($config{builddir}));
509       # The "[]" hack is because in .OPT files, each line inherits the
510       # previous line's file spec as default, so if no directory spec
511       # is present in the current line and the previous line has one that
512       # doesn't apply, you're in for a surprise.
513       my $write_opt =
514           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
515                              $x =~ s|(\.EXE)|$1/SHARE|;
516                              $x =~ s|(\.LIB)|$1/LIB|;
517                              "WRITE OPT_FILE \"$x\"" } @deps)
518           || "\@ !";
519       return <<"EOF";
520 $shlib.EXE : $lib.OLB $deps $ordinalsfile
521         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
522            \$(PERL) $mkdef_pl "$mkdef_key" "VMS" > $shlib.SYMVEC-tmp
523         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
524            \$(PERL) $translatesyms_pl \$(BUILDDIR)CXX\$DEMANGLER_DB. < $shlib.SYMVEC-tmp > $shlib.SYMVEC
525         OPEN/WRITE/SHARE=READ OPT_FILE $shlib.OPT
526         WRITE OPT_FILE "IDENTIFICATION=""V$config{version}"""
527         IF "$mkdef_key" .NES. "ssl" .AND. "$mkdef_key" .NES. "crypto" THEN -
528            TYPE $engine_opt /OUTPUT=OPT_FILE:
529         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
530            TYPE $shlib.SYMVEC /OUTPUT=OPT_FILE:
531         WRITE OPT_FILE "$lib.OLB/LIBRARY"
532         $write_opt ! Comment to protect from empty line
533         CLOSE OPT_FILE
534         LINK /MAP=$shlib.MAP /FULL/SHARE=$shlib.EXE $shlib.OPT/OPT \$(EX_LIBS)
535         - DELETE $shlib.SYMVEC;*
536         - PURGE $shlib.EXE,$shlib.OPT,$shlib.MAP
537 EOF
538   }
539   sub obj2dynlib {
540       my %args = @_;
541       my $lib = $args{lib};
542       my $libd = dirname($lib);
543       my $libn = basename($lib);
544       (my $libn_nolib = $libn) =~ s/^lib//;
545       my @objs = map { "$_.OBJ" } @{$args{objs}};
546       my @deps = map {
547           $config{no_shared} ? $_.".OLB"
548               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
549       my $deps = join(", -\n\t\t", @objs, @deps);
550       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
551       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
552                                                "VMS", "engine.opt")),
553                                rel2abs($config{builddir}));
554       # The "[]" hack is because in .OPT files, each line inherits the
555       # previous line's file spec as default, so if no directory spec
556       # is present in the current line and the previous line has one that
557       # doesn't apply, you're in for a surprise.
558       my $write_opt =
559           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
560                                  "WRITE OPT_FILE \"$x" } @objs).
561           "\"\n\t".
562           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
563                              $x =~ s|(\.EXE)|$1/SHARE|;
564                              $x =~ s|(\.LIB)|$1/LIB|;
565                              "WRITE OPT_FILE \"$x\"" } @deps)
566           || "\@ !";
567       return <<"EOF";
568 $lib.EXE : $deps
569         OPEN/WRITE/SHARE=READ OPT_FILE $lib.OPT
570         TYPE $engine_opt /OUTPUT=OPT_FILE:
571         $write_opt
572         CLOSE OPT_FILE
573         LINK /MAP=$lib.MAP /FULL/SHARE=$lib.EXE $lib.OPT/OPT \$(EX_LIBS)
574         - PURGE $lib.EXE,$lib.OPT,$lib.MAP
575 EOF
576   }
577   sub obj2lib {
578       my %args = @_;
579       my $lib = $args{lib};
580       my $objs = join(", -\n\t\t", map { $_.".OBJ" } (@{$args{objs}}));
581       my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib.OLB $_.OBJ" }
582                                     @{$args{objs}}));
583       return <<"EOF";
584 $lib.OLB : $objs
585         LIBRARY/CREATE/OBJECT $lib
586         $fill_lib
587         - PURGE $lib.OLB
588 EOF
589   }
590   sub obj2bin {
591       my %args = @_;
592       my $bin = $args{bin};
593       my $bind = dirname($bin);
594       my $binn = basename($bin);
595       my @objs = map { "$_.OBJ" } @{$args{objs}};
596       my @deps = map {
597           $config{no_shared} ? $_.".OLB"
598               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
599       my $deps = join(", -\n\t\t", @objs, @deps);
600       # The "[]" hack is because in .OPT files, each line inherits the
601       # previous line's file spec as default, so if no directory spec
602       # is present in the current line and the previous line has one that
603       # doesn't apply, you're in for a surprise.
604       my $write_opt =
605           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
606                                  "WRITE OPT_FILE \"$x" } @objs).
607           "\"\n\t".
608           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
609                              $x =~ s|(\.EXE)|$1/SHARE|;
610                              $x =~ s|(\.OLB)|$1/LIB|;
611                              "WRITE OPT_FILE \"$x\"" } @deps)
612           || "\@ !";
613       return <<"EOF";
614 $bin.EXE : $deps
615         OPEN/WRITE/SHARE=READ OPT_FILE $bin.OPT
616         $write_opt
617         CLOSE OPT_FILE
618         LINK/EXEC=$bin.EXE \$(LDFLAGS) $bin.OPT/OPT \$(EX_LIBS)
619         - PURGE $bin.EXE,$bin.OPT
620 EOF
621   }
622   sub in2script {
623       my %args = @_;
624       my $script = $args{script};
625       return "" if grep { $_ eq $script } @{$args{sources}}; # No overwrite!
626       my $sources = join(" ", @{$args{sources}});
627       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
628                                            "util", "dofile.pl")),
629                            rel2abs($config{builddir}));
630       return <<"EOF";
631 $script : $sources
632         \$(PERL) "-I\$(BUILDDIR)" "-Mconfigdata" $dofile -
633             "-o{- $config{build_file} -}" $sources > $script
634         SET FILE/PROT=(S:RWED,O:RWED,G:RE,W:RE) $script
635         PURGE $script
636 EOF
637   }
638   ""    # Important!  This becomes part of the template result.
639 -}