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