cpp command overwrites input files

Richard Earnshaw rearnsha@arm.com
Wed Jun 30 23:07:00 GMT 1999


> 
> >I've been trying to test gcc-2.95 by trying to build the NetBSD world for 
> >the ARM with it, and I've found a nasty gotcha in the new cpp front-end.  
> >One of the build utils in the NetBSD tree uses the cpp to pre-process 
> >certain include files with the command
> >
> >        cpp -nostdinc -idirafter /usr/include -dM /usr/include/sys/ioctl.h 
> >/usr/include/sys/ioctl_compat.h
> 
> [... and this now will overwrite ioctl_compat.h ...]
> 
> I find it difficult to believe that this command ever worked. 
> /usr/lib/gcc-lib/TARGET/VERSION/cpp has treated its second non-option
> argument as the output file, not another input file, for as far back as the
> ChangeLog goes.  Until gcc-2.95, /bin/cpp was identical with
> /u/l/g-l/T/V/cpp.  I suppose this might have been some magic property of
> -dM, but it was never documented and shouldn't have been relied on.
> 
> The NetBSD utility should do
> 
> cpp -nostdinc -idirafter /usr/include -dM -include /usr/include/sys/ioctl.h \
> 	-include /usr/include/sys/ioctl_compat.h </dev/null
> 
> which will work with gcc-2.95 and with previous versions.  (If your target
> specs are correct, you shouldn't need the -nostdinc -idirafter ... bit.)
> 
> >BTW "cpp -o -" doesn't write to stdout, nor does cpp -E.
> 
> My copy does.  Are you sure?
> 
> zw

Well, waddayaknow?  Turns out that /usr/bin/cpp on NetBSD is a shell 
script that does indeed reformat its input to look like the argument list 
that you suggest.  What caught me out is that I was overriding the tools 
in /usr/bin in order to test the new compiler, so I was then picking up 
the new cpp front end directly.

Thanks for the explanation, and my apologies for wasting any time here.

Case closed: user error.

Richard.

PS. the messing about with the -nostdinc and -idirafter is to make the 
build system work when trying to make a non-installed system (when the 
include files will be somewhere else) or a cross build.




More information about the Gcc-bugs mailing list