1258945Sroberto$! libiberty/vmsbuild.com -- build liberty.olb for VMS host, VMS target
2258945Sroberto$!
3258945Sroberto$ CC	= "gcc /noVerbose/Debug/Incl=([],[-.include])"
4258945Sroberto$ LIBR	= "library /Obj"
5258945Sroberto$ LINK	= "link"
6258945Sroberto$ DELETE= "delete /noConfirm"
7258945Sroberto$ SEARCH= "search /Exact"
8258945Sroberto$ ECHO	= "write sys$output"
9258945Sroberto$ ABORT	= "exit %x002C"
10258945Sroberto$!
11258945Sroberto$ LIB_NAME = "liberty.olb"	!this is what we're going to construct
12258945Sroberto$ WORK_LIB = "new-lib.olb"	!used to guard against an incomplete build
13258945Sroberto$
14258945Sroberto$! manually copied from Makefile.in
15258945Sroberto$ REQUIRED_OFILES = "argv.o basename.o choose-temp.o concat.o cplus-dem.o "-
16258945Sroberto	+ "fdmatch.o fnmatch.o getopt.o getopt1.o getruntime.o hex.o "-
17258945Sroberto	+ "floatformat.o objalloc.o obstack.o spaces.o strerror.o strsignal.o "-
18258945Sroberto	+ "xatexit.o xexit.o xmalloc.o xmemdup.o xstrdup.o xstrerror.o"
19258945Sroberto$! anything not caught by link+search of dummy.* should be added here
20258945Sroberto$ EXTRA_OFILES = ""
21258945Sroberto$!
22258945Sroberto$! move to the directory which contains this command procedure
23258945Sroberto$ old_dir = f$environ("DEFAULT")
24258945Sroberto$ new_dir = f$parse("_._;",f$environ("PROCEDURE")) - "_._;"
25258945Sroberto$ set default 'new_dir'
26258945Sroberto$
27258945Sroberto$ ECHO "Starting libiberty build..."
28258945Sroberto$ create config.h
29258945Sroberto/* libiberty config.h for VMS */
30258945Sroberto#define NEED_sys_siglist
31258945Sroberto#define NEED_strsignal
32258945Sroberto#define NEED_psignal
33258945Sroberto#define NEED_basename
34258945Sroberto$ LIBR 'WORK_LIB' /Create
35258945Sroberto$
36258945Sroberto$! first pass: compile "required" modules
37258945Sroberto$ ofiles = REQUIRED_OFILES + " " + EXTRA_OFILES
38258945Sroberto$ pass = 1
39258945Sroberto$ gosub do_ofiles
40258945Sroberto$
41258945Sroberto$! second pass: process dummy.c, using the first pass' results
42258945Sroberto$ ECHO " now checking run-time library for missing functionality"
43258945Sroberto$ if f$search("dummy.obj").nes."" then  DELETE dummy.obj;*
44258945Sroberto$ define/noLog sys$error _NL:	!can't use /User_Mode here due to gcc
45258945Sroberto$ define/noLog sys$output _NL:	! driver's use of multiple image activation
46258945Sroberto$ on error then continue
47258945Sroberto$ 'CC' dummy.c
48258945Sroberto$ deassign sys$error   !restore, more or less
49258945Sroberto$ deassign sys$output
50258945Sroberto$ if f$search("dummy.obj").eqs."" then  goto pass2_failure1
51258945Sroberto$! link dummy.obj, capturing full linker feedback in dummy.map
52258945Sroberto$ oldmsg = f$environ("MESSAGE")
53258945Sroberto$ set message /Facility/Severity/Identification/Text
54258945Sroberto$ define/User sys$output _NL:
55258945Sroberto$ define/User sys$error _NL:
56258945Sroberto$ LINK/Map=dummy.map/noExe dummy.obj,'WORK_LIB'/Libr,-
57258945Sroberto	gnu_cc:[000000]gcclib.olb/Libr,sys$library:vaxcrtl.olb/Libr
58258945Sroberto$ set message 'oldmsg'
59258945Sroberto$ if f$search("dummy.map").eqs."" then  goto pass2_failure2
60258945Sroberto$ DELETE dummy.obj;*
61258945Sroberto$ SEARCH dummy.map "%LINK-I-UDFSYM" /Output=dummy.list
62258945Sroberto$ DELETE dummy.map;*
63258945Sroberto$ ECHO " check completed"
64258945Sroberto$! we now have a file with one entry per line of unresolvable symbols
65258945Sroberto$ ofiles = ""
66258945Sroberto$ if f$trnlnm("IFILE$").nes."" then  close/noLog ifile$
67258945Sroberto$	open/Read ifile$ dummy.list
68258945Sroberto$iloop: read/End=idone ifile$ iline
69258945Sroberto$	iline = f$edit(iline,"COMPRESS,TRIM,LOWERCASE")
70258945Sroberto$	ofiles = ofiles + " " + f$element(1," ",iline) + ".o"
71258945Sroberto$	goto iloop
72258945Sroberto$idone: close ifile$
73258945Sroberto$ DELETE dummy.list;*
74258945Sroberto$ on error then ABORT
75258945Sroberto$
76258945Sroberto$! third pass: compile "missing" modules collected in pass 2
77258945Sroberto$ pass = 3
78258945Sroberto$ gosub do_ofiles
79258945Sroberto$
80258945Sroberto$! finish up
81258945Sroberto$ LIBR 'WORK_LIB' /Compress /Output='LIB_NAME'	!new-lib.olb -> liberty.olb
82258945Sroberto$ DELETE 'WORK_LIB';*
83258945Sroberto$
84258945Sroberto$! all done
85258945Sroberto$ ECHO "Completed libiberty build."
86258945Sroberto$ type sys$input:
87258945Sroberto
88258945Sroberto  You many wish to do
89258945Sroberto  $ COPY LIBERTY.OLB GNU_CC:[000000]
90258945Sroberto  so that this run-time library resides in the same location as gcc's
91258945Sroberto  support library.  When building gas, be sure to leave the original
92258945Sroberto  copy of liberty.olb here so that gas's build procedure can find it.
93258945Sroberto
94258945Sroberto$ set default 'old_dir'
95258945Sroberto$ exit
96258945Sroberto$
97258945Sroberto$!
98258945Sroberto$! compile each element of the space-delimited list 'ofiles'
99258945Sroberto$!
100258945Sroberto$do_ofiles:
101258945Sroberto$ ofiles = f$edit(ofiles,"COMPRESS,TRIM")
102258945Sroberto$ i = 0
103258945Sroberto$oloop:
104258945Sroberto$ f = f$element(i," ",ofiles)
105258945Sroberto$ if f.eqs." " then  goto odone
106258945Sroberto$ f = f - ".o"	!strip dummy suffix
107258945Sroberto$ ECHO "  ''f'"
108258945Sroberto$ skip_f = 0
109258945Sroberto$ if pass.eq.3 .and. f$search("''f'.c").eqs."" then  gosub chk_deffunc
110258945Sroberto$ if .not.skip_f
111258945Sroberto$ then
112258945Sroberto$   'CC' 'f'.c
113258945Sroberto$   LIBR 'WORK_LIB' 'f'.obj /Insert
114258945Sroberto$   DELETE 'f'.obj;*
115258945Sroberto$ endif
116258945Sroberto$ i = i + 1
117258945Sroberto$ goto oloop
118258945Sroberto$odone:
119258945Sroberto$ return
120258945Sroberto$
121258945Sroberto$!
122258945Sroberto$! check functions.def for a DEFFUNC() entry corresponding to missing file 'f'.c
123258945Sroberto$!
124258945Sroberto$chk_deffunc:
125258945Sroberto$ define/User sys$output _NL:
126258945Sroberto$ define/User sys$error _NL:
127258945Sroberto$ SEARCH functions.def "DEFFUNC","''f'" /Match=AND
128258945Sroberto$ if (($status.and.%x7FFFFFFF) .eq. 1)
129258945Sroberto$ then
130258945Sroberto$   skip_f = 1
131258945Sroberto$   open/Append config_h config.h
132258945Sroberto$   write config_h "#define NEED_''f'"
133258945Sroberto$   close config_h
134258945Sroberto$ endif
135258945Sroberto$ return
136258945Sroberto$
137258945Sroberto$!
138258945Sroberto$pass2_failure1:
139258945Sroberto$! if we reach here, dummy.c failed to compile and we're really stuck
140258945Sroberto$ type sys$input:
141258945Sroberto
142258945Sroberto  Cannot compile the library contents checker (dummy.c + functions.def),
143258945Sroberto  so cannot continue!
144258945Sroberto
145258945Sroberto$! attempt the compile again, without suppressing diagnostic messages this time
146258945Sroberto$ on error then ABORT +0*f$verify(v)
147258945Sroberto$ v = f$verify(1)
148258945Sroberto$ 'CC' dummy.c
149258945Sroberto$ ABORT +0*f$verify(v)	!'f$verify(0)'
150258945Sroberto$!
151258945Sroberto$pass2_failure2:
152258945Sroberto$! should never reach here..
153258945Sroberto$ type sys$input:
154258945Sroberto
155258945Sroberto  Cannot link the library contents checker (dummy.obj), so cannot continue!
156258945Sroberto
157258945Sroberto$! attempt the link again, without suppressing diagnostic messages this time
158258945Sroberto$ on error then ABORT +0*f$verify(v)
159258945Sroberto$ v = f$verify(1)
160258945Sroberto$ LINK/Map=dummy.map/noExe dummy.obj,'WORK_LIB'/Libr,-
161258945Sroberto	gnu_cc:[000000]gcclib.olb/Libr,sys$library:vaxcrtl.olb/Libr
162258945Sroberto$ ABORT +0*f$verify(v)	!'f$verify(0)'
163258945Sroberto$
164258945Sroberto$! not reached
165258945Sroberto$ exit
166258945Sroberto