#
# Simple makefile to build a library for Win32
#
# This makefile assumes Borland bcc32 development environment
# on Windows NT/9x/2000/XP
#

!ifndef BORLAND_DIR
BORLAND_DIR_Not_Defined:
	@echo .
	@echo You must define environment variable BORLAND_DIR to compile.
!endif

TARGET = bacnet
LIBRARY = $(TARGET).lib

CC = $(BORLAND_DIR)\bin\bcc32
TLIB = $(BORLAND_DIR)\bin\tlib
MAKE = $(BORLAND_DIR)\bin\make

BACNET_DEFINES = -DPRINT_ENABLED=1 -DBACFILE -DBACAPP_ALL
BACDL_DEFINE=-DBACDL_BIP=1 -DUSE_INADDR=1
#BACDL_DEFINE=-DBACDL_MSTP=1
DEFINES = $(BACNET_DEFINES) $(BACDL_DEFINE)

# directories
BACNET_PORT = ..\ports\win32
BACNET_OBJECT = ..\demo\object
BACNET_HANDLER = ..\demo\handler
BACNET_CORE = ..\src
BACNET_INCLUDE = ..\include
INCLUDES = \
	-I$(BACNET_INCLUDE) \
	-I$(BACNET_PORT) \
	-I$(BACNET_OBJECT) \
	-I$(BACNET_HANDLER)

CORE1_SRC = $(BACNET_CORE)\indtext.c \
	$(BACNET_CORE)\key.c \
	$(BACNET_CORE)\keylist.c \
	$(BACNET_CORE)\proplist.c \
	$(BACNET_CORE)\debug.c \
	$(BACNET_CORE)\bigend.c \
	$(BACNET_CORE)\filename.c \
	$(BACNET_CORE)\memcopy.c \
	$(BACNET_CORE)\version.c

CORE2_SRC = $(BACNET_CORE)\apdu.c \
	$(BACNET_CORE)\npdu.c \
	$(BACNET_CORE)\bacdcode.c \
	$(BACNET_CORE)\bacint.c \
	$(BACNET_CORE)\bacreal.c \
	$(BACNET_CORE)\bacstr.c \
	$(BACNET_CORE)\bacapp.c \
	$(BACNET_CORE)\bacprop.c \
	$(BACNET_CORE)\bactext.c \
	$(BACNET_CORE)\datetime.c \
	$(BACNET_CORE)\abort.c \
	$(BACNET_CORE)\reject.c \
	$(BACNET_CORE)\bacerror.c \
	$(BACNET_CORE)\tsm.c \
	$(BACNET_CORE)\bacaddr.c \
	$(BACNET_CORE)\address.c

CORE3_SRC = $(BACNET_CORE)\arf.c \
	$(BACNET_CORE)\awf.c \
	$(BACNET_CORE)\cov.c \
	$(BACNET_CORE)\dcc.c \
	$(BACNET_CORE)\iam.c \
	$(BACNET_CORE)\ihave.c \
	$(BACNET_CORE)\ptransfer.c \
	$(BACNET_CORE)\rd.c \
	$(BACNET_CORE)\rp.c \
	$(BACNET_CORE)\rpm.c \
	$(BACNET_CORE)\timesync.c \
	$(BACNET_CORE)\whohas.c \
	$(BACNET_CORE)\whois.c \
	$(BACNET_CORE)\wp.c \
	$(BACNET_CORE)\wpm.c

CORE4_SRC = $(BACNET_CORE)\bacdevobjpropref.c \
	$(BACNET_CORE)\bacpropstates.c \
	$(BACNET_CORE)\alarm_ack.c \
	$(BACNET_CORE)\event.c \
	$(BACNET_CORE)\getevent.c \
	$(BACNET_CORE)\readrange.c \
	$(BACNET_CORE)\timestamp.c

HANDLER_SRC = \
	$(BACNET_HANDLER)\dlenv.c \
	$(BACNET_HANDLER)\txbuf.c \
	$(BACNET_HANDLER)\noserv.c \
	$(BACNET_HANDLER)\h_whois.c \
	$(BACNET_HANDLER)\h_npdu.c \
	$(BACNET_HANDLER)\h_iam.c  \
	$(BACNET_HANDLER)\h_rp.c \
	$(BACNET_HANDLER)\h_rp_a.c \
	$(BACNET_HANDLER)\h_rpm.c \
	$(BACNET_HANDLER)\h_rpm_a.c \
	$(BACNET_HANDLER)\h_wp.c  \
	$(BACNET_HANDLER)\h_wpm.c  \
	$(BACNET_HANDLER)\h_arf.c  \
	$(BACNET_HANDLER)\h_arf_a.c  \
	$(BACNET_HANDLER)\h_awf.c  \
	$(BACNET_HANDLER)\h_rd.c  \
	$(BACNET_HANDLER)\h_dcc.c  \
	$(BACNET_HANDLER)\h_ts.c  \
	$(BACNET_HANDLER)\h_whohas.c  \
	$(BACNET_HANDLER)\h_ihave.c  \
	$(BACNET_HANDLER)\h_cov.c  \
	$(BACNET_HANDLER)\h_ccov.c  \
	$(BACNET_HANDLER)\h_ucov.c  \
	$(BACNET_HANDLER)\s_arfs.c \
	$(BACNET_HANDLER)\s_awfs.c \
	$(BACNET_HANDLER)\s_dcc.c \
	$(BACNET_HANDLER)\s_ihave.c \
	$(BACNET_HANDLER)\s_iam.c  \
	$(BACNET_HANDLER)\s_cov.c  \
	$(BACNET_HANDLER)\s_rd.c \
	$(BACNET_HANDLER)\s_router.c  \
	$(BACNET_HANDLER)\s_rp.c  \
	$(BACNET_HANDLER)\s_rpm.c  \
	$(BACNET_HANDLER)\s_ts.c \
	$(BACNET_HANDLER)\s_cevent.c \
	$(BACNET_HANDLER)\s_uevent.c \
	$(BACNET_HANDLER)\s_whohas.c \
	$(BACNET_HANDLER)\s_whois.c  \
	$(BACNET_HANDLER)\s_ptransfer.c  \
	$(BACNET_HANDLER)\h_upt.c  \
	$(BACNET_HANDLER)\h_pt.c  \
	$(BACNET_HANDLER)\h_pt_a.c  \
	$(BACNET_HANDLER)\h_rr.c \
	$(BACNET_HANDLER)\s_upt.c  \
	$(BACNET_HANDLER)\s_wp.c

OBJECT_SRC = $(BACNET_OBJECT)\device.c \
	$(BACNET_OBJECT)\ai.c \
	$(BACNET_OBJECT)\ao.c \
	$(BACNET_OBJECT)\av.c \
	$(BACNET_OBJECT)\bi.c \
	$(BACNET_OBJECT)\bo.c \
	$(BACNET_OBJECT)\bv.c \
	$(BACNET_OBJECT)\csv.c \
	$(BACNET_OBJECT)\lc.c \
	$(BACNET_OBJECT)\lsp.c \
	$(BACNET_OBJECT)\ms-input.c \
	$(BACNET_OBJECT)\mso.c \
	$(BACNET_OBJECT)\msv.c \
	$(BACNET_OBJECT)\trendlog.c \
	$(BACNET_OBJECT)\bacfile.c

PORT_SRC = $(BACNET_PORT)\bip-init.c \
	$(BACNET_PORT)\rs485.c \
	$(BACNET_PORT)\dlmstp.c \
	$(BACNET_PORT)\timer.c \
	$(BACNET_CORE)\crc.c \
	$(BACNET_CORE)\mstp.c \
	$(BACNET_CORE)\mstptext.c \
	$(BACNET_CORE)\bvlc.c \
	$(BACNET_CORE)\bip.c

CORE1_OBJ = ${CORE1_SRC:.c=.obj}
CORE2_OBJ = ${CORE2_SRC:.c=.obj}
CORE3_OBJ = ${CORE3_SRC:.c=.obj}
CORE4_OBJ = ${CORE4_SRC:.c=.obj}
PORT_OBJ = ${PORT_SRC:.c=.obj}
HANDLER_OBJ = ${HANDLER_SRC:.c=.obj}
OBJECT_OBJ = ${OBJECT_SRC:.c=.obj}

OBJS = ${CORE1_OBJ} \
	${CORE2_OBJ} \
	${CORE3_OBJ} \
	${CORE4_OBJ} \
	${PORT_OBJ} \
	${HANDLER_OBJ} \
	${OBJECT_OBJ}

DEL = ${OBJS:.obj=.del}

# Compiler definitions
#
BCC_CFG = bcc32.cfg

# Include directories
#
INCL_DIRS = -I$(BORLAND_DIR)\include $(INCLUDES)

CFLAGS = $(INCL_DIRS) $(CS_FLAGS) $(DEFINES)
LFLAGS = /E /P4096

# 'all' should be the first one in the makefile

all: $(BCC_CFG) $(OBJS) makefile.b32 $(LIBRARY)
	@echo Finished!

clean: ${DEL}
	del ${LIBRARY}
	del ${BCC_CFG}
#
# Generic rules
#
.SUFFIXES: .cpp .c .sbr .obj .del

#
# cc generic rule
#
.c.obj:
	$(CC) +$(BCC_CFG) -o$@ $<
	$(TLIB) $(LIBRARY) $(LFLAGS) -+"$@"

# delete rule - to delete one at a time
.obj.del:
	del $**

# Compiler configuration file
$(BCC_CFG) :
	Copy &&|
	$(CFLAGS)
	-c
	-y     #include line numbers in OBJ's
	-v     #include debug info
	-w+    #turn on all warnings
	-O2    #optimization 2
	-WM    #multithread
	-w-aus # ignore warning assigned a value that is never used
	-w-sig # ignore warning conversion may lose sig digits
	#-Od    #disable all optimizations
	#-a4    #32 bit data alignment
	#-M     # generate link map
	#-ls    # linker options
	#-WM-   #not multithread
| $@

# EOF: makefile
