feat: ports - zlib, libwapcaplet, libparserutils

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018Ae69wJS7sueQMUwNxV3nX
This commit is contained in:
2026-08-07 20:11:55 +02:00
co-authored by Claude Opus 5
parent 48e97f4e09
commit acb169e2c4
13 changed files with 358 additions and 4 deletions
+113 -4
View File
@@ -1,7 +1,23 @@
# port.mk - Shared rules for MontaukOS ports.
#
# A port builds against a MontaukOS checkout (the SDK) and produces an app
# bundle in $(OUTDIR)/apps/<name>/ containing:
# There are two kinds of port.
#
# NOTE: a port must set its PORT_* variables BEFORE including this file --
# the install rules are expanded at include time.
#
# LIBRARY PORTS set PORT_LIB := 1 and install headers and a static archive
# into the shared ports sysroot at $(PORT_SYSROOT):
#
# sysroot/include/... public headers
# sysroot/lib/lib<x>.a static archive
#
# Dependent ports pick these up automatically: $(PORT_CFLAGS_COMMON) already
# includes -I $(PORT_SYSROOT_INC), so a port that needs zlib just adds
# $(PORT_SYSROOT_LIB)/libz.a to its link line. A library port declares its own
# prerequisites with PORT_DEPENDS (names only, for documentation and for the
# top-level build order).
#
# APPLICATION PORTS produce an app bundle in $(OUTDIR)/apps/<name>/ containing:
#
# <name>.elf the binary
# manifest.toml launcher metadata (name, binary, icon, category)
@@ -75,8 +91,16 @@ SDK_API_VERSION := $(shell sed -n 's/.*apiVersion = \([0-9]\+\);.*/\1/p' \
# ==== Output ==========================================================
OUTDIR ?= $(MTKPORTS_ROOT)/out
BUNDLE_DIR := $(OUTDIR)/apps/$(PORT_NAME)
OBJDIR ?= obj
# Shared sysroot that library ports install into and every port compiles
# against. Kept separate from the MontaukOS SDK so `make clean` here never
# touches the OS tree.
PORT_SYSROOT ?= $(MTKPORTS_ROOT)/sysroot
PORT_SYSROOT_INC := $(PORT_SYSROOT)/include
PORT_SYSROOT_LIB := $(PORT_SYSROOT)/lib
BUNDLE_DIR := $(OUTDIR)/apps/$(PORT_NAME)
TARGET := $(BUNDLE_DIR)/$(PORT_NAME).elf
# ==== Common flags ====================================================
@@ -93,13 +117,96 @@ PORT_CFLAGS_COMMON := \
-msse \
-msse2 \
-isystem $(SDK_LIBC_INC) \
-I $(SDK_INC)
-I $(SDK_INC) \
-I $(PORT_SYSROOT_INC)
PORT_LDFLAGS_COMMON := \
-nostdlib \
-Wl,--gc-sections \
-T $(SDK_LINK_LD)
# ==== NetSurf library ports ===========================================
# NetSurf's libraries share one buildsystem (dev-util/netsurf-buildsystem)
# and all build the same way, so the invocation lives here rather than being
# copied into each port.
#
# It cross-compiles for x86_64-montauk unpatched: HOST is auto-detected from
# `$(CC) -dumpmachine`, and BUILD != HOST puts it in cross mode. CC/AR must be
# passed on the command line (their `origin ... default` checks skip them
# otherwise), while CFLAGS must go through the ENVIRONMENT -- their makefiles
# do `CFLAGS := -I... $(CFLAGS)`, and a command-line CFLAGS would override
# that assignment outright and drop their own include paths.
NS_BUILDSYSTEM := $(MTKPORTS_ROOT)/dev-util/netsurf-buildsystem/upstream
NS_BUILDDIR := build-montauk
NS_CFLAGS := \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-msse \
-msse2 \
-isystem $(SDK_LIBC_INC) \
-I $(SDK_INC) \
-I $(PORT_SYSROOT_INC)
NS_MAKE_ARGS := \
NSSHARED=$(NS_BUILDSYSTEM) \
CC=$(CC) \
AR=$(AR) \
COMPONENT_TYPE=lib-static \
BUILDDIR=$(NS_BUILDDIR) \
WANT_TEST=no
# MAKEFLAGS must be cleared for the sub-make. This file sets `-rR`, which
# disables built-in variables, and their buildsystem probes those with
# `ifeq ($(origin RM),default)` style tests -- under -rR the origin is
# "undefined" instead, so RM/ARFLAGS silently expand to nothing and the
# archive rule tries to *execute* the .a file (exit 127).
NS_MAKE := MAKEFLAGS= $(MAKE)
# Build a NetSurf library in $(1) (its checkout dir) and copy the archive to
# $(PORT_ARCHIVE). Usage in a recipe: $(call ns_build,upstream,wapcaplet)
# A port may add its own flags by setting NS_CFLAGS_EXTRA (expanded at call
# time, so it can be set after this file is included).
ns_build = \
CFLAGS="$(NS_CFLAGS) $(NS_CFLAGS_EXTRA)" $(NS_MAKE) -C $(1) $(NS_MAKE_ARGS) && \
cp $(1)/$(NS_BUILDDIR)/lib$(2).a $(PORT_ARCHIVE)
ns_clean = $(NS_MAKE) -C $(1) $(NS_MAKE_ARGS) clean >/dev/null 2>&1 || true
ifeq ($(PORT_LIB),1)
# ==== Library ports ===================================================
# The port builds $(PORT_ARCHIVE) and lists its public headers in
# $(PORT_HEADERS); port.mk installs both into the shared sysroot. Headers
# keep any subdirectory they are named with (e.g. parserutils/parserutils.h
# installs to sysroot/include/parserutils/parserutils.h), so set
# PORT_HEADER_ROOT to the directory those paths are relative to.
PORT_HEADER_ROOT ?= include
INSTALLED_LIB := $(PORT_SYSROOT_LIB)/$(notdir $(PORT_ARCHIVE))
INSTALLED_HEADERS := $(patsubst $(PORT_HEADER_ROOT)/%,$(PORT_SYSROOT_INC)/%,$(PORT_HEADERS))
$(INSTALLED_LIB): $(PORT_ARCHIVE)
@mkdir -p $(dir $@)
cp $< $@
$(PORT_SYSROOT_INC)/%: $(PORT_HEADER_ROOT)/%
@mkdir -p $(dir $@)
cp $< $@
.PHONY: install-lib
install-lib: $(INSTALLED_LIB) $(INSTALLED_HEADERS)
@echo "installed lib: $(PORT_NAME) -> $(PORT_SYSROOT)"
.PHONY: clean-lib
clean-lib:
rm -rf $(OBJDIR) $(PORT_ARCHIVE) $(INSTALLED_LIB) $(INSTALLED_HEADERS)
else
# ==== Bundle assembly =================================================
# Ports depend on $(BUNDLE_FILES) to get manifest + icon + marker staged
# alongside the ELF their link rule produces.
@@ -129,3 +236,5 @@ bundle: $(TARGET) $(BUNDLE_FILES)
.PHONY: clean-bundle
clean-bundle:
rm -rf $(OBJDIR) $(BUNDLE_DIR)
endif