-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile.toolchain
More file actions
97 lines (85 loc) · 4.22 KB
/
Makefile.toolchain
File metadata and controls
97 lines (85 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# LessUI Docker Toolchain Manager
# Manages platform-specific cross-compilation toolchains
#
# This makefile pulls pre-built toolchain containers from GitHub Container Registry
# and launches them for building LessUI components.
#
# Container images: ghcr.io/lessui-hq/union-<platform>-toolchain:latest
#
# Usage (typically called from main makefile):
# make -f Makefile.toolchain PLATFORM=miyoomini # Enter shell
# make -f Makefile.toolchain PLATFORM=miyoomini build # Build all
#
# Platform Architecture:
# The Docker platform (linux/amd64 or linux/arm64) is configured per-toolchain
# in toolchains.json. This allows proper emulation for toolchains that require
# specific architectures (e.g., trimuismart and tg5040 need amd64).
#
# Adding a new platform:
# 1. Choose approach:
# a) Reuse existing toolchain: Add to toolchains.json with "toolchain" field
# (e.g., rgb30 reuses rk3566 toolchain)
# b) New toolchain: Fork union-<chipset>-toolchain repo to lessui-hq org
# 2. If creating new toolchain:
# - Add .github/workflows/build-container.yml to the fork
# - Trigger workflow to build and publish container
# 3. Add platform entry to toolchains.json with appropriate architecture
#
# DO NOT call this makefile directly unless debugging toolchain issues.
# Use the main makefile's 'shell' and 'build' targets instead.
.PHONY: all build clean pull
ifeq (,$(PLATFORM))
$(error PLATFORM not specified. Use: make -f Makefile.toolchain PLATFORM=<platform>)
endif
# Verify jq is available (required for reading toolchains.json)
JQ_CHECK := $(shell command -v jq 2>/dev/null)
ifeq (,$(JQ_CHECK))
$(error jq is required but not installed. Install with: brew install jq (macOS) or apt install jq (Linux))
endif
# Workspace paths (host and Docker container)
HOST_WORKSPACE = $(shell pwd)/workspace
GUEST_WORKSPACE = /root/workspace
# Pre-built container registry
CONTAINER_REGISTRY = ghcr.io
CONTAINER_ORG = lessui-hq
# Read toolchain name from toolchains.json (defaults to platform name)
# Allows platforms to share toolchains (e.g., rgb30 uses rk3566 toolchain)
TOOLCHAIN_NAME = $(shell jq -r --arg p "$(PLATFORM)" '.toolchains[$$p].toolchain // $$p' toolchains.json 2>/dev/null || echo "$(PLATFORM)")
CONTAINER_NAME = union-$(TOOLCHAIN_NAME)-toolchain
CONTAINER_TAG = latest
CONTAINER_IMAGE = $(CONTAINER_REGISTRY)/$(CONTAINER_ORG)/$(CONTAINER_NAME):$(CONTAINER_TAG)
# Read platform architecture from toolchains.json (defaults to linux/arm64)
# Uses jq --arg for safe variable interpolation (handles special chars in platform names)
DOCKER_PLATFORM = $(shell jq -r --arg p "$(PLATFORM)" '.toolchains[$$p].platform // "linux/arm64"' toolchains.json 2>/dev/null || echo "linux/arm64")
# Common docker run options
DOCKER_RUN = docker run --rm --platform=$(DOCKER_PLATFORM) -e PLATFORM="$(PLATFORM)" -e LOG_FLAGS="$(LOG_FLAGS)" -e OPT_FLAGS="$(OPT_FLAGS)" -e BUILD_HASH="$(BUILD_HASH)" -v $(HOST_WORKSPACE):$(GUEST_WORKSPACE)
# Default target: launch interactive shell (pulls image if missing)
all:
@$(DOCKER_RUN) --pull=missing $(CONTAINER_IMAGE) /bin/bash
# Build all workspace components in Docker (non-interactive)
# Uses -j for parallel builds (nproc detects available cores in container)
build:
@$(DOCKER_RUN) --pull=missing $(CONTAINER_IMAGE) /bin/bash -c '. ~/.bashrc && cd /root/workspace && make -j$$(nproc)'
# Force pull latest container (useful for updates)
pull:
@echo "Pulling latest $(PLATFORM) toolchain..."
@docker pull $(CONTAINER_IMAGE) || \
(echo "" && \
echo "❌ Container not found: $(CONTAINER_IMAGE)" && \
echo "" && \
echo "To add support for $(PLATFORM):" && \
echo " Option A: Reuse existing toolchain" && \
echo " 1. Add \"toolchain\": \"<chipset>\" to toolchains.json" && \
echo " 2. Specify platform architecture (linux/amd64 or linux/arm64)" && \
echo "" && \
echo " Option B: Create new toolchain" && \
echo " 1. Fork union-<chipset>-toolchain to lessui-hq org" && \
echo " 2. Add .github/workflows/build-container.yml" && \
echo " 3. Trigger workflow to build and publish container" && \
echo " 4. Add platform entry to toolchains.json" && \
echo "" && \
exit 1)
@echo "✓ Updated to latest"
# Remove cached Docker image
clean:
@docker rmi $(CONTAINER_IMAGE) 2>/dev/null || true