]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/vmsconfig.com
dc74ff1edc6aa32e30d50ee473a4e2a4e6c9dac7
[thirdparty/gcc.git] / gcc / vmsconfig.com
1 $ !
2 $ ! Set up to compile GCC on VMS.
3 $ !
4 $ ! Set the def dir to proper place for use in batch. Works for interactive too.
5 $flnm = f$enviroment("PROCEDURE") ! get current procedure name
6 $set default 'f$parse(flnm,,,"DEVICE")''f$parse(flnm,,,"DIRECTORY")'
7 $ !
8 $set symbol/scope=(nolocal,noglobal)
9 $if f$trnlnm("IFILE$").nes."" then close/noLog ifile$
10 $ !
11 $ echo = "write sys$output"
12 $ !
13 $ arch_indx = 1 + ((f$getsyi("CPU").ge.128).and.1) ! vax==1, alpha==2
14 $ arch = f$element(arch_indx,"|","|vax|alpha|")
15 $ !
16 $ if f$search("config.h") .nes. "" then delete config.h.*
17 $ if arch .eqs. "vax"
18 $ then
19 $ copy [.config.'arch']xm-vms.h []config.h
20 $ echo "Linked `config.h' to `[.config.''arch']xm-vms.h'."
21 $else
22 $ open/write cfile []config.h
23 $ write cfile "#include "+"""config/"+arch+"/xm-"+arch+".h"+"""
24 $ write cfile "#include "+"""config/"+arch+"/xm-vms.h"+"""
25 $ close cfile
26 $ echo "Created `config.h'."
27 $ endif
28 $ !
29 $ if f$search("tconfig.h") .nes. "" then delete tconfig.h.*
30 $ create []tconfig.h
31 $DECK
32 /* tconfig.h == config.h :: target and host configurations are the same */
33 #include "config.h"
34 $EOD
35 $ echo "Created `tconfig.h'.
36 $ !
37 $ if f$search("hconfig.h") .nes. "" then delete hconfig.h.*
38 $ create []hconfig.h
39 $DECK
40 /* hconfig.h == config.h :: host and target configurations are the same */
41 #include "config.h"
42 $EOD
43 $ echo "Created `hconfig.h'.
44 $ !
45 $ if f$search("tm.h") .nes. "" then delete tm.h.*
46 $ !
47 $ edit/tpu/nojournal/nosection/nodisplay/command=sys$input -
48 [.config.'arch']vms.h /output=[]tm.h
49 $DECK
50 !
51 ! Copy file, changing lines of the form
52 ! #include "vax/*"
53 ! or
54 ! #include "alpha/*"
55 ! into
56 ! #include "config-*"
57 !
58 file := CREATE_BUFFER("file", GET_INFO(COMMAND_LINE, "file_name"));
59 targ := LINE_BEGIN & '#include' & SPAN(ASCII(32)+ASCII(9))
60 & '"' & ('vax' | 'alpha') & '/';
61 rang := CREATE_RANGE(BEGINNING_OF(file), END_OF(file));
62 LOOP
63 incl := SEARCH_QUIETLY(targ, FORWARD, EXACT, rang);
64 EXITIF incl = 0;
65 POSITION(BEGINNING_OF(incl));
66 ERASE(incl);
67 COPY_TEXT('#include "config-');
68 rang := CREATE_RANGE(END_OF(incl), END_OF(file));
69 ENDLOOP;
70 WRITE_FILE(file, GET_INFO(COMMAND_LINE, "output_file"));
71 QUIT
72 $ EOD
73 $ echo "Generated `tm.h' from `[.config.''arch']vms.h'."
74 $ !
75 $ !crude hack to allow compiling from [.cp] subdirectory
76 $ if f$search("config-''arch'.h") .nes. "" then delete config-'arch'.h;*
77 $ copy [.config.'arch']'arch'.h []config-'arch'.h
78 $ echo "Linked `config-''arch'.h' to `[.config.''arch']''arch'.h' for `tm.h'."
79 $ !
80 $ call make_lang_incl "options.h"
81 $ !
82 $ call make_lang_incl "specs.h"
83 $ !
84 $ if arch .eqs. "vax"
85 $ then
86 $ if f$search("''arch'.md") .nes. "" then delete 'arch'.md;*
87 $ copy [.config.'arch']'arch'.md []'arch'.md
88 $ echo "Copied `''arch'.md' from `[.config.''arch']''arch'.md'."
89 $ endif
90 $ !
91 $ if f$search("aux-output.c") .nes. "" then delete aux-output.c.*
92 $ copy [.config.'arch']'arch'.c []aux-output.c
93 $ echo "Linked `aux-output.c' to `[.config.''arch']''arch'.c'.
94 $ !
95 $ !
96 $ !
97 $ ! Create the file version.opt, which helps identify the executable.
98 $ !
99 $search version.c version_string,"="/match=and/output=t.tmp
100 $open ifile$ t.tmp
101 $read ifile$ line
102 $close ifile$
103 $delete t.tmp;
104 $ijk=f$locate("""",line)+1
105 $line=f$extract(ijk,f$length(line)-ijk,line)
106 $ijk=f$locate("""",line)
107 $line=f$extract(0,ijk,line)
108 $ijk=f$locate("\n",line)
109 $line=f$extract(0,ijk,line)
110 $ !
111 $elm=f$element(1," ",line)
112 $ !
113 $write_ident:
114 $open/write ifile$ version.opt
115 $write ifile$ "ident="+""""+elm+""""
116 $close ifile$
117 $purge version.opt
118 $!
119 $!
120 $! create linker options files that lists all of the components for all
121 $! possible compilers. We do this by editing the file Makefile.in, and
122 $! generating the relevant files from it.
123 $!
124 $!
125 $! Make a copy of the makefile if the sources are on a disk that is NFS
126 $! mounted on a unix machine.
127 $if f$search("Makefile.in").eqs."" .and. f$search("$M$akefile.in").nes."" -
128 then copy $M$akefile.in Makefile.in
129 $! This should be automated across all front-end subdirectories.
130 $! For now, it's hardcoded.
131 $if f$search("[.cp]Makefile.in").eqs."" .and. f$search("[.cp]$M$akefile.in").nes."" -
132 then copy [.cp]$M$akefile.in [.cp]Makefile.in
133 $!
134 $!
135 $echo "Now processing Makefile.in to generate linker option files."
136 $edit/TPU/noJournal/noSection/noDisplay/Command=sys$input: Makefile.in -
137 /Start_Position=('arch_indx') ! 1 for vax, 2 for alpha
138 !!
139 VARIABLE makefile_buf, opt_file_buf, complist_buf, extra_compilers; ! Globals.
140 VARIABLE arch; ! String 'vax' or 'alpha', set in configure_makefile().
141
142 !!
143 PROCEDURE process_makefile( )
144 !
145 ! Interpret Makefile.in and subsidiary Make-lang.in templates.
146 !
147 LOCAL range1, cmark, makefilename;
148
149 makefilename := GET_INFO (COMMAND_LINE, 'FILE_NAME'); ! "Makefile.in"
150 makefile_buf := CREATE_BUFFER ("makefile", makefilename);
151 opt_file_buf := CREATE_BUFFER ("opt_file");
152 complist_buf := CREATE_BUFFER ("complist");
153 extra_compilers := CREATE_ARRAY;
154 !
155 SET (NO_WRITE, makefile_buf, ON); ! Used as workspace; don't save it.
156 SET (OUTPUT_FILE, complist_buf, "compilers.list");
157 !
158 ! Make some textual substitutions.
159 !
160 configure_makefile ();
161 !
162 ! Collect a list of supported compilers (``COMPILERS=xxx'' macro).
163 !
164 identify_compilers ();
165 !
166 ! Plus other known compilers described by Make-lang.in makefile fragments.
167 ! Add new entries as needed; args are (target name, subdirectory name).
168 !
169 additional_compiler ("cc1plus", "cp");
170 !
171 WRITE_FILE (complist_buf); ! Now save "compilers.list".
172 !
173 ! Add to this list, as required. The file "Makefile.in" is searched for
174 ! a tag that looks like "LINE_BEGIN + 'tag + (optional space) + "="".
175 ! The contents are assumed to be a list of object files, and from this
176 ! list a VMS linker options file is generated.
177 !
178 generate_option_file ("OBJS", "=", "independent.opt");
179 generate_option_file ("LIB2FUNCS", "=", "libgcc2.list");
180 generate_option_file ("CXX_LIB2FUNCS", "=", "libgcc2-cxx.list");
181 generate_option_file ("BC_ALL", "=", "bc_all.list");
182 generate_option_file ("BI_OBJ", "=", "bi_all.opt");
183 !
184 ! Now change OBJS in the Makefile, so each language specific options file
185 ! does not pick up all of the language independent files.
186 !
187 POSITION (BEGINNING_OF (makefile_buf));
188 COPY_TEXT ("OBJS="); ! New copy with empty value, seen before real OBJS.
189 SPLIT_LINE;
190 !
191 ! Lastly, process each compiler-specific object dependency list.
192 !
193 POSITION (BEGINNING_OF (complist_buf));
194 LOOP
195 cmark := MARK (NONE);
196 EXITIF (cmark = END_OF (complist_buf));
197 ! The current line contains the name of a compiler target, such as "cc1".
198 MESSAGE (CURRENT_LINE); ! Give some interactive feedback.
199 generate_option_file (CURRENT_LINE, ":", CURRENT_LINE + "-objs.opt");
200 POSITION (cmark);
201 MOVE_VERTICAL (1); ! Go to the next line.
202 ENDLOOP;
203 ENDPROCEDURE; !process_makefile
204 !!
205
206 PROCEDURE process_objc_lib( )
207 !
208 ! Interpret objc/Makefile, after finishing the top makefile.
209 !
210 ON_ERROR
211 [TPU$_OPENIN]:
212 MESSAGE ("Cannot load objc/Makefile for ""ObjClib""; skipping it.");
213 RETURN;
214 ENDON_ERROR;
215
216 ERASE (makefile_buf); !discard top Makefile
217 POSITION (END_OF (makefile_buf));
218 READ_FILE ("[.objc]Makefile"); !load objc one
219 MESSAGE ("objclib");
220 pat_replace (ASCII(9), " "); !change any <tab> to <space>
221 generate_option_file ("OBJC_O", "=", "objc-objs.opt");
222 POSITION (BEGINNING_OF (makefile_buf));
223 ! Join any continuation lines; we want the header list to be one line.
224 pat_replace ("\" & LINE_END, );
225 generate_option_file ("OBJC_H", "=", "objc-hdrs.list");
226 ENDPROCEDURE; !process_objc_lib
227 !!
228
229 PROCEDURE configure_makefile( )
230 !
231 ! Plug in some values normally handled by `configure'. Rather than
232 ! replacing the dummy entries, insert the real entries before them.
233 !
234 IF (GET_INFO (COMMAND_LINE, 'START_RECORD') <> 2) THEN
235 arch := 'vax';
236 ELSE
237 arch := 'alpha';
238 ENDIF;
239 POSITION (BEGINNING_OF (makefile_buf));
240 COPY_TEXT ("target=" + arch + "-vms"); SPLIT_LINE;
241 COPY_TEXT ("out_file=aux-output.c"); SPLIT_LINE; ! 'arch'/'arch'.c
242 COPY_TEXT ("out_object_file=aux-output.o"); SPLIT_LINE; ! aux-output.obj
243 COPY_TEXT ("md_file=" + arch + ".md"); SPLIT_LINE; ! 'arch'/'arch'.md
244 COPY_TEXT ("tm_file=tm.h"); SPLIT_LINE; ! 'arch'/tm-vms.h
245 pat_replace ("@" &
246 SPAN("abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ#~0123456789")
247 & "@", ); ! strip `configure' dummy values
248 ENDPROCEDURE; !configure_makefile
249 !!
250
251 PROCEDURE identify_compilers( )
252 !
253 ! Retrieve the list of supported compilers from Makefile.in, and put them
254 ! into file "compilers.list", one per line, for subsequent access from DCL.
255 !
256 LOCAL range1;
257
258 ! Strip most comments from the makefile, to speed up subsequent processing.
259 POSITION (BEGINNING_OF (makefile_buf));
260 pat_replace (LINE_BEGIN & "#" & REMAIN & LINE_END, );
261 pat_replace ("$(exeext)", );
262 pat_replace ("@all_compilers@", );
263 !# ! Convert directory references to VMS syntax (actually, just strip it).
264 !# pat_replace (" $(srcdir)/", " ");
265 ! Look up the ``COMPILERS=cc1 xyzzy'' Makefile macro and put
266 ! its ``cc1 xyzzy'' value into the compilers buffer.
267 POSITION (BEGINNING_OF (complist_buf));
268 !#--at some point we may want to add this--
269 !# recursive_fetch_tag ("CCCP", "="); ! Include the preprocessor.
270 !# POSITION (END_OF (complist_buf));
271 recursive_fetch_tag ("COMPILERS", "=");
272 ! Convert all spaces into newlines, then remove any blank lines.
273 pat_replace (SPAN(" "), LINE_END);
274 pat_replace (LINE_BEGIN & LINE_END, );
275 ENDPROCEDURE; !identify_compilers
276 !!
277
278 PROCEDURE additional_compiler( cname, subdir )
279 !
280 ! Load Make-lang.in for compiler CNAME from SUBDIR and append it to the
281 ! end of Makefile.in's buffer. Add CNAME to the "compilers.list" buffer.
282 !
283 ON_ERROR
284 ! Don't abort if user removes the supporting subdirectory for a
285 ! language she's not interested in.
286 [TPU$_OPENIN]:
287 MESSAGE ("Cannot load " + subdir + "/Make-lang.in for "
288 + '"' + cname + '"' + "; skipping it.");
289 RETURN;
290 ENDON_ERROR;
291
292 POSITION (END_OF (makefile_buf));
293 SPLIT_LINE; ! Separate with a blank line.
294 READ_FILE ("[." + subdir + "]Make-lang.in"); ! Load Makefile fragment.
295 ! Make sure that $(xxx_OTH_SRCS) expands to empty string by renaming $(it)
296 pat_replace ("_OTH_SRCS)", "_OTH_SRCS_dummy_)");
297 ! Convert subdirectory references into VMS syntax.
298 pat_replace ("$(srcdir)/" + subdir + "/", "[." + subdir + "]");
299 ! Add this name to compilers.list.
300 POSITION (END_OF (complist_buf));
301 COPY_TEXT (cname);
302 ! Make array entry indexed by compiler's file name; its value is arbitrary.
303 extra_compilers{cname} := subdir;
304 ENDPROCEDURE; !additional_compiler
305 !!
306
307 PROCEDURE generate_option_file( tag_name, punct, outfile_name )
308 !
309 ! Produce a file listing the names of particular object files, for use
310 ! as input to the linker and also for use in finding source names by
311 ! make-cc1.com. Generally, any name suffix will be suppressed.
312 !
313 LOCAL range1, range2;
314
315 POSITION (BEGINNING_OF (opt_file_buf));
316 recursive_fetch_tag (tag_name, punct);
317 ! First fix up for subdirectory/Make-lang.in.
318 IF (pat_replace ("stamp-objlist" & (SPAN(" ")|LINE_END), " ") > 0) THEN
319 recursive_fetch_tag ("stamp-objlist", ":");
320 ENDIF;
321 ! Now fix up a few things in the output buffer.
322 pat_replace (("bytecode"|"Makefile") & (SPAN(" ")|LINE_END), " ");
323 !# FILL (CURRENT_BUFFER, " ", 1, 80, 0); ! Condense things a bit.
324 pat_replace ("." & ("o"|"c"|"y") & ((SPAN(" ")&LINE_END)|LINE_END), LINE_END);
325 pat_replace ("." & ("o"|"c"|"y") & SPAN(" "), ",");
326 pat_replace (".h" & (SPAN(" ")|LINE_END), ".h,");
327 ! Remove trailing commas, if present.
328 pat_replace ("," & ((SPAN(" ")&LINE_END)|LINE_END), LINE_END);
329 ! Get rid of spaces and blank lines.
330 pat_replace (SPAN(" "), LINE_END);
331 pat_replace (LINE_BEGIN & LINE_END, );
332 ! Second fix up for subdirectory/Make-lang.in;
333 ! avoid "sticky defaults" when linker processes the resulting options file.
334 IF (extra_compilers{outfile_name - "-objs.opt"} <> TPU$K_UNSPECIFIED) THEN
335 POSITION (BEGINNING_OF (opt_file_buf));
336 range1 := CREATE_RANGE (MARK (NONE), END_OF (CURRENT_BUFFER), NONE);
337 LOOP
338 range2 := SEARCH_QUIETLY (LINE_BEGIN | ",", FORWARD, EXACT, range1);
339 EXITIF (range2 = 0);
340 POSITION (BEGINNING_OF (range2));
341 IF (CURRENT_CHARACTER = ",") THEN MOVE_HORIZONTAL (1); ENDIF;
342 ! If it's not already "[.subdir]name", explicitly make it "[]name".
343 IF (CURRENT_CHARACTER <> "[") THEN COPY_TEXT ("[]"); ENDIF;
344 MOVE_HORIZONTAL (1);
345 MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
346 ENDLOOP;
347 ENDIF;
348 ! Now write the output file.
349 SET (OUTPUT_FILE, opt_file_buf, outfile_name);
350 WRITE_FILE (opt_file_buf);
351 ERASE (opt_file_buf); ! Clear buffer out for next opt_file pass.
352 ENDPROCEDURE; !generate_option_file
353 !!
354
355 PROCEDURE recursive_fetch_tag( tag_n, punct )
356 !
357 ! Look up TAG_N, copy it to OPT_FILE_BUF, and then translate any $(...)
358 ! definitions that appear. The translation is put at the current point.
359 !
360 LOCAL mark1, mark2, range1, tag_range, tag_string;
361
362 fetch_tag (tag_n, punct);
363 ! Substitute any makefile symbols $(...).
364 POSITION (BEGINNING_OF (CURRENT_BUFFER));
365 LOOP
366 range1 := SEARCH_QUIETLY ("$(" &
367 SPAN("abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ#~0123456789")
368 & ")", FORWARD, EXACT);
369 EXITIF (range1 = 0);
370 POSITION (BEGINNING_OF (range1));
371 MOVE_HORIZONTAL (2); ! Past opening "$(".
372 mark1 := MARK (NONE);
373 POSITION (END_OF (range1));
374 MOVE_HORIZONTAL (-1); ! In front of closing ")".
375 mark2 := MARK (NONE);
376 tag_range := CREATE_RANGE (mark1, mark2, NONE);
377 POSITION (END_OF (range1));
378 tag_string := STR (tag_range);
379 ERASE (range1);
380 fetch_tag (tag_string, "=");
381 POSITION (BEGINNING_OF (CURRENT_BUFFER));
382 ENDLOOP;
383 ENDPROCEDURE; !recursive_fetch_tag
384 !!
385
386 PROCEDURE fetch_tag( tag_n, punct )
387 !
388 ! Looks up the translation of a tag, and inserts it at the current location
389 ! in the buffer.
390 !
391 LOCAL mark0, mark1, mark2, range2;
392
393 mark0 := MARK (NONE); ! Remember where we started; restore before return.
394 POSITION (BEGINNING_OF (makefile_buf));
395 ! The tag definition always starts in the first column, and might have
396 ! optional space(es) before "=" or ":" punctuation.
397 range2 := SEARCH_QUIETLY (LINE_BEGIN & tag_n & ((SPAN(" ") & punct) | punct),
398 FORWARD, EXACT);
399 IF (range2 = 0) THEN
400 POSITION (mark0);
401 RETURN;
402 ENDIF;
403 POSITION (END_OF (range2));
404 MOVE_HORIZONTAL (1); ! Move beyond "TAG=".
405 mark1 := MARK (NONE);
406 POSITION (BEGINNING_OF (range2));
407 LOOP
408 MOVE_VERTICAL (1);
409 MOVE_HORIZONTAL (-2);
410 EXITIF (CURRENT_CHARACTER <> "\");
411 ERASE_CHARACTER (1);
412 MOVE_HORIZONTAL (1);
413 ENDLOOP;
414 MOVE_HORIZONTAL (1);
415 mark2 := MARK (NONE);
416 range2 := CREATE_RANGE (mark1, mark2, NONE);
417 POSITION (mark0);
418 IF (LENGTH (range2) <> 0) THEN
419 COPY_TEXT (range2);
420 ENDIF;
421 ENDPROCEDURE; !fetch_tag
422 !!
423
424 PROCEDURE pat_replace( oldstring, newstring )
425 !
426 ! Replace all occurrences of a pattern.
427 !
428 LOCAL range1, range2, kill_it, count;
429
430 count := 0;
431 kill_it := (GET_INFO (newstring, 'TYPE') = UNSPECIFIED); ! Omitted arg.
432 range1 := CREATE_RANGE (BEGINNING_OF (CURRENT_BUFFER),
433 END_OF (CURRENT_BUFFER), NONE);
434 LOOP
435 range2 := SEARCH_QUIETLY (oldstring, FORWARD, EXACT, range1);
436 EXITIF (range2 = 0);
437 count := count + 1;
438 POSITION (BEGINNING_OF (range2));
439 ERASE (range2);
440 IF (newstring = LINE_END) THEN
441 SPLIT_LINE;
442 ELSE IF (NOT kill_it) THEN
443 COPY_TEXT (newstring);
444 ENDIF; ENDIF;
445 MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
446 ENDLOOP;
447 RETURN count;
448 ENDPROCEDURE; !pat_replace
449 !!
450
451 !
452 ! This is the main routine.
453 !
454 process_makefile ();
455 process_objc_lib (); !this uses a different makefile
456 QUIT; ! All done; don't write any modified buffers.
457 !!
458 $ echo ""
459 $!
460 $! Remove excessive versions of the option files...
461 $!
462 $ purge *.opt,*.list
463 $!
464 $!
465 $!
466 $ if f$search("config.status") .nes. "" then delete config.status.*
467 $ create config.status
468 $ open/append ifile$ config.status
469 $ write ifile$ "Links are now set up for use with a ''arch' running VMS."
470 $ close ifile$
471 $ type config.status
472 $ echo ""
473 $!
474 $ exit
475 $
476 $!
477 $! Construct a header file based on subdirectory contents
478 $!
479 $make_lang_incl: subroutine
480 $ if f$search(p1).nes."" then delete 'p1';*
481 $ create 'p1' !empty file with ordinary text-file attributes
482 $ open/Append ifile$ 'p1'
483 $ write ifile$ "/* ''p1' */"
484 $ hfile = f$search("[]''p1'")
485 $ topdir = f$parse(hfile,,,"DIRECTORY") - "]"
486 $lang_incl_loop:
487 $ hfile = f$search("[.*]lang-''p1'")
488 $ if hfile.eqs."" then goto lang_incl_done
489 $ dir = f$parse(hfile,,,"DIRECTORY") - "]"
490 $! convert absolute path to relative one, yielding "[.subdir]"
491 $ dir = "[" + f$edit(dir - topdir,"LOWERCASE") + "]"
492 $ write ifile$ "#include ""''dir'lang-''p1'"""
493 $ goto lang_incl_loop
494 $lang_incl_done:
495 $ close ifile$
496 $ echo "Created `''p1''."
497 $ endsubroutine !make_lang_incl