157ebb5d3239a31df779b33e60a4359ad08326cc
[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}->{"[.test]heartbeat_test.OBJ"}
54       = $unified_info{before}->{"[.test]ssltest.OBJ"}
55       = qq(record = F\$PARSE("$sd1","A.;",,,"SYNTAX_ONLY") - "A.;"
56         define record 'record'
57         statem = F\$PARSE("$sd2","A.;",,,"SYNTAX_ONLY") - "A.;"
58         define statem 'statem');
59   $unified_info{after}->{"[.test]heartbeat_test.OBJ"}
60       = $unified_info{after}->{"[.test]ssltest.OBJ"}
61       = qq(deassign statem
62         deassign record);
63   foreach (grep /^\[\.ssl\.(?:record|statem)\].*\.o$/, keys %{$unified_info{sources}}) {
64       (my $x = $_) =~ s|\.o$|.OBJ|;
65       $unified_info{before}->{$x}
66           = qq(record = F\$PARSE("$sd1","A.;",,,"SYNTAX_ONLY") - "A.;"
67         define record 'record'
68         statem = F\$PARSE("$sd2","A.;",,,"SYNTAX_ONLY") - "A.;"
69         define statem 'statem');
70       $unified_info{after}->{$x}
71           = qq(deassign statem
72         deassign record);
73   }
74   #use Data::Dumper;
75   #print STDERR "DEBUG: before:\n", Dumper($unified_info{before});
76   #print STDERR "DEBUG: after:\n", Dumper($unified_info{after});
77   "";
78 -}
79 PLATFORM={- $config{target} -}
80 OPTIONS={- $config{options} -}
81 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
82 SRCDIR={- $config{sourcedir} -}
83 BUILDDIR={- $config{builddir} -}
84
85 VERSION={- $config{version} -}
86 MAJOR={- $config{major} -}
87 MINOR={- $config{minor} -}
88 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
89 SHLIB_VERSION_HISTORY={- $config{shlib_version_history} -}
90 SHLIB_MAJOR={- $config{shlib_major} -}
91 SHLIB_MINOR={- $config{shlib_minor} -}
92 SHLIB_TARGET={- $target{shared_target} -}
93
94 EXE_EXT=.EXE
95 LIB_EXT=.OLB
96 SHLIB_EXT=.EXE
97 OBJ_EXT=.OBJ
98 DEP_EXT=.MMS
99
100 LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @{$unified_info{libraries}}) -}
101 SHLIBS={- join(" ", map { $_."\$(SHLIB_EXT)" } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) -}
102 ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{engines}}) -}
103 PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } grep { !m|^\[\.test\]| } @{$unified_info{programs}}) -}
104 TESTPROGS={- join(", ", map { "-\n\t".$_.".EXE" } grep { m|^\[\.test\]| } @{$unified_info{programs}}) -}
105 SCRIPTS={- join(", ", map { "-\n\t".$_ } @{$unified_info{scripts}}) -}
106 DEPS={- our @deps = map { (my $x = $_) =~ s|\.o$|\$(DEP_EXT)|; $x; }
107                     grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
108                     keys %{$unified_info{sources}};
109         join(", ", map { "-\n\t".$_ } @deps); -}
110
111 # DESTDIR is for package builders so that they can configure for, say,
112 # SYS$COMMON:[OPENSSL] and yet have everything installed in STAGING:[USER].
113 # In that case, configure with --prefix=SYS$COMMON:[OPENSSL] and then run
114 # MMS with /MACROS=(DESTDIR=STAGING:[USER]).  The result will end up in
115 # STAGING:[USER.OPENSSL].
116 # Normally it is left empty.
117 DESTDIR=
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(",", @{$target{defines}}, @{$config{defines}},"OPENSSLDIR=\"\"\"\$(OPENSSLDIR)\"\"\"","ENGINESDIR=\"\"\"\$(ENGINESDIR)\"\"\"") -}) {- $target{cflags} -} {- $config{cflags} -}
130 DEPFLAG= /DEFINE=({- join(",", @{$config{depdefines}}) -})
131 LDFLAGS= {- $target{lflags} -}
132 EX_LIBS= {- $target{ex_libs} ? ",".$target{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 = "$(DESTDIR)"
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 "$(DESTDIR)" .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 "$(DESTDIR)" .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 : configdata.pm, -
206       build_libs_nodep, build_engines_nodep, build_apps_nodep, -
207       depend
208
209 build_libs : configdata.pm, build_libs_nodep, depend
210 build_libs_nodep : $(LIBS)
211 build_engines : configdata.pm, build_engines_nodep, depend
212 build_engines_nodep : $(ENGINES)
213 build_apps : configdata.pm, build_apps_nodep, depend
214 build_apps_nodep : $(PROGRAMS), $(SCRIPTS)
215 build_tests : configdata.pm, build_tests_nodep, depend
216 build_tests_nodep : $(TESTPROGS)
217
218 test tests : configdata.pm, -
219              build_apps_nodep, build_engines_nodep, build_tests_nodep, -
220              depend
221         SET DEFAULT [.test]{- move("test") -}
222         DEFINE SRCTOP {- sourcedir() -}
223         DEFINE BLDTOP {- builddir() -}
224         $(PERL) {- sourcefile("test", "run_tests.pl") -} $(TESTS)
225         DEASSIGN BLDTOP
226         DEASSIGN SRCTOP
227         SET DEFAULT [-]{- move("..") -}
228
229 list-tests :
230         @ TOP=$(SRCDIR) PERL=$(PERL) $(PERL) {- catfile($config{sourcedir},"test", "run_tests.pl") -} list
231
232 # Because VMS wants the generation number (or *) to delete files, we can't
233 # use $(LIBS), $(PROGRAMS) and $(TESTPROGS) directly.
234 libclean :
235         - DELETE []OSSL$LIB*.OLB;*,OSSL$LIB*.LIS;*
236         - DELETE [.crypto...]*.OBJ;*,*.LIS;*
237         - DELETE [.ssl...]*.OBJ;*,*.LIS;*
238         - DELETE [.engines...]*.OBJ;*,*.LIS;*
239         - DELETE []CXX$DEMANGLER_DB.;*
240
241 install : install_sw install_docs
242         @ WRITE SYS$OUTPUT ""
243         @ WRITE SYS$OUTPUT "######################################################################"
244         @ WRITE SYS$OUTPUT ""
245         @ WRITE SYS$OUTPUT "Installation complete"
246         @ WRITE SYS$OUTPUT ""
247         @ IF "$(DESTDIR)" .EQS. "" THEN -
248              PIPE ( WRITE SYS$OUTPUT "Run @$(INSTALLTOP)openssl_startup to set up logical names" ; -
249                     WRITE SYS$OUTPUT "then run @$(INSTALLTOP)openssl_setup to define commands" ; -
250                     WRITE SYS$OUTPUT "" )
251
252 uninstall : uninstall_docs uninstall_sw
253
254 clean : libclean
255         - DELETE []OSSL$LIB*.EXE;*,OSSL$LIB*.MAP;*,OSSL$LIB*.OPT;*
256         - DELETE [.engines...]LIB*.EXE;*,LIB*.MAP;*,LIB*.OPT;*
257         - DELETE [.apps]*.EXE;*,*.MAP;*,*.OPT;*
258         - DELETE [.apps]*.OBJ;*,*.LIS;*
259         - DELETE [.test]*.EXE;*,*.MAP;*,*.OPT;*
260         - DELETE [.test]*.OBJ;*,*.LIS;*
261         - DELETE [.test]*.LOG;*
262         - DELETE []*.MAP;*
263
264 depend : descrip.mms
265 descrip.mms : FORCE
266         @ $(PERL) -pe "if (/^# DO NOT DELETE.*/) { exit(0); }" -
267                 < descrip.mms > descrip.mms-new
268         @ OPEN/APPEND DESCRIP descrip.mms-new
269         @ WRITE DESCRIP "# DO NOT DELETE THIS LINE -- make depend depends on it."
270         {- join("\n\t", map { "\@ IF F\$SEARCH(\"$_\") .NES. \"\" THEN TYPE $_ /OUTPUT=DESCRIP:" } @deps); -}
271         @ CLOSE DESCRIP
272         @ PIPE ( $(PERL) -e "use File::Compare qw/compare_text/; my $x = compare_text(""descrip.mms"",""descrip.mms-new""); exit(0x10000000 + ($x == 0));" || -
273                  RENAME descrip.mms-new descrip.mms )
274         @ IF F$SEARCH("descrip.mms-new") .NES. "" THEN DELETE descrip.mms-new;*
275         -@ SPAWN/OUTPUT=NLA0: PURGE/NOLOG descrip.mms
276
277 # Install helper targets #############################################
278
279 install_sw : all install_dev install_engines install_runtime install_config
280
281 uninstall_sw : uninstall_dev uninstall_engines uninstall_runtime uninstall_config
282
283 install_docs : install_man_docs install_html_docs
284
285 uninstall_docs : uninstall_man_docs uninstall_html_docs
286
287 install_dev : check_INSTALLTOP
288         @ WRITE SYS$OUTPUT "*** Installing development files"
289         @ ! Install header files
290         CREATE/DIR ossl_installroot:[include.openssl]
291         COPY/PROT=W:R openssl:*.h ossl_installroot:[include.openssl]
292         @ ! Install libraries
293         CREATE/DIR ossl_installroot:[LIB.'arch']
294         {- join("\n        ",
295                 map { "COPY/PROT=W:R $_.OLB ossl_installroot:[LIB.'arch']" }
296                 @{$unified_info{libraries}}) -}
297         @ {- output_off() if $disabled{shared}; "" -} !
298         {- join("\n        ",
299                 map { "COPY/PROT=W:RE $_.EXE ossl_installroot:[LIB.'arch']" }
300                 map { $unified_info{sharednames}->{$_} || () }
301                 @{$unified_info{libraries}}) -}
302         @ {- output_on() if $disabled{shared}; "" -} !
303
304 install_runtime : check_INSTALLTOP
305         @ WRITE SYS$OUTPUT "*** Installing runtime files"
306         @ ! Install the main program
307         CREATE/DIR ossl_installroot:[EXE.'arch']
308         COPY/PROT=W:RE [.APPS]openssl.EXE ossl_installroot:[EXE.'arch']
309         @ ! Install scripts
310         CREATE/DIR ossl_installroot:[EXE]
311         COPY/PROT=W:RE [.APPS]CA.pl ossl_installroot:[EXE]
312         COPY/PROT=W:RE [.TOOLS]c_rehash. ossl_installroot:[EXE]c_rehash.pl
313         @ ! Install configuration file
314         COPY/PROT=W:RE {- sourcefile("apps", "openssl-vms.cnf") -} -
315                 ossl_installroot:[000000]openssl.cnf
316
317 install_engines : check_INSTALLTOP
318         @ {- output_off() unless scalar @{$unified_info{engines}}; "" -} !
319         @ WRITE SYS$OUTPUT "*** Installing engines"
320         CREATE/DIR ossl_installroot:[ENGINES.'arch']
321         {- join("\n        ",
322                 map { "COPY/PROT=W:RE $_.EXE ossl_installroot:[ENGINES.'arch']" }
323                 grep(!m|ossltest$|i, @{$unified_info{engines}})) -}
324         @ {- output_on() unless scalar @{$unified_info{engines}}; "" -} !
325
326 install_config : [.VMS]openssl_startup.com [.VMS]openssl_shutdown.com -
327                  check_INSTALLTOP
328         IF "$(DESTDIR)" .EQS. "" THEN -
329                 IF F$SEARCH("OSSL_DATAROOT:[000000]CERTS.DIR;1") .EQS. "" THEN -
330                 CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[CERTS]
331         IF "$(DESTDIR)" .EQS. "" THEN -
332                 IF F$SEARCH("OSSL_DATAROOT:[000000]PRIVATE.DIR;1") .EQS. "" THEN -
333                 CREATE/DIR/PROT=(S:RWED,O:RWE,G:,W:) OSSL_DATAROOT:[PRIVATE]
334         CREATE/DIR ossl_installroot:[SYS$STARTUP]
335         COPY/PROT=W:RE -
336                 [.VMS]openssl_startup.com,openssl_shutdown.com -
337                 ossl_installroot:[SYS$STARTUP]
338         COPY/PROT=W:RE -
339                 {- sourcefile("VMS", "openssl_utils.com") -} -
340                 ossl_installroot:[SYS$STARTUP]
341
342 [.VMS]openssl_startup.com : vmsconfig.pm
343         CREATE/DIR [.VMS]
344         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
345                 {- sourcefile("VMS", "openssl_startup.com.in") -} -
346                 > [.VMS]openssl_startup.com
347
348 [.VMS]openssl_shutdown.com : vmsconfig.pm
349         CREATE/DIR [.VMS]
350         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
351                 {- sourcefile("VMS", "openssl_shutdown.com.in") -} -
352                 > [.VMS]openssl_shutdown.com
353
354 vmsconfig.pm : configdata.pm
355         OPEN/WRITE/SHARE=READ CONFIG []vmsconfig.pm
356         WRITE CONFIG "package vmsconfig;"
357         WRITE CONFIG "use strict; use warnings;"
358         WRITE CONFIG "use Exporter;"
359         WRITE CONFIG "our @ISA = qw(Exporter);"
360         WRITE CONFIG "our @EXPORT = qw(%config %target %withargs %unified_info %disabled);"
361         WRITE CONFIG "our %config = ("
362         WRITE CONFIG "  target => '{- $config{target} -}',"
363         WRITE CONFIG "  version => '$(MAJOR).$(MINOR)',"
364         WRITE CONFIG "  no_shared => '","{- $disabled{shared} -}","',"
365         WRITE CONFIG "  INSTALLTOP => '$(INSTALLTOP)',"
366         WRITE CONFIG "  OPENSSLDIR => '$(OPENSSLDIR)',"
367         WRITE CONFIG "  pointersize => '","{- $target{pointersize} -}","',"
368         WRITE CONFIG "  shared_libs => ["
369         {- join("\n        ", map { "WRITE CONFIG \"    '$_'," } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) || "\@ !" -}
370         WRITE CONFIG "  ],"
371         WRITE CONFIG ");"
372         WRITE CONFIG "our %target = ();"
373         WRITE CONFIG "our %disabled = ();"
374         WRITE CONFIG "our %withargs = ();"
375         WRITE CONFIG "our %unified_info = ();"
376         WRITE CONFIG "1;"
377         CLOSE CONFIG
378
379 check_INSTALLTOP :
380         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
381                 WRITE SYS$ERROR "INSTALLTOP should not be empty"
382         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
383                 EXIT %x10000002
384
385 # Helper targets #####################################################
386
387 # Developer targets ##################################################
388
389 debug_logicals :
390         SH LOGICAL/PROC openssl,internal,ossl_installroot
391         IF "$(DESTDIR)" .EQS. "" THEN -
392                 SH LOGICAL/PROC ossl_dataroot
393
394 # Building targets ###################################################
395
396 configdata.pm : {- join(" ", sourcefile("Configurations", "descrip.mms.tmpl"), sourcefile("Configurations", "common.tmpl")) -} $(SRCDIR)Configure $(SRCDIR)config.com {- join(" ", @{$config{build_infos}}) -}
397         @ WRITE SYS$OUTPUT "Detected changed: $?"
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         @ PIPE ( EXIT %X10000000 )
406
407 {-
408   use File::Basename;
409   use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/;
410
411   sub generatesrc {
412       my %args = @_;
413       my $generator = join(" ", @{$args{generator}});
414
415       if ($args{src} !~ /\.[sS]$/) {
416           return <<"EOF";
417 $args{src} : $args{generator}->[0]
418         \$(PERL) $generator > \$@
419 EOF
420       } else {
421           die "No method to generate assembler source present.\n";
422       }
423   }
424
425   sub src2obj {
426       my %args = @_;
427       my $obj = $args{obj};
428       my $deps = join(", -\n\t\t", @{$args{srcs}}, @{$args{deps}});
429
430       # Because VMS C isn't very good at combining a /INCLUDE path with
431       # #includes having a relative directory (like '#include "../foo.h"),
432       # the best choice is to move to the first source file's intended
433       # directory before compiling, and make sure to write the object file
434       # in the correct position (important when the object tree is other
435       # than the source tree).
436       my $forward = dirname($args{srcs}->[0]);
437       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
438       my $objd = abs2rel(rel2abs(dirname($obj)), rel2abs($forward));
439       my $objn = basename($obj);
440       my $srcs =
441           join(", ",
442                map { abs2rel(rel2abs($_), rel2abs($forward)) } @{$args{srcs}});
443       my $incs =
444           "/INCLUDE=(".join(",",
445                             map {
446                                file_name_is_absolute($_)
447                                ? $_ : catdir($backward,$_)
448                             } @{$args{incs}}).")";
449       my $before = $unified_info{before}->{$obj.".OBJ"} || "\@ !";
450       my $after = $unified_info{after}->{$obj.".OBJ"} || "\@ !";
451
452       return <<"EOF";
453 $obj.OBJ : $deps
454         ${before}
455         SET DEFAULT $forward
456         \$(CC) \$(CFLAGS)${incs} /MMS=(FILE=${objd}${objn}.tmp-MMS,TARGET=$obj.OBJ) /OBJECT=${objd}${objn}.OBJ /REPOSITORY=$backward $srcs
457         SET DEFAULT $backward
458         ${after}
459         \@ PIPE ( \$(PERL) -e "use File::Compare qw/compare_text/; my \$x = compare_text(""$obj.MMS"",""$obj.tmp-MMS""); exit(0x10000000 + (\$x == 0));" || -
460                  RENAME $obj.tmp-MMS $obj.mms )
461         \@ IF F\$SEARCH("$obj.tmp-MMS") .NES. "" THEN DELETE $obj.tmp-MMS;*
462         - PURGE $obj.OBJ
463 EOF
464   }
465   sub libobj2shlib {
466       my %args = @_;
467       my $lib = $args{lib};
468       my $shlib = $args{shlib};
469       my $libd = dirname($lib);
470       my $libn = basename($lib);
471       (my $mkdef_key = $libn) =~ s/^${osslprefix_q}lib//i;
472       my @deps = map {
473           $disabled{shared} ? $_.".OLB"
474               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
475       my $deps = join(", -\n\t\t", @deps);
476       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
477       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
478       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
479                                                "VMS", "engine.opt")),
480                                rel2abs($config{builddir}));
481       my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
482                                              "util", "mkdef.pl")),
483                              rel2abs($config{builddir}));
484       my $translatesyms_pl = abs2rel(rel2abs(catfile($config{sourcedir},
485                                                      "VMS", "translatesyms.pl")),
486                                      rel2abs($config{builddir}));
487       # The "[]" hack is because in .OPT files, each line inherits the
488       # previous line's file spec as default, so if no directory spec
489       # is present in the current line and the previous line has one that
490       # doesn't apply, you're in for a surprise.
491       my $write_opt =
492           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
493                              $x =~ s|(\.EXE)|$1/SHARE|;
494                              $x =~ s|(\.OLB)|$1/LIB|;
495                              "WRITE OPT_FILE \"$x\"" } @deps)
496           || "\@ !";
497       return <<"EOF";
498 $shlib.EXE : $lib.OLB $deps $ordinalsfile
499         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
500            \$(PERL) $mkdef_pl "$mkdef_key" "VMS" > $shlib.SYMVEC-tmp
501         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
502            \$(PERL) $translatesyms_pl \$(BUILDDIR)CXX\$DEMANGLER_DB. < $shlib.SYMVEC-tmp > $shlib.SYMVEC
503         OPEN/WRITE/SHARE=READ OPT_FILE $shlib.OPT
504         WRITE OPT_FILE "IDENTIFICATION=""V$config{version}"""
505         IF "$mkdef_key" .NES. "ssl" .AND. "$mkdef_key" .NES. "crypto" THEN -
506            TYPE $engine_opt /OUTPUT=OPT_FILE:
507         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
508            TYPE $shlib.SYMVEC /OUTPUT=OPT_FILE:
509         WRITE OPT_FILE "$lib.OLB/LIBRARY"
510         $write_opt ! Comment to protect from empty line
511         CLOSE OPT_FILE
512         LINK /MAP=$shlib.MAP /FULL/SHARE=$shlib.EXE $shlib.OPT/OPT \$(EX_LIBS)
513         - DELETE $shlib.SYMVEC;*
514         - PURGE $shlib.EXE,$shlib.OPT,$shlib.MAP
515 EOF
516   }
517   sub obj2dso {
518       my %args = @_;
519       my $lib = $args{lib};
520       my $libd = dirname($lib);
521       my $libn = basename($lib);
522       (my $libn_nolib = $libn) =~ s/^lib//;
523       my @objs = map { "$_.OBJ" } @{$args{objs}};
524       my @deps = map {
525           $disabled{shared} ? $_.".OLB"
526               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
527       my $deps = join(", -\n\t\t", @objs, @deps);
528       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
529       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
530                                                "VMS", "engine.opt")),
531                                rel2abs($config{builddir}));
532       # The "[]" hack is because in .OPT files, each line inherits the
533       # previous line's file spec as default, so if no directory spec
534       # is present in the current line and the previous line has one that
535       # doesn't apply, you're in for a surprise.
536       my $write_opt =
537           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
538                                  "WRITE OPT_FILE \"$x" } @objs).
539           "\"\n\t".
540           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
541                              $x =~ s|(\.EXE)|$1/SHARE|;
542                              $x =~ s|(\.OLB)|$1/LIB|;
543                              "WRITE OPT_FILE \"$x\"" } @deps)
544           || "\@ !";
545       return <<"EOF";
546 $lib.EXE : $deps
547         OPEN/WRITE/SHARE=READ OPT_FILE $lib.OPT
548         TYPE $engine_opt /OUTPUT=OPT_FILE:
549         $write_opt
550         CLOSE OPT_FILE
551         LINK /MAP=$lib.MAP /FULL/SHARE=$lib.EXE $lib.OPT/OPT \$(EX_LIBS)
552         - PURGE $lib.EXE,$lib.OPT,$lib.MAP
553 EOF
554   }
555   sub obj2lib {
556       my %args = @_;
557       my $lib = $args{lib};
558       my $objs = join(", -\n\t\t", map { $_.".OBJ" } (@{$args{objs}}));
559       my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib.OLB $_.OBJ" }
560                                     @{$args{objs}}));
561       return <<"EOF";
562 $lib.OLB : $objs
563         LIBRARY/CREATE/OBJECT $lib
564         $fill_lib
565         - PURGE $lib.OLB
566 EOF
567   }
568   sub obj2bin {
569       my %args = @_;
570       my $bin = $args{bin};
571       my $bind = dirname($bin);
572       my $binn = basename($bin);
573       my @objs = map { "$_.OBJ" } @{$args{objs}};
574       my @deps = map {
575           $disabled{shared} ? $_.".OLB"
576               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
577       my $deps = join(", -\n\t\t", @objs, @deps);
578       # The "[]" hack is because in .OPT files, each line inherits the
579       # previous line's file spec as default, so if no directory spec
580       # is present in the current line and the previous line has one that
581       # doesn't apply, you're in for a surprise.
582       my $write_opt =
583           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
584                                  "WRITE OPT_FILE \"$x" } @objs).
585           "\"\n\t".
586           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
587                              $x =~ s|(\.EXE)|$1/SHARE|;
588                              $x =~ s|(\.OLB)|$1/LIB|;
589                              "WRITE OPT_FILE \"$x\"" } @deps)
590           || "\@ !";
591       return <<"EOF";
592 $bin.EXE : $deps
593         OPEN/WRITE/SHARE=READ OPT_FILE $bin.OPT
594         $write_opt
595         CLOSE OPT_FILE
596         LINK/EXEC=$bin.EXE \$(LDFLAGS) $bin.OPT/OPT \$(EX_LIBS)
597         - PURGE $bin.EXE,$bin.OPT
598 EOF
599   }
600   sub in2script {
601       my %args = @_;
602       my $script = $args{script};
603       return "" if grep { $_ eq $script } @{$args{sources}}; # No overwrite!
604       my $sources = join(" ", @{$args{sources}});
605       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
606                                            "util", "dofile.pl")),
607                            rel2abs($config{builddir}));
608       return <<"EOF";
609 $script : $sources
610         \$(PERL) "-I\$(BUILDDIR)" "-Mconfigdata" $dofile -
611             "-o$target{build_file}" $sources > $script
612         SET FILE/PROT=(S:RWED,O:RWED,G:RE,W:RE) $script
613         PURGE $script
614 EOF
615   }
616   ""    # Important!  This becomes part of the template result.
617 -}