#
# $Id$
#

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

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

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

LD = gcc
LDFLAGS =
LD_OUT = -o $(SPACE)

# 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
#LINKLIBS += -Wl,-(
LINKLIBS += $(foreach lib, $(LIBS), -l$(lib))

# 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

#LINKLIBS += -Wl,-)
LDFLAGS += $(LINKPATHS)

# Note: The empty line directly before 'endef' HAVE TO exist!
# It causes that every echo command will be separated by LF
define lib_object
echo ADDMOD $(file) >> __lib__.tmp

endef

# We have to use a script to overcome the AR limit of max 850 characters
# in commmand line
define create_library
IF EXIST $@ $(RM) $@
echo CREATE $@ > __lib__.tmp
$(foreach file, $^, $(lib_object))
echo SAVE >> __lib__.tmp
echo END >> __lib__.tmp
$(AR) -M < __lib__.tmp
endef

# Under OS/2 || isn't a command separator (inside a shell, that is); correct separator is &
AR = ar
ARFLAGS =
AR_RULE = $(create_library) & $(RM) __lib__.tmp

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