Code Generation integrated in toolchain

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


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 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

# Generating font code

FONT_JSON_SRC_FILENAME := $(subst $(quote),,$(CONFIG_FONT_FILE)) #Extract filename from sdkconfig ""


	@echo "Generating code for font from $<"
	python3 $(COMPONENT_PATH)/ $< > $@

# This is variable will tell which file must be generated and compiled

# Setup component


# 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
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 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