libDaisy icon indicating copy to clipboard operation
libDaisy copied to clipboard

Add ability to compile .cc

Open beserge opened this issue 3 years ago • 4 comments

Add CC_SOURCES and .cc compilation to core/Makefile

beserge avatar Dec 23 '21 15:12 beserge

And at some point, we add support for *.c++ files endings? Hmmm... Wouldn't it make sense to specify the file ending directly in the CPP_SOURCES list instead?

TheSlowGrowth avatar Jan 22 '22 10:01 TheSlowGrowth

@TheSlowGrowth I was kind of thinking the same thing.

It'd be nice if we could just append to the CPP_SOURCES and just have a list of acceptable suffixes.

I think @beserge and I both tried quick hacks on the existing recipes to do that, but it didn't work quite right. Admittedly, my make chops aren't the best.

Would something as simple as this replacement of the separate CC_SOURCES list work as expected?

OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cc=.o)))
vpath %.cc $(sort $(dir $(CPP_SOURCES)))

stephenhensley avatar Jan 24 '22 18:01 stephenhensley

@stephenhensley I did a little poking. Your exact proposal does not work as-is because the current OBJECTS append invocations will pass through file names in the relevant source lists that don't end with the correct extension.

As in, $(CPP_SOURCES:.cpp=.o) will reassign .cpp extensions in the list to .o but leave non-matching extensions unchanged.

However this works (filter CPP_SOURCES into two sub lists, each containing exclusively .cpp or .cc files)

CPP_SOURCES_CPP = $(filter %.cpp, $(CPP_SOURCES))
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES_CPP:.cpp=.o)))
vpath %.cpp $(sort $(dir $(CPP_SOURCES_CPP)))
CPP_SOURCES_CC = $(filter %.cc, $(CPP_SOURCES))
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES_CC:.cc=.o)))
vpath %.cc $(sort $(dir $(CPP_SOURCES_CC)))

This is actually a little more foolproof in general because it ensures that no files with incompatible extensions make it through to OBJECTS. In fact it might be good to add a similar filter statement to the C_SOURCES object append invocation as well.

ndonald2 avatar Apr 24 '23 22:04 ndonald2