# SPDX-License-Identifier: GPL-2.0-or-later
# lwIP — the TCP/IP stack. BSD-3-clause (no advertising clause); see COPYING in
# the tarball and docs/licensing.md.
#
# Unlike every other port here, nothing is installed into the sysroot: lwIP is
# *kernel* code. This directory only fetches and unpacks it, and the top-level
# Makefile compiles the files it wants straight into the kernel, against the
# port headers in kernel/net/lwip/. That is why there is no build or install
# rule below and no dependency on musl.
#
# Chosen over taking a BSD kernel's netinet, and the reason is not licensing --
# FreeBSD's is BSD-3 too. It is that FreeBSD's stack is not a library: it reaches
# into mbufs, epoch(9), netisr, VNET and uma(9), so adopting it means porting
# FreeBSD's kernel infrastructure first. lwIP was written for precisely this
# situation, a small OS with a raw Ethernet driver, and its port layer is a
# handful of files. See docs/roadmap.md phase 2.

include ../mk/port.mk

LWIP_VERSION := 2.2.0
LWIP_URL     := https://download.savannah.nongnu.org/releases/lwip/lwip-$(LWIP_VERSION).zip

TARBALL := $(DISTDIR)/lwip-$(LWIP_VERSION).zip

$(TARBALL): | $(DISTDIR)
	curl -fsSL -o $@ $(LWIP_URL)

download: $(TARBALL)

$(SRCDIR): $(TARBALL)
	mkdir -p $(PORTDIR)
	cd $(PORTDIR) && unzip -q $(abspath $<)
	mv $(PORTDIR)/lwip-$(LWIP_VERSION) $@

# The kernel build depends on this directory existing, nothing more.
all: | $(SRCDIR)

install:

clean:
	rm -rf $(PORTDIR)

distclean: clean
	rm -f $(TARBALL)
