#
# kmouse Makefile
#
#	uncomment the following to have debugging output via klogd
DEBUG = y

#	uncomment the following if you use module versioning (Hmm.. untested)
#MODVERSIONS = y


# Set your own kernel include path ("$(HOME)/linux/include/linux" or whatever)
INCLUDE = /usr/include
CFLAGS = -I$(INCLUDE) $(XCFLAGS)

######### No changes should be needed below this line

TARGET = kmouse
MICE =

ifdef DEBUG
  # -O is needed, because of "extern inline"
  CFLAGS += -g -O -DKMOUSE_DEBUG -Wall
else
  CFLAGS += -O3 -fomit-frame-pointer -Wall
endif

# force make config
ifneq (.config,$(wildcard .config))
beforeall: config
else
include .config
endif

# force make depend
ifneq (.depend,$(wildcard .depend))
all: depend
endif


ifdef CONFIG_PS2_MODULE
  MICE += kmouse-psaux.o
  CONFIG_PS2_PROTOCOL = y
endif

ifdef DEBUG
  MICE += fakemouse.o
endif

######### And now the targets

all: kmouse-config.h $(TARGET).o mouseconfig kdecode $(MICE)

$(TARGET).o: core.o protocols.o
	$(LD) -r $^ -o $@

clean:
	rm -f *.o mouseconfig kdecode *~ .depend

distclean: clean
	rm -f  .config kmouse-config.h

tar:
	n=`basename \`pwd\``; cd ..; tar cvf - $$n | gzip > $$n.tar.gz

distrib: distclean tar

config:
	./configure

ifdef MODVERSIONS
core.o: core.c core.ver $(INCLUDE)/linux/modversions.h
	$(CC) $(CFLAGS) -DMODVERSIONS -include $(INCLUDE)/linux/modversions.h \
	-include core.ver -c core.c -o $@

core.ver: core.c
	$(CC) -E -D__KERNEL__ -D__GENKSYMS__ -DCONFIG_MODVERSIONS \
	-DEXPORT_SYMTAB kmouse.c | genksyms .
endif



# Extract version number from headers.
VER = $(shell awk -F\" '/REL/ {print $$2}' $(INCLUDE)/linux/version.h)

install: $(TARGET).o
	mkdir -p /lib/modules/$(VER)/misc /lib/modules/misc
	install -c $(TARGET).o /lib/modules/$(VER)/misc
	install -c $(TARGET).o /lib/modules/misc
	install -c mouseconfig /usr/sbin
	install -c kdecode /usr/local/bin
	@echo ""
	@echo -n "Now update your /etc/mouse.conf "
	@echo    "by editing a copy of ./mouse.conf"


depend dep:
	$(CC) -MM *.c > .depend

DEPEND DEP:
	$(CC) -M *.c > .depend

ifeq (.depend,$(wildcard .depend))
include .depend
endif


