distdir = dkms-linux-gpib-3.2.21

KERNEL_VERSION := $(shell uname -r)
KERNEL_VERSION ?= $(shell echo `uname -r`)
KDIR          := "/lib/modules/$(KERNEL_VERSION)/build"
DESTDIR       ?=

LINUX_CC := gcc
EXTRA_CFLAGS := -I$(CURDIR)/gpib/include

# EXTRA_CFLAGS := -I/home/sipan/src/external/linux-gpib/branches/local_mods -I/home/sipan/src/external/linux-gpib/branches/local_mods/drivers/gpib/include -I/home/sipan/src/external/linux-gpib/branches/local_mods/include

#all:
#	$(MAKE) -C $(KDIR) V=1  SUBDIRS=$(CURDIR)/gpib EXTRA_CFLAGS="${EXTRA_CFLAGS}" modules
all:
	$(MAKE) -C $(KDIR) V=1  SUBDIRS=$(CURDIR)/gpib CC="$(LINUX_CC) $(EXTRA_CFLAGS)" modules

clean:
	$(MAKE) -C $(KDIR) V=1 SUBDIRS=$(CURDIR)/gpib clean

install:
	$(MAKE) -C $(KDIR) V=1 SUBDIRS=$(CURDIR)/gpib INSTALL_MOD_DIR="gpib" modules_install
	$(DEPMOD) -ae

$(distdir):
	$(shell rm -rf $(distdir); \
	tar czf /tmp/$(distdir).tgz --exclude=.svn --dereference ./; \
	mkdir $(distdir); \
	pushd  $(distdir) > /dev/null; \
	tar xzf /tmp/$(distdir).tgz; \
	popd > /dev/null; \
	rm /tmp/$(distdir).tgz )

dist-gzip: $(distdir)
	$(shell tar czf $(distdir).tar.gz $(distdir); \
	rm -rf $(distdir))

# Post install scripts:
#  if [ -z "$(DESTDIR)" ]; then \
#    groupadd gpib || echo "group gpib exists"; \
#    for i in `seq 0 15`; \
#    do \
#      mknod --mode u=rw,g=rw,o= $(DESTDIR)/dev/gpib$${i} c $(IBMAJOR) $${i} || exit 1; \
#      chown root:gpib $(DESTDIR)/dev/gpib$${i}; \
#    done; \
#    if [ ! -c $(DESTDIR)/dev/gpib0 ]; then \
#      if [ -a $(DESTDIR)/dev/gpib0 ]; then \
#        echo "A file or directory called /dev/gpib0 exists but it is not" \
#          "a character device.  Delete or move it and try again."; \
#        exit 1; \
#      fi; \
#    fi; \
#    ls -l $(DESTDIR)/dev/gpib0 | grep -q "$(IBMAJOR)"; \
#    if [ $$? != 0 ]; then \
#      echo "/dev/gpib0 has the wrong major number. " \
#        "Delete your /dev/gpibX files and try again."; \
#      exit 1; \
#    fi; \
#  fi
#  if [ -d /etc/udev/rules.d ]; then \
#    $(INSTALL_DATA) -D $(top_srcdir)/util/templates/60-gpib.rules $(DESTDIR)/etc/udev/rules.d/60-gpib.rules; \
#  fi
#  if [ -d /etc/udev/permissions.d ]; then \
#    $(INSTALL_DATA) -D $(top_srcdir)/util/templates/10-gpib.permissions $(DESTDIR)/etc/udev/permissions.d/10-gpib.permissions; \
#  fi
