
Eu sei o propósito deste arquivo make; é um Makefile de driver, que invocaria o sistema de compilação do kernel a partir da fonte do kernel. Mas não é possível entender o que exatamente está acontecendo.
# 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
Por exemplo o que está acontecendo aqui:
`${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
e aqui:
obj-m := ofd.o`
Alguém pode me ajudar a entender isso colocando mais alguns comentários?
Eu tirei isso dissolink.
Este arquivo make possui um arquivo .c associado (driver);
/* 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");
Responder1
Conforme explicado nos comentários do Makefile, este Makefile contém duas partes. Isso porque será lido duas vezes. Primeiro quando você chama make na linha de comando, depois por 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
Se KERNELRELEASE
não estiver definido é porque o arquivo é lido pelo make. Você tem um Makefile que chama make com a -C
opção de mudar o diretório para onde está a fonte do seu kernel.
Make então lê o Makefile lá (no diretório de origem do kernel). SUBDIRS
é onde está o código-fonte do seu módulo. (Acho que SUBDIRS
está obsoleto e M
é usado agora).
O sistema de compilação do kernel irá procurar pelo Makefile no diretório do seu módulo para saber o que construir. KERNELRELEASE
será definido, então essa parte será usada:
# Otherwise KERNELRELEASE is defined; we've been invoked from the
# kernel build system and can use its language.
else
obj-m := ofd.o
endif
Você encontrará mais informações ema documentação do kernel.