Code Generation integrated in toolchain

Titi_38
Posts: 1
Joined: Sat Oct 17, 2020 9:16 am

Code Generation integrated in toolchain

Postby Titi_38 » Sat Oct 17, 2020 9:35 am

Hello,

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))
And when I "make", the error is :

Code: Select all

make[1]: *** No rule to make target 'src/generated_srcs/GraphicObject_char.o', needed by 'libDAC_XY_Plotter.a'.  Stop.
Which is normal because component_wrapper.mk generates the targets by listing all the files in the source directory.
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....
Thank you.

Who is online

Users browsing this forum: No registered users and 33 guests