OSDN Git Service

(TPU makefile.in): Reorganize and reformat code.
[pf3gnuchains/gcc-fork.git] / gcc / vmsconfig.com
1 $ !
2 $ !     Set up to compile GCC on VAX/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 $ !
10 $ echo = "write sys$output"
11 $ !
12 $ if f$search("config.h") .nes. "" then delete config.h.*
13 $ copy [.config.vax]xm-vms.h []config.h
14 $ echo "Linked `config.h' to `[.config.vax]xm-vms.h'.
15 $ !
16 $ if f$search("tconfig.h") .nes. "" then delete tconfig.h.*
17 $ create []tconfig.h
18 $DECK
19 /* tconfig.h == config.h :: target and host configurations are the same */
20 #include "config.h"
21 $EOD
22 $ echo "Created `tconfig.h'.
23 $ !
24 $ if f$search("hconfig.h") .nes. "" then delete hconfig.h.*
25 $ create []hconfig.h
26 $DECK
27 /* hconfig.h == config.h :: host and target configurations are the same */
28 #include "config.h"
29 $EOD
30 $ echo "Created `hconfig.h'.
31 $ !
32 $ if f$search("tm.h") .nes. "" then delete tm.h.*
33 $!! copy [.config.vax]vms.h []tm.h
34 $ edit/tpu/nojournal/nosection/nodisplay/command=sys$input -
35         [.config.vax]vms.h /output=[]tm.h
36 $DECK
37 !
38 !  Copy file, changing lines of the form
39 !       #include "vax/*"
40 !  into
41 !       #include "config-*"
42 !
43    file := CREATE_BUFFER("file", GET_INFO(COMMAND_LINE, "file_name"));
44    targ := LINE_BEGIN & '#include' & SPAN(ASCII(32)+ASCII(9)) & '"vax/';
45    rang := CREATE_RANGE(BEGINNING_OF(file), END_OF(file));
46    LOOP
47       incl := SEARCH_QUIETLY(targ, FORWARD, EXACT, rang);
48       EXITIF incl = 0;
49       POSITION(BEGINNING_OF(incl));
50       ERASE(incl);
51       COPY_TEXT('#include "config-');
52       rang := CREATE_RANGE(END_OF(incl), END_OF(file));
53    ENDLOOP;
54    WRITE_FILE(file, GET_INFO(COMMAND_LINE, "output_file"));
55    QUIT
56 $EOD
57 $ echo "Generated `tm.h' from `[.config.vax]vms.h'.
58 $ !
59 $       !crude hack to allow compiling from [.cp] subdirectory
60 $ if f$search("config-vax.h") .nes. "" then delete config-vax.h;*
61 $ copy [.config.vax]vax.h []config-vax.h
62 $ echo "Linked `config-vax.h' to `[.config.vax]vax.h' for `tm.h'."
63 $ !
64 $ if f$search("md.") .nes. "" then delete md..*
65 $ copy [.config.vax]vax.md []md.
66 $ echo "Linked `md' to `[.config.vax]vax.md'.
67 $ !
68 $ if f$search("aux-output.c") .nes. "" then delete aux-output.c.*
69 $ copy [.config.vax]vax.c []aux-output.c
70 $ echo "Linked `aux-output.c' to `[.config.vax]vax.c'.
71 $ !
72 $!
73 $!
74 $! Create the file version.opt, which helps identify the executable.
75 $!
76 $search version.c version_string,"="/match=and/output=t.tmp
77 $open ifile$ t.tmp
78 $read ifile$ line
79 $close ifile$
80 $delete t.tmp;
81 $ijk=f$locate("""",line)+1
82 $line=f$extract(ijk,f$length(line)-ijk,line)
83 $ijk=f$locate("""",line)
84 $line=f$extract(0,ijk,line)
85 $ijk=f$locate("\n",line)
86 $line=f$extract(0,ijk,line)
87 $!
88 $i=0
89 $loop:
90 $elm=f$element(i," ",line)
91 $if elm.eqs."" then goto no_ident
92 $if (elm.les."9").and.(elm.ges."0") then goto write_ident
93 $i=i+1
94 $goto loop
95 $!
96 $no_ident:
97 $elm="?.??"
98 $!
99 $!
100 $write_ident:
101 $open ifile$ version.opt/write
102 $write ifile$ "ident="+""""+elm+""""
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 !!
125 VARIABLE makefile_buf, opt_file_buf, complist_buf, extra_compilers; ! Globals.
126
127 !!
128 PROCEDURE process_makefile( )
129   !
130   ! Intepret Makefile.in and subsidiary Make-lang.in templates.
131   !
132   LOCAL range1, cmark, makefilename;
133
134   makefilename    := GET_INFO (COMMAND_LINE, 'FILE_NAME'); ! "Makefile.in"
135   makefile_buf    := CREATE_BUFFER ("makefile", makefilename);
136   opt_file_buf    := CREATE_BUFFER ("opt_file");
137   complist_buf    := CREATE_BUFFER ("complist");
138   extra_compilers := CREATE_ARRAY;
139   !
140   SET (NO_WRITE, makefile_buf, ON);     ! Used as workspace; don't save it.
141   SET (OUTPUT_FILE, complist_buf, "compilers.list");
142   !
143   ! Collect a list of supported compilers (``COMPILERS=xxx'' macro).
144   !
145   identify_compilers ();
146   !
147   ! Plus other known compilers described by Make-lang.in makefile fragments.
148   ! Add new entries as needed; args are (target name, subdirectory name).
149   !
150   additional_compiler ("cc1plus", "cp");
151   !
152   WRITE_FILE (complist_buf);            ! Now save "compilers.list".
153   !
154   ! Add to this list, as required.  The file "Makefile.in" is searched for
155   ! a tag that looks like "LINE_BEGIN + 'tag + (optional space) + "="".
156   ! The contents are assumed to be a list of object files, and from this
157   ! list a VMS linker options file is generated.
158   !
159   generate_option_file ("OBJS",      "=", "independent.opt");
160   generate_option_file ("LIB2FUNCS", "=", "libgcc2.list");
161   generate_option_file ("BC_ALL",    "=", "bc_all.opt");
162   generate_option_file ("BI_OBJ",    "=", "bi_all.opt");
163   !
164   ! Now change OBJS in the Makefile, so each language specific options file
165   ! does not pick up all of the language independent files.
166   !
167   POSITION (BEGINNING_OF (makefile_buf));
168   COPY_TEXT ("OBJS=");  ! New copy with empty value, seen before real OBJS.
169   SPLIT_LINE;
170   !
171   ! Lastly, process each compiler-specific object dependency list.
172   !
173   POSITION (BEGINNING_OF (complist_buf));
174   LOOP
175     cmark := MARK (NONE);
176     EXITIF (cmark = END_OF (complist_buf));
177     ! The current line contains the name of a compiler target, such as "cc1".
178     MESSAGE (CURRENT_LINE);     ! Give some interactive feedback.
179     generate_option_file (CURRENT_LINE, ":", CURRENT_LINE + "-objs.opt");
180     POSITION (cmark);
181     MOVE_VERTICAL (1);          ! Go to the next line.
182   ENDLOOP;
183 ENDPROCEDURE; !process_makefile
184 !!
185
186 PROCEDURE identify_compilers( )
187   !
188   ! Retrieve the list of supported compilers from Makefile.in, and put them
189   ! into file "compilers.list", one per line, for subsequent access from DCL.
190   !
191   LOCAL range1;
192
193   ! Strip most comments from the makefile, to speed up subsequent processing.
194   POSITION (BEGINNING_OF (makefile_buf));
195   pat_replace (LINE_BEGIN & "#" & REMAIN & LINE_END, );
196 !#  ! Convert directory references to VMS syntax (actually, just strip it).
197 !#  pat_replace (" $(srcdir)/", " ");
198   ! Look up the ``COMPILERS=cc1 xyzzy'' Makefile macro and put
199   ! its ``cc1 xyzzy'' value into the compilers buffer.
200   POSITION (BEGINNING_OF (complist_buf));
201 !#--at some point we may want to add this--
202 !#  recursive_fetch_tag ("CCCP", "=");    ! Include the preprocessor.
203 !#  POSITION (END_OF (complist_buf));
204   recursive_fetch_tag ("COMPILERS", "=");
205   ! Convert all spaces into newlines, then remove any blank lines.
206   pat_replace (SPAN(" "), LINE_END);
207   pat_replace (LINE_BEGIN & LINE_END, );
208 ENDPROCEDURE; !identify_compilers
209 !!
210
211 PROCEDURE additional_compiler( cname, subdir )
212   !
213   ! Load Make-lang.in for compiler CNAME from SUBDIR and append it to the
214   ! end of Makefile.in's buffer.  Add CNAME to the "compilers.list" buffer.
215   !
216   ON_ERROR
217     ! Don't abort if user removes the supporting subdirectory for a
218     ! language she's not interested in.
219     [TPU$_OPENIN]:
220       MESSAGE ("Cannot load " + subdir + "/Make-lang.in for "
221                + '"' + cname + '"' + "; skipping it.");
222       RETURN;
223   ENDON_ERROR;
224
225   POSITION (END_OF (makefile_buf));
226   SPLIT_LINE;   ! Separate with a blank line.
227   READ_FILE ("[." + subdir + "]Make-lang.in");  ! Load Makefile fragment.
228   ! Make sure that $(xxx_OTH_SRCS) expands to empty string by renaming $(it)
229   pat_replace ("_OTH_SRCS)", "_OTH_SRCS_dummy_)");
230   ! Convert subdirectory references into VMS syntax.
231   pat_replace ("$(srcdir)/" + subdir + "/", "[." + subdir + "]");
232   ! Add this name to compilers.list.
233   POSITION (END_OF (complist_buf));
234   COPY_TEXT (cname);
235   ! Make array entry indexed by compiler's file name; its value is arbitrary.
236   extra_compilers{cname} := subdir;
237 ENDPROCEDURE; !additional_compiler
238 !!
239
240 PROCEDURE generate_option_file( tag_name, punct, outfile_name )
241   !
242   ! Produce a file listing the names of particular object files, for use
243   ! as input to the linker and also for use in finding source names by
244   ! make-cc1.com.  Generally, any name suffix will be suppressed.
245   !
246   LOCAL range1, range2;
247
248   POSITION (BEGINNING_OF (opt_file_buf));
249   recursive_fetch_tag (tag_name, punct);
250   ! First fix up for subdirectory/Make-lang.in.
251   IF (pat_replace ("stamp-objlist" & (SPAN(" ")|LINE_END), " ") > 0) THEN
252     recursive_fetch_tag ("stamp-objlist", ":");
253   ENDIF;
254   ! Now fix up a few things in the output buffer.
255   pat_replace (("bytecode"|"Makefile") & (SPAN(" ")|LINE_END), " ");
256 !#  FILL (CURRENT_BUFFER, " ", 1, 80, 0);       ! Condense things a bit.
257   pat_replace ("." & ("o"|"c"|"h"|"y") & ((SPAN(" ")&LINE_END)|LINE_END), LINE_END);
258   pat_replace ("." & ("o"|"c"|"h"|"y") & SPAN(" "), ",");
259 !#  ! Remove trailing commas, if present.  {Above patterns preclude any such.}
260 !#  pat_replace ("," & ((SPAN(" ")&LINE_END)|LINE_END), LINE_END);
261   ! Get rid of spaces and blank lines.
262   pat_replace (SPAN(" "), LINE_END);
263   pat_replace (LINE_BEGIN & LINE_END, );
264   ! Second fix up for subdirectory/Make-lang.in;
265   ! avoid "sticky defaults" when linker processes the resulting options file.
266   IF (extra_compilers{outfile_name - "-objs.opt"} <> TPU$K_UNSPECIFIED) THEN
267     POSITION (BEGINNING_OF (opt_file_buf));
268     range1 := CREATE_RANGE (MARK (NONE), END_OF (CURRENT_BUFFER), NONE);
269     LOOP
270       range2 := SEARCH_QUIETLY (LINE_BEGIN | ",", FORWARD, EXACT, range1);
271       EXITIF (range2 = 0);
272       POSITION (BEGINNING_OF (range2));
273       IF (CURRENT_CHARACTER = ",") THEN  MOVE_HORIZONTAL (1); ENDIF;
274       ! If it's not already "[.subdir]name", explicitly make it "[]name".
275       IF (CURRENT_CHARACTER <> "[") THEN  COPY_TEXT ("[]"); ENDIF;
276       MOVE_HORIZONTAL (1);
277       MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
278     ENDLOOP;
279   ENDIF;
280   ! Now write the output file.
281   SET (OUTPUT_FILE, opt_file_buf, outfile_name);
282   WRITE_FILE (opt_file_buf);
283   ERASE (opt_file_buf);         ! Clear buffer out for next opt_file pass.
284 ENDPROCEDURE; !generate_option_file
285 !!
286
287 PROCEDURE recursive_fetch_tag( tag_n, punct )
288   !
289   ! Look up TAG_N, copy it to OPT_FILE_BUF, and then translate any $(...)
290   ! definitions that appear.  The translation is put at the current point.
291   !
292   LOCAL mark1, mark2, range1, tag_range, tag_string;
293
294   fetch_tag (tag_n, punct);
295   ! Substitute any makefile symbols $(...).
296   POSITION (BEGINNING_OF (CURRENT_BUFFER));
297   LOOP
298     range1 := SEARCH_QUIETLY ("$(" &
299       SPAN("abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ#~0123456789")
300                                    & ")", FORWARD, EXACT);
301     EXITIF (range1 = 0);
302     POSITION (BEGINNING_OF (range1));
303     MOVE_HORIZONTAL (2);        ! Past opening "$(".
304     mark1 := MARK (NONE);
305     POSITION (END_OF (range1));
306     MOVE_HORIZONTAL (-1);       ! In front of closing ")".
307     mark2 := MARK (NONE);
308     tag_range := CREATE_RANGE (mark1, mark2, NONE);
309     POSITION (END_OF (range1));
310     tag_string := STR (tag_range);
311     ERASE (range1);
312     fetch_tag (tag_string, "=");
313     POSITION (BEGINNING_OF (CURRENT_BUFFER));
314   ENDLOOP;
315 ENDPROCEDURE; !recursive_fetch_tag
316 !!
317
318 PROCEDURE fetch_tag( tag_n, punct )
319   !
320   ! Looks up the translation of a tag, and inserts it at the current location
321   ! in the buffer.
322   !
323   LOCAL mark0, mark1, mark2, range2;
324
325   mark0 := MARK (NONE);     ! Remember where we started; restore before return.
326   POSITION (BEGINNING_OF (makefile_buf));
327   ! The tag definition always starts in the first column, and might have
328   ! optional space(es) before "=" or ":" punctutation.
329   range2 := SEARCH_QUIETLY (LINE_BEGIN & tag_n & ((SPAN(" ") & punct) | punct),
330                             FORWARD, EXACT);
331   IF (range2 = 0) THEN
332     POSITION (mark0);
333     RETURN;
334   ENDIF;
335   POSITION (END_OF (range2));
336   MOVE_HORIZONTAL (1);          ! Move beyond "TAG=".
337   mark1 := MARK (NONE);
338   POSITION (BEGINNING_OF (range2));
339   LOOP
340     MOVE_VERTICAL (1);
341     MOVE_HORIZONTAL (-2);
342     EXITIF (CURRENT_CHARACTER <> "\");
343     ERASE_CHARACTER (1);
344     MOVE_HORIZONTAL (1);
345   ENDLOOP;
346   MOVE_HORIZONTAL (1);
347   mark2 := MARK (NONE);
348   range2 := CREATE_RANGE (mark1, mark2, NONE);
349   POSITION (mark0);
350   IF (LENGTH (range2) <> 0) THEN
351     COPY_TEXT (range2);
352   ENDIF;
353 ENDPROCEDURE; !fetch_tag
354 !!
355
356 PROCEDURE pat_replace( oldstring, newstring )
357   !
358   ! Replace all occurences of a pattern.
359   !
360   LOCAL range1, range2, kill_it, count;
361
362   count := 0;
363   kill_it := (GET_INFO (newstring, 'TYPE') = UNSPECIFIED);      ! Omitted arg.
364   range1 := CREATE_RANGE (BEGINNING_OF (CURRENT_BUFFER),
365                           END_OF (CURRENT_BUFFER), NONE);
366   LOOP
367     range2 := SEARCH_QUIETLY (oldstring, FORWARD, EXACT, range1);
368     EXITIF (range2 = 0);
369     count := count + 1;
370     POSITION (BEGINNING_OF (range2));
371     ERASE (range2);
372     IF (newstring = LINE_END) THEN
373       SPLIT_LINE;
374     ELSE IF (NOT kill_it) THEN
375       COPY_TEXT (newstring);
376     ENDIF; ENDIF;
377     MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
378   ENDLOOP;
379   RETURN count;
380 ENDPROCEDURE; !pat_replace
381 !!
382
383 !
384 ! This is the main routine.
385 !
386 process_makefile ();
387 QUIT;   ! All done; don't write any modified buffers.
388 !!
389 $ echo ""
390 $!
391 $! Remove excessive versions of the option files...
392 $!
393 $ purge *.opt
394 $ purge compilers.list,libgcc2.list
395 $!
396 $!
397 $!
398 $ if f$search("config.status") .nes. "" then delete config.status.*
399 $ open/write file config.status
400 $ write file "Links are now set up for use with a vax running VMS."
401 $ close file
402 $ type config.status
403 $ echo ""