Subject: bsd.lib.mk and cc -MD
To: None <tech-toolchain@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: tech-toolchain
Date: 11/15/2003 17:55:33
At the moment bsd.lib.mk runs 'cc ... -o prog.o.tmp' and then does
'ld -X -r prog.o.tmp -o prog.o' to remove unwanted local symbols.

This causes problems with my attempts to pass -MD to cc in order
to get it to create prog.d on the fly - basically it is creating
prog.o.d instead.

This could be fixed by a 'mv -f prog.o.d prog.d' done iff -MD
is in CPPFLAGS - but that file is rather repetitious already.

ISTM that 'objcopy -X' could be used instead of 'ld -X' and that
would significantly simplify the whole makefile (since objcopy
will use a temporary file in order to update an existing file).

This would change the rules from:

.c.o:
	${_MKTARGET_COMPILE}
	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \
		${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}.tmp
.if defined(COPTS) && !empty(COPTS:M*-g*)
	mv ${.TARGET}.tmp ${.TARGET}
.else
	${LD} -x -r ${.TARGET}.tmp -o ${.TARGET}
	rm -f ${.TARGET}.tmp
.endif

to:

.c.o:
	${_MKTARGET_COMPILE}
	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \
		${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
.if !defined(COPTS) || empty(COPTS:M*-g*)
	${OBJCOPY} -x ${.TARGET}
.endif

Thoughts?

	David

-- 
David Laight: david@l8s.co.uk