Message ID | 20210127165856.2090337-1-bkylerussell@gmail.com (mailing list archive) |
---|---|
State | Mainlined, archived |
Headers | show |
Series | Makefile: add version.h dependency on all objects | expand |
On Wed, Jan 27, 2021 at 11:58:56AM -0500, Kyle Russell wrote: > 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 Mmmm, yes. I never see this because I always use a plain 'make -j'. Thanks. > @@ -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
diff --git a/Makefile b/Makefile index 31366446..dbad0f7a 100644 --- a/Makefile +++ b/Makefile @@ -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 \
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 Signed-off-by: Kyle Russell <bkylerussell@gmail.com> --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)