##------------------------------------------------------------------------------
#   elomaxdriver: A linux kernel driver to control http://www.elomax.nl
#                 usb-io modules
#   Copyright (C) 2011  programming <at> kogro org
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
##------------------------------------------------------------------------------
ifneq ($(KERNELRELEASE),)
  #
  # Part 2)  build from the kernel-environment (kbuild)
  #
  obj-m := elomax.o
  elomax-objs :=       \
    this-module.o      \
    debug.o            \
    kernelmodule.o     \
    elomaxdriver.o     \
    elomaxinstance.o
else
  #
  # Part 1)  build from user-environment
  #

  SRCTAR := ./elomax.src.tgz

  KDIR := /usr/src/linux-headers-`uname -r`
  MDIR := /lib/modules/`uname -r`/misc/

default :
	$(MAKE) -C $(KDIR) M=$(PWD) modules

clean:
	$(MAKE) -C $(KDIR) M=$(PWD) clean
	rm -fr ./doc
	rm $(SRCTAR)

install: default
	mkdir -p $(MDIR)
	cp elomax.ko ${MDIR}
	depmod -a
	cp 20-elomax.rules /etc/udev/rules.d/

.PHONY: doc
doc:
	doxygen Doxyfile

.PHONY: srctar
srctar:  $(SRCTAR)

$(SRCTAR):
	tar czf \
	  $@ \
	  COPYING \
	  README \
	  20-elomax.rules \
	  Doxyfile \
	  Makefile \
	  package.txt \
	  *.c \
	  *.h
endif
