# This makefile builds all executables required for the eCall testlab.
# If you use Microsoft NMAKE, ensure your environment is properly configured
# (via vcvars32.bat or similar).

dir_bin   = ..\bin
dir_ecall = ..\..\ecall

CFLAGS   = /nologo /W3 /GS- /D_CRT_SECURE_NO_DEPRECATE /I"$(dir_ecall)"
LFLAGS   = /nologo /OUT:"$(dir_bin)\$@"
LIBFLAGS = /nologo /OUT:"$(dir_bin)\$@"

targets = \
	testsim_demo.exe \
	testlab.exe \
	modem_demo.exe \
	modem_sim.lib \
	modem_sock.lib

win32_lib = WS2_32.LIB

objs_ecall = \
	"$(dir_ecall)\ecall_control.obj" \
	"$(dir_ecall)\ecall_fec.obj" \
	"$(dir_ecall)\ecall_modem.obj" \
	"$(dir_ecall)\ecall_rom.obj" \
	"$(dir_ecall)\ecall_sync.obj" \
	"$(dir_ecall)\modem_ivs.obj" \
	"$(dir_ecall)\modem_psap.obj"

hdrs_ecall = \
	"$(dir_ecall)\ecall_defines.h" \
	"$(dir_ecall)\ecall_control.h" \
	"$(dir_ecall)\ecall_fec.h" \
	"$(dir_ecall)\ecall_modem.h" \
	"$(dir_ecall)\ecall_rom.h" \
	"$(dir_ecall)\ecall_sync.h" \
	"$(dir_ecall)\modemx.h"

objs_sim   = error.obj option.obj ipc_sim.obj
objs_sock  = error.obj option.obj ipc_sock.obj
objs_modem = ivs.obj psap.obj modem.obj
objs_lab   = audio.obj channel.obj control.obj g711.obj process.obj
objs_demo  = $(objs_lab) $(objs_ecall) ivs.obj psap.obj

.SILENT:
default: $(targets)

clean:
	del $(objs_ecall) *.obj 2>NUL
	cd "$(dir_bin)" && del $(targets) 2>NUL

testsim_demo.exe: $(objs_sim) $(objs_demo) testlab_sim.obj
	echo $@
	link $(LFLAGS) $** $(win32_lib)

testlab.exe: $(objs_sock) $(objs_lab) testlab_sock.obj
	echo $@
	link $(LFLAGS) $** $(win32_lib)

modem_demo.exe: $(objs_sock) $(objs_modem) $(objs_ecall)
	echo $@
	link $(LFLAGS) $** $(win32_lib)

modem_sim.lib: $(objs_sim) $(objs_modem)
	echo $@
	lib $(LIBFLAGS) $**

modem_sock.lib: $(objs_sock) $(objs_modem)
	echo $@
	lib $(LIBFLAGS) $**

$(objs_ecall): $(hdrs_ecall)

.c.obj:
	$(CC) $(CFLAGS) /c $< /Fo$@
