Consider Makefiles in the previous examples which were provided, using that example I tried to make one:
obj-m += chardev.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
The output I'm getting is:
maciej@jadwiga:~/Projects/os/chardev$ make
make -C /lib/modules/2.6.26-2-686/build M=/home/maciej/Projects/os/chardev modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.26-2-686'
CC [M] /home/maciej/Projects/os/chardev/chardev.o
/home/maciej/Projects/os/chardev/chardev.c: In function ‘cleanup_module’:
/home/maciej/Projects/os/chardev/chardev.c:72: error: void value not ignored as it ought to be
make[2]: *** [/home/maciej/Projects/os/chardev/chardev.o] Error 1
make[1]: *** [_module_/home/maciej/Projects/os/chardev] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.26-2-686'
make: *** [all] Error 2
/*
* chardev.c: Creates a read-only char device that says how many times
* you've read from the dev file
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <asm/uaccess.h> /* for put_user */
/*
* Prototypes - this would normally go in a .h file
*/
int init_module(void);
void cleanup_module(void);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
#define SUCCESS 0
#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */
#define BUF_LEN 80 /* Max length of the message from the device */
/*
* Global variables are declared as static, so are global within the file.
*/
static int Major; /* Major number assigned to our device driver */
static int Device_Open = 0; /* Is device open?
* Used to prevent multiple access to device */
static char msg[BUF_LEN]; /* The msg the device will give when asked */
static char *msg_Ptr;
static struct file_operations fops = {
.read = device_read,