Member Avatar for BobTheLob

Hey, so I'm having some difficulty getting my make file to work. When I try to make, I get this:

andrew@Samantha ~/Documents/OS_Projects/Chapter 6 $ ls
Makefile  Makefile_old  semaphore.c
andrew@Samantha ~/Documents/OS_Projects/Chapter 6 $ make
make -C /lib/modules/2.6.38-8-generic/build SUBDIRS=/home/andrew/Documents/OS_Projects/Chapter 6 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
make[1]: *** No rule to make target `6'.  Stop.
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
make: *** [default] Error 2

My Makefile code is:

obj-m := semaphore.o
KDIR := /lib/modules/2.6.38-8-generic/build
PWD := $(shell pwd)
default: 
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

And what I'm trying to compile is:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/semaphore.h>
MODULE_LICENSE("GPL");
int num[2][5]={{0,2,4,6,8},{1,3,5,7,9}};

struct semaphore sem_first;
struct semaphore sem_second;
int thread_print_first(void *);
int thread_print_second(void *);

int thread_print_first(void *){
	int i;
	int *num=(int *)p;
	for(i=0;i<5;i++){
		down(&sem_first);
		printk(KERN_INFO"Hello World: %d\n", num[i]);
		up(&sem_second);
	}
	return 0;
}

int thread_print_second (void *){
	int i;
	int *num=(int*)p;
	for(i=0;i<5;i++){
		down(&sem_second);
		printk(KERN_INFO"Hello World: %d\n", num[i]);
		up(&sem_first);
	}
	return 0;
}

static int hello_init(void){
	printk(KERN_ALERT"Hello World enter\n");
	init_MUTEX(&sem_first);
	init_MUTEX_LOCKED(&sem_second);
	kernel_thread(thread_print_first,num[0], CLONE_KERNEL);
	kernel_thread(thread_print_second,num[1],CLONE_KERNEL);
	return 0;
}

static void hello_exit(void) {
	printk(KERN_ALERT"hello world exit\n");
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_AUTHOR("Andrew Stoker");
MODULE_DESCRIPTION("A simple hello world Module");
MODULE_ALIAS("a simplest module");

I'm really quite new to the whole "make" business, and I'm trying to make a module so I can practice adding a module to the kernel. Any ideas on why I'm getting this? I'm running the newest version of Linux Mint, but I also tried the newest version of Ubuntu. So my guess is that I have a critical mistake in my make file, or a really stupid one in my code. But I've looked over both...

The SUBDIRS variable contains a space. From make point of view, the line

make -C /lib/modules/2.6.38-8-generic/build SUBDIRS=/home/andrew/Documents/OS_Projects/Chapter 6 modules

means that SUBDIRS=/home/andrew/Documents/OS_Projects/Chapter , while 6 and modules are targets to make. You may either rename your directory to Chapter_6, or change your makefile to something like

$(MAKE) -C $(KDIR) SUBDIRS=\"$(PWD)\" modules

(untested)

For Linux Kernel Modules I just use

obj-m += test.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
Member Avatar for BobTheLob

Thanks! That did it! It was a stupid mistake with the space problem. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.