Build file templates: be less verbose when reconfiguring
[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 $sover_dirname = sprintf "%02d%02d", split(/\./, $config{shlib_version_number});
13   our $osslver = sprintf "%02d%02d", split(/\./, $config{version});
14
15   our $sourcedir = $config{sourcedir};
16   our $builddir = $config{builddir};
17   sub sourcefile {
18       catfile($sourcedir, @_);
19   }
20   sub buildfile {
21       catfile($builddir, @_);
22   }
23   sub sourcedir {
24       catdir($sourcedir, @_);
25   }
26   sub builddir {
27       catdir($builddir, @_);
28   }
29   sub tree {
30       (my $x = shift) =~ s|\]$|...]|;
31       $x
32   }
33   sub move {
34       my $f = catdir(@_);
35       my $b = abs2rel(rel2abs("."),rel2abs($f));
36       $sourcedir = catdir($b,$sourcedir)
37           if !file_name_is_absolute($sourcedir);
38       $builddir = catdir($b,$builddir)
39           if !file_name_is_absolute($builddir);
40       "";
41   }
42
43   # Because we need to make two computations of these data,
44   # we store them in arrays for reuse
45   our @libs =
46       map { (my $x = $_) =~ s/\.a$//; $x }
47       @{$unified_info{libraries}};
48   our @shlibs =
49       map { $unified_info{sharednames}->{$_} || () }
50       grep(!/\.a$/, @{$unified_info{libraries}});
51   our @install_libs =
52       map { (my $x = $_) =~ s/\.a$//; $x }
53       @{$unified_info{install}->{libraries}};
54   our @install_shlibs =
55       map { $unified_info{sharednames}->{$_} || () }
56       grep(!/\.a$/, @{$unified_info{install}->{libraries}});
57   our @generated = ( ( map { (my $x = $_) =~ s|\.[sS]$|\.asm|; $x }
58                        grep { defined $unified_info{generate}->{$_} }
59                        map { @{$unified_info{sources}->{$_}} }
60                        grep { /\.o$/ } keys %{$unified_info{sources}} ),
61                      ( grep { /\.h$/ } keys %{$unified_info{generate}} ) );
62
63   # This is a horrible hack, but is needed because recursive inclusion of files
64   # in different directories does not work well with HP C.
65   my $sd = sourcedir("crypto", "async", "arch");
66   foreach (grep /\[\.crypto\.async\.arch\].*\.o$/, keys %{$unified_info{sources}}) {
67       (my $x = $_) =~ s|\.o$|.OBJ|;
68       $unified_info{before}->{$x}
69           = qq(arch_include = F\$PARSE("$sd","A.;",,,"SYNTAX_ONLY") - "A.;"
70         define arch 'arch_include');
71       $unified_info{after}->{$x}
72           = qq(deassign arch);
73   }
74   my $sd1 = sourcedir("ssl","record");
75   my $sd2 = sourcedir("ssl","statem");
76   my @ssl_locl_users = grep(/^\[\.(?:ssl\.(?:record|statem)|test)\].*\.o$/,
77                             keys %{$unified_info{sources}});
78   foreach (@ssl_locl_users) {
79       (my $x = $_) =~ s|\.o$|.OBJ|;
80       $unified_info{before}->{$x}
81           = qq(record_include = F\$PARSE("$sd1","A.;",,,"SYNTAX_ONLY") - "A.;"
82         define record 'record_include'
83         statem_include = F\$PARSE("$sd2","A.;",,,"SYNTAX_ONLY") - "A.;"
84         define statem 'statem_include');
85       $unified_info{after}->{$x}
86           = qq(deassign statem
87         deassign record);
88   }
89   # This makes sure things get built in the order they need
90   # to. You're welcome.
91   sub dependmagic {
92       my $target = shift;
93
94       return "$target : build_generated\n\t\pipe \$(MMS) \$(MMSQUALIFIERS) depend && \$(MMS) \$(MMSQUALIFIERS) _$target\n_$target";
95   }
96   #use Data::Dumper;
97   #print STDERR "DEBUG: before:\n", Dumper($unified_info{before});
98   #print STDERR "DEBUG: after:\n", Dumper($unified_info{after});
99   "";
100 -}
101 PLATFORM={- $config{target} -}
102 OPTIONS={- $config{options} -}
103 CONFIGURE_ARGS=({- join(", ",quotify_l(@{$config{perlargv}})) -})
104 SRCDIR={- $config{sourcedir} -}
105 BLDDIR={- $config{builddir} -}
106
107 # Allow both V and VERBOSE to indicate verbosity.  This only applies
108 # to testing.
109 VERBOSE=$(V)
110
111 VERSION={- $config{version} -}
112 MAJOR={- $config{major} -}
113 MINOR={- $config{minor} -}
114 SHLIB_VERSION_NUMBER={- $config{shlib_version_number} -}
115 SHLIB_VERSION_HISTORY={- $config{shlib_version_history} -}
116 SHLIB_MAJOR={- $config{shlib_major} -}
117 SHLIB_MINOR={- $config{shlib_minor} -}
118 SHLIB_TARGET={- $target{shared_target} -}
119
120 EXE_EXT=.EXE
121 LIB_EXT=.OLB
122 SHLIB_EXT=.EXE
123 OBJ_EXT=.OBJ
124 DEP_EXT=.D
125
126 LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @libs) -}
127 SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @shlibs) -}
128 ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{engines}}) -}
129 PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{programs}}) -}
130 SCRIPTS={- join(", ", map { "-\n\t".$_ } @{$unified_info{scripts}}) -}
131 {- output_off() if $disabled{makedepend}; "" -}
132 DEPS={- our @deps = map { (my $x = $_) =~ s|\.o$|\$(DEP_EXT)|; $x; }
133                     grep { $unified_info{sources}->{$_}->[0] =~ /\.c$/ }
134                     keys %{$unified_info{sources}};
135         join(", ", map { "-\n\t".$_ } @deps); -}
136 {- output_on() if $disabled{makedepend}; "" -}
137 GENERATED_MANDATORY={- join(", ", map { "-\n\t".$_ } @{$unified_info{depends}->{""}} ) -}
138 GENERATED={- join(", ", map { "-\n\t".$_ } @generated) -}
139
140 INSTALL_LIBS={- join(", ", map { "-\n\t".$_.".OLB" } @install_libs) -}
141 INSTALL_SHLIBS={- join(", ", map { "-\n\t".$_.".EXE" } @install_shlibs) -}
142 INSTALL_ENGINES={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{install}->{engines}}) -}
143 INSTALL_PROGRAMS={- join(", ", map { "-\n\t".$_.".EXE" } @{$unified_info{install}->{programs}}) -}
144 {- output_off() if $disabled{apps}; "" -}
145 BIN_SCRIPTS=[.tools]c_rehash.pl
146 MISC_SCRIPTS=[.apps]CA.pl, [.apps]tsget.pl
147 {- output_on() if $disabled{apps}; "" -}
148
149 APPS_OPENSSL={- use File::Spec::Functions;
150                 catfile("apps","openssl") -}
151
152 # DESTDIR is for package builders so that they can configure for, say,
153 # SYS$COMMON:[OPENSSL] and yet have everything installed in STAGING:[USER].
154 # In that case, configure with --prefix=SYS$COMMON:[OPENSSL] and then run
155 # MMS with /MACROS=(DESTDIR=STAGING:[USER]).  The result will end up in
156 # STAGING:[USER.OPENSSL].
157 # Normally it is left empty.
158 DESTDIR=
159
160 # Do not edit this manually. Use Configure --prefix=DIR to change this!
161 INSTALLTOP={- our $installtop =
162                   catdir($config{prefix}) || "SYS\$COMMON:[OPENSSL]";
163               $installtop -}
164 SYSTARTUP={- catdir($installtop, '[.SYS$STARTUP]'); -}
165 # This is the standard central area to store certificates, private keys...
166 OPENSSLDIR={- catdir($config{openssldir}) or
167               $config{prefix} ? catdir($config{prefix},"COMMON")
168                               : "SYS\$COMMON:[OPENSSL-COMMON]" -}
169 # The same, but for C
170 OPENSSLDIR_C={- $osslprefix -}DATAROOT:[000000]
171 # Where installed engines reside, for C
172 ENGINESDIR_C={- $osslprefix -}ENGINES{- $sover_dirname.$target{pointer_size} -}:
173
174 CC= {- $config{cc} -}
175 CPP= {- $config{cpp} -}
176 DEFINES={- our $defines = join(",",
177                                '__dummy', # To make comma processing easier
178                                @{$config{defines}}) -}
179 INCLUDES={- our $includes = join(',', @{$config{includes}}) -}
180 CPPFLAGS='qual_includes'{- our $cppflags = join('', @{$config{cppflags}}) -}
181 CPPFLAGS_Q={- (my $x = $cppflags) =~ s|"|""|g;
182               (my $d = $defines) =~ s|"|""|g;
183               $x .= "/INCLUDE=($includes)" if $includes;
184               $x .= "/DEFINE=($d)";
185               $x; -}
186 CFLAGS={- join('', @{$config{cflags}}) -}
187 LDFLAGS= {- join('', @{$config{lflags}}) -}
188 EX_LIBS= {- join('', map { ','.$_ } @{$config{ex_libs}}) -}
189
190 LIB_DEFINES=$(DEFINES){- join("", (map { ",$_" }
191                                    @{$target{shared_defines}},
192                                    'OPENSSLDIR="""$(OPENSSLDIR_C)"""',
193                                    'ENGINESDIR="""$(ENGINESDIR_C)"""')) -}
194 LIB_CPPFLAGS=$(CPPFLAGS)/DEFINE=($(LIB_DEFINES))
195 LIB_CFLAGS=$(CFLAGS){- $target{lib_cflags} // "" -}
196 DSO_DEFINES=$(DEFINES){- join("", (map { ",$_" } @{$target{dso_defines}})) -}
197 DSO_CPPFLAGS=$(CPPFLAGS)/DEFINE=($(DSO_DEFINES))
198 DSO_CFLAGS=$(CFLAGS){- $target{dso_cflags} // "" -}
199 BIN_DEFINES=$(DEFINES){- join("", (map { ",$_" } @{$target{bin_defines}})) -}
200 BIN_CPPFLAGS=$(CPPFLAGS)/DEFINE=($(BIN_DEFINES))
201 BIN_CFLAGS=$(CFLAGS){- $target{bin_cflags} // "" -}
202 NO_INST_LIB_CFLAGS=$(CFLAGS){- $target{no_inst_lib_cflags}
203                                // $target{lib_cflags}
204                                // "" -}
205 NO_INST_DSO_CFLAGS=$(CFLAGS){- $target{no_inst_dso_cflags}
206                                // $target{dso_cflags}
207                                // "" -}
208 NO_INST_BIN_CFLAGS=$(CFLAGS){- $target{no_inst_bin_cflags}
209                                // $target{bin_cflags}
210                                // "" -}
211
212 PERL={- $config{perl} -}
213
214 AS={- $config{as} -}
215 ASFLAGS={- join(' ', @{$config{asflags}}) -}
216 ASOUTFLAG={- $target{asoutflag} -}$(OSSL_EMPTY)
217 PERLASM_SCHEME={- $target{perlasm_scheme} -}
218
219 # .FIRST and .LAST are special targets with MMS and MMK.
220 # The defines in there are for C.  includes that look like
221 # this:
222 #
223 #    #include <openssl/foo.h>
224 #    #include "internal/bar.h"
225 #
226 # will use the logical names to find the files.  Expecting
227 # DECompHP C to find files in subdirectories of whatever was
228 # given with /INCLUDE is a fantasy, unfortunately.
229 NODEBUG=@
230 .FIRST :
231         $(NODEBUG) openssl_inc1 = F$PARSE("[.include.openssl]","A.;",,,"syntax_only") - "A.;"
232         $(NODEBUG) openssl_inc2 = F$PARSE("{- catdir($config{sourcedir},"[.include.openssl]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
233         $(NODEBUG) internal_inc1 = F$PARSE("[.crypto.include.internal]","A.;",,,"SYNTAX_ONLY") - "A.;"
234         $(NODEBUG) internal_inc2 = F$PARSE("{- catdir($config{sourcedir},"[.include.internal]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
235         $(NODEBUG) internal_inc3 = F$PARSE("{- catdir($config{sourcedir},"[.crypto.include.internal]") -}","A.;",,,"SYNTAX_ONLY") - "A.;"
236         $(NODEBUG) DEFINE openssl 'openssl_inc1','openssl_inc2'
237         $(NODEBUG) DEFINE internal 'internal_inc1','internal_inc2','internal_inc3'
238         $(NODEBUG) staging_dir = "$(DESTDIR)"
239         $(NODEBUG) staging_instdir = ""
240         $(NODEBUG) staging_datadir = ""
241         $(NODEBUG) IF staging_dir .NES. "" THEN -
242                 staging_instdir = F$PARSE("A.;",staging_dir,"[]",,"SYNTAX_ONLY")
243         $(NODEBUG) IF staging_instdir - "]A.;" .NES. staging_instdir THEN -
244                 staging_instdir = staging_instdir - "]A.;" + ".OPENSSL-INSTALL]"
245         $(NODEBUG) IF staging_instdir - "A.;" .NES. staging_instdir THEN -
246                 staging_instdir = staging_instdir - "A.;" + "[OPENSSL-INSTALL]"
247         $(NODEBUG) IF staging_dir .NES. "" THEN -
248                 staging_datadir = F$PARSE("A.;",staging_dir,"[]",,"SYNTAX_ONLY")
249         $(NODEBUG) IF staging_datadir - "]A.;" .NES. staging_datadir THEN -
250                 staging_datadir = staging_datadir - "]A.;" + ".OPENSSL-COMMON]"
251         $(NODEBUG) IF staging_datadir - "A.;" .NES. staging_datadir THEN -
252                 staging_datadir = staging_datadir - "A.;" + "[OPENSSL-COMMON]"
253         $(NODEBUG) !
254         $(NODEBUG) ! Installation logical names
255         $(NODEBUG) !
256         $(NODEBUG) installtop = F$PARSE(staging_instdir,"$(INSTALLTOP)","[]A.;",,"SYNTAX_ONLY,NO_CONCEAL") - ".][000000" - "[000000." - "][" - "]A.;" + ".]"
257         $(NODEBUG) datatop = F$PARSE(staging_datadir,"$(OPENSSLDIR)","[]A.;",,"SYNTAX_ONLY,NO_CONCEAL") - ".][000000" - "[000000." - "][" - "]A.;" + ".]"
258         $(NODEBUG) DEFINE ossl_installroot 'installtop'
259         $(NODEBUG) DEFINE ossl_dataroot 'datatop'
260         $(NODEBUG) !
261         $(NODEBUG) ! Figure out the architecture
262         $(NODEBUG) !
263         $(NODEBUG) arch = f$edit( f$getsyi( "arch_name"), "upcase")
264         $(NODEBUG) !
265         $(NODEBUG) ! Set up logical names for the libraries, so LINK and
266         $(NODEBUG) ! running programs can use them.
267         $(NODEBUG) !
268         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEFINE ".uc($_)." 'F\$ENV(\"DEFAULT\")'".uc($_)."\$(SHLIB_EXT)" } @shlibs) || "!" -}
269
270 .LAST :
271         $(NODEBUG) {- join("\n\t\$(NODEBUG) ", map { "DEASSIGN ".uc($_) } @shlibs) || "!" -}
272         $(NODEBUG) DEASSIGN ossl_dataroot
273         $(NODEBUG) DEASSIGN ossl_installroot
274         $(NODEBUG) DEASSIGN internal
275         $(NODEBUG) DEASSIGN openssl
276 .DEFAULT :
277         @ ! MMS cannot handle no actions...
278
279 # The main targets ###################################################
280
281 {- dependmagic('all'); -} : build_libs_nodep, build_engines_nodep, build_programs_nodep
282 {- dependmagic('build_libs'); -} : build_libs_nodep
283 {- dependmagic('build_engines'); -} : build_engines_nodep
284 {- dependmagic('build_programs'); -} : build_programs_nodep
285
286 build_generated : $(GENERATED_MANDATORY)
287 build_libs_nodep : $(LIBS), $(SHLIBS)
288 build_engines_nodep : $(ENGINES)
289 build_programs_nodep : $(PROGRAMS), $(SCRIPTS)
290
291 # Kept around for backward compatibility
292 build_apps build_tests : build_programs
293
294 # Convenience target to prebuild all generated files, not just the mandatory
295 # ones
296 build_all_generated : $(GENERATED_MANDATORY) $(GENERATED)
297
298 test : tests
299 {- dependmagic('tests'); -} : build_programs_nodep, build_engines_nodep
300         @ ! {- output_off() if $disabled{tests}; "" -}
301         SET DEFAULT [.test]{- move("test") -}
302         CREATE/DIR [.test-runs]
303         DEFINE SRCTOP {- sourcedir() -}
304         DEFINE BLDTOP {- builddir() -}
305         DEFINE RESULT_D {- builddir(qw(test test-runs)) -}
306         DEFINE OPENSSL_ENGINES {- builddir("engines") -}
307         DEFINE OPENSSL_DEBUG_MEMORY "on"
308         IF "$(VERBOSE)" .NES. "" THEN DEFINE VERBOSE "$(VERBOSE)"
309         $(PERL) {- sourcefile("test", "run_tests.pl") -} $(TESTS)
310         DEASSIGN OPENSSL_DEBUG_MEMORY
311         DEASSIGN OPENSSL_ENGINES
312         DEASSIGN BLDTOP
313         DEASSIGN SRCTOP
314         SET DEFAULT [-]{- move("..") -}
315         @ ! {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
316         @ WRITE SYS$OUTPUT "Tests are not supported with your chosen Configure options"
317         @ ! {- output_on() if !$disabled{tests}; "" -}
318
319 list-tests :
320         @ ! {- output_off() if $disabled{tests}; "" -}
321         @ DEFINE SRCTOP {- sourcedir() -}
322         @ $(PERL) {- sourcefile("test", "run_tests.pl") -} list
323         @ DEASSIGN SRCTOP
324         @ ! {- if ($disabled{tests}) { output_on(); } else { output_off(); } "" -}
325         @ WRITE SYS$OUTPUT "Tests are not supported with your chosen Configure options"
326         @ ! {- output_on() if !$disabled{tests}; "" -}
327
328 install : install_sw install_ssldirs install_docs
329         @ WRITE SYS$OUTPUT ""
330         @ WRITE SYS$OUTPUT "######################################################################"
331         @ WRITE SYS$OUTPUT ""
332         @ IF "$(DESTDIR)" .EQS. "" THEN -
333              PIPE ( WRITE SYS$OUTPUT "Installation complete" ; -
334                     WRITE SYS$OUTPUT "" ; -
335                     WRITE SYS$OUTPUT "Run @$(SYSTARTUP)openssl_startup{- $osslver -} to set up logical names" ; -
336                     WRITE SYS$OUTPUT "then run @$(SYSTARTUP)openssl_utils{- $osslver -} to define commands" ; -
337                     WRITE SYS$OUTPUT "" )
338         @ IF "$(DESTDIR)" .NES. "" THEN -
339              PIPE ( WRITE SYS$OUTPUT "Staging installation complete" ; -
340                     WRITE SYS$OUTPUT "" ; -
341                     WRITE SYS$OUTPUT "Finish or package in such a way that the contents of the directory tree" ; -
342                     WRITE SYS$OUTPUT staging_instdir ; -
343                     WRITE SYS$OUTPUT "ends up in $(INSTALLTOP)," ; -
344                     WRITE SYS$OUTPUT "and that the contents of the contents of the directory tree" ; -
345                     WRITE SYS$OUTPUT staging_datadir ; -
346                     WRITE SYS$OUTPUT "ends up in $(OPENSSLDIR)" ; -
347                     WRITE SYS$OUTPUT "" ; -
348                     WRITE SYS$OUTPUT "When in its final destination," ; -
349                     WRITE SYS$OUTPUT "Run @$(SYSTARTUP)openssl_startup{- $osslver -} to set up logical names" ; -
350                     WRITE SYS$OUTPUT "then run @$(SYSTARTUP)openssl_utils{- $osslver -} to define commands" ; -
351                     WRITE SYS$OUTPUT "" )
352
353 check_install :
354         spawn/nolog @ossl_installroot:[SYSTEST]openssl_ivp{- $osslver -}.com
355
356 uninstall : uninstall_docs uninstall_sw
357
358 # Because VMS wants the generation number (or *) to delete files, we can't
359 # use $(LIBS), $(PROGRAMS), $(GENERATED) and $(ENGINES)directly.
360 libclean :
361         {- join("\n\t", map { "- DELETE $_.OLB;*" } @libs) || "@ !" -}
362         {- join("\n\t", map { "- DELETE $_.EXE;*,$_.MAP;*" } @shlibs) || "@ !" -}
363
364 clean : libclean
365         {- join("\n\t", map { "- DELETE $_.EXE;*,$_.OPT;*" } @{$unified_info{programs}}) || "@ !" -}
366         {- join("\n\t", map { "- DELETE $_.EXE;*,$_.OPT;*" } @{$unified_info{engines}}) || "@ !" -}
367         {- join("\n\t", map { "- DELETE $_;*" } @{$unified_info{scripts}}) || "@ !" -}
368         {- join("\n\t", map { "- DELETE $_;*" } @generated) || "@ !" -}
369         - DELETE [...]*.MAP;*
370         - DELETE [...]*.D;*
371         - DELETE [...]*.OBJ;*,*.LIS;*
372         - DELETE []CXX$DEMANGLER_DB.;*
373         - DELETE [.VMS]openssl_startup.com;*
374         - DELETE [.VMS]openssl_shutdown.com;*
375         - DELETE []vmsconfig.pm;*
376
377 distclean : clean
378         - DELETE configdata.pm;*
379         - DELETE descrip.mms;*
380
381 depend : descrip.mms
382 descrip.mms : FORCE
383         @ ! {- output_off() if $disabled{makedepend}; "" -}
384         @ $(PERL) -pe "if (/^# DO NOT DELETE.*/) { exit(0); }" -
385                 < descrip.mms > descrip.mms-new
386         @ OPEN/APPEND DESCRIP descrip.mms-new
387         @ WRITE DESCRIP "# DO NOT DELETE THIS LINE -- make depend depends on it."
388         {- join("\n\t", map { "\@ IF F\$SEARCH(\"$_\") .NES. \"\" THEN TYPE $_ /OUTPUT=DESCRIP:" } @deps); -}
389         @ CLOSE DESCRIP
390         @ PIPE ( $(PERL) -e "use File::Compare qw/compare_text/; my $x = compare_text(""descrip.mms"",""descrip.mms-new""); exit(0x10000000 + ($x == 0));" || -
391                  RENAME descrip.mms-new descrip.mms )
392         @ IF F$SEARCH("descrip.mms-new") .NES. "" THEN DELETE descrip.mms-new;*
393         -@ SPAWN/OUTPUT=NLA0: PURGE/NOLOG descrip.mms
394         @ ! {- output_on() if $disabled{makedepend}; "" -}
395
396 # Install helper targets #############################################
397
398 install_sw : all install_shared _install_dev_ns -
399              install_engines _install_runtime_ns -
400              install_startup install_ivp
401
402 uninstall_sw : uninstall_shared _uninstall_dev_ns -
403                uninstall_engines _uninstall_runtime_ns -
404                uninstall_startup uninstall_ivp
405
406 install_docs : install_html_docs
407
408 uninstall_docs : uninstall_html_docs
409
410 install_ssldirs : check_INSTALLTOP
411         - CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[000000]
412         IF F$SEARCH("OSSL_DATAROOT:[000000]CERTS.DIR;1") .EQS. "" THEN -
413                 CREATE/DIR/PROT=(S:RWED,O:RWE,G:RE,W:RE) OSSL_DATAROOT:[CERTS]
414         IF F$SEARCH("OSSL_DATAROOT:[000000]PRIVATE.DIR;1") .EQS. "" THEN -
415                 CREATE/DIR/PROT=(S:RWED,O:RWE,G,W) OSSL_DATAROOT:[PRIVATE]
416         IF F$SEARCH("OSSL_DATAROOT:[000000]MISC.DIR;1") .EQS. "" THEN -
417                 CREATE/DIR/PROT=(S:RWED,O:RWE,G,W) OSSL_DATAROOT:[MISC]
418         COPY/PROT=W:RE $(MISC_SCRIPTS) OSSL_DATAROOT:[MISC]
419         @ ! Install configuration file
420         COPY/PROT=W:R {- sourcefile("apps", "openssl-vms.cnf") -} -
421                 ossl_dataroot:[000000]openssl.cnf-dist
422         IF F$SEARCH("OSSL_DATAROOT:[000000]openssl.cnf") .EQS. "" THEN -
423                 COPY/PROT=W:R {- sourcefile("apps", "openssl-vms.cnf") -} -
424                         ossl_dataroot:[000000]openssl.cnf
425         @ ! Install CTLOG configuration file
426         COPY/PROT=W:R {- sourcefile("apps", "ct_log_list.cnf") -} -
427                 ossl_dataroot:[000000]ct_log_list.cnf-dist
428         IF F$SEARCH("OSSL_DATAROOT:[000000]ct_log_list.cnf") .EQS. "" THEN -
429                 COPY/PROT=W:R {- sourcefile("apps", "ct_log_list.cnf") -} -
430                         ossl_dataroot:[000000]ct_log_list.cnf
431
432 install_shared : check_INSTALLTOP
433         @ {- output_off() if $disabled{shared}; "" -} !
434         @ WRITE SYS$OUTPUT "*** Installing shareable images"
435         @ ! Install shared (runtime) libraries
436         - CREATE/DIR ossl_installroot:[LIB.'arch']
437         {- join("\n        ",
438                 map { "COPY/PROT=W:R $_.EXE ossl_installroot:[LIB.'arch']" }
439                 @install_shlibs) -}
440         @ {- output_on() if $disabled{shared}; "" -} !
441
442 _install_dev_ns : check_INSTALLTOP
443         @ WRITE SYS$OUTPUT "*** Installing development files"
444         @ ! Install header files
445         - CREATE/DIR ossl_installroot:[include.openssl]
446         COPY/PROT=W:R openssl:*.h ossl_installroot:[include.openssl]
447         @ ! Install static (development) libraries
448         - CREATE/DIR ossl_installroot:[LIB.'arch']
449         {- join("\n        ",
450                 map { "COPY/PROT=W:R $_.OLB ossl_installroot:[LIB.'arch']" }
451                 @install_libs) -}
452
453 install_dev : install_shared _install_dev_ns
454
455 _install_runtime_ns : check_INSTALLTOP
456         @ ! Install the main program
457         - CREATE/DIR ossl_installroot:[EXE.'arch']
458         COPY/PROT=W:RE [.APPS]openssl.EXE -
459                 ossl_installroot:[EXE.'arch']openssl{- $osslver -}.EXE
460         @ ! Install scripts
461         COPY/PROT=W:RE $(BIN_SCRIPTS) ossl_installroot:[EXE]
462         @ ! {- output_on() if $disabled{apps}; "" -}
463
464 install_runtime : install_shared _install_runtime_ns
465
466 install_engines : check_INSTALLTOP
467         @ {- output_off() unless scalar @{$unified_info{engines}}; "" -} !
468         @ WRITE SYS$OUTPUT "*** Installing engines"
469         - CREATE/DIR ossl_installroot:[ENGINES{- $sover_dirname.$target{pointer_size} -}.'arch']
470         {- join("\n        ",
471                 map { "COPY/PROT=W:RE $_.EXE ossl_installroot:[ENGINES$sover_dirname$target{pointer_size}.'arch']" }
472                 @{$unified_info{install}->{engines}}) -}
473         @ {- output_on() unless scalar @{$unified_info{engines}}; "" -} !
474
475 install_startup : [.VMS]openssl_startup.com [.VMS]openssl_shutdown.com -
476                  [.VMS]openssl_utils.com, check_INSTALLTOP
477         - CREATE/DIR ossl_installroot:[SYS$STARTUP]
478         COPY/PROT=W:RE [.VMS]openssl_startup.com -
479                 ossl_installroot:[SYS$STARTUP]openssl_startup{- $osslver -}.com
480         COPY/PROT=W:RE [.VMS]openssl_shutdown.com -
481                 ossl_installroot:[SYS$STARTUP]openssl_shutdown{- $osslver -}.com
482         COPY/PROT=W:RE [.VMS]openssl_utils.com -
483                 ossl_installroot:[SYS$STARTUP]openssl_utils{- $osslver -}.com
484
485 install_ivp : [.VMS]openssl_ivp.com check_INSTALLTOP
486         - CREATE/DIR ossl_installroot:[SYSTEST]
487         COPY/PROT=W:RE [.VMS]openssl_ivp.com -
488                 ossl_installroot:[SYSTEST]openssl_ivp{- $osslver -}.com
489
490 [.VMS]openssl_startup.com : vmsconfig.pm {- sourcefile("VMS", "openssl_startup.com.in") -}
491         - CREATE/DIR [.VMS]
492         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
493                 {- sourcefile("VMS", "openssl_startup.com.in") -} -
494                 > [.VMS]openssl_startup.com
495
496 [.VMS]openssl_utils.com : vmsconfig.pm {- sourcefile("VMS", "openssl_utils.com.in") -}
497         - CREATE/DIR [.VMS]
498         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
499                 {- sourcefile("VMS", "openssl_utils.com.in") -} -
500                 > [.VMS]openssl_utils.com
501
502 [.VMS]openssl_shutdown.com : vmsconfig.pm {- sourcefile("VMS", "openssl_shutdown.com.in") -}
503         - CREATE/DIR [.VMS]
504         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
505                 {- sourcefile("VMS", "openssl_shutdown.com.in") -} -
506                 > [.VMS]openssl_shutdown.com
507
508 [.VMS]openssl_ivp.com : vmsconfig.pm {- sourcefile("VMS", "openssl_ivp.com.in") -}
509         - CREATE/DIR [.VMS]
510         $(PERL) "-I." "-Mvmsconfig" {- sourcefile("util", "dofile.pl") -} -
511                 {- sourcefile("VMS", "openssl_ivp.com.in") -} -
512                 > [.VMS]openssl_ivp.com
513
514 vmsconfig.pm : configdata.pm
515         OPEN/WRITE/SHARE=READ CONFIG []vmsconfig.pm
516         WRITE CONFIG "package vmsconfig;"
517         WRITE CONFIG "use strict; use warnings;"
518         WRITE CONFIG "use Exporter;"
519         WRITE CONFIG "our @ISA = qw(Exporter);"
520         WRITE CONFIG "our @EXPORT = qw(%config %target %withargs %unified_info %disabled);"
521         WRITE CONFIG "our %config = ("
522         WRITE CONFIG "  target => '","{- $config{target} -}","',"
523         WRITE CONFIG "  version => '","{- $config{version} -}","',"
524         WRITE CONFIG "  shlib_version_number => '","{- $config{shlib_version_number} -}","',"
525         WRITE CONFIG "  shlib_major => '","{- $config{shlib_major} -}","',"
526         WRITE CONFIG "  shlib_minor => '","{- $config{shlib_minor} -}","',"
527         WRITE CONFIG "  no_shared => '","{- $disabled{shared} -}","',"
528         WRITE CONFIG "  INSTALLTOP => '$(INSTALLTOP)',"
529         WRITE CONFIG "  OPENSSLDIR => '$(OPENSSLDIR)',"
530         WRITE CONFIG "  pointer_size => '","{- $target{pointer_size} -}","',"
531         WRITE CONFIG ");"
532         WRITE CONFIG "our %target = ();"
533         WRITE CONFIG "our %disabled = ();"
534         WRITE CONFIG "our %withargs = ();"
535         WRITE CONFIG "our %unified_info = ();"
536         WRITE CONFIG "1;"
537         CLOSE CONFIG
538
539 install_html_docs : check_INSTALLTOP
540         sourcedir = F$PARSE("{- $sourcedir -}A.;","[]") - "]A.;" + ".DOC]"
541         $(PERL) {- sourcefile("util", "process_docs.pl") -} -
542                 --sourcedir='sourcedir' --destdir=ossl_installroot:[HTML] -
543                 --type=html
544
545 check_INSTALLTOP :
546         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
547                 WRITE SYS$ERROR "INSTALLTOP should not be empty"
548         @ IF "$(INSTALLTOP)" .EQS. "" THEN -
549                 EXIT %x10000002
550
551 # Helper targets #####################################################
552
553 # Developer targets ##################################################
554
555 debug_logicals :
556         SH LOGICAL/PROC openssl,internal,ossl_installroot,ossl_dataroot
557
558 # Building targets ###################################################
559
560 configdata.pm : $(SRCDIR)Configure $(SRCDIR)config.com {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
561         perl configdata.pm -r
562         @ WRITE SYS$OUTPUT "*************************************************"
563         @ WRITE SYS$OUTPUT "***                                           ***"
564         @ WRITE SYS$OUTPUT "***   Please run the same mms command again   ***"
565         @ WRITE SYS$OUTPUT "***                                           ***"
566         @ WRITE SYS$OUTPUT "*************************************************"
567         @ PIPE ( EXIT %X10000000 )
568
569 reconfigure reconf :
570         perl configdata.pm -r
571
572 {-
573   use File::Basename;
574   use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/;
575
576   # Helper function to figure out dependencies on libraries
577   # It takes a list of library names and outputs a list of dependencies
578   sub compute_lib_depends {
579       if ($disabled{shared}) {
580           return map { $_ =~ /\.a$/ ? $`.".OLB" : $_.".OLB" } @_;
581       }
582       return map { $_ =~ /\.a$/
583                    ? $`.".OLB"
584                    : $unified_info{sharednames}->{$_}.".EXE" } @_;
585   }
586
587   # Helper function to deal with inclusion directory specs.
588   # We have to deal with two things:
589   # 1. comma separation and no possibility of trailing comma
590   # 2. no inclusion directories given at all
591   # 3. long compiler command lines
592   # To resolve 1, we need to iterate through the sources of inclusion
593   # directories, and only add a comma when needed.
594   # To resolve 2, we need to have a variable that will hold the whole
595   # inclusion qualifier, or be the empty string if there are no inclusion
596   # directories.  That's the symbol 'qual_includes' that's used in CPPFLAGS
597   # To resolve 3, we creata a logical name TMP_INCLUDES: to hold the list
598   # of inclusion directories.
599   #
600   # This function returns a list of two lists, one being the collection of
601   # commands to execute before the compiler is called, and the other being
602   # the collection of commands to execute after.  It takes as arguments the
603   # collection of strings to include as directory specs.
604   sub includes {
605       my @stuff = ( @_ );
606       my @before = (
607           'qual_includes :=',
608       );
609       my @after = (
610           'DELETE/SYMBOL/LOCAL qual_includes',
611       );
612
613       if (scalar @stuff > 0) {
614           push @before, 'tmp_includes := '.shift(@stuff);
615           while (@stuff) {
616               push @before, 'tmp_add := '.shift(@stuff);
617               push @before, 'IF tmp_includes .NES. "" .AND. tmp_add .NES. "" THEN tmp_includes = tmp_includes + ","';
618               push @before, 'tmp_includes = tmp_includes + tmp_add';
619           }
620           push @before, "IF tmp_includes .NES. \"\" THEN DEFINE tmp_includes 'tmp_includes'";
621           push @before, 'IF tmp_includes .NES. "" THEN qual_includes := /INCLUDE=(tmp_includes:)';
622           push @before, 'DELETE/SYMBOL/LOCAL tmp_includes';
623           push @before, 'DELETE/SYMBOL/LOCAL tmp_add';
624           push @after, 'DEASSIGN tmp_includes:'
625       }
626       return ([ @before ], [ @after ]);
627   }
628
629   sub generatesrc {
630       my %args = @_;
631       (my $target = $args{src}) =~ s/\.[sS]$/.asm/;
632       my $generator = join(" ", @{$args{generator}});
633       my $generator_incs = join("", map { ' "-I'.$_.'"' } @{$args{generator_incs}});
634       my $deps = join(", -\n\t\t", @{$args{generator_deps}}, @{$args{deps}});
635
636       if ($target !~ /\.asm$/) {
637           if ($args{generator}->[0] =~ m|^.*\.in$|) {
638               my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
639                                                    "util", "dofile.pl")),
640                                    rel2abs($config{builddir}));
641               return <<"EOF";
642 $target : $args{generator}->[0] $deps
643         \$(PERL) "-I\$(BLDDIR)" "-Mconfigdata" $dofile \\
644             "-o$target{build_file}" $generator > \$\@
645 EOF
646           } else {
647               return <<"EOF";
648 $target : $args{generator}->[0] $deps
649         \$(PERL)$generator_incs $generator > \$\@
650 EOF
651           }
652       } else {
653           if ($args{generator}->[0] =~ /\.pl$/) {
654               $generator = '$(PERL)'.$generator_incs.' '.$generator;
655           } elsif ($args{generator}->[0] =~ /\.S$/) {
656               $generator = undef;
657           } else {
658               die "Generator type for $src unknown: $generator\n";
659           }
660
661           my $cppflags = { lib => '$(LIB_CPPFLAGS)',
662                            dso => '$(DSO_CPPFLAGS)',
663                            bin => '$(BIN_CPPFLAGS)' } -> {$args{intent}};
664           my @incs_cmds = includes({ lib => '$(LIB_INCLUDES)',
665                                      dso => '$(DSO_INCLUDES)',
666                                      bin => '$(BIN_INCLUDES)' } -> {$args{intent}},
667                                    '$(INCLUDES)',
668                                    @{$args{incs}});
669           my $incs_on = join("\n\t\@ ", @{$incs_cmds[0]}) || '!';
670           my $incs_off = join("\n\t\@ ", @{$incs_cmds[1]}) || '!';
671           if (defined($generator)) {
672               # If the target is named foo.S in build.info, we want to
673               # end up generating foo.s in two steps.
674               if ($args{src} =~ /\.S$/) {
675                    return <<"EOF";
676 $target : $args{generator}->[0] $deps
677         $generator \$\@-S
678         \@ $incs_on
679         PIPE \$(CPP) $cppflags \$\@-S | -
680         \$(PERL) -ne "/^#(\\s*line)?\\s*[0-9]+\\s+""/ or print" > \$\@-i
681         \@ $incs_off
682         RENAME \$\@-i \$\@
683         DELETE \$\@-S
684 EOF
685               }
686               # Otherwise....
687               return <<"EOF";
688 $target : $args{generator}->[0] $deps
689         $generator \$\@
690 EOF
691           }
692           return <<"EOF";
693 $target : $args{generator}->[0] $deps
694         \@ $incs_on
695         SHOW SYMBOL qual_includes
696         PIPE \$(CPP) $cppflags $args{generator}->[0] | -
697         \$(PERL) "-ne" "/^#(\\s*line)?\\s*[0-9]+\\s+""/ or print" > \$\@
698         \@ $incs_off
699 EOF
700       }
701   }
702
703   sub src2obj {
704       my %args = @_;
705       my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x
706                      } ( @{$args{srcs}} );
707       (my $obj = $args{obj}) =~ s|\.o$||;
708       my $deps = join(", -\n\t\t", @srcs, @{$args{deps}});
709
710       # Because VMS C isn't very good at combining a /INCLUDE path with
711       # #includes having a relative directory (like '#include "../foo.h"),
712       # the best choice is to move to the first source file's intended
713       # directory before compiling, and make sure to write the object file
714       # in the correct position (important when the object tree is other
715       # than the source tree).
716       my $forward = dirname($args{srcs}->[0]);
717       my $backward = abs2rel(rel2abs("."), rel2abs($forward));
718       my $objd = abs2rel(rel2abs(dirname($obj)), rel2abs($forward));
719       my $objn = basename($obj);
720       my $srcs =
721           join(", ", map { abs2rel(rel2abs($_), rel2abs($forward)) } @srcs);
722       my $before = $unified_info{before}->{$obj.".OBJ"} || "\@ !";
723       my $after = $unified_info{after}->{$obj.".OBJ"} || "\@ !";
724
725       if ($srcs[0] =~ /\.asm$/) {
726           return <<"EOF";
727 $obj.OBJ : $deps
728         ${before}
729         SET DEFAULT $forward
730         \$(AS) \$(ASFLAGS) \$(ASOUTFLAG)${objd}${objn}.OBJ $srcs
731         SET DEFAULT $backward
732 EOF
733       }
734
735       my $cflags;
736       if ($args{installed}) {
737           $cflags = { lib => '$(LIB_CFLAGS)',
738                       dso => '$(DSO_CFLAGS)',
739                       bin => '$(BIN_CFLAGS)' } -> {$args{intent}};
740       } else {
741           $cflags = { lib => '$(NO_INST_LIB_CFLAGS)',
742                       dso => '$(NO_INST_DSO_CFLAGS)',
743                       bin => '$(NO_INST_BIN_CFLAGS)' } -> {$args{intent}};
744       }
745       $cflags .= { lib => '$(LIB_CPPFLAGS)',
746                    dso => '$(DSO_CPPFLAGS)',
747                    bin => '$(BIN_CPPFLAGS)' } -> {$args{intent}};
748
749       my @incs_cmds = includes({ lib => '$(LIB_INCLUDES)',
750                                  dso => '$(DSO_INCLUDES)',
751                                  bin => '$(BIN_INCLUDES)' } -> {$args{intent}},
752                                '$(INCLUDES)',
753                                map {
754                                    file_name_is_absolute($_)
755                                    ? $_ : catdir($backward,$_)
756                                } @{$args{incs}});
757       my $incs_on = join("\n\t\@ ", @{$incs_cmds[0]}) || '!';
758       my $incs_off = join("\n\t\@ ", @{$incs_cmds[1]}) || '!';
759       my $depbuild = $disabled{makedepend} ? ""
760           : " /MMS=(FILE=${objd}${objn}.tmp-D,TARGET=$obj.OBJ)";
761
762       return <<"EOF"
763 $obj.OBJ : $deps
764         ${before}
765         SET DEFAULT $forward
766         \@ $incs_on
767         \$(CC) ${cflags}${depbuild} /OBJECT=${objd}${objn}.OBJ /REPOSITORY=$backward $srcs
768         \@ $incs_off
769         SET DEFAULT $backward
770         ${after}
771         - PURGE $obj.OBJ
772 EOF
773       . ($disabled{makedepend} ? "" : <<"EOF"
774         \@ PIPE ( \$(PERL) -e "use File::Compare qw/compare_text/; my \$x = compare_text(""$obj.D"",""$obj.tmp-D""); exit(0x10000000 + (\$x == 0));" || -
775                  RENAME $obj.tmp-D $obj.d )
776         \@ IF F\$SEARCH("$obj.tmp-D") .NES. "" THEN DELETE $obj.tmp-D;*
777 EOF
778         );
779   }
780   sub libobj2shlib {
781       my %args = @_;
782       my $lib = $args{lib};
783       my $shlib = $args{shlib};
784       my $libd = dirname($lib);
785       my $libn = basename($lib);
786       my @objs = map { (my $x = $_) =~ s|\.o$|.OBJ|; $x }
787                  grep { $_ =~ m|\.o$| }
788                  @{$args{objs}};
789       my @defs = grep { $_ =~ /\.opt$/ } @{$args{objs}};
790       my @deps = compute_lib_depends(@{$args{deps}});
791       die "More than one symbol vector" if scalar @defs > 1;
792       my $deps = join(", -\n\t\t", @defs, @deps);
793       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
794       my $translatesyms_pl = abs2rel(rel2abs(catfile($config{sourcedir},
795                                                      "VMS", "translatesyms.pl")),
796                                      rel2abs($config{builddir}));
797       # The "[]" hack is because in .OPT files, each line inherits the
798       # previous line's file spec as default, so if no directory spec
799       # is present in the current line and the previous line has one that
800       # doesn't apply, you're in for a surprise.
801       my $write_opt1 =
802           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
803                                  "WRITE OPT_FILE \"$x" } @objs).
804           "\"";
805       my $write_opt2 =
806           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
807                              $x =~ s|(\.EXE)|$1/SHARE|;
808                              $x =~ s|(\.OLB)|$1/LIB|;
809                              "WRITE OPT_FILE \"$x\"" } @deps)
810           || "\@ !";
811       return <<"EOF"
812 $shlib.EXE : $lib.OLB $deps
813         \$(PERL) $translatesyms_pl \$(BLDDIR)CXX\$DEMANGLER_DB. < $defs[0] > $defs[0]-translated
814         OPEN/WRITE/SHARE=READ OPT_FILE $lib-components.OPT
815         $write_opt1
816         $write_opt2
817         CLOSE OPT_FILE
818         LINK \$(LDFLAGS)/SHARE=\$\@ $defs[0]-translated/OPT,-
819                 $lib-components.OPT/OPT \$(EX_LIBS)
820         DELETE $defs[0]-translated;*,$lib-components.OPT;*
821         PURGE $shlib.EXE,$shlib.MAP
822 EOF
823         . ($config{target} =~ m|alpha| ? "" : <<"EOF"
824         SET IMAGE/FLAGS=(NOCALL_DEBUG) \$\@
825 EOF
826         );
827   }
828   sub obj2dso {
829       my %args = @_;
830       my $lib = $args{lib};
831       my $libd = dirname($lib);
832       my $libn = basename($lib);
833       (my $libn_nolib = $libn) =~ s/^lib//;
834       my @objs = map { (my $x = $_) =~ s|\.o$|.OBJ|; $x } @{$args{objs}};
835       my @deps = compute_lib_depends(@{$args{deps}});
836       my $deps = join(", -\n\t\t", @objs, @deps);
837       my $shlib_target = $disabled{shared} ? "" : $target{shared_target};
838       my $engine_opt = abs2rel(rel2abs(catfile($config{sourcedir},
839                                                "VMS", "engine.opt")),
840                                rel2abs($config{builddir}));
841       # The "[]" hack is because in .OPT files, each line inherits the
842       # previous line's file spec as default, so if no directory spec
843       # is present in the current line and the previous line has one that
844       # doesn't apply, you're in for a surprise.
845       my $write_opt1 =
846           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
847                                  "WRITE OPT_FILE \"$x" } @objs).
848           "\"";
849       my $write_opt2 =
850           join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
851                              $x =~ s|(\.EXE)|$1/SHARE|;
852                              $x =~ s|(\.OLB)|$1/LIB|;
853                              "WRITE OPT_FILE \"$x\"" } @deps)
854           || "\@ !";
855       return <<"EOF"
856 $lib.EXE : $deps
857         OPEN/WRITE/SHARE=READ OPT_FILE $lib.OPT
858         TYPE $engine_opt /OUTPUT=OPT_FILE:
859         $write_opt1
860         $write_opt2
861         CLOSE OPT_FILE
862         LINK \$(LDFLAGS)/SHARE=\$\@ $lib.OPT/OPT \$(EX_LIBS)
863         - PURGE $lib.EXE,$lib.OPT,$lib.MAP
864 EOF
865         . ($config{target} =~ m|alpha| ? "" : <<"EOF"
866         SET IMAGE/FLAGS=(NOCALL_DEBUG) \$\@
867 EOF
868         );
869   }
870   sub obj2lib {
871       my %args = @_;
872       (my $lib = $args{lib}) =~ s/\.a$//;
873       my @objs = map { (my $x = $_) =~ s|\.o$|.OBJ|; $x } @{$args{objs}};
874       my $objs = join(", -\n\t\t", @objs);
875       my $fill_lib = join("\n\t", (map { "LIBRARY/REPLACE $lib.OLB $_" }
876                                    @objs));
877       return <<"EOF";
878 $lib.OLB : $objs
879         LIBRARY/CREATE/OBJECT $lib.OLB
880         $fill_lib
881         - PURGE $lib.OLB
882 EOF
883   }
884   sub obj2bin {
885       my %args = @_;
886       my $bin = $args{bin};
887       my $bind = dirname($bin);
888       my $binn = basename($bin);
889       my @objs = map { (my $x = $_) =~ s|\.o$|.OBJ|; $x } @{$args{objs}};
890       my $objs = join(",", @objs);
891       my @deps = compute_lib_depends(@{$args{deps}});
892       my $deps = join(", -\n\t\t", @objs, @deps);
893
894       my $olb_count = scalar grep(m|\.OLB$|, @deps);
895       my $analyse_objs = "@ !";
896       if ($olb_count > 0) {
897           my $analyse_quals =
898               $config{target} =~ m|alpha| ? "/GSD" : "/SECTIONS=SYMTAB";
899           $analyse_objs = "- pipe ANALYSE/OBJECT$analyse_quals $objs | SEARCH SYS\$INPUT \"\"\"main\"\"\" ; nomain = \$severity .NE. 1"
900       }
901       # The "[]" hack is because in .OPT files, each line inherits the
902       # previous line's file spec as default, so if no directory spec
903       # is present in the current line and the previous line has one that
904       # doesn't apply, you're in for a surprise.
905       my $write_opt1 =
906           join(",-\"\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_;
907                                  "\@ WRITE OPT_FILE \"$x" } @objs).
908           "\"";
909       my $write_opt2 =
910           join("\n\t", map { my @lines = ();
911                              my $x = $_ =~ /\[/ ? $_ : "[]".$_;
912                              if ($x =~ m|\.EXE$|) {
913                                  push @lines, "\@ WRITE OPT_FILE \"$x/SHARE\"";
914                              } elsif ($x =~ m|\.OLB$|) {
915                                  (my $l = $x) =~ s/\W/_/g;
916                                  push @lines, 
917                                      "\@ IF nomain THEN WRITE OPT_FILE \"$x/LIB\$(INCLUDE_MAIN_$l)\"",
918                                      "\@ IF .NOT. nomain THEN WRITE OPT_FILE \"$x/LIB\""
919                              }
920                              @lines
921                            } @deps)
922           || "\@ !";
923       # The linking commands looks a bit complex, but it's for good reason.
924       # When you link, say, foo.obj, bar.obj and libsomething.exe/share, and
925       # bar.obj happens to have a symbol that also exists in libsomething.exe,
926       # the linker will warn about it, loudly, and will then choose to pick
927       # the first copy encountered (the one in bar.obj in this example).
928       # On Unix and on Windows, the corresponding maneuvre goes through
929       # silently with the same effect.
930       # With some test programs, made for checking the internals of OpenSSL,
931       # we do this kind of linking deliberately, picking a few specific object
932       # files from within [.crypto] or [.ssl] so we can reach symbols that are
933       # otherwise unreachable (since the shareable images only exports the
934       # symbols listed in [.util]*.num), and then with the shared libraries
935       # themselves.  So we need to silence the warning about multiply defined
936       # symbols, to mimic the way linking work on Unix and Windows, and so
937       # the build isn't interrupted (MMS stops when warnings are signaled,
938       # by default), and so someone building doesn't have to worry where it
939       # isn't necessary.  If there are other warnings, however, we show them
940       # and let it break the build.
941       return <<"EOF"
942 $bin.EXE : $deps
943         $analyse_objs
944         @ OPEN/WRITE/SHARE=READ OPT_FILE $bin.OPT
945         $write_opt1
946         $write_opt2
947         @ CLOSE OPT_FILE
948         TYPE $bin.opt ! For debugging
949         - pipe SPAWN/WAIT/NOLOG/OUT=$bin.LINKLOG -
950                     LINK \$(LDFLAGS)/EXEC=\$\@ $bin.OPT/OPT \$(EX_LIBS) ; -
951                link_status = \$status ; link_severity = link_status .AND. 7
952         @ search_severity = 1
953         -@ IF link_severity .EQ. 0 THEN -
954                 pipe SEARCH $bin.LINKLOG "%","-"/MATCH=AND | -
955                      SPAWN/WAIT/NOLOG/OUT=NLA0: -
956                           SEARCH SYS\$INPUT: "-W-MULDEF,"/MATCH=NOR ; -
957                      search_severity = \$severity
958         @ ! search_severity is 3 when the last search didn't find any matching
959         @ ! string: %SEARCH-I-NOMATCHES, no strings matched
960         @ ! If that was the result, we pretend linking got through without
961         @ ! fault or warning.
962         @ IF search_severity .EQ. 3 THEN link_severity = 1
963         @ ! At this point, if link_severity shows that there was a fault
964         @ ! or warning, make sure to restore the linking status.
965         -@ IF .NOT. link_severity THEN TYPE $bin.LINKLOG
966         -@ DELETE $bin.LINKLOG;*
967         @ IF .NOT. link_severity THEN SPAWN/WAIT/NOLOG EXIT 'link_status'
968         - PURGE $bin.EXE,$bin.OPT
969 EOF
970       . ($config{target} =~ m|alpha| ? "" : <<"EOF"
971         SET IMAGE/FLAGS=(NOCALL_DEBUG) \$\@
972 EOF
973         );
974   }
975   sub in2script {
976       my %args = @_;
977       my $script = $args{script};
978       return "" if grep { $_ eq $script } @{$args{sources}}; # No overwrite!
979       my $sources = join(" ", @{$args{sources}});
980       my $dofile = abs2rel(rel2abs(catfile($config{sourcedir},
981                                            "util", "dofile.pl")),
982                            rel2abs($config{builddir}));
983       return <<"EOF";
984 $script : $sources
985         \$(PERL) "-I\$(BLDDIR)" "-Mconfigdata" $dofile -
986             "-o$target{build_file}" $sources > $script
987         SET FILE/PROT=(S:RWED,O:RWED,G:RE,W:RE) $script
988         PURGE $script
989 EOF
990   }
991   ""    # Important!  This becomes part of the template result.
992 -}