From: William Lallemand Date: Thu, 29 Oct 2026 22:46:35 +0000 (+0000) Subject: BUILD: Makefile: extend the capabilities of EXTRA_MAKE X-Git-Tag: v3.5-dev11~90 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=995295edc9d6c2a9bbf39616631b00e9e0b81c3e;p=haproxy.git BUILD: Makefile: extend the capabilities of EXTRA_MAKE Allow external Makefile.mk loaded through EXTRA_MAKE to extend the main build without adding addon-specific logic to the root Makefile. Provide the following extension points: - EXTRA_USE_OPTS registers additional USE_* switches. Check unknown options after loading the fragments so ERR=1 accepts these switches. - EXTRA_CFLAGS and EXTRA_LDFLAGS append compiler and linker flags. - EXTRA_INCLUDES adds headers to the build dependencies so changes to addon headers trigger recompilation. - EXTRA_LATE_HOOK evaluates addon logic after the object lists and compiler options have been collected, for example to generate metadata from the final build options. - EXTRA_INSTALL and EXTRA_UNINSTALL add targets to the install and uninstall prerequisites. Reuse the existing EXTRA_OBJS variable for objects supplied by addons. Keep all as the default goal so rules in an external fragment do not change what a plain make invocation builds. --- diff --git a/Makefile b/Makefile index 3b3109af5..c3c3e8927 100644 --- a/Makefile +++ b/Makefile @@ -144,6 +144,21 @@ include include/make/errors.mk include include/make/compiler.mk include include/make/options.mk +#### Addons +# External addons are loaded through EXTRA_MAKE after the options are set up. +# Their Makefile.mk fragments may declare options, objects, includes, flags, +# a late hook and install targets through the EXTRA_* variables consumed later +# in this Makefile. +EXTRA_USE_OPTS = +EXTRA_CFLAGS = +EXTRA_INCLUDES = +EXTRA_LATE_HOOK = +EXTRA_LDFLAGS = +EXTRA_INSTALL = +EXTRA_UNINSTALL = +# External fragments may define rules; keep "all" as the default goal. +.DEFAULT_GOAL := all + #### Installation options. DESTDIR = INSTALL = install @@ -358,14 +373,11 @@ use_opts = USE_EPOLL USE_KQUEUE USE_NETFILTER USE_POLL \ USE_MEMORY_PROFILING USE_SHM_OPEN USE_MINIDEBUG \ USE_STATIC_PCRE USE_STATIC_PCRE2 \ USE_PCRE USE_PCRE_JIT USE_PCRE2 USE_PCRE2_JIT \ - USE_QUIC_OPENSSL_COMPAT USE_KTLS + USE_QUIC_OPENSSL_COMPAT USE_KTLS $(EXTRA_USE_OPTS) # preset all variables for all supported build options among use_opts $(reset_opts_vars) -# Check that any USE_* variable that was forced actually exist. -$(warn_unknown_options) - #### Target system options # poll() is always supported, unless explicitly disabled by passing USE_POLL="" @@ -568,7 +580,7 @@ OPTIONS_CFLAGS = OPTIONS_LDFLAGS = OPTIONS_OBJS = -#### Extra objects to be built and integrated (used only for development) +#### Extra objects to be built and integrated, including external addons EXTRA_OBJS = # A compressed table of the symbols which are not exported (mostly the static @@ -876,6 +888,9 @@ ifneq ($(EXTRA_MAKE),) include $(addsuffix /Makefile.mk,$(EXTRA_MAKE)) endif +# Check options after external addons have registered their runtime switches. +$(warn_unknown_options) + # better keep this one close to the end, as several libs above may need it ifneq ($(USE_DL:0=),) DL_LDFLAGS = -ldl @@ -892,6 +907,10 @@ endif #### End of the USE_* options handling, any such option that would be added #### below could be silently ignored. +# Extra compiler flags, including those provided by external addons. +OPTIONS_CFLAGS += $(EXTRA_CFLAGS) +OPTIONS_LDFLAGS += $(EXTRA_LDFLAGS) + # appends all foo_{C,LD}FLAGS to OPTIONS_{C,LD}FLAGS $(collect_opts_flags) @@ -1041,6 +1060,9 @@ OBJS += src/xz_dec_stream.o src/xz_dec_lzma2.o src/xz_crc32.o \ src/xz_crc64.o endif +# Late addon hook, expanded once every OPTIONS_CFLAGS append has happened. +_ := $(EXTRA_LATE_HOOK) + ifneq ($(USE_MINIDEBUG:0=),) MINIDEBUG_TOOL = $(SHELL) scripts/minidbg.sh endif @@ -1050,7 +1072,7 @@ HATERM_OBJS += $(OBJS) src/haterm_init.o src/hbuf.o HALOAD_OBJS += $(OBJS) src/haload_init.o src/haload.o src/hbuf.o # Used only for forced dependency checking. May be cleared during development. -INCLUDES = $(wildcard include/*/*.h) +INCLUDES = $(wildcard include/*/*.h) $(EXTRA_INCLUDES) DEP = $(INCLUDES) .build_opts help: @@ -1245,9 +1267,9 @@ install-bin: $(Q)$(INSTALL) -d "$(DESTDIR)$(SBINDIR)" $(Q)$(INSTALL) haproxy $(EXTRA) "$(DESTDIR)$(SBINDIR)" -install: install-bin install-admin install-man install-doc +install: install-bin install-admin install-man install-doc $(EXTRA_INSTALL) -uninstall: +uninstall: $(EXTRA_UNINSTALL) $(Q)rm -f "$(DESTDIR)$(MANDIR)"/man1/haproxy.1 $(Q)for x in $(DOCUMENTATION); do \ rm -f "$(DESTDIR)$(DOCDIR)"/$$x.txt ; \