Nonrecursive build within gcc directory

Geoff Keating geoffk@cygnus.com
Sun Oct 22 16:27:00 GMT 2000


> Date: Sun, 22 Oct 2000 15:39:20 -0700
> From: "Zack Weinberg" <zackw@Stanford.EDU>
> Cc: gcc-patches@gcc.gnu.org
> Content-Disposition: inline
> User-Agent: Mutt/1.2.5i
> 
> On Sun, Oct 22, 2000 at 02:44:33PM -0700, Geoff Keating wrote:
> > "Zack Weinberg" <zackw@stanford.edu> writes:
> > 
> > > There are a few issues.  The most important one is that we run into
> > > trouble with compilers that can't handle -c and -o simultaneously.
> > > I've added Autoconf logic to prevent them seeing both options
> > > together, but that means all the non-C front end modules wind up in
> > > the toplevel directory rather than where they're supposed to.
> > 
> > The generic way to fix this is to replace 'cc foo.c -c -o /dir/foo.o'
> > with 'cc foo.c -c && mv foo.o /dir/foo.o' which should work as in the
> > separate-source-and-.o directory case there would be no .o files in
> > the source directory, and in the combined case the .c file and .o file
> > will end up in the same directory as we wanted.
> 
> Tried that; it doesn't work for two reasons.  First one is
> 
> $ mv foo.o foo.o; echo $?
> mv: `foo.o' and `foo.o' are the same file
> 1
> $
> 
> even with -f.  Arguably a bug in mv, but I'm not going to force people
> to update fileutils.
> 
> The second problem is that there are several cases where a file in a
> language subdirectory has the exact same name as a file in the top
> level.  Without combined -c and -o, cp/expr.o (for instance) will
> overwrite expr.o.

Ugh.  Then you have to do it in some other directory:

( cd obj-tmpdir && cc ../cp/foo.c -c && mv foo.o ../cp/foo.o )

note that you have to use something like $(dotdot) rather than plain '..'
as the object directory may be an absolute path.  This can be set at
configure time.

> > > There's also a bug in the directory search logic in the gcc 2.95
> > > (and all previous versions) preprocessor, which causes it not to
> > > be able to find headers for cp/parse.c.  (In short, #line messes
> > > up current-directory handling.)  Again, this is only a problem if
> > > you don't do a bootstrap (whether for cross-compilation, or
> > > otherwise).
> > 
> > This is a real problem for cross-compilation.  Could you fix it by
> > adding -I options?
> 
> Sure, if you can tell me how to get -I$(objdir)/$(subdir) into the cc
> command line for all non-C-front-end object files, where $(subdir) is
> accurate.  That'd also eliminate the need to build Fortran's str-*
> files at top level.

( cd obj-tmpdir && \
  cc -I `echo ../cp/foo.o | sed 's-/[^/]*$--'` ../cp/foo.c -c && \
  mv foo.o ../cp/foo.o )

It may be possible to not use sed if we can rely on make filename
functions, as in `$(dir $<)'.

-- 
- Geoffrey Keating <geoffk@cygnus.com>


More information about the Gcc-patches mailing list