Skip to content

Commit 30c7f03

Browse files
bradjcalevy
authored andcommitted
make: libraries can depend on a version
Add `Makefile.version` so a library can express a particular file that must exist for the library to be usable. If that file doesn't exist, the build system knows to run Makefile.setup. This supports updating a library, as even if the needed version changes the built artifacts will still exist and make will not rebuild them.
1 parent 4f18914 commit 30c7f03

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

AppMakefile.mk

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,29 @@ $(call check_no_spaces, PACKAGE_NAME)
5757
# Arguments:
5858
# - $(1): Pattern matching all arch-specific library files.
5959
# - $(2): The path to the library.
60+
# - $(3): The uppercase name of the library.
6061
define EXTERN_LIB_BUILD_RULE
6162

6263
ifneq "$$(wildcard $(2)/Makefile.setup)" ""
6364
# Since a Makefile.setup exists, do any setup steps needed to fetch the library.
65+
66+
ifneq "$$(wildcard $(2)/Makefile.version)" ""
67+
# Since a Makefile.version exists, use it to set the necessary dependency.
68+
include $(2)/Makefile.version
69+
70+
$$($(3)_SENTINEL_FILE):
71+
$$(MAKE) -C $(2) -f Makefile.setup all
72+
$$(MAKE) -C $(2) -f Makefile all
73+
74+
$(1): $$($(3)_SENTINEL_FILE) ;
75+
else
76+
# No Makefile.version, so this will work the first time the library is built.
6477
$(1):
6578
$$(MAKE) -C $(2) -f Makefile.setup all
6679
$$(MAKE) -C $(2) -f Makefile all
80+
endif
6781
else
82+
# No setup needed, just build the library the first time.
6883
$(1):
6984
$$(MAKE) -C $(2) -f Makefile all
7085
endif
@@ -90,8 +105,8 @@ $$(notdir $(1))_BUILDDIR ?= $(1)/build
90105
$$(foreach arch, $$(TOCK_ARCHS), $$(eval LIBS_$$(arch) += $$($(notdir $(1))_BUILDDIR)/$$(arch)/$(notdir $(1)).a))
91106

92107
# Generate rule for building the library.
93-
# $$(info $$(call EXTERN_LIB_BUILD_RULE,$$(foreach arch,$$(TOCK_ARCHS),%/$$(arch)/$(notdir $(1)).a),$(1)))
94-
$$(eval $$(call EXTERN_LIB_BUILD_RULE,$$(foreach arch,$$(TOCK_ARCHS),%/$$(arch)/$(notdir $(1)).a),$(1)))
108+
# $$(info $$(call EXTERN_LIB_BUILD_RULE,$$(foreach arch,$$(TOCK_ARCHS),%/$$(arch)/$(notdir $(1)).a),$(1),$(shell echo '$(notdir $(1))' | tr '[:lower:]' '[:upper:]')))
109+
$$(eval $$(call EXTERN_LIB_BUILD_RULE,$$(foreach arch,$$(TOCK_ARCHS),%/$$(arch)/$(notdir $(1)).a),$(1),$(shell echo '$(notdir $(1))' | tr '[:lower:]' '[:upper:]')))
95110

96111
endef
97112

doc/compilation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ a prerequisite of building the app.
122122
The `Makefile.setup` file should have rules to download the source for the
123123
library.
124124

125+
If a library includes a `Makefile.version` with a `<LIBRARY_NAME>_SENTINEL_FILE`
126+
variable set, that file will be used to determine if the library needs to be
127+
rebuilt.
128+
125129
**Example:** the `u8g2` library uses this.
126130

127131
### Pre-built libraries

0 commit comments

Comments
 (0)