5f47cb8c328b76c41a9a21599477bfacf4d91a37 braney Sun Sep 6 16:57:16 2026 -0700 makefiles: let the compiler write the header dependencies The tree had 72 hand-written "foo.o: bar.h" lines across 15 makefiles, so almost every object was rebuilt only when its own .c file changed. Editing a header left every other object that included it holding the old layout, and the crash landed somewhere the change never touched. The %.o: %.c rule in inc/common.mk now passes -MMD -MP. The compiler writes foo.d beside foo.o listing the headers that compile really read, and an -include reads them back. Nine makefiles keep a compile rule of their own, because they add -DGBROWSE, -DGFSERVER_HUGE or -DCGI_BIN=; each got ${DEPGEN} too. lib and hg/lib are the only two that build objects into a subdirectory, and each reads its own subdirectory .d files at the foot of its own file. Touching hg/hgTracks/wigCommon.h used to rebuild 2 objects. It now rebuilds 11, which is every .c file in that directory that includes the header. A .d file holds rules, and make takes its default goal from the first rule it reads, included files and all. common.mk is read before a makefile's own rules, so the include has to save $(.DEFAULT_GOAL) and set it back afterwards; without that, make in lib built adjacency.o and stopped. Fifteen link rules in directories the build enters named a library on the command line without depending on it. Each now lists it. hg/hgPhyloPlace, hg/visiGene/hgVisiGene and hg/orthoMap were the three whose target is a real file and could go stale. make clean still leaves the .d files. A shared clean:: rule in common.mk would first mean converting about 320 single-colon clean: rules, since make refuses to mix the two forms on one target. A leftover .d cannot break a build: -MP writes an empty target for each header, so a deleted or renamed one does not leave make asking for a file no rule can build. refs #36621 diff --git src/hg/makeDb/genbank/common.mk src/hg/makeDb/genbank/common.mk index 0383d84c55f..5352e0d3f53 100644 --- src/hg/makeDb/genbank/common.mk +++ src/hg/makeDb/genbank/common.mk @@ -1,69 +1,69 @@ KENT = ${GBROOT}/../../.. include ${KENT}/inc/common.mk # FIXME: for now, need to link statically on RH7 or a warning is written # to stdout on RH9, which breaks the program trying to read the output. # Gag me... ifneq ($(wildcard ${GBROOT}/extern/lib/libmysqlclient.a),) MYSQLLIBS=${GBROOT}/extern/lib/libmysqlclient.a STATIC = -static endif ifeq (${MYSQLLIBS},) $(error must set MYSQLLIBS env var) endif ifeq (${HG_WARN},) ifeq (darwin,$(findstring darwin,${OSTYPE})) HG_WARN = -Wall -Wno-unused-variable -Wno-long-double HG_WARN_UNINIT= else ifeq (solaris,$(findstring solaris,${OSTYPE})) HG_WARN = -Wall -Wformat -Wimplicit -Wreturn-type HG_WARN_UNINIT=-Wuninitialized else HG_WARN = -Wall -Wunused-but-set-variable -Wformat -Wimplicit -Wreturn-type HG_WARN_UNINIT=-Wuninitialized endif endif # -Wuninitialized generates a warning without optimization ifeq ($(findstring -O,${COPT}),-O) HG_WARN += ${HG_WARN_UNINIT} endif endif INCL = -I${GBROOT}/src/inc -I${KENT}/inc -I${KENT}/hg/inc CFLAGS = ${COPT} ${STATIC} -DJK_WARN -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE ${HG_WARN} ${INCL} # for debugging hash usage #CFLAGS += -DDUMP_HASH_STATS GB_BINDIR = ${GBROOT}/bin GB_BINARCH = ${GB_BINDIR}/${MACHTYPE} GB_LIBDIR = ${GBROOT}/lib GB_LIBARCH = ${GB_LIBDIR}/${MACHTYPE} LIBGENBANK = $(GB_LIBARCH)/libgenbank.a MYLIBDIR = ${KENT}/lib/$(MACHTYPE) JKLIBS = $(MYLIBDIR)/jkhgap.a $(MYLIBDIR)/jkweb.a $(MYLIBDIR)/jkhgapcgi.a LIBS = $(LIBGENBANK) ${JKLIBS} ${MYSQLLIBS} -lm ${L} TESTBIN = ${GBROOT}/tests/bin TESTBINARCH = ${TESTBIN}/$(MACHTYPE) MKDIR = mkdir -p STRINGIFY = stringify %.o: %.c - ${CC} ${CFLAGS} -c -o $@ $< + ${CC} ${CFLAGS} ${DEPGEN} -c -o $@ $< $(GB_BINARCH)/%: ${O} makefile ${LIBGENBANK} @${MKDIR} -p ${GB_BINARCH} ${CC} ${CFLAGS} -o $@ $O $(LIBS) ${GB_BINDIR}/%: % @${MKDIR} -p ${GB_BINDIR} cp -f $< $@ chmod a-w,a+rx $@