# 
# $Id$
#
# The Harbour Project
# GNU MAKE file for Borland C/C++ 3.x, 4.x, 5.0x

include $(TOP)$(ROOT)config/$(HB_ARCHITECTURE)/global.cf

OBJ_EXT = .obj
EXE_EXT = .exe
LIB_PREF =
LIB_EXT = .lib

$(HB_ARCHITECTURE)_$(HB_COMPILER)_GRANDP = $(subst /,\\,$(GRANDP))
_HB_INC_COMPILE = $(subst /,\\,$(HB_INC_COMPILE))
_HL = $(notdir $(HB_LIB_COMPILE))
ifeq ($(_HL),)
#there is an ending slash
_HB_LIB_COMPILE = $(subst /,\\,$(HB_LIB_COMPILE))
else
_HB_LIB_COMPILE = $(subst /,\\,$(HB_LIB_COMPILE)/)
endif

CC = bcc
CC_IN = -c
CC_OUT = -o
CPPFLAGS = -I$($(HB_ARCHITECTURE)_$(HB_COMPILER)_GRANDP) -I$(_HB_INC_COMPILE)
CFLAGS = -i48 -O2 -mh -d -DHB_LONG_LONG_OFF

# BCC (at least version 3.1) requires that the output file be listed ahead of the input file
CC_RULE = $(CC) $(CPPFLAGS) $(CFLAGS) $(C_USR) $(CC_OUT)$(?F:.c=$(OBJ_EXT)) $(CC_IN) $?


#Note: The empty line below HAVE TO exist!
define link_file
echo. $(file) >> __link__.tmp

endef


define link_exe_file
echo. $(LDFLAGS) -e$@ > __link__.tmp
$(foreach file, $(^F), $(link_file))
$(foreach file, $(LINKLIBS), $(link_file))
-$(LD) @__link__.tmp
endef

LD = bcc
LDFLAGS = -i48 -O2 -mh $(L_USR)
ifeq ($(HB_LIB_COMPILE),)
LINKLIBS += $(foreach lib, $(CONTRIBS), $(TOP)$(ROOT)contrib/$(lib)/$(HB_ARCH)/$(subst lib,,$(lib))$(LIB_EXT))
LINKLIBS += $(foreach lib, $(LIBS), $(TOP)$(ROOT)source/$(lib)/$(HB_ARCH)/$(lib)$(LIB_EXT))
ifeq ($(findstring rdd,$(LIBS)),rdd)
LINKLIBS += $(foreach lib, $(HB_DB_DRIVERS), $(TOP)$(ROOT)source/rdd/$(lib)/$(HB_ARCH)/$(lib)$(LIB_EXT))
endif
else
LINKLIBS += $(foreach lib, $(CONTRIBS), $(subst lib,,$(lib))$(LIB_EXT))
LINKLIBS += $(foreach lib, $(LIBS), $(lib)$(LIB_EXT))
ifeq ($(findstring rdd,$(LIBS)),rdd)
LINKLIBS += $(foreach lib, $(HB_DB_DRIVERS), $(lib)$(LIB_EXT))
endif
endif
LD_RULE = $(link_exe_file)

# Add the specified GT driver library
ifeq ($(findstring rtl,$(LIBS)),rtl)
ifeq ($(HB_LIB_COMPILE),)
LINKLIBS += $(foreach gt, $(HB_GT_LIBS), $(TOP)$(ROOT)source/rtl/$(gt)/$(HB_ARCH)/$(gt)$(LIB_EXT))
else
LINKLIBS += $(foreach gt, $(HB_GT_LIBS), $(gt)$(LIB_EXT))
endif
endif

#Note: The empty line below HAVE TO exist!
define lib_object
echo. -+$(file) &>> __lib__.tmp

endef

define create_library
echo. $@ &> __lib__.tmp
$(foreach file, $(^F), $(lib_object))
echo. ,, >> __lib__.tmp
$(AR) $(ARFLAGS) @__lib__.tmp
del __lib__.tmp
endef

AR = tlib
ARFLAGS = /C $(A_USR)
AR_RULE = $(create_library)

include $(TOP)$(ROOT)config/rules.cf
