caab4045fa20627f1602955c53cacc05ea07de24
braney
  Fri Aug 14 11:01:17 2026 -0700
stop directory makefiles from overriding the tree compiler flags, refs #38094

hg/hgTracks/makefile has carried "COPT = -ggdb" since 2019-02-01.  Every
directory makefile includes inc/common.mk on its first line, so that
assignment came after the tree default and replaced it.  The result is that
hgTracks itself has shipped with no optimization for seven years, while every
library it links against was built with -O3.  Building it with the tree
default is 17.5% faster over a set of eight sessions, and 1.95x faster on a
wide clinical view, with byte identical PNG output.

Twenty three makefiles had a COPT or CFLAGS override.  All are removed here.
hg/visiGene/vgPrepImage keeps its defines, but appends them with += instead
of assigning over the tree flags, because the ERMapper JPEG2000 headers need
them.

Compiling hg/hgTracks with optimization exposed seven errors that only appear
under -O3.  Four source files are fixed: hgTracks.c used an uninitialized
labelfont, expRatioTracks.c and simpleTracks.c had five strncpy calls that
could leave a string unterminated, and netTrack.c had two int buffers too
small to hold the value written into them.  The last two look like real
latent bugs, not warning noise.

checkCompileFlags.sh is added to stop this from recurring.  The topChecks
target runs it, so every build path reaches it.  It fails the build on any
COPT assignment, any CFLAGS assignment that is not +=, and any CFLAGS +=
carrying an -O flag.  The check cannot live in inc/common.mk, because at the
point common.mk is parsed the overriding line has not been read yet.  A
command line override such as "make COPT='-O0 -g'" still works, since the
check reads only file contents.

The 2026 conversion of the tree to -O3 did not find this.  That work was
driven by the warnings -O3 produces, and a directory that overrides COPT
never receives the flag, so it never warns.

Verified: the tree builds at -O3 with no new errors and no new warnings, and
80 rendered images compare pixel identical against the old build.

diff --git src/makefile src/makefile
index d5da91726b5..5063b868a3a 100644
--- src/makefile
+++ src/makefile
@@ -15,30 +15,31 @@
 	${MAKE} clean
 ##
 # topLibs
 ##
 TOP_LIBS = lib parasol/lib submodules/htslib
 ifneq ($(wildcard jkOwnLib/*),)
   TOP_LIBS += jkOwnLib
 endif
 topLibs: ${TOP_LIBS:%=%.topLibs}
 %.topLibs: topChecks
 	${MAKE} -C $*
 
 .PHONY: topChecks
 topChecks:
 	@./checkUmask.sh
+	@./checkCompileFlags.sh
 	@MACHTYPE=${MACHTYPE} ./machTest.sh
 	@./submodules/submoduleSetup
 
 optLib:
 	cd optimalLeaf && ${MAKE}
 
 ##
 # hgLib
 ##
 ifneq ($(wildcard hg/makefile),)
    HGLIB_DIRS += hg/lib
    HGLIB_CHECK = hgLibChecks
 endif
 ifneq ($(wildcard hg/cgilib/makefile),)
    HGLIB_DIRS += hg/cgilib