include $(ROOT_DIR)/bld-mingw/xray_re_sources.inc
SOURCES += $(XRAY_RE_SOURCES)

###############################################################################
# Defaults

OBJ_DIR ?= $(ROOT_DIR)/bld-mingw/_obj
LIB_DIR ?= $(ROOT_DIR)/xray_re

CC := gcc
CFLAGS += -Wall -O2 -mno-cygwin -I$(LIB_DIR)

CXX := g++
CXXFLAGS += -Wall -Wno-unknown-pragmas -O2 -mno-cygwin -mfpmath=sse -msse -mthreads -I$(LIB_DIR)

LD := g++
LDFLAGS := -mno-cygwin -s

###############################################################################
# Vars

OBJS := $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(foreach file, $(SOURCES), $(basename $(notdir $(file))))))

SOURCE_PATHS := $(sort $(foreach file, $(SOURCES), $(subst /:,,$(addsuffix :, $(dir $(file))))))
LIB_PATHS := $(LIB_DIR)

VPATH := $(addprefix :, $(SOURCE_PATHS) $(LIB_PATHS))

###############################################################################
# Build

all: $(OBJ_DIR) $(OBJ_DIR)/$(TARGET)

$(OBJ_DIR):
	echo "$(VPATH)"
	@[ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1

$(OBJ_DIR)/$(TARGET): $(OBJ_DIR) $(OBJS)
	$(LD) -o $@ $(OBJS) $(LDFLAGS)

$(OBJ_DIR)/%.o: %.cxx
	$(CXX) -c $< $(CXXFLAGS) -o $@

$(OBJ_DIR)/%.o: %.cpp
	$(CXX) -c $< $(CXXFLAGS) -o $@

$(OBJ_DIR)/%.o: %.c
	$(CC) -c $< $(CFLAGS) -o $@

FORCE:

clean:
	@[ -d $(OBJ_DIR) ] && cd $(OBJ_DIR) && rm -f *.exe *.[aod]
