Repository navigation
Expand file tree
/
Copy pathboard.mk
More file actions
143 lines (126 loc) · 5.17 KB
/
Copy pathboard.mk
File metadata and controls
143 lines (126 loc) · 5.17 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Force bash as shell for Make
SHELL := /bin/bash
# Targets that don't require board selection
NOCAMERA_TARGETS := help bootstrap setup-hooks update update-buildroot reset-buildroot download-cache agent-info tftpd-start tftpd-stop tftpd-restart tftpd-status tftpd-logs backup-overlay shellcheck lint sort-defconfigs ram-setup
# Check if current target is exempted from board selection
# MAKECMDGOALS contains the targets specified on command line
CURRENT_TARGETS := $(MAKECMDGOALS)
ifeq ($(CURRENT_TARGETS),)
CURRENT_TARGETS := all
endif
# Skip camera selection only if ALL current targets are exempted (no target needs camera)
SKIP_CAMERA_SELECTION := $(if $(filter-out $(NOCAMERA_TARGETS),$(CURRENT_TARGETS)),,yes)
# If target is normally skipped but CAMERA was explicitly provided, honor it
ifneq ($(SKIP_CAMERA_SELECTION),)
ifdef CAMERA
SKIP_CAMERA_SELECTION :=
endif
endif
# Only proceed with board selection if not exempted
ifeq ($(SKIP_CAMERA_SELECTION),)
# --- build session memo ---------------------------------------------
#
# BUILD_MEMO is scoped to the terminal session (parent PID of make).
# This means:
# - Consecutive 'make' runs in the same terminal share the camera memo
# (no need to re-select the camera each time).
# - Concurrent 'make' runs in different terminals use separate memos
# (no collision from parallel builds).
#
# The session ID is the grandparent PID: make's parent is the user's
# shell. /proc/.../stat field 4 is the parent PID on Linux; fall back
# to ps(1) on other systems, and finally to $$ (make's own PID) if
# neither works -- the memo still functions, just without cross-run
# persistence.
#
_BUILD_SESSION := $(shell \
if [ -r /proc/$$PPID/stat ]; then \
awk '{print $$4}' /proc/$$PPID/stat; \
else \
ps -o ppid= -p $$PPID 2>/dev/null || echo "$$$$"; \
fi | tr -d ' ')
BUILD_MEMO := /tmp/thingino-board.$(_BUILD_SESSION)
BUILD_IP_MEMO := $(BUILD_MEMO).ip
INITIAL_CAMERA := $(strip $(CAMERA))
INITIAL_IP := $(strip $(IP))
IP_EXPLICIT := $(filter command line environment environment override,$(origin IP))
ifneq ($(IP_EXPLICIT),)
ifneq ($(strip $(IP)),)
$(shell printf '%s\n' "$(strip $(IP))" > "$(BUILD_IP_MEMO)")
else
$(shell rm -f "$(BUILD_IP_MEMO)")
endif
else ifneq ($(wildcard $(BUILD_IP_MEMO)),)
IP := $(shell cat "$(BUILD_IP_MEMO)")
endif
export IP
# Check if CAMERA was provided via command line (skip all prompts)
ifdef CAMERA
CAMERA_CONFIG := $(shell find $(CAMERA_SUBDIR) -name "$(CAMERA)_defconfig")
else
# CAMERA not provided. If IP is set, try to auto-detect camera from the device.
ifneq ($(strip $(IP)),)
DETECTED_CAMERA := $(shell $(SCRIPTS_DIR)/detect_camera_from_ip.sh $(IP))
endif
# Fall back to interactive selection (auto-detected camera passed as suggestion)
ifeq ($(CAMERA),)
# Use select_camera script for interactive selection (it handles memo internally)
CAMERA := $(shell $(SCRIPTS_DIR)/select_camera.sh $(CAMERA_SUBDIR) $(BUILD_MEMO) $(if $(IP_EXPLICIT),0,1) $(DETECTED_CAMERA) 2>/dev/tty | sed 's/\x1b[^a-zA-Z]*[a-zA-Z]//g' | tr -d '\n\r')
# Check if selection was cancelled
ifeq ($(CAMERA),)
$(error Camera selection cancelled)
endif
# Reload IP from the memo after interactive selection so the current run sees prompt changes.
ifeq ($(IP_EXPLICIT),)
ifneq ($(wildcard $(BUILD_IP_MEMO)),)
IP := $(shell cat "$(BUILD_IP_MEMO)")
else
IP :=
endif
export IP
endif
# After selection, find the config file
CAMERA_CONFIG := $(shell find $(CAMERA_SUBDIR)/$(CAMERA) -name "$(CAMERA)_defconfig")
endif
endif
CAMERA_SOURCED_DURING_LAUNCH := $(if $(and $(strip $(CAMERA)),$(if $(strip $(INITIAL_CAMERA)),,yes)),yes,)
IP_SOURCED_DURING_LAUNCH := $(if $(and $(if $(IP_EXPLICIT),,yes),$(strip $(IP)),$(if $(strip $(INITIAL_IP)),,yes)),yes,)
ifneq ($(filter yes,$(CAMERA_SOURCED_DURING_LAUNCH) $(IP_SOURCED_DURING_LAUNCH)),)
ifneq ($(THINGINO_RESTARTED_WITH_PARAMS),1)
THINGINO_NEEDS_RELAUNCH := 1
RESTART_ARGS := CAMERA=$(CAMERA)$(if $(strip $(IP)), IP=$(IP))
RESTART_DISPLAY_CMD := $(strip $(RESTART_ARGS) $(MAKE) --no-print-directory $(CURRENT_TARGETS))
RESTART_CMD := $(strip THINGINO_RESTARTED_WITH_PARAMS=1 $(RESTART_DISPLAY_CMD))
endif
endif
ifeq ($(CAMERA_CONFIG),)
ifeq ($(CAMERA),)
$(error * No camera selected)
else
$(error * Config file not found for camera: $(CAMERA))
endif
else ifneq ($(shell echo "$(CAMERA_CONFIG)" | wc -w), 1)
$(error * found multiple config files: $(CAMERA_CONFIG))
else
$(info CAMERA_CONFIG = $(CAMERA_CONFIG))
endif
# Ensure CAMERA is set from CAMERA_CONFIG if not already set
CAMERA ?= $(shell basename "$(CAMERA_CONFIG)" | sed -E "s/_defconfig//")
CAMERA_CONFIG_REAL := $(shell realpath "$(BR2_EXTERNAL)/$(CAMERA_CONFIG)" 2>/dev/null)
$(info CAMERA_CONFIG_REAL = $(CAMERA_CONFIG_REAL))
# Check if the camera config file actually exists
ifeq ($(CAMERA_CONFIG_REAL),)
$(error * Camera config file not found: $(BR2_EXTERNAL)/$(CAMERA_CONFIG). Please check if the profile still exists or remove the BUILD_MEMO file: $(BUILD_MEMO))
endif
export CAMERA
$(info CAMERA = $(CAMERA))
# read camera config file
include $(CAMERA_CONFIG_REAL)
else
# Board selection skipped for exempted targets
# Set minimal required variables to prevent errors
CAMERA_CONFIG :=
CAMERA_CONFIG_REAL :=
CAMERA :=
$(info Board selection skipped for target: $(CURRENT_TARGETS))
endif