Skip to contentSkip to conversation

Makefile: add version.h dependency on all objects

PATCH In review Kyle Russell 2 participants 2 messages Jan 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: add version.h dependency on all objects

This guarantees the generated version.h will exist before attempting to compile any c files that include it.

Several source files include the generated version.h, but not all declare a proper make dependency.

$ grep -r 'version\.h' *.c
compile-i386.c:#include "version.h"
lib.c:#include "version.h"
options.c:#include "version.h"

This allows a sufficiently parallelized make invocation to encounter ENOENT.

CC compile-i386.o
compile-i386.c:60:21: fatal error: version.h: No such file or directory compilation terminated.
Makefile:253: recipe for target 'compile-i386.o' failed
make: *** [compile-i386.o] Error 1

---
 Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Makefile +1 -2
index 31366446..dbad0f7a 100644
@@ -249,7 +249,7 @@ libsparse.a: $(LIB_OBJS)
 
 
 cflags   += $($(*)-cflags) $(CPPFLAGS) $(CFLAGS)
-%.o: %.c
+%.o: %.c version.h
 	@echo "  CC      $@"
 	$(Q)$(CC) $(cflags) -c -o $@ $<
 
@@ -260,7 +260,6 @@ cflags   += $($(*)-cflags) $(CPPFLAGS) $(CFLAGS)
 selfcheck: $(OBJS:.o=.sc)
 
 SPARSE_VERSION:=$(shell git describe --dirty 2>/dev/null || echo '$(VERSION)')
-lib.o: version.h
 version.h: FORCE
 	@echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h.tmp
 	@if cmp -s version.h version.h.tmp; then \
Signature · 1 line
2.25.1
#1 lore raw
Quoted 11 lines · Kyle Russell

This guarantees the generated version.h will exist before attempting to compile any c files that include it.

Several source files include the generated version.h, but not all declare a proper make dependency.

$ grep -r 'version\.h' *.c
compile-i386.c:#include "version.h"
lib.c:#include "version.h"
options.c:#include "version.h"
Quoted 8 lines

This allows a sufficiently parallelized make invocation to encounter ENOENT.

CC compile-i386.o
compile-i386.c:60:21: fatal error: version.h: No such file or directory compilation terminated.
Makefile:253: recipe for target 'compile-i386.o' failed
make: *** [compile-i386.o] Error 1

Mmmm, yes. I never see this because I always use a plain 'make -j'. Thanks.

Makefile libsparse.a: $(LIB_OBJS) · line 250

Quoted 4 lines
Makefile +1 -1
@@ -249,7 +249,7 @@ libsparse.a: $(LIB_OBJS)
 cflags   += $($(*)-cflags) $(CPPFLAGS) $(CFLAGS)
-%.o: %.c
+%.o: %.c version.h

This is annoying because now all files need to be rebuild at every changes. I've modified the patch so that single new file (version.c) includes and depends on the generated file.

Best regards,
-- Luc