source: trunk/third/gcc/vmsconfig.com @ 11288

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