# ======================================================================
#                                                                      
#  Immunix CryptoMark 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
VERSION		= 0.1
NAME		= cryptomark
MISC_FILES	= Makefile BUGS NOTES CHANGELOG README

#
# 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)
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 \" )

# macro for the immunix header file for us lazy typers
IMMUNIX_H = $(INCLUDEDIR)/linux/immunix.h


TARGETS = $(CRYPTOMARK)
CRYPTOMARK = cryptomark.o

OBJS = 	\
	mpi-cmp.o	\
	mpih-cmp.o	\
	mpi-bit.o	\
	mpiutil.o	\
	mpih-rshift.o	\
	mpih-lshift.o	\
	mpih-mul1.o	\
	mpih-mul2.o	\
	mpih-mul3.o	\
	mpih-add1.o	\
	mpih-sub1.o	\
	mpih-div.o	\
	mpih-mul.o	\
	mpi-mul.o	\
	mpi-div.o	\
	mpi-add.o	\
	mpi-inv.o	\
	mpi-pow.o	\
	mpi-mpow.o	\
	mpicoder.o	



all: $(TARGETS) 

mainproc.o: mainproc.c

main.o: main.c 

iobuf.o: iobuf.c

armor.o: armor.c

calc_sig.o: calc_sig.c cryptomark.h $(IMMUNIX_H)

verify.o: verify.c cryptomark.h $(IMMUNIX_H)

sysctl.o: sysctl.c subdomain.h

list.o: list.c subdomain.h info.h

prefetch.o: prefetch.c subdomain.h 

info.o: info.c info.h info_p.h


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

clean:
	rm -f *.o *.ver *~ 

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

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

