# Comment/uncomment the following line to enable/disable debugging printouts
#DEBUG = y

# Change it here or specify it on the "make" commandline if your
# relevant kernel source is elsewhere
ifndef KERNELDIR
KERNELDIR = /usr/src/linux
endif

ifndef INCLUDEDIR
INCLUDEDIR = $(KERNELDIR)/include
endif

ifeq ($(DEBUG),y)
  DEBFLAGS = -Wall -O -g -DRSHAPER_DEBUG
else
  DEBFLAGS = -O2
endif

CFLAGS = -Wall $(DEBFLAGS)

CFLAGS += -I$(INCLUDEDIR)

OBJS = rshaper.o
CLIENTS = rshaperctl
MANPAGES = rshaperctl.8

VERSIONFILE = $(INCLUDEDIR)/linux/version.h
VERSION     = $(shell awk -F\" '/REL/ {print $$2}' $(VERSIONFILE))
INSTALLMOD = /lib/modules/$(VERSION)/misc
INSTALLMAN = /usr/local/man/man8
INSTALLBIN = /usr/local/sbin


all: $(OBJS) $(CLIENTS)

install: all
	install -d $(INSTALLMOD) $(INSTALLMAN) $(INSTALLBIN)
	install -c $(OBJS)     $(INSTALLMOD)
	install -c $(CLIENTS)  $(INSTALLBIN)
	install -c $(MANPAGES) $(INSTALLMAN)

uninstall:
	for n in $(OBJS);     do rm -f $(INSTALLMOD)/$$n; done
	for n in $(CLIENTS);  do rm -f $(INSTALLBIN)/$$n; done
	for n in $(MANPAGES); do rm -f $(INSTALLMAN)/$$n; done

clean:
	rm -f *.o $(CLIENTS) *~ core

tar:
	@if [ "x" = "x$(RELEASE)" ]; then \
	    n=`basename \`pwd\``; cd ..; tar cvf - $$n | gzip > $$n.tar.gz; \
	    echo 'you can set a numeric $$(RELEASE) to make a named tar'; \
	else \
	    mkdir ../rshaper-$(RELEASE) || exit 1; \
	     cp -a . ../rshaper-$(RELEASE) && cd .. && \
	        tar --exclude '*/CVS*' \
			-cvzf rshaper-$(RELEASE).tar.gz rshaper-$(RELEASE); \
	fi

distrib: clean tar
