Skip to content

Commit

Permalink
[make] Remove duplicate compile rules for modes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
schultetwin1 committed Nov 10, 2023
1 parent 94a1511 commit 5856227
Showing 1 changed file with 20 additions and 51 deletions.
71 changes: 20 additions & 51 deletions make/compile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 :=
Expand Down

0 comments on commit 5856227

Please sign in to comment.