PWD := $(shell pwd)

ifeq ($(shell uname -r|cut -b 1-3),2.5)
# 2.5
KDIR := /lib/modules/$(shell uname -r)/build
DIRS := $(wildcard $(PWD)/kmemprof-*)

default:
	$(MAKE) -C $(KDIR) 'SUBDIRS=$(DIRS)' modules

clean:
	find . \( -name '*.o' -o -name '*.ko' -o -name '*~' \
		-o -name '*.mod.c' -o -name '.*.cmd' \) \
		-type f -print | xargs rm -f

install:
	-mkdir -p modules
	cp $(wildcard kmemprof-*/*.ko) modules/
else
# 2.4
SHELL=/bin/bash
DIRS= $(wildcard kmemprof-*)

all:
	for i in $(DIRS); \
	do $(MAKE) -C $$i -f Makefile-2.4 all; \
	done

install:
	-mkdir modules
	chmod +x bin/*
	for i in $(DIRS); \
	do cp $$i/$$i.o modules; \
	done

clean:
	for i in $(DIRS); \
	do $(MAKE) -C $$i -f Makefile-2.4 clean; \
	done
	-rm modules/*
	-rm bin/*~ doc/*~ *~
endif
