# Comment/uncomment the following line to disable/enable debugging
#DEBUG = y
CC=gcc
LD=ld
prefix = 
bindir = /usr/sbin

# Change it here or specify it on the "make" commandline
INCLUDEDIR = -I/lib/modules/`uname -r`/build/include -I/usr/include

ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DCPINT_DEBUG # "-O" is needed to expand inlines
else
  DEBFLAGS = -O2
endif

CFLAGS = -D__KERNEL__ -DMODULE -Wall $(DEBFLAGS)
CFLAGS += $(INCLUDEDIR)

# Extract version number from headers.
VER = `uname -r`

TARGET = cpint
OBJS = $(TARGET).o
SRC = main.c cmdmain.c monmain.c actmain.c
COMMAND = hcp mongen monstat actgen

all: .depend $(TARGET).o $(COMMAND)

main.o : cpint.h

cmdmain.o : cpint.h cpcmd.h

monmain.o : monmain.c applmon.h cpint.h

actmain.o : cpint.h

$(TARGET).o: $(SRC:.c=.o)
	$(LD) -r $^ -o $@ 

hcp : hcp.o
	$(CC) -o $@ $^

mongen : mongen.o
	$(CC) -o $@ $^

actgen : actgen.o
	$(CC) -o $@ $^

monstat : monstat.o sysinfo.o
	$(CC) -o $@ $^

hcp.o : hcp.c
	$(CC) -o $@ -I. -O2 -c hcp.c

mongen.o : mongen.c
	$(CC) -o $@ -I. -O2 -c mongen.c

monstat.o : monstat.c
	$(CC) -o $@ -I. -O2 -c monstat.c

sysinfo.o : sysinfo.c
	$(CC) -o $@ -I. -O2 -c sysinfo.c

actgen.o : actgen.c
	$(CC) -o $@ -I. -O2 -c actgen.c

install:
	install -d ${prefix}/lib/modules/$(VER)/misc ${prefix}/lib/modules/misc
	install -c $(TARGET).o ${prefix}/lib/modules/$(VER)/misc
	install -c $(TARGET).o ${prefix}/lib/modules/misc
	install -d ${prefix}${bindir}
	install -c -m 750 cpint_load ${prefix}${bindir}
	install -c -m 750 cpint_unload ${prefix}${bindir}
	install -c -m 750 mongen ${prefix}${bindir}
	install -c -m 750 monstat ${prefix}${bindir}
	install -c -m 750 hcp ${prefix}${bindir}

clean:
	rm -f *.o *~ core .depend mongen monstat actgen hcp

depend .depend dep:
	$(CC) $(CFLAGS) -M *.c > $@


ifeq (.depend,$(wildcard .depend))
include .depend
endif
