Loading...
Searching...
No Matches
blob.inc.mk
1
34
35# use "blobs/blob" so the headers can be included as "blob/foo.h", but
36# we don't have to add $(BINDIR)/$(MODULE) to the include path.
37BLOB_HDR_DIR ?= $(BINDIR)/$(MODULE)/blobs/blob
38BLOB_H := $(BLOBS:%=$(BLOB_HDR_DIR)/%.h)
39
40ifneq (, $(BLOB_H))
41 # add $(BINDIR)/$(MODULE)/blobs to include path
42 CFLAGS += -I$(dir $(BLOB_HDR_DIR))
43endif
44
45# In order to allow automatic folder creation in subtrees,
46# this Makefile makes use SECONDEXPANSION, PRECIOUS and
47# order only prerequisites.
48# Folder targets are "tagged" by appending "/."
49# The final recipe uses "| $$(@D)/." to create necessary trees.
50#
51# Inspiration from:
52# http://ismail.badawi.io/blog/2017/03/28/automatic-directory-creation-in-make/
53#
54.PRECIOUS: $(BLOB_HDR_DIR)/. $(BLOB_HDR_DIR)%/.
55
56$(BLOB_HDR_DIR)/.:
57 @mkdir -p $@
58
59$(BLOB_HDR_DIR)%/.:
60 @mkdir -p $@
61
62XXD ?= xxd
63
64$(BLOB_H): $(BLOB_HDR_DIR)/%.h: % $(BLOBS) | $$(@D)/.
65 @command -v $(XXD) > /dev/null 2>&1 || ( \
66 echo "error: xxd binary '$(XXD)' not found! (Maybe install vim package?)"; exit 1)
67
68 ${Q}cd $(dir $<); xxd -i $(notdir $<) | sed 's/^unsigned/const unsigned/g'> $@
69
70# make C and C++ objects of this module depend on generated headers, so they
71# get re-build on changes to the blob files.
72$(OBJC) $(OBJCXX): $(BLOB_H)