Skip to content

Commit

Permalink
Makefile: Don't rebuild targets multiple times on parallel build.
Browse files Browse the repository at this point in the history
The nets Makefile previously called the "all" target in the net_imap
sub-Makefile, which in turn would build all the files in that
subdirectory. However, this resulted in duplicate builds when
parallelizing a build (e.g. make -j2), since the net_imap/%.o
target would get called multiple times (depending on -j number),
which effectively called $(SUBMAKE) -C net_imap all multiple times.
Instead of doing this, call the specific target name in the
sub-Makefile instead, so that the nets Makefile only rebuilds an
individual target.
  • Loading branch information
InterLinked1 committed Nov 23, 2024
1 parent 31d956d commit e52aa24
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 2 additions & 1 deletion nets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ IMAP_OBJ = $(patsubst %.c,%.o,$(IMAP_SRC))

# XXX if nets/net_imap/imap.h is modified, only net_imap.c is automatically recompiled,
# not any nets/net_imap/*.c source files that include it
# XXX If using -j[>1], some files in net_imap/ are recompiled multiple times (parallel build bug)

# Subdirectory with components for net_imap
net_imap/%.o: $(IMAP_SRC)
@+$(SUBMAKE) --no-builtin-rules -C net_imap all
@+$(SUBMAKE) --no-builtin-rules -C net_imap $(basename $(notdir $@)).o

net_imap.so : net_imap.o $(IMAP_OBJ)
@echo " [LD] $< $(IMAP_OBJ) -> $@"
Expand Down
2 changes: 0 additions & 2 deletions nets/net_imap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ DEPENDS := $(patsubst %.c,%.d,$(IMAP_SRC))
# the include directory is in the parent's parent
INC = -I../..

all: $(MOD_SO)

-include $(DEPENDS)

$(DEPENDS):
Expand Down

0 comments on commit e52aa24

Please sign in to comment.