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