# this is a Makefile that can be used to create template.so on Windows
#
# to use this:
#     cd <into-the-current-directory>
#     nmake /f NMakefile
#
# to remove temporary files:
#     nmake /f NMakefile clean
#
# to remove all files from prior builds
#     nmake /f NMakefile cleanall
#
# to rebuild from scratch
#     make /f NMakefile rebuild
#
# to test execution and sensitivities
#     make /f NMakefile test

# make sure environment is properly set up
!IFNDEF ESP_ROOT
!ERROR ESP_ROOT must be set -- Please fix the environment...
!ENDIF
!IFNDEF ESP_ARCH
!ERROR ESP_ARCH must be set -- Please fix the environment...
!ENDIF

# define the directories that hold the header and library files
IDIR  = $(ESP_ROOT)\include
LDIR  = $(ESP_ROOT)\lib

# set up environment variables that are appropriate for this architecture
!include $(IDIR)\$(ESP_ARCH).$(MSVC)

# default is to build template.so
default:	$(LDIR)\template.dll

# build directions for the various needed files
$(LDIR)\template.dll:	template.obj
	-del $(LDIR)\template.dll $(LDIR)\template.lib $(LDIR)\template.exp
	link /out:$(LDIR)\template.dll /dll /def:%ESP_ROOT%\src\OpenCSM\udp.def template.obj $(LDIR)\ocsm.lib $(LDIR)\egads.lib
	$(MCOMP) /manifest $(LDIR)\template.dll.manifest /outputresource:$(LDIR)\template.dll;2

template.obj:	template.c
	cl /c $(COPTS) $(DEFINE) /I$(IDIR) template.c

# dependencies on .h files
template.c:		$(IDIR)\udpUtilities.h $(IDIR)\udpUtilities.c
$(IDIR)\udpUtilities.h:	$(IDIR)\udp.h          $(IDIR)\egads.h
$(IDIR)\udpUtilities.c: $(IDIR)\OpenCSM.h      $(IDIR)\common.h

# remove temporary files
clean:
	-del template.obj

# remove all files from a previous build
cleanall:	clean
	-del $(LDIR)\template.dll

# rebuild from scratch
rebuild:	cleanall default

# test execution and sensitivities
test:	default
	serveESP -batch -verify template_1.csm
	sensCSM  -geom          template_1.csm
	sensCSM  -tess          template_1.csm
	-del port*.jrnl
	-del bad.triangles
