"Also note that CFLAGS should never be set in mk.conf."
In the context where this sentence occurs, it can also be interpreted as
"appending to CFLAGS is fine, just don't override it, as its default
value includes the DBG variable". Not sure why nobody fixed this
ambiguous wording in the past 17 years.
so I used COPTS instead of CFLAGS
That doesn't work in pkgsrc since in
pkgtools/bootstrap-mk-files/files/sys.mk, the default value for CFLAGS
does not include COPTS.
To find this out, I ran this command in emulators/dosbox:
bmake -V CFLAGS -dA 2>&1 | less
In the output, I searched for "Global: CFLAGS" and then went backwards
to "Parse_PushInput" to see which file caused the variable assignment.
In the NetBSD base system, COPTS is not added to CFLAGS unconditionally,
as the output of this command reveals:
grep 'CFLAGS.*COPTS' /usr/share/mk/*.mk
From the filenames in the output, you can see that COPTS only applies to
host libraries, kernel modules, libraries and programs. Notably, this
excludes pkgsrc packages.