Skip to content

Build system: handle library version updates and update u8g2 library #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions AppMakefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions doc/compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<LIBRARY_NAME>_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
Expand Down
5 changes: 2 additions & 3 deletions u8g2/Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions u8g2/Makefile.app
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 3 additions & 10 deletions u8g2/Makefile.setup
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@
### 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.
$(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)
15 changes: 15 additions & 0 deletions u8g2/Makefile.version
Original file line number Diff line number Diff line change
@@ -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