OSDN Git Service

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