TOP=..
S=.
CC=cl.exe
LINKER=link.exe
RSC=rc.exe
	
# debugging
#CFLAGS= -DSTRICT -GX -Od -Fdntptime.pdb -Zi -W3 -Zp
#LDBG=-DEBUG -PDB:ntptime.pdb
#RSC_PROJ=/l 0x409 /fontptime.res /d _DEBUG 

# no debugging
CFLAGS= -DSTRICT -GX -W3 -DACTIVATE_FTRACE=0
LDBG=
RSC_PROJ=/l 0x409 /fontptime.res /d NDEBUG 

OBJS=ntptime.res base-exception.obj enable-set-time.obj lasterr-exception.obj \
     log-directory.obj log-stuff.obj ms-to-ntp.obj ntp-long-fixed.obj \
     ntp-service.obj is-ras-active.obj raise-priority.obj regstuff.obj \
     simple-exception.obj wrap-service.obj wrap-winsock.obj ntp-events.obj \
     ntp-real-events.obj kiss-exception.obj

PROGS=ntptime.exe

all: $(PROGS)

ntptime.exe: ntptime.obj $(OBJS)
	$(LINKER) -SUBSYSTEM:windows -OUT:ntptime.exe $(LDBG) ntptime.obj \
	$(OBJS) kernel32.lib user32.lib advapi32.lib wsock32.lib

ntptime.res : ntptime.rc resource.h
	$(RSC) $(RSC_PROJ) $(S)\ntptime.rc

base-exception.obj: $(S)\base-exception.cpp $(S)\base-exception.h
	$(CC) $(CFLAGS) -c -Tp $(S)\base-exception.cpp

enable-set-time.obj: $(S)\base-exception.h $(S)\enable-set-time.cpp \
        $(S)\enable-set-time.h $(S)\lasterr-exception.h
	$(CC) $(CFLAGS) -c -Tp $(S)\enable-set-time.cpp

lasterr-exception.obj: $(S)\base-exception.h $(S)\lasterr-exception.cpp \
        $(S)\lasterr-exception.h
	$(CC) $(CFLAGS) -c -Tp $(S)\lasterr-exception.cpp

log-directory.obj: $(S)\log-directory.cpp $(S)\log-directory.h \
	$(S)\wrap-critical.h $(S)\log-stuff.h
	$(CC) $(CFLAGS) -c -Tp $(S)\log-directory.cpp

log-stuff.obj: $(S)\log-stuff.cpp $(S)\log-stuff.h $(S)\wrap-critical.h
	$(CC) $(CFLAGS) -c -Tp $(S)\log-stuff.cpp

ms-to-ntp.obj: $(S)\ms-to-ntp.cpp $(S)\ms-to-ntp.h
	$(CC) $(CFLAGS) -c -Tp $(S)\ms-to-ntp.cpp

ntp-long-fixed.obj: $(S)\ms-to-ntp.h $(S)\ntp-long-fixed.cpp \
        $(S)\ntp-long-fixed.h
	$(CC) $(CFLAGS) -c -Tp $(S)\ntp-long-fixed.cpp

ntp-service.obj: $(S)\base-exception.h $(S)\enable-set-time.h \
        $(S)\lasterr-exception.h $(S)\log-directory.h $(S)\log-stuff.h \
	$(S)\ntp-long-fixed.h $(S)\ntp-packet.h $(S)\ntp-service.cpp \
	$(S)\ntp-service.h $(S)\raise-priority.h $(S)\regstuff.h \
	$(S)\wrap-critical.h $(S)\wrap-service.h $(S)\wrap-socket.h \
	$(S)\wrap-winsock.h $(S)\ntp-events.h $(S)\ntp-real-events.h
	$(CC) $(CFLAGS) -c -Tp $(S)\ntp-service.cpp

is-ras-active.obj: $(S)\base-exception.h $(S)\enable-set-time.h \
        $(S)\lasterr-exception.h $(S)\log-directory.h $(S)\log-stuff.h \
	$(S)\ntp-long-fixed.h $(S)\ntp-packet.h $(S)\is-ras-active.cpp \
	$(S)\ntp-service.h $(S)\raise-priority.h $(S)\regstuff.h \
	$(S)\wrap-critical.h $(S)\wrap-service.h $(S)\wrap-socket.h \
	$(S)\wrap-winsock.h
	$(CC) $(CFLAGS) -c -Tp $(S)\is-ras-active.cpp

ntptime.obj: $(S)\base-exception.h $(S)\lasterr-exception.h \
	$(S)\log-directory.h $(S)\log-stuff.h \
        $(S)\ntp-service.h $(S)\ntptime.cpp $(S)\wrap-critical.h \
        $(S)\wrap-service.h
	$(CC) $(CFLAGS) -c -Tp $(S)\ntptime.cpp

raise-priority.obj: $(S)\base-exception.h $(S)\lasterr-exception.h \
        $(S)\raise-priority.cpp $(S)\raise-priority.h
	$(CC) $(CFLAGS) -c -Tp $(S)\raise-priority.cpp

regstuff.obj: $(S)\base-exception.h $(S)\lasterr-exception.h \
        $(S)\regstuff.cpp $(S)\regstuff.h $(S)\simple-exception.h
	$(CC) $(CFLAGS) -c -Tp $(S)\regstuff.cpp

simple-exception.obj: $(S)\base-exception.h $(S)\simple-exception.cpp \
        $(S)\simple-exception.h
	$(CC) $(CFLAGS) -c -Tp $(S)\simple-exception.cpp

wrap-service.obj: $(S)\log-directory.h $(S)\log-stuff.h $(S)\wrap-critical.h \
	$(S)\wrap-sc-handle.h $(S)\wrap-service.cpp $(S)\wrap-service.h
	$(CC) $(CFLAGS) -c -Tp $(S)\wrap-service.cpp

wrap-winsock.obj: $(S)\base-exception.h $(S)\lasterr-exception.h \
        $(S)\simple-exception.h $(S)\wrap-winsock.cpp $(S)\wrap-winsock.h
	$(CC) $(CFLAGS) -c -Tp $(S)\wrap-winsock.cpp

ntp-events.obj: $(S)\ntp-events.h $(S)\ntp-events.cpp
	$(CC) $(CFLAGS) -c -Tp $(S)\ntp-events.cpp

ntp-real-events.obj: $(S)\ntp-events.h $(S)\ntp-real-events.cpp \
	$(S)\ntp-real-events.h $(S)\events.h $(S)\lasterr-exception.h \
	$(S)\simple-exception.h $(S)\log-stuff.h
	$(CC) $(CFLAGS) -c -Tp $(S)\ntp-real-events.cpp

kiss-exception.obj: $(S)\base-exception.h $(S)\kiss-exception.cpp \
        $(S)\kiss-exception.h
	$(CC) $(CFLAGS) -c -Tp $(S)\kiss-exception.cpp

clean:
	rm -f ntptime.obj $(OBJS) $(PROGS)
