Subject: Re: Turning off optimization on selected files.
To: None <tech-kern@netbsd.org>
From: Simon J. Gerraty <sjg@quick.com.au>
List: tech-kern
Date: 06/09/2000 17:25:33
>>If I know that a small set of MI source files will break the compiler if
>>compiled with optimization on, is there some easy way to turn it off in,
>>say, sys/${ARCH}/conf/Makefile.${ARCH}?

>Yes.  That's one of the reasons I added ODE's :U modifier.

Here you go:

PROG=t
SRCS=t1.c t2.c

COPT_t2.o=-O0

.include <bsd.prog.mk>

$ make t
cc  -O2  -Werror   -c t1.c
cc  -O0  -Werror   -c t2.c
cc   -o t t1.o t2.o 
$

Index: sys.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/sys.mk,v
retrieving revision 1.57
diff -u -p -r1.57 sys.mk
--- sys.mk      2000/05/02 03:44:36     1.57
+++ sys.mk      2000/06/09 07:20:40
@@ -27,11 +27,11 @@ CC?=                cc
     ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb" || \
     ${MACHINE_ARCH} == "sparc" || \
     ${MACHINE_ARCH} == "vax"
-DBG?=  -O2
+COPT?= -O2
 .else
-DBG?=  -O
+COPT?= -O
 .endif
-CFLAGS?=       ${DBG}
+CFLAGS?=       ${DBG} ${COPT_${.TARGET}:U${COPT}}
 COMPILE.c?=    ${CC} ${CFLAGS} ${CPPFLAGS} -c
 LINK.c?=       ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}

Oh I guess I stopped it doing the CFLAGS?= -O already :-)
I've made it COPT above since that is what folk normally want
to turn on/off per target, and left DBG in CFLAGS even though its
not set by default.  I often use:

rm foo.o
make DBG=-g COPT=-O0
when debugging.

Anyone got better ideas on the names for these variables etc?

--sjg