Skip to content

Commit e04d4c9

Browse files
committed
extmod/zephyr_kernel: Relocate generated headers to build directory.
Modified zephyr_kernel.mk to generate Zephyr headers in the board-specific build directory instead of source tree, addressing build hygiene issue where artifacts were created throughout the repository. Changes: - ZEPHYR_GEN now points to $(BUILD)/zephyr_gen instead of source tree - Generated headers (version.h, offsets.h, log_msg.h) output to $(BUILD)/zephyr_gen_root/zephyr/ to mirror Zephyr's layout - Include paths updated to prefer build-generated headers over static stubs - Added mkdir -p to generation rules to ensure directory creation - Removed build artifact version.h from source tree Build artifacts now isolated in board build folder (e.g., build-NUCLEO_F429ZI/zephyr_gen_root/) instead of scattered through extmod/zephyr_kernel/generated/, ports/extmod/, ports/lib/, and lib/zephyr/include/. Static stub files in extmod/zephyr_kernel/generated/ remain in source tree as they are hand-written compatibility shims, not auto-generated artifacts. Signed-off-by: Andrew Leech <[email protected]>
1 parent d198c5e commit e04d4c9

File tree

2 files changed

+16
-37
lines changed

2 files changed

+16
-37
lines changed

extmod/zephyr_kernel/generated/zephyr/version.h

Lines changed: 0 additions & 24 deletions
This file was deleted.

extmod/zephyr_kernel/zephyr_kernel.mk

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ endif
1010
# Zephyr paths
1111
ZEPHYR_BASE := $(TOP)/lib/zephyr
1212
ZEPHYR_KERNEL := $(TOP)/extmod/zephyr_kernel
13-
ZEPHYR_GEN := $(ZEPHYR_KERNEL)/generated/zephyr
13+
ZEPHYR_GEN := $(BUILD)/zephyr_gen
1414

15-
# Zephyr include paths (order matters - generated/ first for overrides)
15+
# Zephyr include paths (order matters - build-generated first, then static stubs)
1616
ZEPHYR_INC := \
17+
-I$(BUILD)/zephyr_gen_root \
1718
-I$(ZEPHYR_KERNEL)/generated \
1819
-I$(ZEPHYR_BASE)/include \
1920
-I$(ZEPHYR_BASE)/kernel/include \
@@ -36,15 +37,15 @@ $(error Unsupported ZEPHYR_ARCH: $(ZEPHYR_ARCH))
3637
endif
3738
ZEPHYR_CFLAGS := -include $(ZEPHYR_CONFIG_HEADER) -Wno-error -Wno-macro-redefined
3839

39-
# Generated header files
40+
# Generated header files (mimic Zephyr's build layout)
4041
ZEPHYR_GEN_HEADERS := \
41-
$(ZEPHYR_GEN)/version.h \
42-
$(ZEPHYR_GEN)/syscalls/log_msg.h
42+
$(BUILD)/zephyr_gen_root/zephyr/version.h \
43+
$(BUILD)/zephyr_gen_root/zephyr/syscalls/log_msg.h
4344

4445
# POSIX architecture uses static offsets.h stub (no real offsets needed)
4546
# Other architectures would generate offsets.h from offsets.c
4647
ifneq ($(ZEPHYR_ARCH),posix)
47-
ZEPHYR_GEN_HEADERS += $(ZEPHYR_GEN)/offsets.h
48+
ZEPHYR_GEN_HEADERS += $(BUILD)/zephyr_gen_root/zephyr/offsets.h
4849
endif
4950

5051
# Offsets source file (architecture-specific)
@@ -57,27 +58,29 @@ endif
5758

5859
# Rule to compile offsets.c to object file
5960
# Note: ZEPHYR_OFFSETS_EXTRA_CFLAGS can be set by ports (e.g., to undefine STM32 macros)
60-
$(BUILD)/zephyr_offsets.o: $(ZEPHYR_OFFSETS_C) $(ZEPHYR_GEN)/version.h
61+
$(BUILD)/zephyr_offsets.o: $(ZEPHYR_OFFSETS_C) $(BUILD)/zephyr_gen_root/zephyr/version.h
6162
@echo "CC (Zephyr offsets) $<"
6263
$(Q)$(CC) $(CFLAGS) $(ZEPHYR_INC) $(ZEPHYR_CFLAGS) $(ZEPHYR_OFFSETS_EXTRA_CFLAGS) \
6364
-include $(ZEPHYR_KERNEL)/zephyr_config_cortex_m.h -c -o $@ $<
6465

6566
# Rule to generate offsets.h from offsets.o using Zephyr's official script
66-
$(ZEPHYR_GEN)/offsets.h: $(BUILD)/zephyr_offsets.o
67+
$(BUILD)/zephyr_gen_root/zephyr/offsets.h: $(BUILD)/zephyr_offsets.o
6768
@echo "GEN (Zephyr) $@"
69+
$(Q)mkdir -p $(dir $@)
6870
$(Q)python3 $(ZEPHYR_BASE)/scripts/build/gen_offset_header.py \
6971
-i $< \
7072
-o $@
7173

7274
# Rule to generate version.h from Zephyr VERSION file
73-
$(ZEPHYR_GEN)/version.h: $(ZEPHYR_BASE)/VERSION $(ZEPHYR_KERNEL)/gen_zephyr_version.py
75+
$(BUILD)/zephyr_gen_root/zephyr/version.h: $(ZEPHYR_BASE)/VERSION $(ZEPHYR_KERNEL)/gen_zephyr_version.py
7476
@echo "GEN (Zephyr) $@"
77+
$(Q)mkdir -p $(dir $@)
7578
$(Q)python3 $(ZEPHYR_KERNEL)/gen_zephyr_version.py \
7679
-i $< \
7780
-o $@
7881

7982
# Rule to generate empty log_msg.h stub (logging disabled)
80-
$(ZEPHYR_GEN)/syscalls/log_msg.h:
83+
$(BUILD)/zephyr_gen_root/zephyr/syscalls/log_msg.h:
8184
@echo "GEN (Zephyr) $@"
8285
$(Q)mkdir -p $(dir $@)
8386
$(Q)echo '/* Auto-generated log_msg syscalls stub - logging disabled (CONFIG_LOG=0) */' > $@
@@ -126,7 +129,7 @@ ZEPHYR_ARCH_SRC_C += \
126129
$(ZEPHYR_KERNEL)/posix_minimal_board.c
127130

128131
# Add POSIX arch include paths (generated headers and arch headers)
129-
ZEPHYR_INC += -I$(ZEPHYR_KERNEL)/generated/zephyr/arch/posix
132+
ZEPHYR_INC += -I$(BUILD)/zephyr_gen_root/zephyr/arch/posix
130133
ZEPHYR_INC += -I$(ZEPHYR_BASE)/arch/posix/include
131134
endif
132135

@@ -154,7 +157,7 @@ ZEPHYR_ARCH_SRC_S := \
154157
$(ZEPHYR_BASE)/arch/arm/core/cortex_m/swap_helper.S
155158

156159
# Add ARM Cortex-M include paths
157-
ZEPHYR_INC += -I$(ZEPHYR_KERNEL)/generated/zephyr/arch/arm
160+
ZEPHYR_INC += -I$(BUILD)/zephyr_gen_root/zephyr/arch/arm
158161
ZEPHYR_INC += -I$(ZEPHYR_BASE)/arch/arm/include
159162
ZEPHYR_INC += -I$(ZEPHYR_BASE)/arch/arm/include/cortex_m
160163
ZEPHYR_INC += -I$(ZEPHYR_BASE)/arch/arm/core/cortex_m
@@ -163,7 +166,7 @@ ZEPHYR_INC += -I$(ZEPHYR_BASE)/arch/arm/core/cortex_m
163166
CMSIS_DIR ?= $(TOP)/lib/cmsis
164167
ZEPHYR_INC += -I$(CMSIS_DIR)/inc
165168
# Add our CMSIS wrapper (provides cmsis_core.h)
166-
ZEPHYR_INC += -I$(ZEPHYR_KERNEL)/generated
169+
ZEPHYR_INC += -I$(BUILD)/zephyr_gen_root
167170
endif
168171

169172
# Export for ports to use

0 commit comments

Comments
 (0)