Integrating ressource files into sketch compilation process with Arduino IDE

My projects are going to involve a sketch and a number of resource files (html, css, txt or even the ins sketch itself)

I don’t want to embed theses resources directly into the sketch as I want to use the appropriate/relevant tool to edit/maintain them directly.

I want the content of these resources files to be converted (using xxd -I ) into const char arrays declarations in files that I can either :
- leverage using a #include directive in the sketch .
- process with the compiler and integrate the .o output into the linking process ..

I want the whole process to be automated during compilation ….

How do I trigger the creation of these includable files from the ressource files in the project folder when I launch a compilation in the Arduino IDE ?
(Given the size and number of these resources files I am not worried about efficiency … I can live with running xxd -I on each file every time I compile as long as I don’t have to trigger it independently )

Given that the output of xxd -I is only variable declarations (and no code) is it better to use a #include directive to insert them in the sketch or put the output of xxd -I to a C file and put it through the compiler directly to get a .o file to be linked with the whole project ? (how do I make sure all the .o files generated this way are included at link time ?)

I believe that in a typical software dev tool chain this would be handled through recipes of sorts in a Makefile .. however I would like to keep using the Arduino IDE and not use a CLI to compile projects.
I have tried looking for tips on “how to” essentially modify the compile process in the Arduino IDE but I havent found anything promising yet.

I am open to suggestions ..


Information on how to modify the compile process is here:

You can think of platform.txt as analogous to a makefile.

You would probably want to run xxd in a pre-build hook:

Use of platform.local.txt will allow you to isolate your changes to a dedicated file, making it easier to update to new versions of the boards platform you are modifying:

Or you can create a minimal custom boards platform that contains only the necessary modifications to the build properties and references everything else from a stock boards platform:

couldn't you create a Makefile to build the files you need prior to running the IDE build?

i'm curious what you intend to use xxd for, it just creates a hex dump of a file?

xxd with the -i option create a hex dump formatted as a C const char array declaration ...
This will allow me to embed blocks of text directly referring to a variable name in my sketch. (without having to worry about special characters that would break / have to be escaped if I used a string definition put directly in a sketch )

As in0 suggested makefiles in the context of arduino IDE are called platform.txt / platform.local.txt .. -> the thought is to put recipes in these to automate the creation of .h or .o files based on the xxd output and integrate them in the compile process for the sketch ...

With this approach I hope to be able to embed html, css etc directly into the code ... a special case i am particularly interested is embedding the source code (.ino) in the code ... with the proper mechanism (your app serving a webpage) you can access the exact source code of your app as it is running .. helpful if you want to make sure the exact source (with whatever mods are introduced over time) is distributed with every instance of your app ...

Thanks for the great tips ... this looks like it will enable me to achieve what i was looking up to do ...
Moving forward with exploring recipes in platform.local.txt ...

why not just "embed" it as a char array?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.