https://cgit.freebsd.org/ports/tree/devel/wasi-libc/Makefile#n40
chunk 2: avoid rebuilding everything in fake

chunk 1: wasi-libc requires some compiler headers that we remove from our
llvm ports so we include them here instead

last chunk: adapt regex for our grep
chunk 3 & 4: syms for llvm22
cf https://github.com/WebAssembly/wasi-libc/commit/2fc32bc81b9f07f8d9525edea59bfbaf760c06d6
and adapted from https://github.com/WebAssembly/wasi-libc/commit/3fa18af1 for __wasip1__ define
Index: Makefile
--- Makefile.orig
+++ Makefile
@@ -498,7 +498,7 @@ endif
 #    should come earlier in the search path, so they can "override"
 #    and/or `#include_next` the public headers. `-isystem` (like
 #    `-idirafter`) comes later in the search path than `-I`.
-CFLAGS += -isystem "$(SYSROOT_INC)"
+CFLAGS += -isystem "$(SYSROOT_INC)" -isystem "${WRKDIR}/sysroot/include"
 
 # These variables describe the locations of various files and directories in
 # the build tree.
@@ -889,7 +889,7 @@ ifeq ($(CHECK_SYMBOLS),yes)
 finish: check-symbols
 endif
 
-install: finish
+install:
 	mkdir -p "$(INSTALL_DIR)"
 	cp -p -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)"
 
@@ -925,7 +925,7 @@ check-symbols: $(STARTUP_FILES) libc
 	for undef_sym in $$("$(NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \
 	    |grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \
 	    grep -q '\<'$$undef_sym'\>' "$(DEFINED_SYMBOLS)" || echo $$undef_sym; \
-	done | grep -E -v "^__mul|__memory_base|__indirect_function_table|__tls_base" > "$(UNDEFINED_SYMBOLS)"
+	done | grep -E -v "^__mul|__memory_base|__indirect_function_table|__wasm_first_page_end|__tls_base" > "$(UNDEFINED_SYMBOLS)"
 ifneq ($(WASI_SNAPSHOT), p2)
 	grep '^_*imported_wasi_' "$(UNDEFINED_SYMBOLS)" \
 	    > "$(SYSROOT_LIB)/libc.imports"
@@ -998,6 +998,7 @@ endif
 	    -U__wasm_nontrapping_fptoint__ \
 	    $(if $(filter-out expected/wasm32-wasip1-threads,$(EXPECTED_TARGET_DIR)),-U__wasm_bulk_memory__) \
 	    -U__wasm_bulk_memory_opt__ \
+	    -U__wasip1__ \
 	    -U__GNUC__ \
 	    -U__GNUC_MINOR__ \
 	    -U__GNUC_PATCHLEVEL__ \
@@ -1007,19 +1008,20 @@ endif
 	    -U__FLT_EVAL_METHOD__ -Wno-builtin-macro-redefined \
 	    | sed -e 's/__[[:upper:][:digit:]]*_ATOMIC_\([[:upper:][:digit:]_]*\)_LOCK_FREE/__compiler_ATOMIC_\1_LOCK_FREE/' \
 	    | sed -e 's/__GNUC_VA_LIST $$/__GNUC_VA_LIST 1/' \
-	    | grep -v '^#define __\(BOOL\|INT_\(LEAST\|FAST\)\(8\|16\|32\|64\)\|INT\|LONG\|LLONG\|SHRT\)_WIDTH__' \
-	    | grep -v '^#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_\(1\|2\|4\|8\)' \
+	    | egrep -v '^#define __(BOOL|INT_(LEAST|FAST)(8|16|32|64)|INT|LONG|LLONG|SHRT)_WIDTH__' \
+	    | egrep -v '^#define __MEMORY_SCOPE_(DEVICE|SINGLE|SYSTEM|WRKGRP|WVFRNT)' \
+	    | egrep -v '^#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_(1|2|4|8)' \
 	    | grep -v '^#define __FPCLASS_' \
 	    | grep -v '^#define __FLT128_' \
 	    | grep -v '^#define __MEMORY_SCOPE_' \
-	    | grep -v '^#define __GCC_\(CON\|DE\)STRUCTIVE_SIZE' \
+	    | egrep -v '^#define __GCC_(CON|DE)STRUCTIVE_SIZE' \
 	    | grep -v '^#define __STDC_EMBED_' \
-	    | grep -v '^#define __\(DBL\|FLT\|LDBL\)_NORM_MAX__' \
+	    | egrep -v '^#define __(DBL|FLT|LDBL)_NORM_MAX__' \
 	    | grep -v '^#define NDEBUG' \
 	    | grep -v '^#define __OPTIMIZE__' \
 	    | grep -v '^#define assert' \
 	    | grep -v '^#define __NO_INLINE__' \
-	    | grep -v '^#define __U\?INT.*_C(' \
+	    | egrep -v '^#define __U?INT.*_C\(' \
 	    > "$(SYSROOT_SHARE)/predefined-macros.txt"
 
 	# Check that the computed metadata matches the expected metadata.
