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 compilation 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: Id472045cc2e65bf542dfbf0ff52089be224c9d13
  • Loading branch information
schultetwin1 authored and travisg committed Dec 4, 2023
1 parent b0b2665 commit 6414dd1
Showing 1 changed file with 17 additions and 48 deletions.
65 changes: 17 additions & 48 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) $(THUMBCFLAGS)
$(MODULE_CPPOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_NOFLOAT) $(THUMBCFLAGS)
$(MODULE_CCOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_NOFLOAT) $(THUMBCFLAGS)
$(MODULE_ASMOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_NOFLOAT) $(THUMBCFLAGS)

$(MODULE_FLOAT_COBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_FLOAT) $(THUMBCFLAGS)
$(MODULE_FLOAT_CPPOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_FLOAT) $(THUMBCFLAGS)
$(MODULE_FLOAT_CCOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_FLOAT) $(THUMBCFLAGS)
$(MODULE_FLOAT_ASMOBJS): ARCH_COMPILEFLAGS += $(ARCH_COMPILEFLAGS_FLOAT) $(THUMBCFLAGS)


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,65 +66,22 @@ $(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 $@

$(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 $@

$(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) $(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 $@
Expand Down

0 comments on commit 6414dd1

Please sign in to comment.