#
# Makefile for rsbac decision module example. 
#
# Author and (c) 1999-2005 Amon Ott <ao@compuniverse.com>
#

# Set this to your kernel directory

# comment out, if kernel is not SMP or has no MODVERSIONS
#SMP=1
#MODVERSIONS=1

DESTDIR		:=
PREFIX		:= $(DESTDIR)/usr/local

# comment out, if RSBAC kernel has no PROC support
CONFIG_RSBAC_PROC := 1

KERN		:= /lib/modules/`uname -r`/
KERNSOURCE	:= $(KERN)/source
MODDIR		:= $(KERN)/misc
KERNVER		:= $(shell uname -r|cut -d "." -f1,2)
PWD		:= $(shell pwd)
# set this to your bin dir
BINDIR		:= $(PREFIX)/bin

# ----- nothing should be changed below -----
#HELPPATH = $(KERNELDIR)/rsbac/help

CC		:= gcc 

CFLAGS		:= -O2 -Wall -DCONFIG_RSBAC 
SFLAGS 		:= -lrsbac
MFLAGS 		:= -D__KERNEL__ -DMODULE -DCONFIG_RSBAC_REG
CFLAGS 		+= -I$(PREFIX)/include -I/usr/include -I $(KERNSOURCE)/include

ifdef SMP
MFLAGS		+=-D__SMP__
endif
ifdef MODVERSIONS
MFLAGS 		+= -DMODVERSIONS 
MFLAGS 		+= -include -I$(PREFIX)/include/linux/modversions.h \
		-I/usr/include/linux/modversions.h
endif

ifdef CONFIG_RSBAC_PROC
MFLAGS		+=-DCONFIG_RSBAC_PROC
endif

obj-m 		:= reg_sample1.o reg_sample3.o
MODULES		:= reg_sample1.o reg_sample3.o
PROGS		:= reg_syscall

LIBS 		:= 

all :
ifeq ($(KERNVER), 2.4)
	set -e
	for i in $(PROGS) ; do $(MAKE) CFLAGS="$(CFLAGS) $(SFLAGS)" $$i ; done
	for i in $(MODULES) ; do $(MAKE) CFLAGS="$(CFLAGS) $(MFLAGS)" $$i ; done
else
	@make -C $(KERNSOURCE) SUBDIRS=$(PWD) modules
endif
install : $(MODULES) $(PROGS)
	-bash -c "if test ! -d $(MODDIR) ; then mkdir $(MODDIR) ; fi"
	install -m 644 $(MODULES) $(MODDIR)
	-depmod -a
	-bash -c "if test ! -d $(BINDIR) ; then mkdir $(BINDIR) ; fi"
	install -m 644 $(PROGS) $(BINDIR)

uninstall :
	-bash -c "cd $(MODDIR) && rm $(MODULES)"
	-bash -c "cd $(BINDIR) && rm $(PROGS)"

clean :
ifeq ($(KERNVER), 2.4)
	rm -f $(MODULES) $(PROGS)
else
	@make -C $(KERNSOURCE) SUBDIRS=$(PWD) clean
endif
