# tthsum makefile
# 
# Makefile for NMAKE that comes with Microsofts
# cl.exe C/C++ compiler and link.exe linker.

INSTALLDIR = $(WINDIR)

CFLAGS = /Ox /Ot /GF /GL /nologo
CPPFLAGS = /DUSE_TEXTS /DNDEBUG
LD = link.exe
LDFLAGS = /LIBPATH:$(BINS) /NOLOGO /LTCG /OPT:REF

BINS = obj-win32
TTHSUM = $(BINS)\tthsum.exe
TEST = $(BINS)\test.exe
APP_OBJS = $(BINS)\base32.obj $(BINS)\escape.obj $(BINS)\getopt.obj \
	$(BINS)\read.obj $(BINS)\texts.obj $(BINS)\thex.obj \
	$(BINS)\tiger.obj $(BINS)\tthsum.obj $(BINS)\utf8.obj
TST_OBJS = $(BINS)\base32_test.obj $(BINS)\endian_test.obj \
	$(BINS)\escape_test.obj $(BINS)\getopt_test.obj \
	$(BINS)\read_test.obj $(BINS)\texts_test.obj $(BINS)\thex_test.obj \
	$(BINS)\tiger_test.obj $(BINS)\types_test.obj \
	$(BINS)\utf8_test.obj
LIBS = setargv.obj


all: tthsum test runtest

install: tthsum
	copy $(TTHSUM) "$(INSTALLDIR)" 
	copy tthsum.html "$(INSTALLDIR)\tthsum.html" 
	copy Changelog.txt "$(INSTALLDIR)\tthsum.txt" 

uninstall:
	IF EXIST "$(INSTALLDIR)\tthsum.exe" del "$(INSTALLDIR)\tthsum.exe"
	IF EXIST "$(INSTALLDIR)\tthsum.txt" del "$(INSTALLDIR)\tthsum.txt"
	IF EXIST "$(INSTALLDIR)\tthsum.html" del "$(INSTALLDIR)\tthsum.html"

tthsum: $(TTHSUM)

test: $(TEST)

runtest: test tthsum
	$(BINS)\test.exe
	$(BINS)\tthsum.exe $(BINS)\tthsum.exe $(BINS)\test.exe \
		| $(BINS)\tthsum -cv

clean:
	del /q /s $(BINS)\ 
	rmdir $(BINS)

.c{$(BINS)}.obj::
	@IF NOT EXIST "$(BINS)" mkdir $(BINS)
	$(CC) $(CPPFLAGS) $(CFLAGS) $< /c /Fo$(BINS)\ 
	
$(TTHSUM): $(APP_OBJS) $(BINS)\main.obj
	$(LD) $(LDFLAGS) $(APP_OBJS) $(BINS)\main.obj $(LIBS) /OUT:$(TTHSUM)

$(TEST): $(APP_OBJS) $(TST_OBJS) $(BINS)\test.obj
	$(LD) $(LDFLAGS) $(APP_OBJS) $(TST_OBJS) $(BINS)\test.obj $(LIBS) \
		/OUT:$(TEST)
