# Makefile for sks (win32)
# gcc (Mingw32)

CFLAGS = -DWIN32
WIN=1
VER		=0.93
ES=0
EN=1
CC=gcc
MAKE=mingw32-make

# *******************************
# ***** START build configuration area
# ***** You may comment/uncomment definitions and flags
# ***** Some defs/flags have mandatory alternative, some not
# ******************************

INST=C:\WINDOWS

# ******* If you don't have 'libtommath' installed
LTM = tfm

# ******* If you don't have 'libtomcrypt' installed
LTC = ltc

# ******** If you don't have 'zlib' installed
GZ = zlib

# specify architecture here
ARCH	=i386
#ARCH=pentium4

# specify language ES, EN or input as command-line option i.e.: 'make SLANG=0'
#SLANG=$(ES)

CFLAGS	+= -s -march=$(ARCH) -DVERSION='"$(VER)"' -DSKS_LANG=$(SLANG)

# uses /dev/random or WinNT crypt-random
CFLAGS += -DDEVRANDOM

#warnings
CFLAGS += -Wall
#-Wsign-compare -W -Wno-unused -Wshadow -Werror

#  optimize for SPEED (don't include SIZE options)
#CFLAGS += -O3 -funroll-loops
#  add -fomit-frame-pointer.  v3.2 is buggy for certain platforms!
#CFLAGS += -fomit-frame-pointer -DFULLTABLES

#  optimize for SIZE (don't include SPEED options)
CFLAGS += -Os -DSMALL_CODE

# *******************************
# ***** END build configuration area
# ******************************


# ******** If you don't have 'zlib' installed
ifdef GZ

default: gz sks

gz: $(GZ)/libz.a

$(GZ)/libz.a:
	$(MAKE) -C $(GZ) -f win32/Makefile.gcc libz.a
	
ZLIB = $(GZ)/libz.a
CFLAGS += -I$(GZ)
else

# ******** If you DO have 'zlib' installed
default: sks
ZLIB = -lz
endif

# ******* If you don't have 'libtommath' installed
ifdef LTM

LTMLIB = $(LTM)/mpi.o
CFLAGS += -I$(LTM)

else

# ******* If you DO have 'libtommath' installed
LTMLIB = -ltommath
endif

# ******* If you don't have 'libtocrypt' installed
ifdef LTC

LTCLIB=$(LTC)/aes.o $(LTC)/tiger.o
CFLAGS += -I$(LTC)

else

# ******* If you DO have 'libtomcrypt' installed:
LTCLIB = -ltomcrypt
endif

ECC_OBJS= gflib.o eclib.o eccrypt.o
gflib.o: gflib.c gflib.h
eclib.o: eclib.c eclib.h gflib.h
eccrypt.o: eccrypt.c eccrypt.h eclib.h gflib.h
util.o: util.c sks.h

UTIL_OBJS=binasc.o util.o entropy.o hash.o symcrypt.o

KEY_OBJS=keyring.o

# *** Build the 'kernel'
LIBS = $(UTIL_OBJS) $(ECC_OBJS) $(KEY_OBJS) $(LTMLIB) $(LTCLIB) $(ZLIB)

sks.o: sks.c sks_msg_en.h sks_msg_es.h sks.h

DEPLIST = $(UTIL_OBJS) $(KEY_OBJS) $(ECC_OBJS) sks.o

ifdef LTM
DEPLIST += $(LTMLIB)
endif
ifdef LTC
DEPLIST += $(LTCLIB)
endif
ifdef GZ
DEPLIST += gz
endif

lang_test:
	echo $(SLANG);

sks: $(DEPLIST)
	$(CC) -o $@ $@.o $(LIBS)

# *** Clean

PIGS = *.o sks.exe sks.sig
ifdef LTM
PIGS += $(LTM)\mpi.o
endif
ifdef LTC
PIGS += $(LTC)\aes.o $(LTC)\tiger.o
endif
ifdef GZ
PIGS += $(GZ)\*.o $(GZ)\*.a
endif

clean: limpia
limpia:
		del $(PIGS)

# Tests
skstest: skstest.o $(ECC_OBJS) $(UTIL_OBJS) $(KEY_OBJS)
	$(CC) $@.o  $(UTIL_OBJS) $(ECC_OBJS) $(KEY_OBJS) $(LTCLIB) $(LTMLIB) $(ZLIB) -o $@
#skstest: skstest.o $(LTC_OBJS) $(ECC_OBJS) $(UTIL_OBJS)
#	$(CC) $@.o -I. $(LTC_OBJS) $(ECC_OBJS) $(UTIL_OBJS) $(LTMLIB) $(ZLIB) -o $@


install: sks
	copy sks.exe $(INST)

