##
## Name:     Makefile.msvc
## Purpose:  Makefile for IMath library and associated tools
##           for Microsoft Visual Studio 2005
## Author:   Matus Horvath <matus.horvath@nextra.sk>
##
## Copyright (C) 2006 Matus Horvath.  Permission has been granted to use,
## modify, and redistribute this file according to the terms of the IMath
## license.
##
## Usage: nmake /f Makefile.msvc
##

# --- begin configuration section ---

## Settings for Microsoft Windows systems using nmake.
## To build with debugging, add DEBUG=Y on the "nmake" command line.
CC=cl.exe
LD=link.exe
CFLAGS=$(CFLAGS) -nologo -I. -D_CRT_SECURE_NO_DEPRECATE $(DCFLAGS)
LDFLAGS=$(LDFLAGS) -nologo $(DLDFLAGS)
LIBS=$(DLIBS)

!if "$(DEBUG)" == "Y"
DCFLAGS=-ZI -Od -DDEBUG=1 -DTRACEABLE_FREE=1
DLDFLAGS=-DEBUG
#DLIBS=-lefence
!else
DCFLAGS=-O2 -Ob2
DLDFLAGS=
#DLIBS=
!endif

## Visual Studio C/C++ 2005 compiler supports "long long" 64-bit type.  
CFLAGS=$(CFLAGS) -DUSE_LONG_LONG

# --- end of configuration section ---
TARGETS=imtest.exe pi.exe bintest.exe findprime.exe
HDRS=imath.h imrat.h iprime.h imdrover.h rsamath.h
SRCS=$(HDRS:.h=.c) $(TARGETS:.exe=.c)
OBJS=$(SRCS:.c=.obj)
EXAMPLES=input.exe basecvt.exe rounding.exe

.c.obj:
	$(CC) $(CFLAGS) -c $<

all: objs examples test

objs: $(OBJS)

# Because Visual Studio does not permit Unix shell syntax, you will
# have to run the tests manually once the "test" target is built.
test: imtest.exe pi.exe
#	@ echo ""
#	@ echo "Running tests, you should not see any 'FAILED' lines here."
#	@ echo "If you do, please see doc.txt for how to report a bug."
#	@ echo ""
#	(cd tests && ./test.sh)

$(EXAMPLES): imath.obj imrat.obj iprime.obj examples/$*.obj
	@move $*.obj examples/$*.obj
	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)

examples: $(EXAMPLES)

imtest.exe: imtest.obj imath.obj imrat.obj imdrover.obj
	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)

pi.exe: pi.obj imath.obj
	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)

findprime.exe: findprime.obj imath.obj iprime.obj
	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)

rtest.exe: rtest.obj imath.obj rsamath.obj
	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)

bintest.exe: imath.obj bintest.obj
	$(LD) $(LDFLAGS) -out:$@ $** $(LIBS)

clean:
	del /q /f *.exe *.obj examples\*.obj

# End of Makefile.msvc
