[Lldb-commits] [PATCH] D94890: Makefile.rules: Avoid redundant .d generation and make restart

Fangrui Song via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Jan 17 17:01:39 PST 2021


MaskRay created this revision.
MaskRay added reviewers: friss, JDevlieghere, labath, rupprecht.
MaskRay requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Take an example when `CXX_SOURCES` is main.cpp.

main.d is a included file. make will rebuild main.d, re-executes itself [1] to read
in the new main.d file, then rebuild main.o, finally link main.o into a.out.
main.cpp is parsed twice in this process.

This patch merges .d generation into .o generation [2], writes explicit rules
for .c/.m and deletes suffix rules for %.m and %.o. Since a target can be
satisfied by either of .c/.cpp/.m/.mm, we use double-colon rules [3].

Since suffix rules are disabled, the implicit rule for archive member targets is
no long available [4]. Rewrite and simplify the archive rule.

[1]: https://www.gnu.org/software/make/manual/html_node/Remaking-Makefiles.html
[2]: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
[3]: https://www.gnu.org/software/make/manual/html_node/Double_002dColon.html
[4]: https://www.gnu.org/software/make/manual/html_node/Archive-Update.html

ObjC/ObjCXX tests only run on macOS. I don't have testing environment.  Hope
someone can do it for me.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94890

Files:
  lldb/packages/Python/lldbsuite/test/make/Makefile.rules


Index: lldb/packages/Python/lldbsuite/test/make/Makefile.rules
===================================================================
--- lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -570,13 +570,8 @@
 # Make the archive
 #----------------------------------------------------------------------
 ifneq "$(ARCHIVE_NAME)" ""
-ifeq "$(OS)" "Darwin"
-$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
-	$(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
-	$(RM) $(ARCHIVE_OBJECTS)
-else
-$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
-endif
+$(ARCHIVE_NAME): $(ARCHIVE_OBJECTS)
+	$(AR) $(ARFLAGS) $@ $^
 endif
 
 #----------------------------------------------------------------------
@@ -628,12 +623,24 @@
 # Make the precompiled header and compile C++ sources against it
 #----------------------------------------------------------------------
 
-#ifneq "$(PCH_OUTPUT)" ""
+ifneq "$(PCH_OUTPUT)" ""
 $(PCH_OUTPUT) : $(PCH_CXX_SOURCE)
 	$(CXX) $(CXXFLAGS) -x c++-header -o $@ $<
-%.o : %.cpp $(PCH_OUTPUT)
-	$(CXX) $(PCHFLAGS) $(CXXFLAGS) -c -o $@ $<
-#endif
+endif
+
+.SUFFIXES:
+
+%.o:: %.c %.d
+	$(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
+
+%.o:: %.cpp %.d $(PCH_OUTPUT)
+	$(CXX) $(PCHFLAGS) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
+
+%.o:: %.m %.d
+	$(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
+
+%.o:: %.mm %.d
+	$(CXX) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
 
 #----------------------------------------------------------------------
 # Automatic variables based on items already entered. Below we create
@@ -641,43 +648,21 @@
 # that end with .c with .o, and we also create a list of prerequisite
 # files by replacing all .c files with .d.
 #----------------------------------------------------------------------
-PREREQS := $(OBJECTS:.o=.d)
+PREREQS := $(OBJECTS:.o=.d) $(ARCHIVE_OBJECTS:.o=.d)
 DWOS := $(OBJECTS:.o=.dwo) $(ARCHIVE_OBJECTS:.o=.dwo)
 ifneq "$(DYLIB_NAME)" ""
 	DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
 	DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo)
 endif
 
-#----------------------------------------------------------------------
-# Rule for Generating Prerequisites Automatically using .d files and
-# the compiler -MM option. The -M option will list all system headers,
-# and the -MM option will list all non-system dependencies.
-#----------------------------------------------------------------------
-%.d: %.c
-	$(CC) -M $(CFLAGS) $< -MF $@ -MT $@ -MT $*.o
-
-%.d: %.cpp
-	@$(CXX) -M $(CXXFLAGS) $< -MF $@ -MT $@ -MT $*.o
-
-%.d: %.m
-	@$(CC) -M $(CFLAGS) $< -MF $@ -MT $@ -MT $*.o
-
-%.d: %.mm
-	@$(CXX) -M $(CXXFLAGS) $< -MF $@ -MT $@ -MT $*.o
+# Don't error if a .d file is deleted.
+$(PREREQS) $(DYLIB_PREREQS): ;
 
 #----------------------------------------------------------------------
 # Include all of the makefiles for each source file so we don't have
 # to manually track all of the prerequisites for each source file.
 #----------------------------------------------------------------------
-sinclude $(PREREQS)
-ifneq "$(DYLIB_NAME)" ""
-	sinclude $(DYLIB_PREREQS)
-endif
-
-# Define a suffix rule for .mm -> .o
-.SUFFIXES: .mm .o
-.mm.o:
-	$(CXX) $(CXXFLAGS) -c $<
+include $(wildcard $(PREREQS) $(DYLIB_PREREQS))
 
 .PHONY: clean
 dsym:	$(DSYM)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94890.317248.patch
Type: text/x-patch
Size: 3312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210118/be67735c/attachment-0001.bin>


More information about the lldb-commits mailing list