How does a program get its path name?

Fred Fish fnf at fishpond.UUCP
Wed Feb 24 10:58:36 AEST 1988


In article <7304 at brl-smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>I don't know of any "cc"s that work like that.  Usually the pathnames
>of the slave programs are hard-wired into the "cc" code, although
>they're sometimes configurable via the makefile for cc when it's built.

One technique that I have found very useful, and it only takes about a half
day to implement, is to define a "SGS tree" that looks something like the
following, with indentation showing the tree structure:

		ROOTDIR
			bin
				cc
				as
				ld
			lib
				cpp
				c0
				c1
				crt0.o
				libc.a
			usr
				include
					stdio.h
					...
					sys

Let ROOTDIR be any arbitrary directory, which if a particular executable
is invoked with a pathname beginning with '/', can be discovered simply
by picking it out of argv[0].  If for example, cc finds it was invoked
as "/tools/bin/cc", then it sets ROOTDIR to "/tools", and then prepends
this ROOTDIR to the names of the executables it expects to exec,
"bin/ld", "bin/as", etc.  The default ROOTDIR is "/", so everything
works as expected if the executables live in their "normal" homes.
Also, cpp must be similarly modified to let it find ROOTDIR/usr/include,
and ld must be modified to let it find ROOTDIR/lib/libc.a for "-lc".

This scheme has the advantage that the binaries dynamically adjust to
their location in the filesystem tree, and can be moved at will.  The only
serious disadvantage is that if they don't live in their normal places,
then they must always be invoked with their full pathnames, but a shell
alias usually takes care of that problem.  In addition, they MUST NOT
be found via $PATH searches unless they live in their normal places
(/bin/cc for example) because they will then pick up the wrong files 
implied by ROOTDIR, which is "/" by default.  All in all, I have found
the ease of maintaining multiple SGS's on a system, and renaming or
moving them at will, to outweigh these minor gotchas.

Incidentally, this feature seems to survived in /bin/cc long enough to
make it into A/UX, but somewhere along the way cpp and ld lost it.

-Fred




		   
-- 
# Fred Fish    hao!noao!mcdsun!fishpond!fnf     (602) 921-1113
# Ye Olde Fishpond, 1346 West 10th Place, Tempe, AZ 85281  USA



More information about the Comp.unix.questions mailing list