pmaports/device/downstream/linux-amazon-checkers/0005-Add-modinst-Makefile.patch
user0-07161 13649dbb71
amazon-checkers: enable wifi, fix crashes
I've also added myself as a maintainer everywhere as I forgot to do that
in the initial MR.

Co-authored-by: Clayton Craft <craftyguy@postmarketos.org>
Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/7203>
2025-10-18 10:03:55 +00:00

132 lines
3.8 KiB
Diff

From 2d9ed388316294678a3efa8ae113d54ed32e54a0 Mon Sep 17 00:00:00 2001
From: user0-07161 <user0thenyancat@proton.me>
Date: Wed, 15 Oct 2025 15:15:39 +0200
Subject: [PATCH] add modinst makefile
---
scripts/Makefile.modinst | 41 +++++++++++++++++++++++++
scripts/depmod.sh | 64 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+)
create mode 100644 scripts/Makefile.modinst
create mode 100755 scripts/depmod.sh
diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
new file mode 100644
index 0000000..07650ee
--- /dev/null
+++ b/scripts/Makefile.modinst
@@ -0,0 +1,41 @@
+# ==========================================================================
+# Installing modules
+# ==========================================================================
+
+PHONY := __modinst
+__modinst:
+
+include scripts/Kbuild.include
+
+#
+
+__modules := $(sort $(shell grep -h '\.ko$$' /dev/null $(wildcard $(MODVERDIR)/*.mod)))
+modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o)))
+
+PHONY += $(modules)
+__modinst: $(modules)
+ @:
+
+# Don't stop modules_install if we can't sign external modules.
+quiet_cmd_modules_install = INSTALL $@
+ cmd_modules_install = \
+ mkdir -p $(2) ; \
+ cp $@ $(2) ; \
+ $(mod_strip_cmd) $(2)/$(notdir $@) ; \
+ $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) && \
+ $(mod_compress_cmd) $(2)/$(notdir $@)
+
+# Modules built outside the kernel source tree go into extra by default
+INSTALL_MOD_DIR ?= extra
+ext-mod-dir = $(INSTALL_MOD_DIR)$(subst $(patsubst %/,%,$(KBUILD_EXTMOD)),,$(@D))
+
+modinst_dir = $(if $(KBUILD_EXTMOD),$(ext-mod-dir),kernel/$(@D))
+
+$(modules):
+ $(call cmd,modules_install,$(MODLIB)/$(modinst_dir))
+
+
+# Declare the contents of the .PHONY variable as phony. We keep that
+# information in a variable so we can use it in if_changed and friends.
+
+.PHONY: $(PHONY)
diff --git a/scripts/depmod.sh b/scripts/depmod.sh
new file mode 100755
index 0000000..122599b
--- /dev/null
+++ b/scripts/depmod.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# A depmod wrapper used by the toplevel Makefile
+
+if test $# -ne 3; then
+ echo "Usage: $0 /sbin/depmod <kernelrelease> <symbolprefix>" >&2
+ exit 1
+fi
+DEPMOD=$1
+KERNELRELEASE=$2
+SYMBOL_PREFIX=$3
+
+if ! test -r System.map -a -x "$DEPMOD"; then
+ exit 0
+fi
+
+# older versions of depmod don't support -P <symbol-prefix>
+# support was added in module-init-tools 3.13
+if test -n "$SYMBOL_PREFIX"; then
+ release=$("$DEPMOD" --version)
+ package=$(echo "$release" | cut -d' ' -f 1)
+ if test "$package" = "module-init-tools"; then
+ version=$(echo "$release" | cut -d' ' -f 2)
+ later=$(printf '%s\n' "$version" "3.13" | sort -V | tail -n 1)
+ if test "$later" != "$version"; then
+ # module-init-tools < 3.13, drop the symbol prefix
+ SYMBOL_PREFIX=""
+ fi
+ fi
+ if test -n "$SYMBOL_PREFIX"; then
+ SYMBOL_PREFIX="-P $SYMBOL_PREFIX"
+ fi
+fi
+
+# older versions of depmod require the version string to start with three
+# numbers, so we cheat with a symlink here
+depmod_hack_needed=true
+tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
+mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
+if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
+ if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
+ -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
+ depmod_hack_needed=false
+ fi
+fi
+rm -rf "$tmp_dir"
+if $depmod_hack_needed; then
+ symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
+ ln -s "$KERNELRELEASE" "$symlink"
+ KERNELRELEASE=99.98.$KERNELRELEASE
+fi
+
+set -- -ae -F System.map
+if test -n "$INSTALL_MOD_PATH"; then
+ set -- "$@" -b "$INSTALL_MOD_PATH"
+fi
+"$DEPMOD" "$@" "$KERNELRELEASE" $SYMBOL_PREFIX
+ret=$?
+
+if $depmod_hack_needed; then
+ rm -f "$symlink"
+fi
+
+exit $ret
--
2.51.0