This commit is useful if there is a need to generate a file
that can be included into the application at build time.
The file can also be compressed automatically when embedding it.
Files to be generated are listed in
generate_inc_file
generate_inc_gz_file
variables.
How to use this commit in your application:
1. Add this to your application Makefile
SRC = $(ZEPHYR_BASE)/<your-app-dir>/src
include $(ZEPHYR_BASE)/scripts/Makefile.gen
2. Add needed binary/other embedded files into src/Makefile
to "generate_inc_file" or "generate_inc_gz_file" variables:
# List of files that are used to generate a file that can be
# included into .c file.
generate_inc_file += \
echo-apps-cert.der \
echo-apps-key.der \
file.bin
generate_inc_gz_file += \
index.html
include $(ZEPHYR_BASE)/scripts/Makefile.gen
3. In the application, do something with the embedded file
static const unsigned char inc_file[] = {
#include "file.bin.inc"
};
static const unsigned char gz_inc_file[] = {
#include "index.html.gz.inc"
};
The generated files in ${SRC}/*.inc are automatically removed
when you do "make pristine"
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
35 lines
1.1 KiB
Makefile
35 lines
1.1 KiB
Makefile
# vim: filetype=make
|
|
#
|
|
|
|
# Special rules to generate a file that can be included into a source file.
|
|
# ---------------------------------------------------------------------------
|
|
generated_inc_files = $(foreach f,$(generate_inc_file),$(notdir $(f)).inc)
|
|
generated_inc_gz_files = \
|
|
$(foreach f,$(generate_inc_gz_file),$(notdir $(f)).gz.inc)
|
|
|
|
$(notdir %).inc: $(generate_inc_file)
|
|
$(Q)${ZEPHYR_BASE}/scripts/file2hex.py --file $* > $@
|
|
|
|
$(notdir %).gz.inc: $(generate_inc_gz_file)
|
|
$(Q)${ZEPHYR_BASE}/scripts/file2hex.py --gzip --file $* > $@
|
|
|
|
PHONY += embed_inc_files
|
|
embed_inc_files: $(generated_inc_files)
|
|
|
|
PHONY += embed_inc_gz_files
|
|
embed_inc_gz_files: $(generated_inc_gz_files)
|
|
|
|
_embed_inc_files:
|
|
$(Q)$(MAKE) -C $(SRC) embed_inc_files Q=$(Q)
|
|
_embed_inc_gz_files:
|
|
$(Q)$(MAKE) -C $(SRC) embed_inc_gz_files Q=$(Q)
|
|
_remove_gen_files:
|
|
$(Q)rm -f $(SRC)/*.inc
|
|
|
|
PHONY += _embed_inc_files _embed_inc_gz_files _remove_gen_files
|
|
|
|
all: _embed_inc_files _embed_inc_gz_files
|
|
flash: _embed_inc_files _embed_inc_gz_files
|
|
run: _embed_inc_files _embed_inc_gz_files
|
|
pristine: _remove_gen_files
|