
나는 이 make 파일의 목적을 알고 있습니다. 이는 커널 소스에서 커널의 빌드 시스템을 호출하는 드라이버의 Makefile입니다. 그러나 정확히 무슨 일이 일어나고 있는지 이해할 수 없습니다.
# Makefile – makefile of our first driver
# if KERNELRELEASE is not defined, we've been called directly from the command line.
# Invoke the kernel build system.
ifeq (${KERNELRELEASE},)
KERNEL_SOURCE := /usr/src/linux
PWD := $(shell pwd)
default:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
clean:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
# Otherwise KERNELRELEASE is defined; we've been invoked from the
# kernel build system and can use its language.
else
obj-m := ofd.o
endif
예를 들어 여기서 무슨 일이 일어나고 있는지:
`${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
그리고 여기:
obj-m := ofd.o`
누군가 더 많은 의견을 제시하여 이 내용을 이해하는 데 도움을 줄 수 있습니까?
나는 이것을 이것에서 가져왔다.링크.
이 make 파일에는 연관된 .c 파일(드라이버)이 있습니다.
/* ofd.c – Our First Driver code */
#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h>
static int __init ofd_init(void) /* Constructor */
{
printk(KERN_INFO "Namaskar: ofd registered");
return 0;
}
static void __exit ofd_exit(void) /* Destructor */
{
printk(KERN_INFO "Alvida: ofd unregistered");
}
module_init(ofd_init);
module_exit(ofd_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Anil Kumar Pugalia <[email protected]>");
MODULE_DESCRIPTION("Our First Driver");
답변1
Makefile 주석에서 설명했듯이 이 Makefile에는 두 부분이 있습니다. 두 번 읽게 되기 때문이다. 먼저 명령줄에서 make를 호출한 다음 kbuild를 호출합니다.
# if KERNELRELEASE is not defined, we've been called directly from the command line.
# Invoke the kernel build system.
ifeq (${KERNELRELEASE},)
KERNEL_SOURCE := /usr/src/linux
PWD := $(shell pwd)
default:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
clean:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
정의되어 있지 않으면 KERNELRELEASE
make가 파일을 읽었기 때문입니다. -C
커널 소스가 있는 디렉토리를 변경하는 옵션 과 함께 make를 호출하는 Makefile이 있습니다 .
그런 다음 Make는 거기(커널 소스 디렉토리)에서 Makefile을 읽습니다. SUBDIRS
모듈 소스 코드가 있는 곳입니다. (내 생각에는 SUBDIRS
더 이상 사용되지 않으며 M
지금은 대신 사용됩니다.)
커널 빌드 시스템은 무엇을 빌드할지 알기 위해 모듈 디렉토리에서 Makefile을 찾습니다. KERNELRELEASE
설정되어 해당 부분이 사용됩니다.
# Otherwise KERNELRELEASE is defined; we've been invoked from the
# kernel build system and can use its language.
else
obj-m := ofd.o
endif
자세한 내용은 다음에서 확인하세요.커널 문서.