# ======================================================================
#                                                                      
#  Immunix CoDomain Module
#  Copyright 1998, 1999, 2000 Wirex Communications &
#			Oregon Graduate Institute
#
#	Written by Steve Beattie <steve@wirex.net> and
#		Greg Kroah-Hartman <greg@wirex.com>
#
# ======================================================================

# stuff to make a release tarball
RELEASE_ROOT	= Immunix
VERSION		= 0.3
NAME		= immunix-md5
MISC_FILES	= Makefile BUGS NOTES CHANGELOG

#
# Determine if the user is using a StackGuarded compiler, and if so, set
# the switch to turn off the canary death handler option.
#
CANARY_FLAG := $(shell if $(CC) -fno-canary-all-functions -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-fno-canary-all-functions"; fi)
CANARY_FLAG += $(shell if $(CC) -mno-terminator-canary -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mno-terminator-canary"; fi)

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

# Change it here or specify it on the "make" commandline
INCLUDEDIR = /usr/include

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

CFLAGS := -malign-loops=2 -malign-jumps=2 -malign-functions=2 -D__KERNEL__ \
	-DMODULE -Wall -Wstrict-prototypes $(CANARY_FLAG) \
	-fomit-frame-pointer $(DEBFLAGS)
CFLAGS += -I$(INCLUDEDIR)

# add a check for SMP
CFLAGS += $(shell if grep "SMP" $(INCLUDEDIR)/linux/compile.h > /dev/null; then echo "-D__SMP__" ; fi)


LINKER=ld -r


# get the kernel version from the include file
# we need this to determine where to put the module for installation.
KERNEL_VERSION = $(shell grep UTS_RELEASE $(INCLUDEDIR)/linux/version.h | cut -f 2 -d \" )


TARGETS = immunix-md5.o
OBJS = md5.o calc_sig.o


all: $(TARGETS) 

md5.o: md5.c md5.h immunix-md5_version.h $(INCLUDEDIR)/linux/immunix.h

calc_sig.o: calc_sig.c md5.h immunix-md5_version.h $(INCLUDEDIR)/linux/immunix.h

immunix-md5_version.h: Makefile
	@echo \#define IMMUNIX_MD5_VERSION \"$(VERSION)\" > .ver
	@mv -f .ver $@


$(TARGETS): $(OBJS)
	$(LINKER) -o $@ $(OBJS)

clean:
	rm -f *.o *.ver *~
	-rm immunix-md5_version.h 

install: all
	-mkdir /lib/modules/$(KERNEL_VERSION)/
	-mkdir /lib/modules/$(KERNEL_VERSION)/misc/
	cp $(TARGETS) /lib/modules/$(KERNEL_VERSION)/misc/

release:
	-rm -rf $(RELEASE_ROOT)
	mkdir $(RELEASE_ROOT)
	mkdir $(RELEASE_ROOT)/$(NAME)-$(VERSION)
	cp *.c $(RELEASE_ROOT)/$(NAME)-$(VERSION)
	cp *.h $(RELEASE_ROOT)/$(NAME)-$(VERSION)
	-cp $(MISC_FILES) $(RELEASE_ROOT)/$(NAME)-$(VERSION)
	tar czv -f $(NAME)-$(VERSION).tar.gz $(RELEASE_ROOT)
	rm -rf $(RELEASE_ROOT)

