Small rename fest in unified, obj2dynlib -> obj2dso
[openssl.git] / Configurations / descrip.mms.tmpl
1 ## descrip.mms to build OpenSSL on OpenVMS
2 ##
3 ## {- join("\n## ", @autowarntext) -}
4 {-
5   use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/;
6
7   # Our prefix, claimed when speaking with the VSI folks Tuesday
8   # January 26th 2016
9   our $osslprefix = 'OSSL$';
10   (our $osslprefix_q = $osslprefix) =~ s/\$/\\\$/;
11
12   our $sourcedir = $config{sourcedir};
13   our $builddir = $config{builddir};
14   sub sourcefile {
15       catfile($sourcedir, @_);
16   }
17   sub buildfile {
18       catfile($builddir, @_);
19   }
20   sub sourcedir {
21       catdir($sourcedir, @_);
22   }
23   sub builddir {
24       catdir($builddir, @_);
25   }
26   sub tree {
27       (my $x = shift) =~ s|\]$|...]|;
28       $x
29   }
30   sub move {
31       my $f = catdir(@_);
32       my $b = abs2rel(rel2abs("."),rel2abs($f));
33       $sourcedir = catdir($b,$sourcedir)
34           if !file_name_is_absolute($sourcedir);
35       $builddir = catdir($b,$builddir)
36           if !file_name_is_absolute($builddir);
37       "";
38   }
39
40   # This is a horrible hack, but is needed because recursive inclusion of files
41   # in different directories does not work well with HP C.
42   my $sd = sourcedir("crypto", "async", "arch");
43   foreach (grep /\[\.crypto\.async\.arch\].*\.o$/, keys %{$unified_info{sources}}) {
44       (my $x = $_) =~ s|\.o$|.OBJ|;
45       $unified_info{before}->{$x}
46           = qq(arch = F\$PARSE("$sd","A.;",,,"SYNTAX_ONLY") - "A.;"
47         define arch 'arch');
48       $unified_info{after}->{$x}
49           = qq(deassign arch);
50   }
51   my $sd1 = sourcedir("ssl","record");
52   my $sd2 = sourcedir("ssl","statem");
53   $unified_info{before}->{"[.crypto.ct]ct_lib.OBJ"}
54       = $unified_info{before}->{"[.test]heartbeat_test.OBJ"}
55       = $unified_info{before}->{"[.test]ssltest.OBJ"}
56       = qq(record = F\$PARSE("$sd1","A.;",,,"SYNTAX_ONLY") - "A.;"
57         define record 'record'
58         statem = F\$PARSE("$sd2","A.;",,,"SYNTAX_ONLY") - "A.;"
59         define statem 'statem');
60   $unified_info{after}->{"[.crypto.ct]ct_lib.OBJ"}
61       = $unified_info{after}->{"[.test]heartbeat_test.OBJ"}
62       = $unified_info{after}->{"[.test]ssltest.OBJ"}
63       = qq(deassign statem
64         deassign record);
65   foreach (grep /^\[\.ssl\.(?:record|statem)\].*\.o$/, keys %{$unified_info{sources}}) {
66       (my $x = $_) =~ s|\.o$|.OBJ|;
67       $unified_info{before}->{$x}
68           = qq(record = F\$PARSE("$sd1","A.;",,,"SYNTAX_ONLY") - "A.;"
69         define record 'record'
70         statem = F\$PARSE("$sd2","A.;",,,"SYNTAX_ONLY") - "A.;"
71         define statem 'statem');
72       $unified_info{after}->{$x}
73           = qq(deassign statem
74         deassign record);
75   }
76   #use Data::Dumper;
77   #print STDERR "DEBUG: before:\n", Dumper($unified_info{before});
78   #print STDERR "DEBUG: after:\n", Dumper($unified_info{after});
79   "";
80 -}
81 PLATFORM={- $config{target} -}
82 OPTIONS={- $config{options} -}
83 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
84 SRCDIR={- $config{sourcedir} -}
85 BUILDDIR={- $config{builddir} -}
86
87 VERSION={- $config{version} -}
88 MAJOR={- $config{major} -}
89 MINOR={- $config{minor} -}
90 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
91 SHLIB_VERSION_HISTORY={- $config{shlib_version_history} -}
92 SHLIB_MAJOR={- $config{shlib_major} -}
93 SHLIB_MINOR={- $config{shlib_minor} -}
94 SHLIB_TARGET={- $target{shared_target} -}
95
96 EXE_EXT=.EXE
97 LIB_EXT=.OLB
98 SHLIB_EXT=.EXE
99 OBJ_EXT=.OBJ
100 DEP_EXT=.MMS
101
102 LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @{$unified_info{libraries}}) -}
103 SHLIBS={- join(" ", map { $_."\$(SHLIB_EXT)" } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) -}
104 ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{engines}}) -}
105 PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } grep { !m|^\[\.test\]| } @{$unified_info{programs}}) -}
106 TESTPROGS={- join(", ", map { "-\n\t".$_.".EXE" } grep { m|^\[\.test\]| } @{$unified_info{programs}}) -}
107 SCRIPTS={- join(", ", map { "-\n\t".$_ } @{$unified_info{scripts}}) -}
108 DEPS={- our @deps = map { (my $x = $_) =~ s|\.o$|\$(DEP_EXT)|; $x; }
109                     grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
110                     keys %{$unified_info{sources}};
111         join(", ", map { "-\n\t".$_ } @deps); -}
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(",", @{$config{defines}},"OPENSSLDIR=\"\"\"\$(OPENSSLDIR)\"\"\"","ENGINESDIR=\"\"\"\$(ENGINESDIR)\"\"\"") -}) {- $config{cflags} -}
132 DEPFLAG= /DEFINE=({- join(",", @{$config{depdefines}}) -})
133 LDFLAGS= {- $config{lflags} -}
134 EX_LIBS= {- $config{ex_libs} ? ",".$config{ex_libs} : "" -}
135
136 PERL={- $config{perl} -}
137
138 # We let the C compiler driver to take care of .s files. This is done in
139 # order to be excused from maintaining a separate set of architecture
140 # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC
141 # gcc, then the driver will automatically translate it to -xarch=v8plus
142 # and pass it down to assembler.
143 AS={- $target{as} -}
144 ASFLAG={- $target{asflags} -}
145
146 # .FIRST and .LAST are special targets with MMS and MMK.
147 # The defines in there are for C.  includes that look like
148 # this:
149 #
150 #    #include <openssl/foo.h>
151 #    #include "internal/bar.h"
152 #
153 # will use the logical names to find the files.  Expecting
154 # DECompHP C to find files in subdirectories of whatever was
155 # given with /INCLUDE is a fantasy, unfortunately.
156 NODEBUG=@
157 .FIRST :
158         $(NODEBUG) openssl_inc1 = F$PARSE("[.include.openssl]","A.;",,,"syntax_only") - "A.;"
159         $(NODEBUG) openssl_inc2 = F$PARSE("{- catdir($config{sourcedir},"[.include.openssl]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
160         $(NODEBUG) internal_inc1 = F$PARSE("[.crypto.include.internal]","A.;",,,"SYNTAX_ONLY") - "A.;"
161         $(NODEBUG) internal_inc2 = F$PARSE("{- catdir($config{sourcedir},"[.include.internal]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
162         $(NODEBUG) internal_inc3 = F$PARSE("{- catdir($config{sourcedir},"[.crypto.include.internal]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
163         $(NODEBUG) DEFINE openssl 'openssl_inc1','openssl_inc2'
164         $(NODEBUG) DEFINE internal 'internal_inc1','internal_inc2','internal_inc3'
165         $(NODEBUG) staging_dir = "$(DESTDIR)"
166         $(NODEBUG) IF staging_dir .NES. "" THEN -
167                 staging_dir = F$PARSE("A.;",staging_dir,"[]",,"SYNTAX_ONLY") - "A.;"
168         $(NODEBUG) !
169         $(NODEBUG) ! Installation logical names
170         $(NODEBUG) !
171         $(NODEBUG) installtop_dev = F$PARSE(staging_dir,"$(INSTALLTOP)",,"DEVICE","SYNTAX_ONLY")
172         $(NODEBUG) ! Because there are no routines to merge directories, we have to
173         $(NODEBUG) ! do it ourselves
174         $(NODEBUG) IF staging_dir .NES. "" THEN -
175                 staging_dir = F$PARSE(staging_dir,"[000000]",,"DIRECTORY","SYNTAX_ONLY")
176         $(NODEBUG) installtop_dir = F$PARSE("$(INSTALLTOP)","[000000]",,"DIRECTORY","SYNTAX_ONLY")
177         $(NODEBUG) IF staging_dir .NES. "" .AND. staging_dir .NES. "[000000]" THEN -
178                 installtop_dir = staging_dir - "]" + "." + (installtop_dir - "[")
179         $(NODEBUG) installtop_dir = installtop_dir - "]" + ".]"
180         $(NODEBUG) DEFINE ossl_installroot 'installtop_dev''installtop_dir'
181         $(NODEBUG) !
182         $(NODEBUG) datatop = F$PARSE("$(OPENSSLDIR)","[000000]A.;",,,"SYNTAX_ONLY") -
183                 - "]A.;" + ".]"
184         $(NODEBUG) IF "$(DESTDIR)" .EQS. "" THEN -
185                 DEFINE ossl_dataroot 'datatop'
186         $(NODEBUG) !
187         $(NODEBUG) ! Figure out the architecture
188         $(NODEBUG) !
189         $(NODEBUG) arch == f$edit( f$getsyi( "arch_name"), "upcase")
190         $(NODEBUG) !
191         $(NODEBUG) ! Set up logical names for the libraries, so LINK and
192         $(NODEBUG) ! running programs can use them.
193         $(NODEBUG) !
194         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEFINE ".uc($_)." 'F\$ENV(\"DEFAULT\")'".uc($_)."\$(SHLIB_EXT)" } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) || "!" -}
195
196 .LAST :
197         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEASSIGN ".uc($_) } map { $unified_info{sharednames}->{$_} || () } @{$unified_info{libraries}}) || "!" -}
198         $(NODEBUG) IF "$(DESTDIR)" .EQS. "" THEN DEASSIGN ossl_dataroot
199         $(NODEBUG) DEASSIGN ossl_installroot
200         $(NODEBUG) DEASSIGN internal
201         $(NODEBUG) DEASSIGN openssl
202 .DEFAULT :
203         @ ! MMS cannot handle no actions...
204
205 # The main targets ###################################################
206
207 all : configdata.pm, -
208       build_libs_nodep, build_engines_nodep, build_apps_nodep, -
209       depend
210
211 build_libs : configdata.pm, build_libs_nodep, depend
212 build_libs_nodep : $(LIBS)
213 build_engines : configdata.pm, build_engines_nodep, depend
214 build_engines_nodep : $(ENGINES)
215 build_apps : configdata.pm, build_apps_nodep, depend
216 build_apps_nodep : $(PROGRAMS), $(SCRIPTS)
217 build_tests : configdata.pm, build_tests_nodep, depend
218 build_tests_nodep : $(TESTPROGS)
219
220 test tests : configdata.pm, -
221              build_apps_nodep, build_engines_nodep, build_tests_nodep, -
222              depend, rehash
223         SET DEFAULT [.test]{- move("test") -}
224         DEFINE SRCTOP {- sourcedir() -}
225         DEFINE BLDTOP {- builddir() -}
226         $(PERL) {- sourcefile("test", "run_tests.pl") -} $(TESTS)
227         DEASSIGN BLDTOP
228         DEASSIGN SRCTOP
229         SET DEFAULT [-]{- move("..") -}
230
231 list-tests :
232         @ TOP=$(SRCDIR) PERL=$(PERL) $(PERL) {- catfile($config{sourcedir},"test", "run_tests.pl") -} list
233
234 # Because VMS wants the generation number (or *) to delete files, we can't
235 # use $(LIBS), $(PROGRAMS) and $(TESTPROGS) directly.
236 libclean :
237         - DELETE []OSSL$LIB*.OLB;*,OSSL$LIB*.LIS;*
238         - DELETE [.crypto...]*.OBJ;*,*.LIS;*
239         - DELETE [.ssl...]*.OBJ;*,*.LIS;*
240         - DELETE [.engines...]*.OBJ;*,*.LIS;*
241         - DELETE []CXX$DEMANGLER_DB.;*
242
243 install : install_sw install_docs
244         @ WRITE SYS$OUTPUT ""
245         @ WRITE SYS$OUTPUT "######################################################################"
246         @ WRITE SYS$OUTPUT ""
247         @ WRITE SYS$OUTPUT "Installation complete"
248         @ WRITE SYS$OUTPUT ""
249         @ IF "$(DESTDIR)" .NES. "" THEN EXIT 1
250         @ WRITE SYS$OUTPUT "Run @$(INSTALLTOP)openssl_startup to set up logical names"
251         @ WRITE SYS$OUTPUT "then run @$(INSTALLTOP)openssl_setup to define commands"
252         @ WRITE SYS$OUTPUT ""
253
254 uninstall : uninstall_docs uninstall_sw
255
256 clean : libclean
257         - DELETE []OSSL$LIB*.EXE;*,OSSL$LIB*.MAP;*,OSSL$LIB*.OPT;*
258         - DELETE [.engines...]LIB*.EXE;*,LIB*.MAP;*,LIB*.OPT;*
259         - DELETE [.apps]*.EXE;*,*.MAP;*,*.OPT;*
260         - DELETE [.apps]*.OBJ;*,*.LIS;*
261         - DELETE [.test]*.EXE;*,*.MAP;*,*.OPT;*
262         - DELETE [.test]*.OBJ;*,*.LIS;*
263         - DELETE [.test]*.LOG;*
264         - DELETE []*.MAP;*
265
266 depend : descrip.mms
267 descrip.mms : FORCE
268         @ $(PERL) -pe "if (/^# DO NOT DELETE.*/) { exit(0); }" -
269                 < descrip.mms > descrip.mms-new
270         @ OPEN/APPEND DESCRIP descrip.mms-new
271         @ WRITE DESCRIP "# DO NOT DELETE THIS LINE -- make depend depends on it."
272         {- join("\n\t", map { "\@ IF F\$SEARCH(\"$_\") .NES. \"\" THEN TYPE $_ /OUTPUT=DESCRIP:" } @deps); -}
273         @ CLOSE DESCRIP
274         @ PIPE ( $(PERL) -e "use File::Compare qw/compare_text/; my $x = compare_text(""descrip.mms"",""descrip.mms-new""); exit(0x10000000 + ($x == 0));" || -
275                  RENAME descrip.mms-new descrip.mms )
276         @ IF F$SEARCH("descrip.mms-new") .NES. "" THEN DELETE descrip.mms-new;*
277         -@ SPAWN/OUTPUT=NLA0: PURGE/NOLOG descrip.mms
278
279 # Install helper targets #############################################
280
281 install_sw : all install_dev install_engines install_runtime install_config
282
283 uninstall_sw : uninstall_dev uninstall_engines uninstall_runtime uninstall_config
284
285 install_docs : install_man_docs install_html_docs
286
287 uninstall_docs : uninstall_man_docs uninstall_html_docs
288
289 install_dev : check_INSTALLTOP
290         @ WRITE SYS$OUTPUT "*** Installing development files"
291         @ ! Install header files
292         CREATE/DIR ossl_installroot:[include.openssl]
293         COPY/PROT=W:R openssl:*.h ossl_installroot:[include.openssl]
294         @ ! Install libraries
295         CREATE/DIR ossl_installroot:[LIB.'arch']
296         {- join("\n        ",
297                 map { "COPY/PROT=W:R $_.OLB ossl_installroot:[LIB.'arch']" }
298                 @{$unified_info{libraries}}) -}
299         @ {- output_off() if $config{no_shared}; "" -} !
300         {- join("\n        ",
301                 map { "COPY/PROT=W:RE $_.EXE ossl_installroot:[LIB.'arch']" }
302                 map { $unified_info{sharednames}->{$_} || () }
303                 @{$unified_info{libraries}}) -}
304         @ {- output_on() if $config{no_shared}; "" -} !
305
306 install_runtime : check_INSTALLTOP
307         @ WRITE SYS$OUTPUT "*** Installing runtime files"
308         @ ! Install the main program
309         CREATE/DIR ossl_installroot:[EXE.'arch']
310         COPY/PROT=W:RE [.APPS]openssl.EXE ossl_installroot:[EXE.'arch']
311         @ ! Install scripts
312         CREATE/DIR ossl_installroot:[EXE]
313         COPY/PROT=W:RE [.APPS]CA.pl ossl_installroot:[EXE]
314         COPY/PROT=W:RE [.TOOLS]c_rehash. ossl_installroot:[EXE]c_rehash.pl
315         @ ! Install configuration file
316         COPY/PROT=W:RE {- sourcefile("apps", "openssl-vms.cnf") -} -
317                 ossl_installroot:[000000]openssl.cnf
318
319 install_engines : check_INSTALLTOP
320         @ {- output_off() if $config{no_shared}; "" -} !
321         @ WRITE SYS$OUTPUT "*** Installing engines"
322         CREATE/DIR ossl_installroot:[ENGINES.'arch']
323         COPY/PROT=W:RE [.ENGINES]*.EXE ossl_installroot:[ENGINES.'arch']
324         @ {- output_on() if $config{no_shared}; "" -} !
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);"
361         WRITE CONFIG "our %config = ("
362         WRITE CONFIG "  target => '{- $config{target} -}',"
363         WRITE CONFIG "  version => '$(MAJOR).$(MINOR)',"
364         WRITE CONFIG "  no_shared => '","{- $config{no_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 %withargs = ();"
374         WRITE CONFIG "our %unified_info = ();"
375         WRITE CONFIG "1;"
376         CLOSE CONFIG
377
378 check_INSTALLTOP :
379         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
380                 WRITE SYS$ERROR "INSTALLTOP should not be empty"
381         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
382                 EXIT %x10000002
383
384 # Helper targets #####################################################
385
386 rehash : copy-certs, build_apps_nodep
387         !MCR [.apps]openssl.exe rehash {- builddir("certs", "demo") -}
388         $(PERL) [.tools]c_rehash. [.certs.demo]
389
390 copy-certs :
391         @ IF F$SEARCH("{- buildfile("certs.dir") -}") .EQS. "" THEN -
392              CREATE/DIR {- builddir("certs") -}
393         -@ IF "{- sourcedir("certs") -}" .NES. "{- builddir("certs") -}" THEN -
394              COPY {- tree(sourcedir("certs")) -}*.* {- tree(builddir("certs")) -}
395
396 # Developer targets ##################################################
397
398 debug_logicals :
399         SH LOGICAL/PROC openssl,internal,ossl_installroot
400         IF "$(DESTDIR)" .EQS. "" THEN -
401                 SH LOGICAL/PROC ossl_dataroot
402
403 # Building targets ###################################################
404
405 configdata.pm : {- sourcefile("Configurations", "descrip.mms.tmpl") -} $(SRCDIR)Configure ! $(SRCDIR)config.com
406         @ WRITE SYS$OUTPUT "Detected changed: $?"
407         @ WRITE SYS$OUTPUT "Reconfiguring..."
408         perl $(SRCDIR)Configure reconf
409         @ WRITE SYS$OUTPUT "*************************************************"
410         @ WRITE SYS$OUTPUT "***                                           ***"
411         @ WRITE SYS$OUTPUT "***   Please run the same mms command again   ***"
412         @ WRITE SYS$OUTPUT "***                                           ***"
413         @ WRITE SYS$OUTPUT "*************************************************"
414         @ PIPE ( EXIT %X10000000 )
415
416 {-
417   use File::Basename;
418   use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/;
419   sub src2obj {
420       my %args = @_;
421       my $obj = $args{obj};
422       my $deps = join(", -\n\t\t", @{$args{srcs}}, @{$args{deps}});
423
424       # Because VMS C isn't very good at combining a /INCLUDE path with
425       # #includes having a relative directory (like '#include "../foo.h"),
426       # the best choice is to move to the first source file's intended
427       # directory before compiling, and make sure to write the object file
428       # in the correct position (important when the object tree is other
429       # than the source tree).
430       my $forward = dirname($args{srcs}->[0]);
431       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
432       my $objd = abs2rel(rel2abs(dirname($obj)), rel2abs($forward));
433       my $objn = basename($obj);
434       my $srcs =
435           join(", ",
436                map { abs2rel(rel2abs($_), rel2abs($forward)) } @{$args{srcs}});
437       my $incs =
438           "/INCLUDE=(".join(",",
439                             map {
440                                file_name_is_absolute($_)
441                                ? $_ : catdir($backward,$_)
442                             } @{$args{incs}}).")";
443       my $before = $unified_info{before}->{$obj.".OBJ"} || "\@ !";
444       my $after = $unified_info{after}->{$obj.".OBJ"} || "\@ !";
445
446       return <<"EOF";
447 $obj.MMS : $deps
448         ${before}
449         SET DEFAULT $forward
450         \$(CC) \$(CFLAGS)${incs} /MMS=(FILE=${objd}${objn}.MMS,TARGET=$obj.OBJ) /NOOBJECT $srcs
451         SET DEFAULT $backward
452         ${after}
453         - PURGE $obj.MMS
454 $obj.OBJ : $obj.MMS
455         ${before}
456         SET DEFAULT $forward
457         \$(CC) \$(CFLAGS)${incs} /OBJECT=${objd}${objn}.OBJ /REPOSITORY=$backward $srcs
458         SET DEFAULT $backward
459         ${after}
460         - PURGE $obj.OBJ
461 EOF
462   }
463   sub libobj2shlib {
464       my %args = @_;
465       my $lib = $args{lib};
466       my $shlib = $args{shlib};
467       my $libd = dirname($lib);
468       my $libn = basename($lib);
469       (my $mkdef_key = $libn) =~ s/^${osslprefix_q}lib//i;
470       my @deps = map {
471           $config{no_shared} ? $_.".OLB"
472               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
473       my $deps = join(", -\n\t\t", @deps);
474       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
475       my $ordinalsfile = defined($args{ordinals}) ? $args{ordinals}->[1] : "";
476       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
477                                                "VMS", "engine.opt")),
478                                rel2abs($config{builddir}));
479       my $mkdef_pl = abs2rel(rel2abs(catfile($config{sourcedir},
480                                              "util", "mkdef.pl")),
481                              rel2abs($config{builddir}));
482       my $translatesyms_pl = abs2rel(rel2abs(catfile($config{sourcedir},
483                                                      "VMS", "translatesyms.pl")),
484                                      rel2abs($config{builddir}));
485       # The "[]" hack is because in .OPT files, each line inherits the
486       # previous line's file spec as default, so if no directory spec
487       # is present in the current line and the previous line has one that
488       # doesn't apply, you're in for a surprise.
489       my $write_opt =
490           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
491                              $x =~ s|(\.EXE)|$1/SHARE|;
492                              $x =~ s|(\.LIB)|$1/LIB|;
493                              "WRITE OPT_FILE \"$x\"" } @deps)
494           || "\@ !";
495       return <<"EOF";
496 $shlib.EXE : $lib.OLB $deps $ordinalsfile
497         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
498            \$(PERL) $mkdef_pl "$mkdef_key" "VMS" > $shlib.SYMVEC-tmp
499         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
500            \$(PERL) $translatesyms_pl \$(BUILDDIR)CXX\$DEMANGLER_DB. < $shlib.SYMVEC-tmp > $shlib.SYMVEC
501         OPEN/WRITE/SHARE=READ OPT_FILE $shlib.OPT
502         WRITE OPT_FILE "IDENTIFICATION=""V$config{version}"""
503         IF "$mkdef_key" .NES. "ssl" .AND. "$mkdef_key" .NES. "crypto" THEN -
504            TYPE $engine_opt /OUTPUT=OPT_FILE:
505         IF "$mkdef_key" .EQS. "ssl" .OR. "$mkdef_key" .EQS. "crypto" THEN -
506            TYPE $shlib.SYMVEC /OUTPUT=OPT_FILE:
507         WRITE OPT_FILE "$lib.OLB/LIBRARY"
508         $write_opt ! Comment to protect from empty line
509         CLOSE OPT_FILE
510         LINK /MAP=$shlib.MAP /FULL/SHARE=$shlib.EXE $shlib.OPT/OPT \$(EX_LIBS)
511         - DELETE $shlib.SYMVEC;*
512         - PURGE $shlib.EXE,$shlib.OPT,$shlib.MAP
513 EOF
514   }
515   sub obj2dso {
516       my %args = @_;
517       my $lib = $args{lib};
518       my $libd = dirname($lib);
519       my $libn = basename($lib);
520       (my $libn_nolib = $libn) =~ s/^lib//;
521       my @objs = map { "$_.OBJ" } @{$args{objs}};
522       my @deps = map {
523           $config{no_shared} ? $_.".OLB"
524               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
525       my $deps = join(", -\n\t\t", @objs, @deps);
526       my $shlib_target = $config{no_shared} ? "" : $target{shared_target};
527       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
528                                                "VMS", "engine.opt")),
529                                rel2abs($config{builddir}));
530       # The "[]" hack is because in .OPT files, each line inherits the
531       # previous line's file spec as default, so if no directory spec
532       # is present in the current line and the previous line has one that
533       # doesn't apply, you're in for a surprise.
534       my $write_opt =
535           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
536                                  "WRITE OPT_FILE \"$x" } @objs).
537           "\"\n\t".
538           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
539                              $x =~ s|(\.EXE)|$1/SHARE|;
540                              $x =~ s|(\.LIB)|$1/LIB|;
541                              "WRITE OPT_FILE \"$x\"" } @deps)
542           || "\@ !";
543       return <<"EOF";
544 $lib.EXE : $deps
545         OPEN/WRITE/SHARE=READ OPT_FILE $lib.OPT
546         TYPE $engine_opt /OUTPUT=OPT_FILE:
547         $write_opt
548         CLOSE OPT_FILE
549         LINK /MAP=$lib.MAP /FULL/SHARE=$lib.EXE $lib.OPT/OPT \$(EX_LIBS)
550         - PURGE $lib.EXE,$lib.OPT,$lib.MAP
551 EOF
552   }
553   sub obj2lib {
554       my %args = @_;
555       my $lib = $args{lib};
556       my $objs = join(", -\n\t\t", map { $_.".OBJ" } (@{$args{objs}}));
557       my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib.OLB $_.OBJ" }
558                                     @{$args{objs}}));
559       return <<"EOF";
560 $lib.OLB : $objs
561         LIBRARY/CREATE/OBJECT $lib
562         $fill_lib
563         - PURGE $lib.OLB
564 EOF
565   }
566   sub obj2bin {
567       my %args = @_;
568       my $bin = $args{bin};
569       my $bind = dirname($bin);
570       my $binn = basename($bin);
571       my @objs = map { "$_.OBJ" } @{$args{objs}};
572       my @deps = map {
573           $config{no_shared} ? $_.".OLB"
574               : $unified_info{sharednames}->{$_}.".EXE"; } @{$args{deps}};
575       my $deps = join(", -\n\t\t", @objs, @deps);
576       # The "[]" hack is because in .OPT files, each line inherits the
577       # previous line's file spec as default, so if no directory spec
578       # is present in the current line and the previous line has one that
579       # doesn't apply, you're in for a surprise.
580       my $write_opt =
581           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
582                                  "WRITE OPT_FILE \"$x" } @objs).
583           "\"\n\t".
584           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
585                              $x =~ s|(\.EXE)|$1/SHARE|;
586                              $x =~ s|(\.OLB)|$1/LIB|;
587                              "WRITE OPT_FILE \"$x\"" } @deps)
588           || "\@ !";
589       return <<"EOF";
590 $bin.EXE : $deps
591         OPEN/WRITE/SHARE=READ OPT_FILE $bin.OPT
592         $write_opt
593         CLOSE OPT_FILE
594         LINK/EXEC=$bin.EXE \$(LDFLAGS) $bin.OPT/OPT \$(EX_LIBS)
595         - PURGE $bin.EXE,$bin.OPT
596 EOF
597   }
598   sub in2script {
599       my %args = @_;
600       my $script = $args{script};
601       return "" if grep { $_ eq $script } @{$args{sources}}; # No overwrite!
602       my $sources = join(" ", @{$args{sources}});
603       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
604                                            "util", "dofile.pl")),
605                            rel2abs($config{builddir}));
606       return <<"EOF";
607 $script : $sources
608         \$(PERL) "-I\$(BUILDDIR)" "-Mconfigdata" $dofile -
609             "-o$target{build_file}" $sources > $script
610         SET FILE/PROT=(S:RWED,O:RWED,G:RE,W:RE) $script
611         PURGE $script
612 EOF
613   }
614   ""    # Important!  This becomes part of the template result.
615 -}