I was trying to compile a kernel module source code, until I noticed that some whitespaces where causing mismatched path names. The directory under which I found myself was:
axor@vacuum:~/software/CS 8803/Operating System Concepts/Chapter 2/ch2$ ls
Makefile simple.c
The error into which I incurred:
axor@vacuum:~/software/CS 8803/Operating System Concepts/Chapter 2/ch2$ make
make -C /lib/modules/4.9.0-3-amd64/build M="/home/none/software/CS 8803/Operating System Concepts/Chapter 2/ch2" modules
make[1]: Entering directory '/usr/src/linux-headers-4.9.0-3-amd64'
/usr/src/linux-headers-4.9.0-3-common/scripts/Makefile.build:44: /home/none/software/CS/Makefile: No such file or directory
make[4]: *** No rule to make target '/home/none/software/CS/Makefile'. Stop.
make[3]: *** [/usr/src/linux-headers-4.9.0-3-common/Makefile:1507: _module_/home/none/software/CS] Error 2
make[2]: *** [Makefile:150: sub-make] Error 2
make[1]: *** [Makefile:8: all] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.9.0-3-amd64'
make: *** [Makefile:4: all] Error 2
Now, it was clear to me that the white spaces in the directory names were causing the problem. I renamed the interested directory tree into ~/software/CS-8803/Operating-System-Concepts/Chapter-2/ch2
and all of that worked.
Question: how can I get the following makefile to work correctly even under directory names containing whitespaces?
obj-m += simple.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
/usr/src/linux-headers-4.9.0-3-amd64
.