On Thu, Feb 06, 2025 at 03:19:56PM -0600, Eric Sandeen wrote: > Enable "make C=1" sparse checking when files get rebuilt. To check > all files, run "make clean" first. > > Enable "make C=2" sparse checking of all files without rebuilding them. > > Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx> Looks just like the one in xfsprogs and the kernel! Reviewed-by: "Darrick J. Wong" <djwong@xxxxxxxxxx> --D > --- > Makefile | 14 ++++++++++++++ > include/buildrules | 19 +++++++++++++++++++ > 2 files changed, 33 insertions(+) > > diff --git a/Makefile b/Makefile > index f6f91a4d..79779d5e 100644 > --- a/Makefile > +++ b/Makefile > @@ -14,6 +14,20 @@ else > Q = @ > endif > > +CHECK=sparse > +CHECK_OPTS=-Wsparse-all -Wbitwise -Wno-transparent-union -Wno-return-void -Wno-undef \ > + -Wno-non-pointer-null -D__CHECK_ENDIAN__ -D__linux__ > + > +ifeq ("$(origin C)", "command line") > + CHECK_CMD=$(CHECK) $(CHECK_OPTS) > + CHECKSRC=$(C) > +else > + CHECK_CMD=@true > + CHECKSRC=0 > +endif > + > +export CHECK_CMD CHECKSRC > + > MAKEOPTS = --no-print-directory Q=$(Q) > > TOPDIR = . > diff --git a/include/buildrules b/include/buildrules > index bf187662..6c2b7e18 100644 > --- a/include/buildrules > +++ b/include/buildrules > @@ -35,6 +35,21 @@ endif > # Standard targets > # > > +ifeq ($(CHECKSRC),2) > + > +# Check every .c file with sparse CHECK_CMD, do not call compiler > +$(LTCOMMAND) $(LTLIBRARY) : $(SUBDIRS) $(OBJECTS) > +.PHONY: $(LTCOMMAND) $(LTLIBRARY) > + > +%.lo %.o : %.c FORCE > + @echo " [CHECK] $<" > + $(Q)$(CHECK_CMD) $(CFLAGS) $< > + > +FORCE: > + > +else > +# Regular build, possibly calling sparse CHECK_CMD as well > + > ifdef LTCOMMAND > $(LTCOMMAND) : $(SUBDIRS) $(OBJECTS) $(LTDEPENDENCIES) > @echo " [LD] $*" > @@ -49,12 +64,16 @@ $(LTLIBRARY) : $(SUBDIRS) $(LTOBJECTS) > %.lo: %.c > @echo " [CC] $@" > $(Q)$(LTCOMPILE) -c $< > + $(Q)$(CHECK_CMD) $(CFLAGS) $< > else > + > %.o: %.c > @echo " [CC] $@" > $(Q)$(CC) $(CFLAGS) -c $< > + $(Q)$(CHECK_CMD) $(CFLAGS) $< > > endif > +endif > > ifdef POTHEAD > %.pot: $(XGETTEXTFILES) > -- > 2.48.0 > >