Subject: Re: another makefile mystery: COPTS
To: Bill Studenmund <>
From: Todd Whitesel <>
List: tech-toolchain
Date: 01/19/2000 01:43:59
> > Why do kernel makefiles put things like -O2 and warning flags in COPTS?
> > Worse, the default contents appear to vary by arch.
> Because that's where it belongs? ;-) COPTS is for things for cc1, and is
> passed to the c compiler when it's compiling.

Actually CFLAGS is used for that, and it is put together from COPTS and
other macros (this also varies by arch, which strikes me as natural but
unnecessary code drift of the balkanization kind). and friends seem to be doing much of the same thing, except that
COPTS has no default and the -O2 shows up as the initial default for CFLAGS,
which then gets a lot of stuff added to it using += lines. (This is based on
a less-than-thorough UTSL; those include'd .mk files are getting pretty

I've seen other conventions in reserving macros for users to set things on
the command line: vxWorks user makefiles have macros like ADDED_CFLAGS; the
GNU ones (in GDB anyway) use CFLAGS (yup) for this and default it to -g.

> What defaults get blown away?

threegx:101% grep ^COPTS */conf/Makefile.*
alpha/conf/Makefile.alpha:COPTS?=               -O2
amiga/conf/Makefile.amiga:COPTS?=       -O2
arm32/conf/Makefile.arm32:COPTS?=       -O2
atari/conf/Makefile.atari:COPTS?=       -O2
bebox/conf/Makefile.bebox:COPTS?=       -O2
evbsh3/conf/Makefile.evbsh3:COPTS?=     -O2
evbsh3/conf/Makefile.evbsh3.el:COPTS?=  -O2
hp300/conf/Makefile.hp300:COPTS?=       -O2
hpcmips/conf/Makefile.hpcmips:COPTS?=   -O2
i386/conf/Makefile.i386:COPTS?= -O2
mac68k/conf/Makefile.mac68k:COPTS?= -O2
macppc/conf/Makefile.macppc:COPTS?= -O2 -pipe
mmeye/conf/Makefile.mmeye:COPTS?=       -O2
mvme68k/conf/Makefile.mvme68k:COPTS?=   -O2
news68k/conf/Makefile.news68k:COPTS?=   -O2
newsmips/conf/Makefile.newsmips:COPTS?= -O2
next68k/conf/Makefile.next68k:COPTS?= -O2
ofppc/conf/Makefile.ofppc:COPTS?= -O2
pc532/conf/Makefile.pc532:COPTS?=       -O2 -msb
pica/conf/Makefile.pica:COPTS?= -O2
pmax/conf/Makefile.pmax:COPTS?= -O2
sh3/conf/Makefile.sh3:COPTS?=   -O2
sh3/conf/        -g -O 
sh3/conf/Makefile.sh3.le:COPTS?=        -g -O -ml 
sparc/conf/Makefile.sparc:COPTS?=       -O2
sparc64/conf/Makefile.sparc64:COPTS?=   -O2
sun3/conf/Makefile.sun3:COPTS?= -O2 -fno-defer-pop
vax/conf/Makefile.vax:COPTS?= -O2
x68k/conf/Makefile.x68k:COPTS?= -O2

> Part of the idea (I thought) of how the kernel make files worked is that
> you config a kernel, and then make it. They don't include any other make
> files (except for kernel ones, like libkern and friends) - they are fairly
> independent of the normal build process (much more self contained than
> userland builds).

That is correct.

But I don't think it should presume that I'll never want to throw in an
extra option (like -pipe) from the command line without editing the makefile.
I also might be using a higher-level process to config and build kernels,
and that might want to add its own options too, perhaps in the environment.

I am in fact doing this to rebuild systems from source and to do snapshots.
I use an upper-level make with empty timestamp files because that has other
nice properties which are useful for continuing after an error. In the ideal
case where no errors occur, the current procedure can be as simple as this:

	get new sources onto the machine.
	``make cleandir''	(not the cleandir you know; clears log files)
	``make kernel''		(updates /netbsd and /netbsd.old, and stops)
	reboot and smoke-test the new kernel (best done manually).
	``make world''		(make build && make snapshot, mainly)
	upload contents of RELEASEDIR to FTP site.

For now I think I will just work up a set of diffs that add ADDED_CFLAGS or
something like that to both kernel & userland, and if it works out well I
will just send-PR it.

Todd Whitesel
toddpw @