From 58562274896175655de1d5d25cdfa455175cb22f Mon Sep 17 00:00:00 2001 From: Matt Schulte Date: Fri, 10 Nov 2023 14:08:43 -0800 Subject: [PATCH] [make] Remove duplicate compile rules for modes Currently, the compilation rules are mostly duplicated for normal vs float vs ARM source files. This fix deduplicates the compliation logic for these different "mode" of source files by using make's Target-specific variable functionality. https://www.gnu.org/software/make/manual/make.html#Target_002dspecific This change was tested by using [`bear`](https://github.com/rizsotto/Bear) to generate a compile_commands.json file. The file was generated both before and after the change and the json diff'd to ensure the generated compile commands were not changed. Change-Id: Ie7f68fb981e4f1efad81316780c4fa22c75ee578 --- make/compile.mk | 71 ++++++++++++++----------------------------------- 1 file changed, 20 insertions(+), 51 deletions(-) diff --git a/make/compile.mk b/make/compile.mk index 2ba75484b..17e09af4c 100644 --- a/make/compile.mk +++ b/make/compile.mk @@ -32,6 +32,18 @@ MODULE_ARM_CPPOBJS := $(call TOBUILDDIR,$(patsubst %.cpp,%.cpp.o,$(MODULE_ARM_CP MODULE_ARM_CCOBJS := $(call TOBUILDDIR,$(patsubst %.cc,%.cc.o,$(MODULE_ARM_CCSRCS))) MODULE_ARM_ASMOBJS := $(call TOBUILDDIR,$(patsubst %.S,%.S.o,$(MODULE_ARM_ASMSRCS))) +# Add specific overrides for the different modes +$(MODULE_COBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_NOFLOAT) +$(MODULE_CPPOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_NOFLOAT) +$(MODULE_CCOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_NOFLOAT) +$(MODULE_ASMOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_NOFLOAT) + +$(MODULE_FLOAT_COBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_FLOAT) +$(MODULE_FLOAT_CPPOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_FLOAT) +$(MODULE_FLOAT_CCOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_FLOAT) +$(MODULE_FLOAT_ASMOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_FLOAT) + + MODULE_OBJS := $(MODULE_COBJS) $(MODULE_CPPOBJS) $(MODULE_CCOBJS) $(MODULE_ASMOBJS) MODULE_OBJS += $(MODULE_FLOAT_COBJS) $(MODULE_FLOAT_CPPOBJS) $(MODULE_FLOAT_CCOBJS) $(MODULE_FLOAT_ASMOBJS) MODULE_OBJS += $(MODULE_ARM_COBJS) $(MODULE_ARM_CPPOBJS) $(MODULE_ARM_CCOBJS) $(MODULE_ARM_ASMOBJS) @@ -54,68 +66,25 @@ $(MODULE_OBJS): MODULE_ASMFLAGS:=$(MODULE_ASMFLAGS) $(MODULE_OBJS): MODULE_SRCDEPS:=$(MODULE_SRCDEPS) $(MODULE_OBJS): MODULE_INCLUDES:=$(MODULE_INCLUDES) -# normal compile options -$(MODULE_COBJS): $(BUILDDIR)/%.c.o: %.c $(MODULE_SRCDEPS) - @$(MKDIR) - $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(ARCH_COMPILEFLAGS_NOFLOAT) $(MODULE_COMPILEFLAGS) $(GLOBAL_CFLAGS) $(ARCH_CFLAGS) $(MODULE_CFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ - -$(MODULE_CPPOBJS): $(BUILDDIR)/%.cpp.o: %.cpp $(MODULE_SRCDEPS) - @$(MKDIR) - $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(ARCH_COMPILEFLAGS_NOFLOAT) $(MODULE_COMPILEFLAGS) $(GLOBAL_CPPFLAGS) $(ARCH_CPPFLAGS) $(MODULE_CPPFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ - -$(MODULE_CCOBJS): $(BUILDDIR)/%.cc.o: %.cc $(MODULE_SRCDEPS) - @$(MKDIR) - $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(ARCH_COMPILEFLAGS_NOFLOAT) $(MODULE_COMPILEFLAGS) $(GLOBAL_CPPFLAGS) $(ARCH_CPPFLAGS) $(MODULE_CPPFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ - -$(MODULE_ASMOBJS): $(BUILDDIR)/%.S.o: %.S $(MODULE_SRCDEPS) - @$(MKDIR) - $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(ARCH_COMPILEFLAGS_NOFLOAT) $(MODULE_COMPILEFLAGS) $(GLOBAL_ASMFLAGS) $(ARCH_ASMFLAGS) $(MODULE_ASMFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ - -# compile options with floating point -$(MODULE_FLOAT_COBJS): $(BUILDDIR)/%.c.o: %.c $(MODULE_SRCDEPS) - @$(MKDIR) - $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(ARCH_COMPILEFLAGS_FLOAT) $(MODULE_COMPILEFLAGS) $(GLOBAL_CFLAGS) $(ARCH_CFLAGS) $(MODULE_CFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ - -$(MODULE_FLOAT_CPPOBJS): $(BUILDDIR)/%.cpp.o: %.cpp $(MODULE_SRCDEPS) - @$(MKDIR) - $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(ARCH_COMPILEFLAGS_FLOAT) $(MODULE_COMPILEFLAGS) $(GLOBAL_CPPFLAGS) $(ARCH_CPPFLAGS) $(MODULE_CPPFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ - -$(MODULE_FLOAT_CCOBJS): $(BUILDDIR)/%.cc.o: %.cc $(MODULE_SRCDEPS) - @$(MKDIR) - $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(ARCH_COMPILEFLAGS_FLOAT) $(MODULE_COMPILEFLAGS) $(GLOBAL_CPPFLAGS) $(ARCH_CPPFLAGS) $(MODULE_CPPFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ - -$(MODULE_FLOAT_ASMOBJS): $(BUILDDIR)/%.S.o: %.S $(MODULE_SRCDEPS) - @$(MKDIR) - $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(ARCH_COMPILEFLAGS_FLOAT) $(MODULE_COMPILEFLAGS) $(GLOBAL_ASMFLAGS) $(ARCH_ASMFLAGS) $(MODULE_ASMFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ - -# overridden arm versions -$(MODULE_ARM_COBJS): $(BUILDDIR)/%.c.o: %.c $(MODULE_SRCDEPS) +$(MODULE_COBJS) $(MODULE_FLOAT_COBJS) $(MODULE_ARM_COBJS): $(BUILDDIR)/%.c.o: %.c $(MODULE_SRCDEPS) @$(MKDIR) $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(MODULE_COMPILEFLAGS) $(GLOBAL_CFLAGS) $(ARCH_CFLAGS) $(MODULE_CFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ + $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(MODULE_COMPILEFLAGS) $(GLOBAL_CFLAGS) $(ARCH_CFLAGS) $(MODULE_CFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ -$(MODULE_ARM_CPPOBJS): $(BUILDDIR)/%.cpp.o: %.cpp $(MODULE_SRCDEPS) +$(MODULE_CPPOBJS) $(MODULE_FLOAT_CPPOBJS) $(MODULE_ARM_CPPOBJS): $(BUILDDIR)/%.cpp.o: %.cpp $(MODULE_SRCDEPS) @$(MKDIR) $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(MODULE_COMPILEFLAGS) $(GLOBAL_CPPFLAGS) $(ARCH_CPPFLAGS) $(MODULE_CPPFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ + $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(MODULE_COMPILEFLAGS) $(GLOBAL_CPPFLAGS) $(ARCH_CPPFLAGS) $(MODULE_CPPFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ -$(MODULE_ARM_CCOBJS): $(BUILDDIR)/%.cc.o: %.cc $(MODULE_SRCDEPS) +$(MODULE_CCOBJS) $(MODULE_FLOAT_CCOBJS) $(MODULE_ARM_CCOBJS): $(BUILDDIR)/%.cc.o: %.cc $(MODULE_SRCDEPS) @$(MKDIR) $(info compiling $<) - $(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(MODULE_COMPILEFLAGS) $(GLOBAL_CPPFLAGS) $(ARCH_CPPFLAGS) $(MODULE_CPPFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ + $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(MODULE_COMPILEFLAGS) $(GLOBAL_CPPFLAGS) $(ARCH_CPPFLAGS) $(MODULE_CPPFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ -$(MODULE_ARM_ASMOBJS): $(BUILDDIR)/%.S.o: %.S $(MODULE_SRCDEPS) +$(MODULE_ASMOBJS) $(MODULE_FLOAT_ASMOBJS) $(MODULE_ARM_ASMOBJS): $(BUILDDIR)/%.S.o: %.S $(MODULE_SRCDEPS) @$(MKDIR) $(info compiling $<) - $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(MODULE_COMPILEFLAGS) $(GLOBAL_ASMFLAGS) $(ARCH_ASMFLAGS) $(MODULE_ASMFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ + $(NOECHO)$(CC) $(GLOBAL_OPTFLAGS) $(MODULE_OPTFLAGS) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(MODULE_COMPILEFLAGS) $(GLOBAL_ASMFLAGS) $(ARCH_ASMFLAGS) $(MODULE_ASMFLAGS) $(THUMBCFLAGS) $(GLOBAL_INCLUDES) $(MODULE_INCLUDES) -c $< -MD -MP -MT $@ -MF $(@:%o=%d) -o $@ # clear some variables we set here MODULE_CSRCS :=