(TPU makefile.in): Reorganize and reformat code.
authorkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 12 May 1995 18:39:59 +0000 (18:39 +0000)
committerkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 12 May 1995 18:39:59 +0000 (18:39 +0000)
Make generated .opt files have more consistent format (all comma
separated, excess whitespace eliminated);
(additional_compiler): New routine.
(process_makefile): Use it to handle cc1plus via cp/Make-lang.in.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@9655 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/vmsconfig.com

index 6009ee6..4ff9377 100644 (file)
@@ -120,216 +120,272 @@ $if f$search("[.cp]Makefile.in").eqs."" .and. f$search("[.cp]$M$akefile.in").nes
 $!
 $!
 $echo "Now processing Makefile.in to generate linker option files."
-$edit/tpu/nojournal/nosection/nodisplay/command=sys$input
-   PROCEDURE generate_option_file (TAG_NAME, outfile)
-        position (beginning_of (newbuffer));
-        recursive_fetch_tag (TAG_NAME);
-!
-! Now fix up a few things in the output buffer
-!
-       pat_replace ("bytecode "," ");
-       pat_replace (".o ",",");
-       pat_replace (".o","");  !appear at end of lines.
-!
-! Remove trailing commas, if present.
-!
-       position (beginning_of (newbuffer));
-       LOOP
-         range1 := search_quietly("," & ((SPAN(" ") & LINE_END) | LINE_END),
-                                  FORWARD, EXACT);
-         exitif range1 = 0;
-         position (beginning_of (range1));
-         erase(range1);
-         split_line;           
-         ENDLOOP;
-! get rid of leading spaces on lines.
-        position (beginning_of (current_buffer)) ;
-       LOOP
-          range1 := search_quietly ( LINE_BEGIN & " ", FORWARD, EXACT) ;
-         EXITIF range1 = 0;
-         position (end_of (range1));
-         erase_character(1);
-       ENDLOOP;       
-!
-! Now write the output file.
-!
-       SET(OUTPUT_FILE, newbuffer, outfile);
-      write_file (newbuffer);
-      erase (newbuffer);
-   ENDPROCEDURE;
+$edit/TPU/noJournal/noSection/noDisplay/Command=sys$input: Makefile.in
+!!
+VARIABLE makefile_buf, opt_file_buf, complist_buf, extra_compilers; ! Globals.
 
-!
-! Looks up a tag, copies it to newbuffer, and then translates any $(...)
-! definitions that appear.  The translation is put at the current point.
-!
-   PROCEDURE recursive_fetch_tag (TAG_N);
-   fetch_tag (TAG_N);
-!
-! substitute any  makefile symbols $(...)
-!
-        position (beginning_of (current_buffer)) ;
-       LOOP
-         range1 := search_quietly ("$(" &  
+!!
+PROCEDURE process_makefile( )
+  !
+  ! Intepret Makefile.in and subsidiary Make-lang.in templates.
+  !
+  LOCAL range1, cmark, makefilename;
+
+  makefilename   := GET_INFO (COMMAND_LINE, 'FILE_NAME'); ! "Makefile.in"
+  makefile_buf   := CREATE_BUFFER ("makefile", makefilename);
+  opt_file_buf   := CREATE_BUFFER ("opt_file");
+  complist_buf   := CREATE_BUFFER ("complist");
+  extra_compilers := CREATE_ARRAY;
+  !
+  SET (NO_WRITE, makefile_buf, ON);    ! Used as workspace; don't save it.
+  SET (OUTPUT_FILE, complist_buf, "compilers.list");
+  !
+  ! Collect a list of supported compilers (``COMPILERS=xxx'' macro).
+  !
+  identify_compilers ();
+  !
+  ! Plus other known compilers described by Make-lang.in makefile fragments.
+  ! Add new entries as needed; args are (target name, subdirectory name).
+  !
+  additional_compiler ("cc1plus", "cp");
+  !
+  WRITE_FILE (complist_buf);           ! Now save "compilers.list".
+  !
+  ! Add to this list, as required.  The file "Makefile.in" is searched for
+  ! a tag that looks like "LINE_BEGIN + 'tag + (optional space) + "="".
+  ! The contents are assumed to be a list of object files, and from this
+  ! list a VMS linker options file is generated.
+  !
+  generate_option_file ("OBJS",      "=", "independent.opt");
+  generate_option_file ("LIB2FUNCS", "=", "libgcc2.list");
+  generate_option_file ("BC_ALL",    "=", "bc_all.opt");
+  generate_option_file ("BI_OBJ",    "=", "bi_all.opt");
+  !
+  ! Now change OBJS in the Makefile, so each language specific options file
+  ! does not pick up all of the language independent files.
+  !
+  POSITION (BEGINNING_OF (makefile_buf));
+  COPY_TEXT ("OBJS="); ! New copy with empty value, seen before real OBJS.
+  SPLIT_LINE;
+  !
+  ! Lastly, process each compiler-specific object dependency list.
+  !
+  POSITION (BEGINNING_OF (complist_buf));
+  LOOP
+    cmark := MARK (NONE);
+    EXITIF (cmark = END_OF (complist_buf));
+    ! The current line contains the name of a compiler target, such as "cc1".
+    MESSAGE (CURRENT_LINE);    ! Give some interactive feedback.
+    generate_option_file (CURRENT_LINE, ":", CURRENT_LINE + "-objs.opt");
+    POSITION (cmark);
+    MOVE_VERTICAL (1);         ! Go to the next line.
+  ENDLOOP;
+ENDPROCEDURE; !process_makefile
+!!
+
+PROCEDURE identify_compilers( )
+  !
+  ! Retrieve the list of supported compilers from Makefile.in, and put them
+  ! into file "compilers.list", one per line, for subsequent access from DCL.
+  !
+  LOCAL range1;
+
+  ! Strip most comments from the makefile, to speed up subsequent processing.
+  POSITION (BEGINNING_OF (makefile_buf));
+  pat_replace (LINE_BEGIN & "#" & REMAIN & LINE_END, );
+!#  ! Convert directory references to VMS syntax (actually, just strip it).
+!#  pat_replace (" $(srcdir)/", " ");
+  ! Look up the ``COMPILERS=cc1 xyzzy'' Makefile macro and put
+  ! its ``cc1 xyzzy'' value into the compilers buffer.
+  POSITION (BEGINNING_OF (complist_buf));
+!#--at some point we may want to add this--
+!#  recursive_fetch_tag ("CCCP", "=");   ! Include the preprocessor.
+!#  POSITION (END_OF (complist_buf));
+  recursive_fetch_tag ("COMPILERS", "=");
+  ! Convert all spaces into newlines, then remove any blank lines.
+  pat_replace (SPAN(" "), LINE_END);
+  pat_replace (LINE_BEGIN & LINE_END, );
+ENDPROCEDURE; !identify_compilers
+!!
+
+PROCEDURE additional_compiler( cname, subdir )
+  !
+  ! Load Make-lang.in for compiler CNAME from SUBDIR and append it to the
+  ! end of Makefile.in's buffer.  Add CNAME to the "compilers.list" buffer.
+  !
+  ON_ERROR
+    ! Don't abort if user removes the supporting subdirectory for a
+    ! language she's not interested in.
+    [TPU$_OPENIN]:
+      MESSAGE ("Cannot load " + subdir + "/Make-lang.in for "
+              + '"' + cname + '"' + "; skipping it.");
+      RETURN;
+  ENDON_ERROR;
+
+  POSITION (END_OF (makefile_buf));
+  SPLIT_LINE;  ! Separate with a blank line.
+  READ_FILE ("[." + subdir + "]Make-lang.in"); ! Load Makefile fragment.
+  ! Make sure that $(xxx_OTH_SRCS) expands to empty string by renaming $(it)
+  pat_replace ("_OTH_SRCS)", "_OTH_SRCS_dummy_)");
+  ! Convert subdirectory references into VMS syntax.
+  pat_replace ("$(srcdir)/" + subdir + "/", "[." + subdir + "]");
+  ! Add this name to compilers.list.
+  POSITION (END_OF (complist_buf));
+  COPY_TEXT (cname);
+  ! Make array entry indexed by compiler's file name; its value is arbitrary.
+  extra_compilers{cname} := subdir;
+ENDPROCEDURE; !additional_compiler
+!!
+
+PROCEDURE generate_option_file( tag_name, punct, outfile_name )
+  !
+  ! Produce a file listing the names of particular object files, for use
+  ! as input to the linker and also for use in finding source names by
+  ! make-cc1.com.  Generally, any name suffix will be suppressed.
+  !
+  LOCAL range1, range2;
+
+  POSITION (BEGINNING_OF (opt_file_buf));
+  recursive_fetch_tag (tag_name, punct);
+  ! First fix up for subdirectory/Make-lang.in.
+  IF (pat_replace ("stamp-objlist" & (SPAN(" ")|LINE_END), " ") > 0) THEN
+    recursive_fetch_tag ("stamp-objlist", ":");
+  ENDIF;
+  ! Now fix up a few things in the output buffer.
+  pat_replace (("bytecode"|"Makefile") & (SPAN(" ")|LINE_END), " ");
+!#  FILL (CURRENT_BUFFER, " ", 1, 80, 0);      ! Condense things a bit.
+  pat_replace ("." & ("o"|"c"|"h"|"y") & ((SPAN(" ")&LINE_END)|LINE_END), LINE_END);
+  pat_replace ("." & ("o"|"c"|"h"|"y") & SPAN(" "), ",");
+!#  ! Remove trailing commas, if present.  {Above patterns preclude any such.}
+!#  pat_replace ("," & ((SPAN(" ")&LINE_END)|LINE_END), LINE_END);
+  ! Get rid of spaces and blank lines.
+  pat_replace (SPAN(" "), LINE_END);
+  pat_replace (LINE_BEGIN & LINE_END, );
+  ! Second fix up for subdirectory/Make-lang.in;
+  ! avoid "sticky defaults" when linker processes the resulting options file.
+  IF (extra_compilers{outfile_name - "-objs.opt"} <> TPU$K_UNSPECIFIED) THEN
+    POSITION (BEGINNING_OF (opt_file_buf));
+    range1 := CREATE_RANGE (MARK (NONE), END_OF (CURRENT_BUFFER), NONE);
+    LOOP
+      range2 := SEARCH_QUIETLY (LINE_BEGIN | ",", FORWARD, EXACT, range1);
+      EXITIF (range2 = 0);
+      POSITION (BEGINNING_OF (range2));
+      IF (CURRENT_CHARACTER = ",") THEN  MOVE_HORIZONTAL (1); ENDIF;
+      ! If it's not already "[.subdir]name", explicitly make it "[]name".
+      IF (CURRENT_CHARACTER <> "[") THEN  COPY_TEXT ("[]"); ENDIF;
+      MOVE_HORIZONTAL (1);
+      MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
+    ENDLOOP;
+  ENDIF;
+  ! Now write the output file.
+  SET (OUTPUT_FILE, opt_file_buf, outfile_name);
+  WRITE_FILE (opt_file_buf);
+  ERASE (opt_file_buf);                ! Clear buffer out for next opt_file pass.
+ENDPROCEDURE; !generate_option_file
+!!
+
+PROCEDURE recursive_fetch_tag( tag_n, punct )
+  !
+  ! Look up TAG_N, copy it to OPT_FILE_BUF, and then translate any $(...)
+  ! definitions that appear.  The translation is put at the current point.
+  !
+  LOCAL mark1, mark2, range1, tag_range, tag_string;
+
+  fetch_tag (tag_n, punct);
+  ! Substitute any makefile symbols $(...).
+  POSITION (BEGINNING_OF (CURRENT_BUFFER));
+  LOOP
+    range1 := SEARCH_QUIETLY ("$(" &
       SPAN("abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ#~0123456789")
-                                   & ")", FORWARD, EXACT) ;
-         EXITIF range1 = 0;
-         position (beginning_of (range1));
-         move_horizontal(2);
-         mark_1 := MARK (NONE);
-         position (end_of (range1));
-         move_horizontal(-1);
-         mark_2 := MARK (NONE);
-         tag_range := CREATE_RANGE(MARK_1, MARK_2, NONE);
-         position (end_of (range1));
-         tag_string := STR (tag_range);
-         erase (range1);
-         fetch_tag (LINE_BEGIN & tag_string & ((SPAN(" ") & "=") | "="));
-          position (beginning_of (current_buffer)) ;
-       ENDLOOP;       
-   ENDPROCEDURE;
+                                  & ")", FORWARD, EXACT);
+    EXITIF (range1 = 0);
+    POSITION (BEGINNING_OF (range1));
+    MOVE_HORIZONTAL (2);       ! Past opening "$(".
+    mark1 := MARK (NONE);
+    POSITION (END_OF (range1));
+    MOVE_HORIZONTAL (-1);      ! In front of closing ")".
+    mark2 := MARK (NONE);
+    tag_range := CREATE_RANGE (mark1, mark2, NONE);
+    POSITION (END_OF (range1));
+    tag_string := STR (tag_range);
+    ERASE (range1);
+    fetch_tag (tag_string, "=");
+    POSITION (BEGINNING_OF (CURRENT_BUFFER));
+  ENDLOOP;
+ENDPROCEDURE; !recursive_fetch_tag
+!!
 
-!
-! Looks up the translation of a tag, and inserts it at the current location
-! in the buffer
-!
-   PROCEDURE fetch_tag (TAG_N);
-      LOCAL mark1, mark2, mark3, range2;
-      mark3 := MARK(NONE) ;
-      position (beginning_of (mainbuffer)) ;
-      range2 := search_quietly (TAG_N, FORWARD, EXACT) ;
-      IF (range2 = 0) then 
-       position (mark3);
-       return;
-       endif;
-      position (end_of (range2)) ;
-      MOVE_HORIZONTAL(1);
-      mark1 := MARK(NONE) ;
-      position (beginning_of (range2)) ;
-      MOVE_VERTICAL(1);
-      MOVE_HORIZONTAL(-2);
-      LOOP
-       EXITIF CURRENT_CHARACTER <> "\" ;
-       ERASE_CHARACTER(1);
-       MOVE_HORIZONTAL(1);
-       MOVE_VERTICAL(1);
-       MOVE_HORIZONTAL(-2);
-       ENDLOOP;
-      MOVE_HORIZONTAL(1);
-      mark2 := MARK(NONE) ;
-      range2 := CREATE_RANGE(mark1, mark2, NONE) ;
-      position (mark3);
-      if (length(range2) = 0) then return; endif;
-      copy_text(range2);
-   ENDPROCEDURE;
+PROCEDURE fetch_tag( tag_n, punct )
+  !
+  ! Looks up the translation of a tag, and inserts it at the current location
+  ! in the buffer.
+  !
+  LOCAL mark0, mark1, mark2, range2;
 
-   PROCEDURE pat_replace (
-      oldstring, !
-      newstring)  !
-      LOCAL range2;
-      position (beginning_of (current_buffer)) ;
-      LOOP
-         range2 := search_quietly (oldstring, FORWARD, EXACT) ;
-         EXITIF range2 = 0 ;
-         position (beginning_of (range2)) ;
-         erase (range2) ;
-         copy_text (newstring) ;
-         ENDLOOP ;
-   ENDPROCEDURE ;
+  mark0 := MARK (NONE);     ! Remember where we started; restore before return.
+  POSITION (BEGINNING_OF (makefile_buf));
+  ! The tag definition always starts in the first column, and might have
+  ! optional space(es) before "=" or ":" punctutation.
+  range2 := SEARCH_QUIETLY (LINE_BEGIN & tag_n & ((SPAN(" ") & punct) | punct),
+                           FORWARD, EXACT);
+  IF (range2 = 0) THEN
+    POSITION (mark0);
+    RETURN;
+  ENDIF;
+  POSITION (END_OF (range2));
+  MOVE_HORIZONTAL (1);         ! Move beyond "TAG=".
+  mark1 := MARK (NONE);
+  POSITION (BEGINNING_OF (range2));
+  LOOP
+    MOVE_VERTICAL (1);
+    MOVE_HORIZONTAL (-2);
+    EXITIF (CURRENT_CHARACTER <> "\");
+    ERASE_CHARACTER (1);
+    MOVE_HORIZONTAL (1);
+  ENDLOOP;
+  MOVE_HORIZONTAL (1);
+  mark2 := MARK (NONE);
+  range2 := CREATE_RANGE (mark1, mark2, NONE);
+  POSITION (mark0);
+  IF (LENGTH (range2) <> 0) THEN
+    COPY_TEXT (range2);
+  ENDIF;
+ENDPROCEDURE; !fetch_tag
+!!
 
-!                !
-! ...fix this... !
-!                !
- procedure temporary_cplusplus_hack()
-  position(end_of(compiler_list));
-  copy_text("cc1plus");
-  position(end_of(mainbuffer));
-  copy_text("cc1plus: [.cp]call,[.cp]decl,[.cp]errfn,[.cp]expr,[.cp]pt,[.cp]sig\");  split_line;
-  copy_text(" [.cp]typeck2,[.cp]class,[.cp]decl2,[.cp]error,[.cp]gc,[.cp]lex\");  split_line;
-  copy_text(" [.cp]parse,[.cp]ptree,[.cp]spew,[.cp]typeck,[.cp]cvt,[.cp]edsel\");  split_line;
-  copy_text(" [.cp]except,[.cp]init,[.cp]method,[.cp]search,[.cp]tree,[.cp]xref\");  split_line;
-  copy_text(" []c-common\");  split_line;
-  copy_text(" bc-emit,bc-optab\");  split_line;
-  copy_text(" obstack");  split_line;
- endprocedure;
+PROCEDURE pat_replace( oldstring, newstring )
+  !
+  ! Replace all occurences of a pattern.
+  !
+  LOCAL range1, range2, kill_it, count;
 
+  count := 0;
+  kill_it := (GET_INFO (newstring, 'TYPE') = UNSPECIFIED);     ! Omitted arg.
+  range1 := CREATE_RANGE (BEGINNING_OF (CURRENT_BUFFER),
+                         END_OF (CURRENT_BUFFER), NONE);
+  LOOP
+    range2 := SEARCH_QUIETLY (oldstring, FORWARD, EXACT, range1);
+    EXITIF (range2 = 0);
+    count := count + 1;
+    POSITION (BEGINNING_OF (range2));
+    ERASE (range2);
+    IF (newstring = LINE_END) THEN
+      SPLIT_LINE;
+    ELSE IF (NOT kill_it) THEN
+      COPY_TEXT (newstring);
+    ENDIF; ENDIF;
+    MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
+  ENDLOOP;
+  RETURN count;
+ENDPROCEDURE; !pat_replace
+!!
 
 !
-! this is the start of the main procedure
-   filename := GET_INFO (COMMAND_LINE, 'file_name') ;
-   mainbuffer := CREATE_BUFFER ("Makefile.in", "Makefile.in") ;
-   newbuffer := CREATE_BUFFER("outfile");
-   compiler_list := CREATE_BUFFER("compilers");
+! This is the main routine.
 !
-! Add to this list, as required.  The file "Makefile.in" is searched for a
-! tag that looks like "LINE_BEGIN + 'tag + (optional space) + "="".  The
-! contents are assumed to be a list of object files, and from this list a
-! VMS linker options file is generated.
-!
-   position (beginning_of (compiler_list));
-   recursive_fetch_tag(LINE_BEGIN & "COMPILERS" & ((SPAN(" ") & "=") | "="));
-   position (beginning_of (compiler_list));
-   LOOP ! kill leading spaces.
-       exitif current_character <> " ";
-       erase_character(1);
-       ENDLOOP;
-   position (beginning_of (compiler_list));
-      LOOP ! remove any double spaces.
-         range1 := search_quietly ("  ", FORWARD, EXACT) ; EXITIF range1 = 0 ;
-         position (beginning_of (range1)) ;
-         erase_character(1);
-         ENDLOOP ;
-   position (end_of (compiler_list));
-   move_horizontal(-1);
-   LOOP ! kill trailing spaces.
-       exitif current_character <> " ";
-       erase_character(1);
-       move_horizontal(-1);
-       ENDLOOP;
-   position (beginning_of (compiler_list));
-      LOOP
-         range1 := search_quietly (" ", FORWARD, EXACT) ;
-         EXITIF range1 = 0 ;
-         position (beginning_of (range1)) ;
-         erase (range1) ;
-        split_line;
-         ENDLOOP ;
-!                         !
-! This needs to be fixed. !
-!                         !
-       temporary_cplusplus_hack();
-!
-! We now have a list of supported compilers.  Now write it, and use it.
-!
-       SET(OUTPUT_FILE, compiler_list, "compilers.list");
-      write_file (compiler_list);
-   generate_option_file(LINE_BEGIN & "OBJS" & ((SPAN(" ") & "=") | "="),
-                       "independent.opt");
-   generate_option_file(LINE_BEGIN & "LIB2FUNCS" & ((SPAN(" ") & "=") | "="),
-                       "libgcc2.list");
-   generate_option_file(LINE_BEGIN & "BC_ALL" & ((SPAN(" ") & "=") | "="),
-                       "bc_all.opt");
-   generate_option_file(LINE_BEGIN & "BI_OBJ" & ((SPAN(" ") & "=") | "="),
-                       "bi_all.opt");
-!
-! Now change OBJS in the Makefile, so each language specific options file 
-! does not pick up all of the language independent files.
-!
-   position (beginning_of (mainbuffer));
-   range1 := search_quietly (LINE_BEGIN & "OBJS" & ((SPAN(" ") & "=") | "="),
-                            FORWARD, EXACT) ;
-   position (end_of (range1));
-   split_line;
-   position (beginning_of (compiler_list));
-   LOOP
-     cmark := mark(NONE);
-     exitif cmark = end_of(compiler_list);
-     message(current_line);
-     generate_option_file(LINE_BEGIN & current_line & ((SPAN(" ") & ":") | ":"),
-                         current_line+"-objs.opt");
-     position (cmark);
-     move_vertical(1);
-   ENDLOOP ;
-   quit ;
+process_makefile ();
+QUIT;  ! All done; don't write any modified buffers.
+!!
 $ echo ""
 $!
 $! Remove excessive versions of the option files...