README revision 33965
1139749SimpThis directory contains the -liberty library of free software.
2126706SwpaulIt is a collection of subroutines used by various GNU programs.
3126706SwpaulCurrent members include:
4126706Swpaul
5126706Swpaul	getopt -- get options from command line
6126706Swpaul	obstack -- stacks of arbitrarily-sized objects
7126706Swpaul	strerror -- error message strings corresponding to errno
8126706Swpaul	strtol -- string-to-long conversion
9126706Swpaul	strtoul -- string-to-unsigned-long conversion
10126706Swpaul
11126706SwpaulWe expect many of the GNU subroutines that are floating around to
12126706Swpauleventually arrive here.
13126706Swpaul
14126706SwpaulTo build the library, do:
15126706Swpaul
16126706Swpaul	./configure HOSTTYPE
17126706Swpaul	make
18126706Swpaul
19126706SwpaulPlease report bugs and fixes to "bug-gnu-utils@prep.ai.mit.edu".  Thank you.
20126706Swpaul
21126706SwpaulADDING A NEW FILE
22126706Swpaul=================
23126706Swpaul
24126706SwpaulThere are two sets of files:  Those that are "required" will be
25126706Swpaulincluded in the library for all configurations, while those
26126706Swpaulthat are "optional" will be included in the library only if "needed."
27126706Swpaul
28126706SwpaulTo add a new required file, edit Makefile to add the source file
29126706Swpaulname to CFILES and the object file to REQUIRED_OFILES.
30126706Swpaul
31126706SwpaulAdding a new optional file is more fragile.  As a general rule,
32126706Swpaulan optional file will be included in the library if it provides
33126706Swpaulfunctionality missing in the "standard" C library.
34126706SwpaulFor most hosts, the Makefile automatically figures out which
35126706Swpaulfunctionality is missing by compiling and linking a dummy test
36126706Swpaulprogram, and examining the error messages.
37126706Swpaul
38126706SwpaulSo to get this to work, you should do the following:
39129972Swpaul
40126706Swpaul1) Select one function defined in the file you're adding.
41126706SwpaulFor example, the getcwd function.
42126706Swpaul2) Add that function to the list in the file functions.def.
43126706Swpaul3) The name of the new file must be the same as the function
44126706Swpaulyou've chosen with the .c suffix added.  E.g. getcwd() must be
45126706Swpauldefined in getcwd.c.  (The file can define other functions as well.)
46126706Swpaul4) In Makefile.in, add the name of the source file (e.g. getcwd.c)
47126706Swpaulto CFILES.
48126706Swpaul
49126706SwpaulThe file you've added (e.g. getcwd.c) should compile and work
50126706Swpaulon all hosts where it is needed (e.g. not found when linking
51126706Swpaulthe dummy.c program).  It does not have to work or even
52126706Swpaulcompile on hosts where it is not needed.
53126706Swpaul
54126706SwpaulHOW THE AUTOMATIC CONFIGURATION WORKS
55126706Swpaul=====================================
56126706Swpaul
57189488SweongyoThe libiberty.a target (in RULE1) depends on $(DO_ALSO).
58194677SthompsaFor normal configurations, DO_ALSO=needed-list.
59126706Swpaul
60126706SwpaulSo needed-list is first made.  The needed-list rule compiles
61145485Swpauldummy.c.  Because dummy.c includes functions.def, the
62126706Swpaulresulting object file will contain a call to each of the
63126706Swpauloptional functions (for simplicity assume each optional file
64126706Swpauldefines a single function).  This object file will be linked
65126706Swpaulagainst the standard libraries (as defined by using $(CC)
66126706Swpauland various flags).  Any function missing will causes the
67126706Swpaullinker to emit an error message.  We assume the name
68126706Swpaulof the missing function(s) are in the error message(s).
69126706SwpaulThe awk script find-needed.awk has been generated from
70126706Swpaulfunctions.def.  It is used to search the linker output
71131953Swpaulmessages for words that match the functions listed in
72131953Swpaulfunctions.def.  The list of functions found is written
73146016Swpaulon a single line to the file needed-list.
74146016Swpaul
75141524SwpaulAfter needed-list has been generated, the libiberty.a
76126706Swpaultarget (in RULE1) just calls 'make' recursively.
77126706SwpaulIt passes the contents of needed-list using the
78126706Swpauldefinition (expanded) HOST_OFILES="`cat needed-list`".
79126706SwpaulIt also tells the inferior 'make' to use RULE2.
80126706Swpaul
81126706SwpaulThe inferior 'make' is very conventional:  The main
82126706Swpaulrule is $(RULE2) (which is libiberty.a).  It depends
83126706Swpaulon a list of object files: $(REQUIRED_OFILES) $(HOST_OFILES)
84126706Swpaul(and $(EXTRA_OFILES), which is usually empty).  The superior
85126706Swpaul'make' passes in $(HOST_OFILES); the others are fixed
86126706Swpaulin the Makefile.
87126706Swpaul
88126706SwpaulADDING A NEW CONFIGURATION
89126706Swpaul==========================
90126706Swpaul
91131953SwpaulOn most hosts you should be able to use the scheme for automatically
92131953Swpaulfiguring out which files are needed.  In that case, you probably
93131953Swpauldon't need a special Makefile stub for that configuration.
94126706Swpaul
95126706SwpaulIf the fully automatic scheme doesn't work, you may be able to get
96126706Swpaulby with defining EXTRA_OFILES in your Makefile stub.  This is
97126706Swpaula list of object file names that should be treated as required
98126706Swpaulfor this configuration - they will be included in libiberty.a,
99126706Swpaulregardless of whatever might be in the C library.  Moreover,
100126706Swpaulwhen the dummy.c program is linked, it will be linked with
101126706Swpaul$(EXTRA_OFILES).  Therefore, if a function in functions.def
102126706Swpaulis defined by one of the EXTRA_OFILES, it will not be listed as
103126706Swpaul"needed".  Thus if your hal9000 host needs a special implementation
104126706Swpaulof getcwd, you can just create hal9000-getcwd.c, and define:
105141524Swpaul	EXTRA_OFILES=hal9000-getcwd.o
106126706SwpaulOr if you want to use the libiberty version of strstr(),
107145485Swpauleven though there is a version in the C library (it might be
108146016Swpaulbuggy or slow), just define:
109146016Swpaul	EXTRA_OFILES=strstr.o
110145485Swpaul
111145485SwpaulYou can create a "manual" host configuration FOO with a file
112145485Swpaulconfig/mh-FOO.  In it, the HOST_OFILES macro should explicitly
113216558Stijllist that subset of the optional files that should be in the
114216558Stijllibrary.  You should also set:
115216558Stijl	DO_ALSO =
116146016SwpaulThis overrides all of the magic needed to automatically
117146016Swpauldetermine which files are "needed."  However, keeping that list
118146016Swpaulup to date is another matter...
119216558Stijl
120216558StijlHOW THE MANUAL CONFIGURATION WORKS
121216558Stijl==================================
122216558Stijl
123216558StijlThis also uses a recursive make, but the superior make
124145485Swpauldoes not do anything interesting - it just calls the
125216558Stijlinferior make with HOST_OFILES defined as $(HOST_OFILES),
126216558Stijlwhich is the list you created in your configuration.
127145485Swpaul
128145485SwpaulYou probably don't want to depend on manual configuration,
129145485Swpaulbecause keeping the HOST_OFILES list up-to-date will be a pain.
130145485Swpaul