From c0b9a34bfbf946975be608e4e0dfb2d7e01fe586 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Fri, 3 Apr 2026 17:07:27 -0300 Subject: [PATCH] fix(build): auto-init submodules, auto-apply lwIP patch, fix corrupt patch The build system now handles submodules and patches automatically so a fresh 'git clone' + 'make' works without manual steps: - Makefile: add LWIP_SENTINEL target that runs 'git submodule update --init --recursive' if lwIP sources are missing. - Makefile: add .lwip_patched marker target that applies the lwIP volatile patch (patches/lwip-tcpip-volatile.patch) once after submodule init. Kernel build depends on this marker. - Makefile: clean target now removes .lwip_patched marker. - patches/lwip-tcpip-volatile.patch: regenerated with correct hunk header (@@ -55,9 +55,9 @@ instead of broken @@ -55,8 +55,8 @@) and repo-root-relative paths (third_party/lwip/...). - user/doom/Makefile: fix error message to reference 'git submodule update --init' instead of 'git clone'. Check for actual header file instead of just directory existence. - .gitignore: add .lwip_patched marker, remove temp hello/hello.c. --- .gitignore | 5 ++--- Makefile | 19 +++++++++++++++++-- patches/lwip-tcpip-volatile.patch | 7 ++++++- user/doom/Makefile | 6 +++--- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index d34e8665..b9e626fc 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,5 @@ toolchain/logs/ # third_party/lwip -> git submodule # user/doom/doomgeneric -> git submodule -# Others -hello -hello.c +# Build markers +.lwip_patched diff --git a/Makefile b/Makefile index ed206836..45968437 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,21 @@ KERNEL_NAME := adros-$(ARCH).bin SRC_DIR := src BUILD_DIR := build/$(ARCH) +# --- Submodule auto-init --- +# If lwIP source is missing, the submodules haven't been initialized. +LWIP_SENTINEL := third_party/lwip/src/core/init.c +$(LWIP_SENTINEL): + @echo " GIT Initializing submodules..." + @git submodule update --init --recursive + +# Apply lwIP patches (once, after submodule init) +.lwip_patched: $(LWIP_SENTINEL) + @if git apply --check patches/lwip-tcpip-volatile.patch 2>/dev/null; then \ + git apply patches/lwip-tcpip-volatile.patch; \ + echo " PATCH lwip-tcpip-volatile"; \ + fi + @touch $@ + # Minimal kernel sources shared across all architectures KERNEL_COMMON := main.c console.c utils.c cmdline.c driver.c cpu_features.c C_SOURCES := $(addprefix $(SRC_DIR)/kernel/,$(KERNEL_COMMON)) @@ -184,7 +199,7 @@ KERNEL_OBJ := $(filter-out $(BOOT_OBJ), $(OBJ)) all: $(KERNEL_NAME) -$(KERNEL_NAME): $(OBJ) +$(KERNEL_NAME): .lwip_patched $(OBJ) @echo " LD $@" @$(LD) $(LDFLAGS) -n -o $@ $(BOOT_OBJ) $(KERNEL_OBJ) $(shell $(CC) $(ARCH_CFLAGS) -print-libgcc-file-name) @@ -397,7 +412,7 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.S @$(AS) $(ASFLAGS) $< -o $@ clean: - rm -rf build $(KERNEL_NAME) $(INITRD_IMG) adros-*.iso + rm -rf build $(KERNEL_NAME) $(INITRD_IMG) adros-*.iso .lwip_patched @$(MAKE) -C user/ulibc clean --no-print-directory 2>/dev/null || true @if [ -f user/doom/Makefile ]; then $(MAKE) -C user/doom clean --no-print-directory 2>/dev/null || true; fi diff --git a/patches/lwip-tcpip-volatile.patch b/patches/lwip-tcpip-volatile.patch index a905fec8..f197c388 100644 --- a/patches/lwip-tcpip-volatile.patch +++ b/patches/lwip-tcpip-volatile.patch @@ -1,6 +1,9 @@ +diff --git a/third_party/lwip/src/api/tcpip.c b/third_party/lwip/src/api/tcpip.c +index 0891f9e..e0ae887 100644 --- a/third_party/lwip/src/api/tcpip.c +++ b/third_party/lwip/src/api/tcpip.c -@@ -55,8 +55,8 @@ +@@ -55,9 +55,9 @@ + #define TCPIP_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct tcpip_msg, MEMP_TCPIP_MSG_API, name, ERR_MEM) #define TCPIP_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_TCPIP_MSG_API, name) -/* global variables */ @@ -10,3 +13,5 @@ +static volatile tcpip_init_done_fn tcpip_init_done; +static void * volatile tcpip_init_done_arg; static sys_mbox_t tcpip_mbox; + + #if LWIP_TCPIP_CORE_LOCKING diff --git a/user/doom/Makefile b/user/doom/Makefile index 5301dd77..595f70da 100644 --- a/user/doom/Makefile +++ b/user/doom/Makefile @@ -65,9 +65,9 @@ ALL_OBJ := $(DG_OBJ) $(ADAPTER_OBJ) all: check-doomgeneric doom.elf check-doomgeneric: - @if [ ! -d doomgeneric ]; then \ - echo "ERROR: doomgeneric/ directory not found."; \ - echo "Run: git clone https://github.com/ozkl/doomgeneric.git"; \ + @if [ ! -f doomgeneric/doomgeneric/doomgeneric.h ]; then \ + echo "ERROR: doomgeneric/ submodule not initialized."; \ + echo "Run from repo root: git submodule update --init --recursive"; \ exit 1; \ fi -- 2.43.0