#####
# Paths
#####

# This path should point to where the icmp files are.
!ifndef ICMP_DIR
ICMP_DIR=../icmp_dev-0.1.1
!endif
ICMP_INCLUDE=$(ICMP_DIR)
ICMP_LIB=$(ICMP_DIR)/i386

# This is where you want the compiler to put the binaries
# (including bing.exe).
BIN=bin

#####
# Macro definitions
#####

# General options
APPVER = 4.0
TARGETOS = BOTH
TARGETLANG = LANG_FRENCH
CPU=i386
!ifndef DEBUG
NODEBUG=1
!endif

!include <win32.mak>

# compilation
!ifdef BROWSER
cbrowser=-FR$(*D)/ 
!endif

!ifdef DEBUG
cdebug=-Od -Zi -Fd$(*D)/ 
!endif

!ifdef DLL
bing_cvars=$(cvarsdll)
!else
bing_cvars=$(cvars)
!endif

bing_cvars=-nologo $(bing_cvars) $(cdebug) $(cbrowser) -D$(CPU) -DNO_RANDOM -I$(ICMP_INCLUDE) -I. -Iinclude -c -Fo$(*D)/ 

# linking
!ifdef DEBUG
!ifdef DLL
ldebug=-debug msvcrtd.lib
!else
ldebug=-debug libcd.lib
!endif
!endif

bing_lflags=-nologo -nodefaultlib $(ldebug) -out:$@

!ifdef DLL
bing_libs=$(conlibsdll)
!else
bing_libs=$(conlibs)
!endif

bing_libs=$(bing_libs) wsock32.lib $(ICMP_LIB)/icmp.lib 

######
# What to do
######

L_OBJS= \
	$(BIN)/bing.obj \
	$(BIN)/icmp_win32.obj \
	$(BIN)/getopt.obj \

L_EXE= \
	$(BIN)/bing.exe \

L_BSC= \
!ifdef BROWSER
	$(BIN)/bing.bsc \
!endif

all:	bin_dir $(L_EXE) $(L_BSC)

clean:
	if exist $(BIN)\*.obj del $(BIN)\*.obj
	if exist $(BIN)\*.exe del $(BIN)\*.exe
	if exist $(BIN)\*.ilk del $(BIN)\*.ilk
	if exist $(BIN)\*.pdb del $(BIN)\*.pdb
	if exist $(BIN)\*.sbr del $(BIN)\*.sbr
	if exist $(BIN)\*.bsc del $(BIN)\*.bsc
	if exist $(BIN)\nul rmdir $(BIN)

bin_dir:
	-if not exist $(BIN)\nul mkdir $(BIN)

help:
	@echo "Usage: nmake -f makefile.nt [DLL=1] [DEBUG=1] [BROWSER=1] [all | clean | help]
	@echo "
	@echo "   DLL=1
	@echo "      Causes bing to be dynamically linked with the C library.
	@echo "   DEBUG=1
	@echo "      Set DEBUG to 1 to generate debugging information for bing
	@echo "   BROWSER=1
	@echo "      Use this option to generate information for the Microsoft browser
	@echo "
	@echo "   all
	@echo "      This causes bing to be built as specified by the options
	@echo "      above. This is the default action. Note that if you 
	@echo "      change the options you should probably do a 'make clean'
	@echo "      before you re-generate bing.
	@echo "   clean
	@echo "      This action deletes all the generated files *including* 'bing.exe'.
	@echo "   help
	@echo "      This action displays this help information.

######
# Commands
######

# compilation
$(L_OBJS):
	$(CC) $(bing_cvars) -o $*.obj $**

# link
$(L_EXE):
	$(link) $(bing_lflags) $(bing_libs) $**

# browser
!ifdef BROWSER
$(L_BSC):
	bscmake -nologo -o $@ $**
!endif

#####
# Dependencies
#####

$(BIN)/bing.obj: bing.c
$(BIN)/icmp_win32.obj: win32/icmp_win32.c
$(BIN)/getopt.obj: win32/getopt.c

$(BIN)/bing.exe: \
	$(BIN)/bing.obj \
	$(BIN)/icmp_win32.obj \
	$(BIN)/getopt.obj \

!ifdef BROWSER
$(BIN)/bing.bsc: \
	$(BIN)/bing.sbr \
	$(BIN)/icmp_win32.sbr \
	$(BIN)/getopt.sbr \
!endif
