0
キーワードmodules
を2回使用するサンプルメークファイルを示します(パスに表示されるものとPHONYは別です)。"モジュール"はこのMakefileで何を参照していますか?
# Path to the kbuild Makefile of the kernel to compile against
export KERNEL_BUILD_PATH := /lib/modules/$(shell uname -r)/build
# Name of this kernel module
export KERNEL_MODULE := hello
# List of kernel headers to include (e.g.: "linux/netdevice.h")
export KERNEL_INCLUDE :=
# Path to the directory where kernel build artifacts should be stored
export BUILD_DIRECTORY := build
# List of C files to compile into this kernel module
export C_FILES := $(wildcard src/*.c)
# List of all Rust files that will be compiled into this kernel module
export RUST_FILES := $(wildcard src/*.rs)
# Base directory of the Rust compiler
export RUST_ROOT := /usr
# Rust compiler settings
export CARGO = $(RUST_ROOT)/bin/xargo
export CARGOFLAGS =
export RCFLAGS =
export RELEASE =
-include ./config.mk
# Top-level project directory
export BASE_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
# Prevent command echoing, unless the (Kbuild-style) `V=1` parameter is set
ifneq "$(V)" "1"
.SILENT:
endif
all modules: ${BUILD_DIRECTORY}/Makefile
@$(MAKE) -C "${KERNEL_BUILD_PATH}" M="${BASE_DIR}/${BUILD_DIRECTORY}" modules
cp "${BUILD_DIRECTORY}/${KERNEL_MODULE}.ko" "${KERNEL_MODULE}.ko"
# Make sure there always is a target `Makefile` for kbuild in place
${BUILD_DIRECTORY}/Makefile: kbuild.mk
@mkdir -p "${BUILD_DIRECTORY}/src"
cp "kbuild.mk" "${BUILD_DIRECTORY}/Makefile"
insmod:
sudo insmod "${KERNEL_MODULE}.ko"
dmesg | tail
rmmod:
sudo rmmod "${KERNEL_MODULE}"
dmesg | tail
clean:
rm -rf "${BUILD_DIRECTORY}"
$(CARGO) clean
test: ${KERNEL_MODULE}.ko
sudo insmod "${KERNEL_MODULE}.ko"
sudo rmmod "${KERNEL_MODULE}"
dmesg | tail -3
.PHONY: all modules clean insmod rmmod test
私の質問は以下のとおりです。ライン35で
- 、
all modules
は、例えば二つの別々のターゲットを指しありませんall
とmodules
一緒に?もしそうなら、私たちはなぜ2つの異なる名前を持つ同じルールに名前をつけますか?ルールは再帰的になりませんか? - 36行目の末尾に表示されるキーワード
module
の意味は? - 36行目では、
M=
は何の略ですか?
の内側に表示されます変数を渡しますすべてのモジュールはnターゲットの名前。これは、全く異なる2つのターゲット、 'all'と' modules'が定義されており、どちらも同じレシピを持つことを意味します。したがって、 'make all'または' make modules'を実行すると、同じレシピが実行されます。これは、ルール全体を2回書くこととまったく同じです。ターゲットは 'all'、ターゲットは' modules'です。ただし、タイピングは少ないです。 – MadScientist
はい、あなたは正しいです。 「すべて:モジュール」を実行してターゲットモジュールを作成する方がより明確になるという意味で、「目標の不幸な名前」を書きました。しかし、あなたは正しいです。これは単一のターゲットではなく、2つの別個のターゲットです。 – mko