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