-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathboard.mk
More file actions
120 lines (104 loc) · 4.19 KB
/
board.mk
File metadata and controls
120 lines (104 loc) · 4.19 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
# Force bash as shell for Make
SHELL := /bin/bash
# Targets that don't require board selection
NOCAMERA_TARGETS := help bootstrap update update-buildroot update-buildroot-patches reset-buildroot download-cache agent-info tftpd-start tftpd-stop tftpd-restart tftpd-status tftpd-logs
# 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_MEMO := /tmp/thingino-board.$(shell ps -o ppid= -p $$PPID | xargs)
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
# Check if CAMERA was provided via command line
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) 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")
else
# CAMERA was provided via command line, find its config
CAMERA_CONFIG := $(shell find $(CAMERA_SUBDIR) -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