Skip to content

Commit

Permalink
Build: wrap make invocations with flock(1)
Browse files Browse the repository at this point in the history
Lock each directory before entering it so when using -j, the same
dependency isn't built more than once at a time.

This doesn't get full -j parallelism though, since one make child
will be sitting idle waiting for flock to receive its lock and
continue making (which should then do nothing since it will have
been built already).  Unfortunately there's not much that can be
done to fix that since it can't proceed until its dependency is
built by another make process.
  • Loading branch information
jcs authored and awesomekling committed Dec 28, 2019
1 parent d622e4d commit 0b50133
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
1 change: 0 additions & 1 deletion AK/Tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ SHARED_TEST_OBJS = \

define execute-command
$(1)

endef

all: $(PROGRAMS)
Expand Down
4 changes: 2 additions & 2 deletions Applications/Browser/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ LIB_DEPS = GUI HTML Draw IPC Protocol Core

main.cpp: ../../Libraries/LibHTML/CSS/PropertyID.h
../../Libraries/LibHTML/CSS/PropertyID.h:
@$(MAKE) -C ../../Libraries/LibHTML
@flock ../../Libraries/LibHTML $(MAKE) -C ../../Libraries/LibHTML

main.cpp: ../../Servers/ProtocolServer/ProtocolClientEndpoint.h
../../Servers/ProtocolServer/ProtocolClientEndpoint.h:
@$(MAKE) -C $(dir $(@))
@flock ../../Servers/ProtocolServer $(MAKE) -C $(dir $(@))

include ../../Makefile.common
2 changes: 1 addition & 1 deletion Libraries/LibAudio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LIBRARY = libaudio.a

AClientConnection.cpp: ../../Servers/AudioServer/AudioClientEndpoint.h
../../Servers/AudioServer/AudioClientEndpoint.h:
@$(MAKE) -C $(dir $(@))
@flock $(dir $(@)) $(MAKE) -C $(dir $(@))

install:
mkdir -p $(SERENITY_BASE_DIR)/Root/usr/include/LibAudio/
Expand Down
7 changes: 3 additions & 4 deletions Libraries/LibC/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.NOTPARALLEL:

AK_OBJS = \
../../AK/StringImpl.o \
../../AK/String.o \
Expand Down Expand Up @@ -62,7 +60,6 @@ OBJS = $(AK_OBJS) $(LIBC_OBJS)
EXTRA_OBJS = setjmp.ao crti.ao crtn.ao

crt0.o: crt0.cpp
$(QUIET) $(CXX) $(CXXFLAGS) -o crt0.o -c crt0.cpp

crtio.o: crti.ao
$(QUIET) cp crti.ao crti.o
Expand All @@ -76,7 +73,9 @@ DEFINES = -DSERENITY_LIBC_BUILD

LIBRARY = libc.a

all: crt0.o $(EXTRA_OBJS) $(LIBRARY) install
POST_LIBRARY_BUILD = $(QUIET) $(MAKE) install

all: crt0.o $(EXTRA_OBJS) $(LIBRARY)

install:
mkdir -p $(SERENITY_BASE_DIR)/Root/usr/include/sys/
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibGUI/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ LIBRARY = libgui.a
GWindowServerConnection.cpp: ../../Servers/WindowServer/WindowServerEndpoint.h

../../Servers/WindowServer/WindowServerEndpoint.h:
@$(MAKE) -C $(dir $(@))
@flock $(dir $(@)) $(MAKE) -C $(dir $(@))

install:
mkdir -p $(SERENITY_BASE_DIR)/Root/usr/include/LibGUI/
Expand Down
8 changes: 4 additions & 4 deletions Libraries/LibHTML/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ GENERATE_CSS_PROPERTYID_CPP = CodeGenerators/Generate_CSS_PropertyID_cpp/Generat
GENERATE_CSS_PROPERTYID_H = CodeGenerators/Generate_CSS_PropertyID_h/Generate_CSS_PropertyID_h

$(GENERATE_CSS_PROPERTYID_H):
@$(MAKE) -C $(dir $(GENERATE_CSS_PROPERTYID_H))
@flock $(dir $(GENERATE_CSS_PROPERTYID_H)) $(MAKE) -C $(dir $(GENERATE_CSS_PROPERTYID_H))

$(GENERATE_CSS_PROPERTYID_CPP):
@$(MAKE) -C $(dir $(GENERATE_CSS_PROPERTYID_CPP))
@flock $(dir $(GENERATE_CSS_PROPERTYID_CPP)) $(MAKE) -C $(dir $(GENERATE_CSS_PROPERTYID_CPP))

CSS/DefaultStyleSheetSource.cpp: CSS/Default.css Scripts/GenerateStyleSheetSource.sh
@echo "GENERATE $@"
$(QUIET) Scripts/GenerateStyleSheetSource.sh default_stylesheet_source $< > $@

CSS/PropertyID.h: CSS/Properties.json $(GENERATE_CSS_PROPERTYID_H)
@echo "GENERATE $@"
$(QUIET) $(GENERATE_CSS_PROPERTYID_H) $< > $@
$(QUIET) flock CSS $(GENERATE_CSS_PROPERTYID_H) $< > $@

CSS/PropertyID.cpp: CSS/Properties.json $(GENERATE_CSS_PROPERTYID_CPP)
@echo "GENERATE $@"
$(QUIET) $(GENERATE_CSS_PROPERTYID_CPP) $< > $@
$(QUIET) flock CSS $(GENERATE_CSS_PROPERTYID_CPP) $< > $@

EXTRA_CLEAN = CSS/DefaultStyleSheetSource.cpp CSS/PropertyID.h CSS/PropertyID.cpp

Expand Down
2 changes: 1 addition & 1 deletion Libraries/LibProtocol/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ LIBRARY = libprotocol.a

Download.cpp: ../../Servers/ProtocolServer/ProtocolClientEndpoint.h
../../Servers/ProtocolServer/ProtocolClientEndpoint.h:
@$(MAKE) -C $(dir $(@))
@flock $(dir $(@)) $(MAKE) -C $(dir $(@))

include ../../Makefile.common
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ ifeq ($(UNAME_S),Darwin)
test:
else
test:
$(QUIET) $(MAKE) -C AK/Tests clean all clean
$(QUIET) flock AK/Tests $(MAKE) -C AK/Tests clean all clean
endif

8 changes: 5 additions & 3 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,21 @@ $(PROGRAM): $(STATIC_LIB_DEPS) $(SUFFIXED_OBJS) $(EXTRA_OBJS)
$(LIBRARY): $(SUFFIXED_OBJS) $(EXTRA_OBJS)
@echo "LIB $@"
$(QUIET) $(AR) rcs $@ $(OBJS) $(EXTRA_OBJS) $(LIBS)
$(POST_LIBRARY_BUILD)

#.PHONY: $(STATIC_LIB_DEPS)
$(STATIC_LIB_DEPS):
@$(MAKE) -C $(dir $(@))
@flock $(dir $(@)) $(MAKE) -C $(dir $(@))

IPCCOMPILER = $(SERENITY_BASE_DIR)/DevTools/IPCCompiler/IPCCompiler
IPCCOMPILER: $(IPCCOMPILER)
$(IPCCOMPILER):
@$(MAKE) -C $(dir $(@))
@flock $(dir $(@)) $(MAKE) -C $(dir $(@))

FORMCOMPILER = $(SERENITY_BASE_DIR)/DevTools/FormCompiler/FormCompiler
FORMCOMPILER: $(FORMCOMPILER)
$(FORMCOMPILER):
@$(MAKE) -C $(dir $(@))
@flock $(dir $(@)) $(MAKE) -C $(dir $(@))

.DEFAULT_GOAL := all

Expand Down
6 changes: 3 additions & 3 deletions Makefile.subdir
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
subdirs: $(SUBDIRS)
$(SUBDIRS):
@$(MAKE) -C $@
@flock $@ $(MAKE) -C $@

all: $(subdirs)

SUBDIRS_CLEAN = $(addsuffix .clean,$(SUBDIRS))
clean: $(SUBDIRS_CLEAN)
$(SUBDIRS_CLEAN): %.clean:
@$(MAKE) -C $* clean
@flock $* $(MAKE) -C $* clean

SUBDIRS_INSTALL = $(addsuffix .install,$(SUBDIRS))
install: $(SUBDIRS_INSTALL)
$(SUBDIRS_INSTALL): %.install:
@$(MAKE) -C $* install
@flock $* $(MAKE) -C $* install

.PHONY: all clean install $(SUBDIRS)

0 comments on commit 0b50133

Please sign in to comment.