Commit efe7d021 by Richard Kenner

(TPU makefile.in): Reorganize and reformat code.

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.

From-SVN: r9655
parent a3c1ce7b
...@@ -120,216 +120,272 @@ $if f$search("[.cp]Makefile.in").eqs."" .and. f$search("[.cp]$M$akefile.in").nes ...@@ -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." $echo "Now processing Makefile.in to generate linker option files."
$edit/tpu/nojournal/nosection/nodisplay/command=sys$input $edit/TPU/noJournal/noSection/noDisplay/Command=sys$input: Makefile.in
PROCEDURE generate_option_file (TAG_NAME, outfile) !!
position (beginning_of (newbuffer)); VARIABLE makefile_buf, opt_file_buf, complist_buf, extra_compilers; ! Globals.
recursive_fetch_tag (TAG_NAME);
! !!
! Now fix up a few things in the output buffer PROCEDURE process_makefile( )
! !
pat_replace ("bytecode "," "); ! Intepret Makefile.in and subsidiary Make-lang.in templates.
pat_replace (".o ",","); !
pat_replace (".o",""); !appear at end of lines. LOCAL range1, cmark, makefilename;
!
! Remove trailing commas, if present. makefilename := GET_INFO (COMMAND_LINE, 'FILE_NAME'); ! "Makefile.in"
! makefile_buf := CREATE_BUFFER ("makefile", makefilename);
position (beginning_of (newbuffer)); 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 LOOP
range1 := search_quietly("," & ((SPAN(" ") & LINE_END) | LINE_END), cmark := MARK (NONE);
FORWARD, EXACT); EXITIF (cmark = END_OF (complist_buf));
exitif range1 = 0; ! The current line contains the name of a compiler target, such as "cc1".
position (beginning_of (range1)); MESSAGE (CURRENT_LINE); ! Give some interactive feedback.
erase(range1); generate_option_file (CURRENT_LINE, ":", CURRENT_LINE + "-objs.opt");
split_line; POSITION (cmark);
MOVE_VERTICAL (1); ! Go to the next line.
ENDLOOP; ENDLOOP;
! get rid of leading spaces on lines. ENDPROCEDURE; !process_makefile
position (beginning_of (current_buffer)) ; !!
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 LOOP
range1 := search_quietly ( LINE_BEGIN & " ", FORWARD, EXACT) ; range2 := SEARCH_QUIETLY (LINE_BEGIN | ",", FORWARD, EXACT, range1);
EXITIF range1 = 0; EXITIF (range2 = 0);
position (end_of (range1)); POSITION (BEGINNING_OF (range2));
erase_character(1); 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; ENDLOOP;
! ENDIF;
! Now write the output file. ! Now write the output file.
! SET (OUTPUT_FILE, opt_file_buf, outfile_name);
SET(OUTPUT_FILE, newbuffer, outfile); WRITE_FILE (opt_file_buf);
write_file (newbuffer); ERASE (opt_file_buf); ! Clear buffer out for next opt_file pass.
erase (newbuffer); ENDPROCEDURE; !generate_option_file
ENDPROCEDURE; !!
! PROCEDURE recursive_fetch_tag( tag_n, punct )
! Looks up a tag, copies it to newbuffer, and then translates any $(...) !
! definitions that appear. The translation is put at the current point. ! 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.
PROCEDURE recursive_fetch_tag (TAG_N); !
fetch_tag (TAG_N); LOCAL mark1, mark2, range1, tag_range, tag_string;
!
! substitute any makefile symbols $(...) fetch_tag (tag_n, punct);
! ! Substitute any makefile symbols $(...).
position (beginning_of (current_buffer)) ; POSITION (BEGINNING_OF (CURRENT_BUFFER));
LOOP LOOP
range1 := search_quietly ("$(" & range1 := SEARCH_QUIETLY ("$(" &
SPAN("abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ#~0123456789") SPAN("abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ#~0123456789")
& ")", FORWARD, EXACT) ; & ")", FORWARD, EXACT);
EXITIF range1 = 0; EXITIF (range1 = 0);
position (beginning_of (range1)); POSITION (BEGINNING_OF (range1));
move_horizontal(2); MOVE_HORIZONTAL (2); ! Past opening "$(".
mark_1 := MARK (NONE); mark1 := MARK (NONE);
position (end_of (range1)); POSITION (END_OF (range1));
move_horizontal(-1); MOVE_HORIZONTAL (-1); ! In front of closing ")".
mark_2 := MARK (NONE); mark2 := MARK (NONE);
tag_range := CREATE_RANGE(MARK_1, MARK_2, NONE); tag_range := CREATE_RANGE (mark1, mark2, NONE);
position (end_of (range1)); POSITION (END_OF (range1));
tag_string := STR (tag_range); tag_string := STR (tag_range);
erase (range1); ERASE (range1);
fetch_tag (LINE_BEGIN & tag_string & ((SPAN(" ") & "=") | "=")); fetch_tag (tag_string, "=");
position (beginning_of (current_buffer)) ; POSITION (BEGINNING_OF (CURRENT_BUFFER));
ENDLOOP; ENDLOOP;
ENDPROCEDURE; ENDPROCEDURE; !recursive_fetch_tag
!!
! PROCEDURE fetch_tag( tag_n, punct )
! Looks up the translation of a tag, and inserts it at the current location !
! in the buffer ! 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; LOCAL mark0, mark1, mark2, 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 pat_replace ( mark0 := MARK (NONE); ! Remember where we started; restore before return.
oldstring, ! POSITION (BEGINNING_OF (makefile_buf));
newstring) ! ! The tag definition always starts in the first column, and might have
LOCAL range2; ! optional space(es) before "=" or ":" punctutation.
position (beginning_of (current_buffer)) ; 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 LOOP
range2 := search_quietly (oldstring, FORWARD, EXACT) ; MOVE_VERTICAL (1);
EXITIF range2 = 0 ; MOVE_HORIZONTAL (-2);
position (beginning_of (range2)) ; EXITIF (CURRENT_CHARACTER <> "\");
erase (range2) ; ERASE_CHARACTER (1);
copy_text (newstring) ; MOVE_HORIZONTAL (1);
ENDLOOP ; ENDLOOP;
ENDPROCEDURE ; MOVE_HORIZONTAL (1);
mark2 := MARK (NONE);
! ! range2 := CREATE_RANGE (mark1, mark2, NONE);
! ...fix this... ! POSITION (mark0);
! ! IF (LENGTH (range2) <> 0) THEN
procedure temporary_cplusplus_hack() COPY_TEXT (range2);
position(end_of(compiler_list)); ENDIF;
copy_text("cc1plus"); ENDPROCEDURE; !fetch_tag
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;
! this is the start of the main procedure kill_it := (GET_INFO (newstring, 'TYPE') = UNSPECIFIED); ! Omitted arg.
filename := GET_INFO (COMMAND_LINE, 'file_name') ; range1 := CREATE_RANGE (BEGINNING_OF (CURRENT_BUFFER),
mainbuffer := CREATE_BUFFER ("Makefile.in", "Makefile.in") ; END_OF (CURRENT_BUFFER), NONE);
newbuffer := CREATE_BUFFER("outfile");
compiler_list := CREATE_BUFFER("compilers");
!
! 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 LOOP
range1 := search_quietly (" ", FORWARD, EXACT) ; range2 := SEARCH_QUIETLY (oldstring, FORWARD, EXACT, range1);
EXITIF range1 = 0 ; EXITIF (range2 = 0);
position (beginning_of (range1)) ; count := count + 1;
erase (range1) ; POSITION (BEGINNING_OF (range2));
split_line; ERASE (range2);
ENDLOOP ; IF (newstring = LINE_END) THEN
! ! SPLIT_LINE;
! This needs to be fixed. ! ELSE IF (NOT kill_it) THEN
! ! COPY_TEXT (newstring);
temporary_cplusplus_hack(); ENDIF; ENDIF;
! MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
! We now have a list of supported compilers. Now write it, and use it. ENDLOOP;
! RETURN count;
SET(OUTPUT_FILE, compiler_list, "compilers.list"); ENDPROCEDURE; !pat_replace
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 ! This is the main routine.
! does not pick up all of the language independent files.
! !
position (beginning_of (mainbuffer)); process_makefile ();
range1 := search_quietly (LINE_BEGIN & "OBJS" & ((SPAN(" ") & "=") | "="), QUIT; ! All done; don't write any modified buffers.
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 ;
$ echo "" $ echo ""
$! $!
$! Remove excessive versions of the option files... $! Remove excessive versions of the option files...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment