2 $ ! Set up to compile GCC on VAX/VMS
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")'
8 $set symbol/scope=(nolocal,noglobal)
10 $ echo = "write sys$output"
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'.
16 $ if f$search("tconfig.h") .nes. "" then delete tconfig.h.*
19 /* tconfig.h == config.h :: target and host configurations are the same */
22 $ echo "Created `tconfig.h'.
24 $ if f$search("hconfig.h") .nes. "" then delete hconfig.h.*
27 /* hconfig.h == config.h :: host and target configurations are the same */
30 $ echo "Created `hconfig.h'.
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
38 ! Copy file, changing lines of the form
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));
47 incl := SEARCH_QUIETLY(targ, FORWARD, EXACT, rang);
49 POSITION(BEGINNING_OF(incl));
51 COPY_TEXT('#include "config-');
52 rang := CREATE_RANGE(END_OF(incl), END_OF(file));
54 WRITE_FILE(file, GET_INFO(COMMAND_LINE, "output_file"));
57 $ echo "Generated `tm.h' from `[.config.vax]vms.h'.
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'."
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'.
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'.
74 $! Create the file version.opt, which helps identify the executable.
76 $search version.c version_string,"="/match=and/output=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)
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
101 $open ifile$ version.opt/write
102 $write ifile$ "ident="+""""+elm+""""
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.
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
122 $echo "Now processing Makefile.in to generate linker option files."
123 $edit/TPU/noJournal/noSection/noDisplay/Command=sys$input: Makefile.in
125 VARIABLE makefile_buf, opt_file_buf, complist_buf, extra_compilers; ! Globals.
128 PROCEDURE process_makefile( )
130 ! Intepret Makefile.in and subsidiary Make-lang.in templates.
132 LOCAL range1, cmark, makefilename;
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;
140 SET (NO_WRITE, makefile_buf, ON); ! Used as workspace; don't save it.
141 SET (OUTPUT_FILE, complist_buf, "compilers.list");
143 ! Collect a list of supported compilers (``COMPILERS=xxx'' macro).
145 identify_compilers ();
147 ! Plus other known compilers described by Make-lang.in makefile fragments.
148 ! Add new entries as needed; args are (target name, subdirectory name).
150 additional_compiler ("cc1plus", "cp");
152 WRITE_FILE (complist_buf); ! Now save "compilers.list".
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.
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");
164 ! Now change OBJS in the Makefile, so each language specific options file
165 ! does not pick up all of the language independent files.
167 POSITION (BEGINNING_OF (makefile_buf));
168 COPY_TEXT ("OBJS="); ! New copy with empty value, seen before real OBJS.
171 ! Lastly, process each compiler-specific object dependency list.
173 POSITION (BEGINNING_OF (complist_buf));
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");
181 MOVE_VERTICAL (1); ! Go to the next line.
183 ENDPROCEDURE; !process_makefile
186 PROCEDURE identify_compilers( )
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.
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
211 PROCEDURE additional_compiler( cname, subdir )
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.
217 ! Don't abort if user removes the supporting subdirectory for a
218 ! language she's not interested in.
220 MESSAGE ("Cannot load " + subdir + "/Make-lang.in for "
221 + '"' + cname + '"' + "; skipping it.");
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));
235 ! Make array entry indexed by compiler's file name; its value is arbitrary.
236 extra_compilers{cname} := subdir;
237 ENDPROCEDURE; !additional_compiler
240 PROCEDURE generate_option_file( tag_name, punct, outfile_name )
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.
246 LOCAL range1, range2;
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", ":");
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);
270 range2 := SEARCH_QUIETLY (LINE_BEGIN | ",", FORWARD, EXACT, range1);
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;
277 MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
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
287 PROCEDURE recursive_fetch_tag( tag_n, punct )
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.
292 LOCAL mark1, mark2, range1, tag_range, tag_string;
294 fetch_tag (tag_n, punct);
295 ! Substitute any makefile symbols $(...).
296 POSITION (BEGINNING_OF (CURRENT_BUFFER));
298 range1 := SEARCH_QUIETLY ("$(" &
299 SPAN("abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ#~0123456789")
300 & ")", FORWARD, EXACT);
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);
312 fetch_tag (tag_string, "=");
313 POSITION (BEGINNING_OF (CURRENT_BUFFER));
315 ENDPROCEDURE; !recursive_fetch_tag
318 PROCEDURE fetch_tag( tag_n, punct )
320 ! Looks up the translation of a tag, and inserts it at the current location
323 LOCAL mark0, mark1, mark2, range2;
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),
335 POSITION (END_OF (range2));
336 MOVE_HORIZONTAL (1); ! Move beyond "TAG=".
337 mark1 := MARK (NONE);
338 POSITION (BEGINNING_OF (range2));
341 MOVE_HORIZONTAL (-2);
342 EXITIF (CURRENT_CHARACTER <> "\");
347 mark2 := MARK (NONE);
348 range2 := CREATE_RANGE (mark1, mark2, NONE);
350 IF (LENGTH (range2) <> 0) THEN
353 ENDPROCEDURE; !fetch_tag
356 PROCEDURE pat_replace( oldstring, newstring )
358 ! Replace all occurences of a pattern.
360 LOCAL range1, range2, kill_it, count;
363 kill_it := (GET_INFO (newstring, 'TYPE') = UNSPECIFIED); ! Omitted arg.
364 range1 := CREATE_RANGE (BEGINNING_OF (CURRENT_BUFFER),
365 END_OF (CURRENT_BUFFER), NONE);
367 range2 := SEARCH_QUIETLY (oldstring, FORWARD, EXACT, range1);
370 POSITION (BEGINNING_OF (range2));
372 IF (newstring = LINE_END) THEN
374 ELSE IF (NOT kill_it) THEN
375 COPY_TEXT (newstring);
377 MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
380 ENDPROCEDURE; !pat_replace
384 ! This is the main routine.
387 QUIT; ! All done; don't write any modified buffers.
391 $! Remove excessive versions of the option files...
394 $ purge compilers.list,libgcc2.list
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."