diff --git a/AppMakefile.mk b/AppMakefile.mk index a1a0e5c84..055752c67 100644 --- a/AppMakefile.mk +++ b/AppMakefile.mk @@ -57,14 +57,29 @@ $(call check_no_spaces, PACKAGE_NAME) # Arguments: # - $(1): Pattern matching all arch-specific library files. # - $(2): The path to the library. +# - $(3): The uppercase name of the library. define EXTERN_LIB_BUILD_RULE ifneq "$$(wildcard $(2)/Makefile.setup)" "" # Since a Makefile.setup exists, do any setup steps needed to fetch the library. + +ifneq "$$(wildcard $(2)/Makefile.version)" "" +# Since a Makefile.version exists, use it to set the necessary dependency. +include $(2)/Makefile.version + +$$($(3)_SENTINEL_FILE): + $$(MAKE) -C $(2) -f Makefile.setup all + $$(MAKE) -C $(2) -f Makefile all + +$(1): $$($(3)_SENTINEL_FILE) ; +else +# No Makefile.version, so this will work the first time the library is built. $(1): $$(MAKE) -C $(2) -f Makefile.setup all $$(MAKE) -C $(2) -f Makefile all +endif else +# No setup needed, just build the library the first time. $(1): $$(MAKE) -C $(2) -f Makefile all endif @@ -90,8 +105,8 @@ $$(notdir $(1))_BUILDDIR ?= $(1)/build $$(foreach arch, $$(TOCK_ARCHS), $$(eval LIBS_$$(arch) += $$($(notdir $(1))_BUILDDIR)/$$(arch)/$(notdir $(1)).a)) # Generate rule for building the library. -# $$(info $$(call EXTERN_LIB_BUILD_RULE,$$(foreach arch,$$(TOCK_ARCHS),%/$$(arch)/$(notdir $(1)).a),$(1))) -$$(eval $$(call EXTERN_LIB_BUILD_RULE,$$(foreach arch,$$(TOCK_ARCHS),%/$$(arch)/$(notdir $(1)).a),$(1))) +# $$(info $$(call EXTERN_LIB_BUILD_RULE,$$(foreach arch,$$(TOCK_ARCHS),%/$$(arch)/$(notdir $(1)).a),$(1),$(shell echo '$(notdir $(1))' | tr '[:lower:]' '[:upper:]'))) +$$(eval $$(call EXTERN_LIB_BUILD_RULE,$$(foreach arch,$$(TOCK_ARCHS),%/$$(arch)/$(notdir $(1)).a),$(1),$(shell echo '$(notdir $(1))' | tr '[:lower:]' '[:upper:]'))) endef diff --git a/doc/compilation.md b/doc/compilation.md index c6ce166b3..555901217 100644 --- a/doc/compilation.md +++ b/doc/compilation.md @@ -122,6 +122,10 @@ a prerequisite of building the app. The `Makefile.setup` file should have rules to download the source for the library. +If a library includes a `Makefile.version` with a `_SENTINEL_FILE` +variable set, that file will be used to determine if the library needs to be +rebuilt. + **Example:** the `u8g2` library uses this. ### Pre-built libraries diff --git a/u8g2/Makefile b/u8g2/Makefile index 6b55615d5..fe56086cd 100644 --- a/u8g2/Makefile +++ b/u8g2/Makefile @@ -1,11 +1,10 @@ -# Git hash of the library to use -VERSION_HASH := c4f9cd9f8717661c46be16bfbcb0017d785db3c1 +include Makefile.version # Base folder definitions TOCK_USERLAND_BASE_DIR ?= .. LIBNAME := u8g2 $(LIBNAME)_DIR := $(TOCK_USERLAND_BASE_DIR)/$(LIBNAME) -LIB_SRC_DIR := $($(LIBNAME)_DIR)/u8g2-$(VERSION_HASH) +LIB_SRC_DIR := $($(LIBNAME)_DIR)/u8g2-$(U8G2_VERSION_HASH) # List all C and Assembly files $(LIBNAME)_SRCS_ALL += $(wildcard $(LIB_SRC_DIR)/csrc/u8g2*.c) diff --git a/u8g2/Makefile.app b/u8g2/Makefile.app index db645d1a7..30ffa0b67 100644 --- a/u8g2/Makefile.app +++ b/u8g2/Makefile.app @@ -1,5 +1,5 @@ -# Git hash of the library to use. Must match the hash in Makefile. -U8G2_VERSION_HASH := c4f9cd9f8717661c46be16bfbcb0017d785db3c1 +# Git hash of the library to use. Must match the hash in Makefile.version. +U8G2_VERSION_HASH := bde09fbf787892c79a184e88b124aa5c79393aed # Base folder definitions U8G2_LIB_DIR := $(TOCK_USERLAND_BASE_DIR)/u8g2 diff --git a/u8g2/Makefile.setup b/u8g2/Makefile.setup index f54dc709e..e276b59f0 100644 --- a/u8g2/Makefile.setup +++ b/u8g2/Makefile.setup @@ -2,14 +2,7 @@ ### Helper Makefile for downloading the U8G2 library and unzipping. ### -TOCK_USERLAND_BASE_DIR ?= .. - -# Git hash of the library to use. Must match the hash in Makefile. -U8G2_VERSION_HASH := c4f9cd9f8717661c46be16bfbcb0017d785db3c1 - -# Base folder definitions -U8G2_LIB_DIR := $(TOCK_USERLAND_BASE_DIR)/u8g2 -U8G2_SRC_DIR := $(U8G2_LIB_DIR)/u8g2-$(U8G2_VERSION_HASH) +include Makefile.version # Rules to download the source repository if needed. These are here so that the # expanded library is available before calling into the library Makefile. @@ -17,8 +10,8 @@ $(U8G2_SRC_DIR).zip: curl -L --output $(U8G2_SRC_DIR).zip https://codeload.github.com/olikraus/u8g2/zip/$(U8G2_VERSION_HASH) # The .h file will exist when the library is unzipped. -$(U8G2_SRC_DIR)/csrc/u8g2.h: | $(U8G2_SRC_DIR).zip +$(U8G2_SENTINEL_FILE): | $(U8G2_SRC_DIR).zip unzip -q -d $(U8G2_LIB_DIR) $(U8G2_SRC_DIR).zip # Main rule to check if we need to fetch the library. -all: | $(U8G2_SRC_DIR)/csrc/u8g2.h +all: | $(U8G2_SENTINEL_FILE) diff --git a/u8g2/Makefile.version b/u8g2/Makefile.version new file mode 100644 index 000000000..ed7451b5b --- /dev/null +++ b/u8g2/Makefile.version @@ -0,0 +1,15 @@ +### +### Helper Makefile for the version of the library. +### + +TOCK_USERLAND_BASE_DIR ?= .. + +# Git hash of the library to use. Must match the hash in Makefile. +U8G2_VERSION_HASH := bde09fbf787892c79a184e88b124aa5c79393aed + +# Base folder definitions +U8G2_LIB_DIR := $(TOCK_USERLAND_BASE_DIR)/u8g2 +U8G2_SRC_DIR := $(U8G2_LIB_DIR)/u8g2-$(U8G2_VERSION_HASH) + +# The file we use to determine if the library has been fetched and built. +U8G2_SENTINEL_FILE := $(U8G2_SRC_DIR)/csrc/u8g2.h