Makefile:10: recipe for target 'modules' failed on multiple debian distros - linux

FIXED
The problem was that I had spaces somewhere in the path to my source directory.
In this case, "Source Builds" had a space and screwed everything up.
Make sure you don't have any spaces anywhere in your folder names between root and your make directory.
So this error:
make[1]: ** No rule to make target 'Builds/ digimend-kernel-drivers-master'. Stop.
Came from the space in: ~/Source Builds/digimend-kernel-drivers-master
debian wheezy, jessie and now simplice 6 sid
I installed the build essentials package
the linux headers package for my kernel
ive tried on kernel 3.2.04, 3.16 and now 3.12
gcc version 4.9.2 (Debian 4.9.2-8)
GNU Make 4.0
this is what i get when i try to make.
willy#semplice:~/Source Builds/digimend-kernel-drivers-master$ make
make -C /lib/modules/3.12-7.semplice.0-desktop-686/build SUBDIRS=/home/willy/Source Builds/digimend-kernel-drivers-master modules
make[1]: Entering directory '/usr/src/linux-headers-3.12-7.semplice.0-desktop-686'
make[1]: *** No rule to make target 'Builds/digimend-kernel-drivers-master'. Stop.
make[1]: Leaving directory '/usr/src/linux-headers-3.12-7.semplice.0-desktop-686'
Makefile:10: recipe for target 'modules' failed
make: *** [modules] Error 2
Heres the makefile
ifneq ($(KERNELRELEASE),)
obj-m := hid-huion.o hid-uclogic.o
else
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
UDEV_RULES := /lib/udev/rules.d/70-hid-rebind.rules
DEPMOD_CONF := /etc/depmod.d/digimend.conf
HID_REBIND := /sbin/hid-rebind
modules modules_install clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) $#
install: modules_install
install -D -m 0644 digimend.conf $(DEPMOD_CONF)
depmod -a
install hid-rebind $(HID_REBIND)
install -m 0644 hid-rebind.rules $(UDEV_RULES)
udevadm control --reload
uninstall:
rm -vf $(UDEV_RULES) $(HID_REBIND) $(DEPMOD_CONF) \
/lib/modules/*/extra/hid-huion.ko \
/lib/modules/*/extra/hid-uclogic.ko
udevadm control --reload
depmod -a
endif
what is going on here... I am getting sad

FIXED
The problem was that I had spaces somewhere in the path to my source directory.
In this case, "Source Builds" had a space and screwed everything up.
Make sure you don't have any spaces anywhere in your folder names between root and your make directory.
So this error:
make[1]: ** No rule to make target 'Builds/ digimend-kernel-drivers-master'. Stop.
Came from the space in: ~/Source Builds/digimend-kernel-drivers-master
– user4369678

Related

How to write a Linux kernel module makefile?

I'm trying to write a simple hello world kernel module. I'm working in Ubuntu 18.04.2 LTS on Virtual Box. In the directory /usr/src I created a directory named hello and inside that hello directory I've created hello.c and a makefile. Here is my makefile:
obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
When I make the command "sudo make" I get this output:
make -C /lib/modules/5.3.0-28-generic/build M= modules
make[1]: Entering directory '/usr/src/linux-headers-5.3.0-28-generic'
make[2]: *** No rule to make target 'arch/x89/tools/relocs_32.c', needed by 'arch/x86/tools/relocs_32.o'. Stop.
arch/x86/Makefile:232: recipe for target 'archscripts' failed
make[1]: *** [archscripts] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.3.0-28-generic'
makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
I've tried a few variations of my makefile including changing "PWD" to "shell pwd". I've installed all the essential tools and libraries as far as I know. What could be the problem here?
Variable PWD is set by the shell, so your Makefile relies on make invocation to be performed from the shell, as we normally do when type make in the terminal.
But sudo make executes make from a plain user environment. This environment lacks for PWD variable, so your Makefile behaves incorrectly. This can be found from your output:
make -C /lib/modules/5.3.0-28-generic/build M= modules
Use $(shell pwd) expression instead, it is more reliable:
obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
Alternatively, you may call make with root privileges using this way:
sudo /bin/sh -c make
This way make is executed not from the plain root environment, but under an intermediate shell. This shell sets PWD variable.
Update
As noted by #Ian Abbott in the comments, another alternative for $(PWD) is $(CURDIR). Variable CURDIR is set by the make itself (precisely, by GNU Make). See also that question: bash: What is the difference between PWD and CURDIR?.
Your Makefile should look like this
obj-m += hello.o
Then your build command will look like
make -C $KDIR M=$PWD
Where $KDIR is the source tree of your kernel build.
is the way. The rest is handled by the kbuild system.
Please refer to refer to the official documentation for building off-tree modules

Raspberry PI: make command not working with below makefile

Makefile:
module=usb-it950x
EXTRA_CFLAGS = -DEXPORT_SYMTAB
CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
MACHINE = $(shell uname -m)
KDIR26 := /lib/modules/$(CURRENT)/kernel/drivers/media
DEST = /lib/modules/$(CURRENT)/kernel/$(MDIR)
LMDIR26 := /lib/firmware
usb-it950x-objs := \
it950x-core.o it950x-drv.o iocontrol.o \
tuner.o cmd.o IT9133.o ADF4351.o \
IT9507.o Omega.o eagleTuner.o \
standard.o usb2impl.o modulatorUser.o user.o
obj-m += usb-it950x.o
default:
#(cp api/*.* ./; cp src/*.* ./)
make -s -C $(KDIR) SUBDIRS=$(PWD) modules
Also, I can compile the makefile at ubuntu.
But, I am trying compile abobe makefile at raspberry pi.
Error Log:
make -C /lib/modules/4.14.98-v7+/build SUBDIRS=/home/pi/it950x_driver modules
make[1]: *** /lib/modules/4.14.98-v7+/build: No such file or directory. Stop.
Makefile:20: recipe for target 'default' failed
make: *** [default] Error 2
How I can compile this makefile at raspberry pi(raspbian)?
You do not have a Makefile at /lib/modules/4.14.98-v7+/build on your pi. (your initial recipe for default runs, but then calls make with a -C that points to a directory with no makefile, and your error message comes from that).
Try doing an ls /lib/modules/, and see what directories it has in there. Note that this web page implies that you have to install the kernel headers onto a pi board manually...

How to build a linux kernel module against with a prebuilt kernel output directory?

My customer send me the prebuilt kernel output directory(They can not release the kernel source tree to us). This output directory is as below(under /home/michael/Clients/android_p_Hzh/kernel/kernel/):
arch
block
build-in.o
certs
...
.config
Makefile
Module.symvers
source (symbol link to a local source tree in my customer's file system)
Is it possible to build my external module against with this directory?
/home/michael/Source/Linux/br_driver is my driver's directory. I have tried to build my driver under this directory as below make command:
make CROSS_COMPILE=x86_64-poky-linux- -C
/home/michael/Clients/android_p_Hzh/kernel/kernel/ M=pwd $1
It fails with below output:
*** No rule to make target '/home/michael/Source/Linux/br_driver/common.o' needed by ...
The Makefile under br_driver is like below:
brt-objs := $(BRTOFILES)
obj-$(DRIVER_TYPE) += brt.o
all:
#echo "$(MAKE) --no-print-directory -C $(KDIR) SUBDIRS=$(CURDIR) modules"
#$(MAKE) --no-print-directory -C $(KDIR) SUBDIRS=$(CURDIR) modules
clean:
rm -rf *.o *.ko *.mod.c *~ .*.cmd *.o.cmd .*.o.cmd \
Module.symvers modules.order .tmp_versions modules.builtin
install:
#$(MAKE) --no-print-directory -C $(KDIR) \
SUBDIRS=$(CURDIR) modules_install
I have resolved this problem. The only things I need is the .config and Modules.symvers. The key operation is make oldconfig and modules_prepare.

Makefile for kernel kecho command issue

This a makefile for compiling the kernel module.
# Makefile – makefile of our first driver
#
# if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq (${KERNELRELEASE},)
obj-m = first-driver.o
# Otherwise we were called directly from the command line.
# Invoke the kernel build system.
else
KERNEL_SOURCE := /lib/modules/2.6.32-504.8.1.el6.x86_64/build
PWD := $(shell pwd)
default:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
#echo kernel first-driver is ready
#$(kecho) 'Kernel: $# is ready'
clean:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
endif
.PHONY : install remove
install :
sudo insmod first-driver.ko
remove :
sudo rmmod first-driver
Here I have used echo and kecho as per kernel makefile documantation but it giving the following error:
make -C /lib/modules/2.6.32-504.8.1.el6.x86_64/build SUBDIRS=/home/betatest/Device-Driver-Test modules
make[1]: Entering directory '/usr/src/kernels/2.6.32-504.8.1.el6.x86_64'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory '/usr/src/kernels/2.6.32-504.8.1.el6.x86_64'
kernel first-driver is ready
make: Kernel: default is ready: Command not found
Makefile:16: recipe for target 'default' failed
make: *** [default] Error 127
I am using GNU make version 4.1 and gcc version 4.4.7 where am I going wrong. Thanks.....
What is kecho variable's is assigned to? in the line #$(kecho) 'Kernel: $# is ready' kecho's value is null so the make considers only #$(kecho) 'Kernel: $# is ready' as a rule.
Did you forget to assign kecho to something at the beginning of the file? Like
kecho='echo'

make: no rule to make target

i have written a simple linux module & its make file
this is my module
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void) {
printk("<1> Hello world!\n");
return 0;
}
static void hello_exit(void) {
printk("<1> Bye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
this is my make file
obj-m :=Hello.o
KDIR = /usr/src/linux-headers-3.5.0-17
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
when i execute make -f MakeFile
it gives following o/p
make -C /usr/src/linux-headers-3.5.0-17 SUBDIRS=/home/linux/Desktop modules
make[1]: Entering directory `/usr/src/linux-headers-3.5.0-17'
WARNING: Symbol version dump /usr/src/linux-headers-3.5.0-17/Module.symvers
is missing; modules will have no dependencies and modversions.
scripts/Makefile.build:44: /home/linux/Desktop/Makefile: No such file or directory
make[2]: *** No rule to make target `/home/linux/Desktop/Makefile'. Stop.
make[1]: *** [_module_/home/linux/Desktop] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-17'
make: *** [all] Error 2
can any one tell me how to get rid of these errors.
Thanks in advance
Make the below change in your Makefile
First check which kernel is running by typing uname -a
Then go to cd /usr/src/
then check your linux source-code name
for e.g
uname -a Linux vinay-VirtualBox 3.2.0-50-generic-pae #76-Ubuntu SMP Tue Jul 9 19:24:55 UTC 2013 i686 i686 i386 GNU/Linux
here its source-code name is linux-headers-3.2.0-50-generic-pae
same thing in your case
e.g
linux-headers-3.2.0-23 linux-headers-3.2.0-23-generic-pae
so use linux-headers-3.2.0-23-generic-pae instead of
linux-headers-3.2.0-23 i.e replace same in your makefile
i.e KDIR=/usr/src/linux-headers-3.5.0-17-generic-pae
or in order to avoid above problem use
KDIR == /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
KDIR == /lib/modules/$(shell uname -r)/build
$(MAKE) -C $(KDIR) M=$(PWD) modules
obj-m += xyz.o
KDIR:=/usr/src/linux-headers-3.5.0-46-generic
all:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
Are you sure /usr/src/ contains linux-headers-3.5.0-46-generic files?
if this is not the case, download:
sudo apt-get install linux-headers-3.5.0-46
sudo apt-get install linux-headers-3.5.0-46-generic

Resources