# ======================================================================
#                                                                      
#  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		= 1.0-pre3
RELEASE_ROOT	= Immunix
NAME		= cryptomark
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 \" )

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


TARGETS = $(CRYPTOMARK)
CRYPTOMARK = cryptomark.o

RC_FILE :=	rc.cryptomark
RC_TARGET :=	cryptomark

CIPHER_OBJS := \
	gnupg/cipher/construct.o	\
	gnupg/cipher/dynload.o		\
	gnupg/cipher/elgamal.o		\
	gnupg/cipher/md.o      		\
	gnupg/cipher/md5.o     		\
	gnupg/cipher/pubkey.o		\
	gnupg/cipher/rmd160.o		\
	gnupg/cipher/sha1.o

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

GNUPG_OJS :=	\
	gnupg/armor.o		\
	gnupg/iobuf.o		\
	gnupg/plaintext.o	\
	gnupg/memory.o		\
	gnupg/parse-packet.o	\
	gnupg/misc.o		\
	gnupg/free-packet.o	\
	gnupg/mdfilter.o	\
	gnupg/fileutil.o	\
	gnupg/kbnode.o		\
	gnupg/strgutil.o	\
	gnupg/getkey.o		\
	gnupg/keyid.o		\
	gnupg/status.o		\
	gnupg/ringedit.o	\
	gnupg/sig-check.o	\
	gnupg/pkclist.o		\
	gnupg/seskey.o		\
	gnupg/build-packet.o	\
	gnupg/mainproc.o

OBJS =	\
	$(GNUPG_OJS)	\
	$(CIPHER_OBJS)	\
	$(MPI_OBJS)	\
	main.o		\
	calc_sig.o	\
        proc.o          \
	verify.o	


all: $(TARGETS) 

main.o: main.c cryptomark.h cryptomark_version.h $(IMMUNIX_H)

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

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

proc.o: proc.c cryptomark.h $(IMMUNIX_H) cryptomark_version.h

cryptomark_version.h:	Makefile
	@echo \#define CRYPTOMARK_VERSION \"$(VERSION)\" > .ver
	@mv -f .ver $@
        

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

clean:
	rm -f `find . -name '*.o'`
	-rm cryptomark_version.h

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

	# install the startup script
	# (yes this is a blatent assumption that this is a RedHat like box...)
	-cp $(RC_FILE) /etc/rc.d/init.d/$(RC_TARGET)
	-chmod 755 /etc/rc.d/init.d/$(RC_TARGET)
	-/sbin/chkconfig --add $(RC_TARGET)

release: clean
	-rm -rf ../$(NAME)-$(VERSION)
	-rm -rf $(NAME)-$(VERSION).tar.gz
	mkdir ../$(NAME)-$(VERSION)
	cp -R * ../$(NAME)-$(VERSION)
	# cp *.h $(NAME)-$(VERSION)
	# cp $(MISC_FILES) $(NAME)-$(VERSION)
	mv ../$(NAME)-$(VERSION) .
	tar czv -f $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
	rm -rf $(NAME)-$(VERSION)

