For my project I created a component.
In this component I have a little Python script that generates C code.
This C code is needed by the component in order to compile (and most importantly to link) correctly.
I would like this C code to be generated automatically whenever I do "make" in the global project.
But I've been struggling with setting component.mk to do so.
So far here is what I have :
Code: Select all
# # Setup variable for source code generation # GENERATED_CODE_C_RELATIVE_PATH := src/generated_srcs GENERATED_CODE_C_ABSOLUTE_PATH := $(COMPONENT_PATH)/$(GENERATED_CODE_C_RELATIVE_PATH) # # Generating font code # FONT_CODE_C_FILEPATH := $(GENERATED_CODE_C_ABSOLUTE_PATH)/GraphicObject_char.c quote:=" FONT_JSON_SRC_FILENAME := $(subst $(quote),,$(CONFIG_FONT_FILE)) #Extract filename from sdkconfig "" FONT_JSON_SRC_FILEPATH := $(COMPONENT_PATH)/data/$(FONT_JSON_SRC_FILENAME) .PHONY: $(FONT_CODE_C_FILEPATH) $(FONT_CODE_C_FILEPATH): $(FONT_JSON_SRC_FILEPATH) @echo "Generating code for font from $<" python3 $(COMPONENT_PATH)/font_to_code.py $< > $@ # # This is variable will tell which file must be generated and compiled # GENERATED_FILES := $(FONT_CODE_C_FILEPATH) # # Setup component # COMPONENT_ADD_INCLUDEDIRS := ./include COMPONENT_PRIV_INCLUDEDIRS += ./priv_include COMPONENT_SRCDIRS += ./src ./$(GENERATED_CODE_C_RELATIVE_PATH) COMPONENT_EXTRA_CLEAN := $(GENERATED_CODE_C_ABSOLUTE_PATH)/* # # Setup component objs (what esp-idf will compile) # src2obj = $(patsubst %.c,%.o,$(1)) ##Auto find obj by iterating on src dir COMPONENT_OBJS := $(foreach compsrcdir,$(COMPONENT_SRCDIRS),$(call src2obj, $(wildcard $(COMPONENT_PATH)/$(compsrcdir)/*.c))) ##Add generated file COMPONENT_OBJS += $(foreach file, $(GENERATED_FILES), $(call src2obj, $(file))) ##Make relative by removing COMPONENT_PATH from all found object paths COMPONENT_OBJS := $(patsubst $(COMPONENT_PATH)/%,%,$(COMPONENT_OBJS))
Code: Select all
make: *** No rule to make target 'src/generated_srcs/GraphicObject_char.o', needed by 'libDAC_XY_Plotter.a'. Stop.
My file doesn't exists yet => No target for .o is generated => nothing triggers my file generation
So my questions are :
- Can the esp-idf toolchain supports automatic code generation ?
- Am I going the right way ?
- How I am supposed to do it ?
- Did someone ever did it ? because I found nothing about it....