
# -*- PIXIE-4 Makefile for Windows -*-

# The extension of an object file
OBJ := obj
# The extension of Igor Pro .xop
XOPLIB  := xop
# The extension of a dynamic library
DYNLIB  := dll
# The extension of a static library
STATLIB := lib

# The archiver
AR := lib

# This should be the compiler
CC := cl

# This should be the resource compiler
RC := rc

# Compiler flags
CFLAG_COMPILE 	:= -c
CFLAG_OUT     	:= /Fo
INCFLAGS 	:= /I "inc" /I "."
CFLAGS_LIB 	:= /nologo /Od /Zp2 /W3 /D "WIN32" /D "XIA_WINDOZE" /D "COMPILE_IGOR_XOP" \
                     /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" \
                     /D "PIXIELIB_EXPORTS" /FD /D "_CRT_SECURE_NO_DEPRECATE"



#CFLAGS_SAMPLE  := /nologo /Zp2 /W3 /Gm /ZI /Od /D "WIN32" /D "XIA_WINDOZE" \
#              /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" \
#             /D "PIXIELIB_EXPORTS" /FD /D "_CRT_SECURE_NO_DEPRECATE"

CFLAGS_SAMPLE  := /Zi /nologo /W1 /WX- /O2 /Oy- /Gm- /EHsc /GS /fp:precise /Zc:wchar_t \
               /Zc:forScope /Gd /analyze- /errorReport:queue  /D "WIN32" /D "XIA_WINDOZE" \
              /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" \
             /D "PIXIELIB_EXPORTS" /FD /D "_CRT_SECURE_NO_DEPRECATE"

# Resource compiler flags
RCFLAGS 	:= /v /l 0x409 /d "NDEBUG"
RCINCFLAGS 	:= /i"inc"

# This should be the linker
LINK := link

# Any flags that go before the object files in the linker pass
LINK_PRE_FLAGS := 

# Linker output flag
LINK_FLAG_OUT := /out:

# Dynamic linker flags
DYN_LIB_LINK_FLAGS := /NOLOGO /DLL /MANIFEST /NODEFAULTLIB:"libcmtd.lib" \
		      /MACHINE:X86 /ERRORREPORT:PROMPT /OPT:NOREF \
		      /libpath:"lib"
		      
# Static linker flags
STAT_LIB_LINK_FLAGS := /lib /libpath:"$(LIB_ROOT)" /machine:I386 \
                       /libpath:"c:\program files\microsoft visual studio 8\vc\lib" \
                       /out:"$(LIB_ROOT)\$(NAME).$(STATLIB)"

# Stock Win32 libraries
SYSTEM_LIBS := user32.lib version.lib
		
EXTRA_LIBS := winmm.lib IGOR.lib "XOPSupport.lib"

# Precompiled PLX library 
PLX_LIB := PlxApi.lib

EXTRA_FILES := *.idb *.xop *.ilk *.pch *.exp *.lib *.manifest *.pdb

XOPLIBNAME = Pixie

.SUFFIXES: .obj .res .rc

# PIXIE-4 library object files to create
LIBOBJS = Boot.$(OBJ) \
          ua_par_io.$(OBJ) \
          eeprom.$(OBJ) \
          pixie_c.$(OBJ) \
          utilities.$(OBJ) \
          globals.$(OBJ)

XOPLIBOBJS = pixie4_iface.$(OBJ) \
             pixie4_igor.$(OBJ)

SAMPLEOBJ = SamplePrograms/SampleBoot.$(OBJ) \
			SamplePrograms/SampleADCTrace.$(OBJ) \
			SamplePrograms/SampleMCARun.$(OBJ) \
			SamplePrograms/SampleListMode.$(OBJ) \
            SamplePrograms/SampleTest0x9100.$(OBJ)

XOPRCOBJS = PixieWinCustom.res

DYNXOPLIB  = Debug/$(PREFIX_LIB)$(XOPLIBNAME).$(XOPLIB)

# Targets
all: xop
.PHONY: all

.rc.res: 
	$(RC) $(RCFLAGS) $(RCINCFLAGS) $< 

.c.$(OBJ):
	$(CC) $(CFLAGS) $(INCFLAGS) $(CFLAG_COMPILE) $< $(CFLAG_OUT)$@

clean:
	-rm $(LIBOBJS) $(XOPLIBOBJS) $(XOPRCOBJS) $(SAMPLEOBJ) 
	-rm SamplePrograms/SampleBoot.exe
	-rm SamplePrograms/SampleADCTrace.exe
	-rm SamplePrograms/SampleMCARun.exe
	-rm SamplePrograms/SampleListMode.exe 
	-rm SamplePrograms/SampleTest0x9100.exe 
	-rm Debug/*.manifest $(EXTRA_FILES) Debug/*.xop
.PHONY: clean

xop: CFLAGS = $(CFLAGS_LIB)
xop: clean $(LIBOBJS) $(XOPLIBOBJS) $(XOPRCOBJS)
	$(LINK) $(LINK_PRE_FLAGS) $(DYN_LIB_LINK_FLAGS) \
		$(LINK_FLAG_OUT)$(DYNXOPLIB) \
		$(LIBOBJS) $(XOPLIBOBJS) $(XOPRCOBJS) $(PLX_LIB) $(EXTRA_LIBS) $(SYSTEM_LIBS)
.PHONY: xop

sample: CFLAGS = $(CFLAGS_SAMPLE)
sample: clean $(LIBOBJS) $(SAMPLEOBJ)
	$(LINK) $(LINK_FLAG_OUT)SamplePrograms/SampleBoot.exe       $(LIBOBJS) SamplePrograms/SampleBoot.$(OBJ)       $(PLX_LIB) $(SYSTEM_LIBS) /libpath:"lib"
	$(LINK) $(LINK_FLAG_OUT)SamplePrograms/SampleADCTrace.exe   $(LIBOBJS) SamplePrograms/SampleADCTrace.$(OBJ)   $(PLX_LIB) $(SYSTEM_LIBS) /libpath:"lib"
	$(LINK) $(LINK_FLAG_OUT)SamplePrograms/SampleMCARun.exe     $(LIBOBJS) SamplePrograms/SampleMCARun.$(OBJ)     $(PLX_LIB) $(SYSTEM_LIBS) /libpath:"lib"
	$(LINK) $(LINK_FLAG_OUT)SamplePrograms/SampleListMode.exe   $(LIBOBJS) SamplePrograms/SampleListMode.$(OBJ)   $(PLX_LIB) $(SYSTEM_LIBS) /libpath:"lib"
	$(LINK) $(LINK_FLAG_OUT)SamplePrograms/SampleTest0x9100.exe $(LIBOBJS) SamplePrograms/SampleTest0x9100.$(OBJ) $(PLX_LIB) $(SYSTEM_LIBS) /libpath:"lib"
.PHONY: sample

