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)
9 $if f$trnlnm("IFILE$").nes."" then close/noLog ifile$
11 $ echo = "write sys$output"
13 $ if f$search("config.h") .nes. "" then delete config.h.*
14 $ copy [.config.vax]xm-vms.h []config.h
15 $ echo "Linked `config.h' to `[.config.vax]xm-vms.h'.
17 $ if f$search("tconfig.h") .nes. "" then delete tconfig.h.*
20 /* tconfig.h == config.h :: target and host configurations are the same */
23 $ echo "Created `tconfig.h'.
25 $ if f$search("hconfig.h") .nes. "" then delete hconfig.h.*
28 /* hconfig.h == config.h :: host and target configurations are the same */
31 $ echo "Created `hconfig.h'.
33 $ if f$search("tm.h") .nes. "" then delete tm.h.*
34 $!! copy [.config.vax]vms.h []tm.h
35 $ edit/tpu/nojournal/nosection/nodisplay/command=sys$input -
36 [.config.vax]vms.h /output=[]tm.h
39 ! Copy file, changing lines of the form
44 file := CREATE_BUFFER("file", GET_INFO(COMMAND_LINE, "file_name"));
45 targ := LINE_BEGIN & '#include' & SPAN(ASCII(32)+ASCII(9)) & '"vax/';
46 rang := CREATE_RANGE(BEGINNING_OF(file), END_OF(file));
48 incl := SEARCH_QUIETLY(targ, FORWARD, EXACT, rang);
50 POSITION(BEGINNING_OF(incl));
52 COPY_TEXT('#include "config-');
53 rang := CREATE_RANGE(END_OF(incl), END_OF(file));
55 WRITE_FILE(file, GET_INFO(COMMAND_LINE, "output_file"));
58 $ echo "Generated `tm.h' from `[.config.vax]vms.h'.
60 $ !crude hack to allow compiling from [.cp] subdirectory
61 $ if f$search("config-vax.h") .nes. "" then delete config-vax.h;*
62 $ copy [.config.vax]vax.h []config-vax.h
63 $ echo "Linked `config-vax.h' to `[.config.vax]vax.h' for `tm.h'."
65 $ call make_lang_incl "options.h"
67 $ call make_lang_incl "specs.h"
69 $ if f$search("vax.md") .nes. "" then delete vax.md;*
70 $ copy [.config.vax]vax.md []vax.md
71 $ echo "Copied `vax.md' from `[.config.vax]vax.md'."
73 $ if f$search("aux-output.c") .nes. "" then delete aux-output.c.*
74 $ copy [.config.vax]vax.c []aux-output.c
75 $ echo "Linked `aux-output.c' to `[.config.vax]vax.c'.
79 $! Create the file version.opt, which helps identify the executable.
81 $search version.c version_string,"="/match=and/output=t.tmp
86 $ijk=f$locate("""",line)+1
87 $line=f$extract(ijk,f$length(line)-ijk,line)
88 $ijk=f$locate("""",line)
89 $line=f$extract(0,ijk,line)
90 $ijk=f$locate("\n",line)
91 $line=f$extract(0,ijk,line)
95 $elm=f$element(i," ",line)
96 $if elm.eqs."" then goto no_ident
97 $if (elm.les."9").and.(elm.ges."0") then goto write_ident
106 $open ifile$ version.opt/write
107 $write ifile$ "ident="+""""+elm+""""
112 $! create linker options files that lists all of the components for all
113 $! possible compilers. We do this by editing the file Makefile.in, and
114 $! generating the relevant files from it.
117 $! Make a copy of the makefile if the sources are on a disk that is NFS
118 $! mounted on a unix machine.
119 $if f$search("Makefile.in").eqs."" .and. f$search("$M$akefile.in").nes."" -
120 then copy $M$akefile.in Makefile.in
121 $! This should be automated across all front-end subdirectories.
122 $! For now, it's hardcoded.
123 $if f$search("[.cp]Makefile.in").eqs."" .and. f$search("[.cp]$M$akefile.in").nes."" -
124 then copy [.cp]$M$akefile.in [.cp]Makefile.in
127 $echo "Now processing Makefile.in to generate linker option files."
128 $edit/TPU/noJournal/noSection/noDisplay/Command=sys$input: Makefile.in
130 VARIABLE makefile_buf, opt_file_buf, complist_buf, extra_compilers; ! Globals.
133 PROCEDURE process_makefile( )
135 ! Interpret Makefile.in and subsidiary Make-lang.in templates.
137 LOCAL range1, cmark, makefilename;
139 makefilename := GET_INFO (COMMAND_LINE, 'FILE_NAME'); ! "Makefile.in"
140 makefile_buf := CREATE_BUFFER ("makefile", makefilename);
141 opt_file_buf := CREATE_BUFFER ("opt_file");
142 complist_buf := CREATE_BUFFER ("complist");
143 extra_compilers := CREATE_ARRAY;
145 SET (NO_WRITE, makefile_buf, ON); ! Used as workspace; don't save it.
146 SET (OUTPUT_FILE, complist_buf, "compilers.list");
148 ! Make some textual substitutions.
150 configure_makefile ();
152 ! Collect a list of supported compilers (``COMPILERS=xxx'' macro).
154 identify_compilers ();
156 ! Plus other known compilers described by Make-lang.in makefile fragments.
157 ! Add new entries as needed; args are (target name, subdirectory name).
159 additional_compiler ("cc1plus", "cp");
161 WRITE_FILE (complist_buf); ! Now save "compilers.list".
163 ! Add to this list, as required. The file "Makefile.in" is searched for
164 ! a tag that looks like "LINE_BEGIN + 'tag + (optional space) + "="".
165 ! The contents are assumed to be a list of object files, and from this
166 ! list a VMS linker options file is generated.
168 generate_option_file ("OBJS", "=", "independent.opt");
169 generate_option_file ("LIB2FUNCS", "=", "libgcc2.list");
170 generate_option_file ("BC_ALL", "=", "bc_all.list");
171 generate_option_file ("BI_OBJ", "=", "bi_all.opt");
173 ! Now change OBJS in the Makefile, so each language specific options file
174 ! does not pick up all of the language independent files.
176 POSITION (BEGINNING_OF (makefile_buf));
177 COPY_TEXT ("OBJS="); ! New copy with empty value, seen before real OBJS.
180 ! Lastly, process each compiler-specific object dependency list.
182 POSITION (BEGINNING_OF (complist_buf));
184 cmark := MARK (NONE);
185 EXITIF (cmark = END_OF (complist_buf));
186 ! The current line contains the name of a compiler target, such as "cc1".
187 MESSAGE (CURRENT_LINE); ! Give some interactive feedback.
188 generate_option_file (CURRENT_LINE, ":", CURRENT_LINE + "-objs.opt");
190 MOVE_VERTICAL (1); ! Go to the next line.
192 ENDPROCEDURE; !process_makefile
195 PROCEDURE process_objc_lib( )
197 ! Interpret objc/Makefile, after finishing the top makefile.
201 MESSAGE ("Cannot load objc/Makefile for ""ObjClib""; skipping it.");
205 ERASE (makefile_buf); !discard top Makefile
206 POSITION (END_OF (makefile_buf));
207 READ_FILE ("[.objc]Makefile"); !load objc one
209 pat_replace (ASCII(9), " "); !change any <tab> to <space>
210 generate_option_file ("OBJC_O", "=", "objc-objs.opt");
211 POSITION (BEGINNING_OF (makefile_buf));
212 ! Join any continuation lines; we want the header list to be one line.
213 pat_replace ("\" & LINE_END, );
214 generate_option_file ("OBJC_H", "=", "objc-hdrs.list");
215 ENDPROCEDURE; !process_objc_lib
218 PROCEDURE configure_makefile( )
220 ! Plug in some values normally handled by `configure'. Rather than
221 ! replacing the dummy entries, insert the real entries before them.
223 POSITION (BEGINNING_OF (makefile_buf));
224 COPY_TEXT ("target=vax-vms"); SPLIT_LINE;
225 COPY_TEXT ("out_file=aux-output.c"); SPLIT_LINE; ! vax/vax.c
226 COPY_TEXT ("out_object_file=aux-output.o"); SPLIT_LINE; ! aux-output.obj
227 COPY_TEXT ("md_file=vax.md"); SPLIT_LINE; ! vax/vax.md
228 COPY_TEXT ("tm_file=tm.h"); SPLIT_LINE; ! vax/tm-vms.h
229 ENDPROCEDURE; !configure_makefile
232 PROCEDURE identify_compilers( )
234 ! Retrieve the list of supported compilers from Makefile.in, and put them
235 ! into file "compilers.list", one per line, for subsequent access from DCL.
239 ! Strip most comments from the makefile, to speed up subsequent processing.
240 POSITION (BEGINNING_OF (makefile_buf));
241 pat_replace (LINE_BEGIN & "#" & REMAIN & LINE_END, );
242 !# ! Convert directory references to VMS syntax (actually, just strip it).
243 !# pat_replace (" $(srcdir)/", " ");
244 ! Look up the ``COMPILERS=cc1 xyzzy'' Makefile macro and put
245 ! its ``cc1 xyzzy'' value into the compilers buffer.
246 POSITION (BEGINNING_OF (complist_buf));
247 !#--at some point we may want to add this--
248 !# recursive_fetch_tag ("CCCP", "="); ! Include the preprocessor.
249 !# POSITION (END_OF (complist_buf));
250 recursive_fetch_tag ("COMPILERS", "=");
251 ! Convert all spaces into newlines, then remove any blank lines.
252 pat_replace (SPAN(" "), LINE_END);
253 pat_replace (LINE_BEGIN & LINE_END, );
254 ENDPROCEDURE; !identify_compilers
257 PROCEDURE additional_compiler( cname, subdir )
259 ! Load Make-lang.in for compiler CNAME from SUBDIR and append it to the
260 ! end of Makefile.in's buffer. Add CNAME to the "compilers.list" buffer.
263 ! Don't abort if user removes the supporting subdirectory for a
264 ! language she's not interested in.
266 MESSAGE ("Cannot load " + subdir + "/Make-lang.in for "
267 + '"' + cname + '"' + "; skipping it.");
271 POSITION (END_OF (makefile_buf));
272 SPLIT_LINE; ! Separate with a blank line.
273 READ_FILE ("[." + subdir + "]Make-lang.in"); ! Load Makefile fragment.
274 ! Make sure that $(xxx_OTH_SRCS) expands to empty string by renaming $(it)
275 pat_replace ("_OTH_SRCS)", "_OTH_SRCS_dummy_)");
276 ! Convert subdirectory references into VMS syntax.
277 pat_replace ("$(srcdir)/" + subdir + "/", "[." + subdir + "]");
278 ! Add this name to compilers.list.
279 POSITION (END_OF (complist_buf));
281 ! Make array entry indexed by compiler's file name; its value is arbitrary.
282 extra_compilers{cname} := subdir;
283 ENDPROCEDURE; !additional_compiler
286 PROCEDURE generate_option_file( tag_name, punct, outfile_name )
288 ! Produce a file listing the names of particular object files, for use
289 ! as input to the linker and also for use in finding source names by
290 ! make-cc1.com. Generally, any name suffix will be suppressed.
292 LOCAL range1, range2;
294 POSITION (BEGINNING_OF (opt_file_buf));
295 recursive_fetch_tag (tag_name, punct);
296 ! First fix up for subdirectory/Make-lang.in.
297 IF (pat_replace ("stamp-objlist" & (SPAN(" ")|LINE_END), " ") > 0) THEN
298 recursive_fetch_tag ("stamp-objlist", ":");
300 ! Now fix up a few things in the output buffer.
301 pat_replace (("bytecode"|"Makefile") & (SPAN(" ")|LINE_END), " ");
302 !# FILL (CURRENT_BUFFER, " ", 1, 80, 0); ! Condense things a bit.
303 pat_replace ("." & ("o"|"c"|"y") & ((SPAN(" ")&LINE_END)|LINE_END), LINE_END);
304 pat_replace ("." & ("o"|"c"|"y") & SPAN(" "), ",");
305 pat_replace (".h" & (SPAN(" ")|LINE_END), ".h,");
306 ! Remove trailing commas, if present.
307 pat_replace ("," & ((SPAN(" ")&LINE_END)|LINE_END), LINE_END);
308 ! Get rid of spaces and blank lines.
309 pat_replace (SPAN(" "), LINE_END);
310 pat_replace (LINE_BEGIN & LINE_END, );
311 ! Second fix up for subdirectory/Make-lang.in;
312 ! avoid "sticky defaults" when linker processes the resulting options file.
313 IF (extra_compilers{outfile_name - "-objs.opt"} <> TPU$K_UNSPECIFIED) THEN
314 POSITION (BEGINNING_OF (opt_file_buf));
315 range1 := CREATE_RANGE (MARK (NONE), END_OF (CURRENT_BUFFER), NONE);
317 range2 := SEARCH_QUIETLY (LINE_BEGIN | ",", FORWARD, EXACT, range1);
319 POSITION (BEGINNING_OF (range2));
320 IF (CURRENT_CHARACTER = ",") THEN MOVE_HORIZONTAL (1); ENDIF;
321 ! If it's not already "[.subdir]name", explicitly make it "[]name".
322 IF (CURRENT_CHARACTER <> "[") THEN COPY_TEXT ("[]"); ENDIF;
324 MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
327 ! Now write the output file.
328 SET (OUTPUT_FILE, opt_file_buf, outfile_name);
329 WRITE_FILE (opt_file_buf);
330 ERASE (opt_file_buf); ! Clear buffer out for next opt_file pass.
331 ENDPROCEDURE; !generate_option_file
334 PROCEDURE recursive_fetch_tag( tag_n, punct )
336 ! Look up TAG_N, copy it to OPT_FILE_BUF, and then translate any $(...)
337 ! definitions that appear. The translation is put at the current point.
339 LOCAL mark1, mark2, range1, tag_range, tag_string;
341 fetch_tag (tag_n, punct);
342 ! Substitute any makefile symbols $(...).
343 POSITION (BEGINNING_OF (CURRENT_BUFFER));
345 range1 := SEARCH_QUIETLY ("$(" &
346 SPAN("abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ#~0123456789")
347 & ")", FORWARD, EXACT);
349 POSITION (BEGINNING_OF (range1));
350 MOVE_HORIZONTAL (2); ! Past opening "$(".
351 mark1 := MARK (NONE);
352 POSITION (END_OF (range1));
353 MOVE_HORIZONTAL (-1); ! In front of closing ")".
354 mark2 := MARK (NONE);
355 tag_range := CREATE_RANGE (mark1, mark2, NONE);
356 POSITION (END_OF (range1));
357 tag_string := STR (tag_range);
359 fetch_tag (tag_string, "=");
360 POSITION (BEGINNING_OF (CURRENT_BUFFER));
362 ENDPROCEDURE; !recursive_fetch_tag
365 PROCEDURE fetch_tag( tag_n, punct )
367 ! Looks up the translation of a tag, and inserts it at the current location
370 LOCAL mark0, mark1, mark2, range2;
372 mark0 := MARK (NONE); ! Remember where we started; restore before return.
373 POSITION (BEGINNING_OF (makefile_buf));
374 ! The tag definition always starts in the first column, and might have
375 ! optional space(es) before "=" or ":" punctuation.
376 range2 := SEARCH_QUIETLY (LINE_BEGIN & tag_n & ((SPAN(" ") & punct) | punct),
382 POSITION (END_OF (range2));
383 MOVE_HORIZONTAL (1); ! Move beyond "TAG=".
384 mark1 := MARK (NONE);
385 POSITION (BEGINNING_OF (range2));
388 MOVE_HORIZONTAL (-2);
389 EXITIF (CURRENT_CHARACTER <> "\");
394 mark2 := MARK (NONE);
395 range2 := CREATE_RANGE (mark1, mark2, NONE);
397 IF (LENGTH (range2) <> 0) THEN
400 ENDPROCEDURE; !fetch_tag
403 PROCEDURE pat_replace( oldstring, newstring )
405 ! Replace all occurrences of a pattern.
407 LOCAL range1, range2, kill_it, count;
410 kill_it := (GET_INFO (newstring, 'TYPE') = UNSPECIFIED); ! Omitted arg.
411 range1 := CREATE_RANGE (BEGINNING_OF (CURRENT_BUFFER),
412 END_OF (CURRENT_BUFFER), NONE);
414 range2 := SEARCH_QUIETLY (oldstring, FORWARD, EXACT, range1);
417 POSITION (BEGINNING_OF (range2));
419 IF (newstring = LINE_END) THEN
421 ELSE IF (NOT kill_it) THEN
422 COPY_TEXT (newstring);
424 MODIFY_RANGE (range1, MARK (NONE), END_OF (range1));
427 ENDPROCEDURE; !pat_replace
431 ! This is the main routine.
434 process_objc_lib (); !this uses a different makefile
435 QUIT; ! All done; don't write any modified buffers.
439 $! Remove excessive versions of the option files...
445 $ if f$search("config.status") .nes. "" then delete config.status.*
446 $ create config.status
447 Links are now set up for use with a vax running VMS.
454 $! Construct a header file based on subdirectory contents
456 $make_lang_incl: subroutine
457 $ if f$search(p1).nes."" then delete 'p1';*
458 $ create 'p1' !empty file with ordinary text-file attributes
459 $ open/Append ifile$ 'p1'
460 $ write ifile$ "/* ''p1' */"
461 $ hfile = f$search("[]''p1'")
462 $ topdir = f$parse(hfile,,,"DIRECTORY") - "]"
464 $ hfile = f$search("[.*]lang-''p1'")
465 $ if hfile.eqs."" then goto lang_incl_done
466 $ dir = f$parse(hfile,,,"DIRECTORY") - "]"
467 $! convert absolute path to relative one, yielding "[.subdir]"
468 $ dir = "[" + f$edit(dir - topdir,"LOWERCASE") + "]"
469 $ write ifile$ "#include ""''dir'lang-''p1'"""
470 $ goto lang_incl_loop
473 $ echo "Created `''p1''."
474 $ endsubroutine !make_lang_incl