From 911fa82d4cb60632a1eab48f195d9c3f9cd63a3c Mon Sep 17 00:00:00 2001 From: kzangeli Date: Sat, 5 Sep 2026 17:28:38 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20COR=5FHTTP=5FSERVER=20=E2=80=94=20selec?= =?UTF-8?q?t=20the=20HTTP=20server=20at=20build=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit libmicrohttpd is an external shared library, built from source in the broker's Dockerfile at a pinned version, and mapped by every process. This library is where the HTTP server lives, so this is where the choice has to be made. make COR_HTTP_SERVER=mhd # libmicrohttpd (default) make COR_HTTP_SERVER=builtin # the epoll server in this repo Emitted as a 0/1 PAIR rather than one flag, so the source reads `#if COR_HTTP_SERVER_MHD` and -Wundef - now on for this library - turns a misspelling into a compile error instead of silently selecting the other implementation. In CFLAGS and not DFLAGS: a caller who passes DFLAGS on the command line REPLACES it, and would drop these along with every other default. That is recorded in the note above CFLAGS because it has already cost a wrong build once. `builtin` is refused with a message rather than built: the flags are right and the backend they select does not exist here yet, so a build would fail at link with a pile of missing MHD symbols and nothing to say why. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01TGatXwrHx1CreL49sCuS37 --- makefile | 32 +++++++++++++++++++++++++++++++- obj/debug/.flags | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index 57d34c8..f9d8eae 100644 --- a/makefile +++ b/makefile @@ -37,7 +37,37 @@ DFLAGS = # EXTRA_CFLAGS is appended LAST, so a caller's -O0 / -Wno-error also win over the # -O2 / -Werror here, which is what an instrumented build needs. # -CFLAGS = -O2 -Wall -Werror -fPIC -Wno-unused-function -fstack-protector-all $(DFLAGS) $(INCLUDE) -MMD -MP $(EXTRA_CFLAGS) +# +# COR_HTTP_SERVER - which HTTP server this build carries. Two, and exactly one. +# +# mhd libmicrohttpd, an external shared library +# builtin the epoll server in this repo, no external dependency +# +# Emitted as a 0/1 PAIR rather than one flag, so the source reads +# `#if COR_HTTP_SERVER_MHD` and -Wundef turns a misspelling into a compile error +# instead of silently selecting the other implementation. Same discipline as the +# COR_FEATURE_* defines the broker compiles with. +# +# In CFLAGS and not DFLAGS on purpose - see the note above: a caller who passes +# DFLAGS on the command line would drop these along with every other default. +# +COR_HTTP_SERVER ?= mhd +ifeq ($(COR_HTTP_SERVER),mhd) + HTTP_SERVER_FLAGS = -DCOR_HTTP_SERVER_MHD=1 -DCOR_HTTP_SERVER_BUILTIN=0 +else ifeq ($(COR_HTTP_SERVER),builtin) + # + # Refused rather than built: the flags below are right, and the server backend + # they select does not exist in this repo yet, so a build would fail at link + # with a pile of missing MHD symbols and no clue why. The switch says what it + # is waiting for instead. + # + $(error COR_HTTP_SERVER=builtin: the built-in HTTP server is not wired into this library yet - use 'mhd') + HTTP_SERVER_FLAGS = -DCOR_HTTP_SERVER_MHD=0 -DCOR_HTTP_SERVER_BUILTIN=1 +else + $(error COR_HTTP_SERVER must be 'mhd' or 'builtin', not '$(COR_HTTP_SERVER)') +endif + +CFLAGS = -O2 -Wall -Werror -Wundef -fPIC -Wno-unused-function -fstack-protector-all $(DFLAGS) $(HTTP_SERVER_FLAGS) $(INCLUDE) -MMD -MP $(EXTRA_CFLAGS) LIB_SOURCES = corRestInit.c \ corMimeType.c \ corRestStop.c \ diff --git a/obj/debug/.flags b/obj/debug/.flags index e46bf99..195dc5f 100644 --- a/obj/debug/.flags +++ b/obj/debug/.flags @@ -1 +1 @@ --O2 -Wall -Werror -fPIC -Wno-unused-function -fstack-protector-all -I.. -MMD -MP -g -DDEBUG +-O2 -Wall -Werror -Wundef -fPIC -Wno-unused-function -fstack-protector-all -DCOR_HTTP_SERVER_MHD=1 -DCOR_HTTP_SERVER_BUILTIN=0 -I.. -MMD -MP -g -DDEBUG