#
# $Id$
#

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

OBJ_EXT = .o
EXE_EXT = .exe
LIB_PREF = lib
LIB_EXT = .a

CC = gcc
CC_IN = -c
CC_OUT = -o
CPPFLAGS = -I. -I$(HB_INC_COMPILE) -mno-cygwin
CFLAGS = -Wall

LD = gcc
LD_OUT = -o

# Add all libraries specified in LIBS.
ifeq ($(HB_LIB_COMPILE),)
LINKPATHS += $(foreach lib, $(LIBS), -L$(TOP)$(ROOT)source/$(lib)/$(ARCH))
else
LINKPATHS += -L$(HB_LIB_COMPILE)
endif

# The -( option could be appropriate to link against libraries with
# cyclic dependencies, but I think it is not really necessary if the
# libraries are kept in proper order.
# LINKLIBS += -Wl,-(

LINKLIBS += $(foreach lib, $(LIBS), -l$(lib))

# This library is needed for CharToOemBuff() and OemToCharBuff() support.
LINKLIBS += -luser32

# If LIBS specifies the rdd library, add all DB drivers.
ifeq ($(findstring rdd,$(LIBS)),rdd)
LINKPATHS += $(foreach drv, $(HB_DB_DRIVERS), -L$(TOP)$(ROOT)source/rdd/$(drv)/$(ARCH))
LINKLIBS += $(foreach drv, $(HB_DB_DRIVERS), -l$(drv))
endif

# Add the specified GT driver library
ifeq ($(findstring rtl,$(LIBS)),rtl)
LINKPATHS += -L$(TOP)$(ROOT)source/rtl/$(HB_GT_LIB)/$(ARCH)
LINKLIBS += -l$(HB_GT_LIB)
endif

# HB_SCREEN_LIB: empty, or one of ncurses, slang
# HB_SCREEN_LIB=ncurses
# HB_SCREEN_LIB=slang

ifneq ($(HB_SCREEN_LIB),)
LINKLIBS += -l$(HB_SCREEN_LIB)
endif

# Add the optional user path(s)
ifneq ($(LNK_USR_PATH),)
LINKPATHS += $(foreach path, $(LNK_USR_PATH), -L$(path))
endif

# Add the optional user libarary (or libraries)
ifneq ($(LNK_USR_LIB),)
LINKLIBS += $(foreach lib, $(LNK_USR_LIB), -l$(lib))
endif

# The -) option could be appropriate to link against libraries with
# cyclic dependencies, but I think it is not really necessary if the
# libraries are kept in proper order.
# LINKLIBS += -Wl,-)

LDFLAGS = $(LINKPATHS) -mno-cygwin

AR = ar
ARFLAGS =
AR_RULE = $(AR) $(ARFLAGS) r $@ $^ || $(RM) $@

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