CFLAGS = -m486 -O2 -Wall
LDFLAGS = -s -N
CC=gcc
BINDIR=/sbin

# If block device 31 is in use, change the definition below:
HW_MAJOR=31

PROGS=insmod rmmod ksyms lsmod
# If you want to, you can use the old ksyms.sh instead
# Just change the make-rule below

MANS1=insmod.1 ksyms.1 lsmod.1 rmmod.1
MANS2=modules.2
MAN1DIR=/usr/man/man1
MAN2DIR=/usr/man/man2

all: $(PROGS)

#ksyms: ksyms.sh
#	cp ksyms.sh ksyms
#	chmod a+x ksyms

lsmod: lsmod.sh
	cp lsmod.sh lsmod
	chmod a+x lsmod

drv_hello.o:	drv_hello.c  /linux/tools/version.h
	$(CC) $(CFLAGS) drv_hello.c -c -O6 -D__KERNEL__ -DLINUX -o drv_hello.o

/dev/hw:
	if [ ! -c /dev/hw ]; then mknod /dev/hw c $(HW_MAJOR) 0;fi

test: $(PROGS) drv_hello.o /dev/hw
	@echo Installing drv_hello.o with insmod
	./insmod drv_hello.o HW_MAJOR=$(HW_MAJOR)
	@echo This is the output from lsmod
	./lsmod
	@echo You should now see 5 lines of the greeting:
	head -5 /dev/hw
	@echo Removing drv_hello with rmmod
	./rmmod drv_hello
	@echo It is gone...
	./lsmod

clean:
	rm -f *.o $(PROGS) /dev/hw

install: $(PROGS)
	@set -x ;for i in $(PROGS) ; do install -c $$i $(BINDIR) ; done
	@set -x ;for i in $(MANS1) ; do install -c $$i $(MAN1DIR) ; done
	@set -x ;for i in $(MANS2) ; do install -c $$i $(MAN2DIR) ; done

