
COMPILER = dmc

ifeq ($(findstring /sh.exe, $(SHELL)), /sh.exe)
UNIX_TOOLS=1
DATA_INSTALLER = cp -f
PROG_INSTALLER = cp -f
else
DATA_INSTALLER = copy /y
PROG_INSTALLER = copy /y
endif

CC = dmc
AR = lib

include make/makefile.lst
EXT_HEADERS += $(EXT_HEADERS_PATH)/wgl_ext_defs.h $(EXT_HEADERS_PATH)/wgl_ext_api.h $(EXT_HEADERS_PATH)/wgl_ext_list.h $(EXT_HEADERS_PATH)/wgl_ext_alias.h


FLAGS = -mn -Jm

ifdef DEBUGMODE
FLAGS += -DDEBUGMODE -g
ifdef LOGLEVEL
FLAGS += -DLOGLEVEL=$(LOGLEVEL)
endif
else
FLAGS += -o -6
endif

ifdef STATICALLEGRO
FLAGS += -DALLEGRO_STATICLINK
ALLEGRO_LIB = alleg_s.lib
else
ALLEGRO_LIB = alleg.lib
endif


SRC_DIR_U = $(subst \,/,$(SRC_DIR))
SRC_DIR_D = $(subst /,\,$(SRC_DIR))

OBJ_DIR_U = $(subst \,/,$(OBJ_DIR))
OBJ_DIR_D = $(subst /,\,$(OBJ_DIR))

EXAMPLE_DIR_U = $(subst \,/,$(EXAMPLE_DIR))
EXAMPLE_DIR_D = $(subst /,\,$(EXAMPLE_DIR))

LIB_PATH_U = $(subst \,/,$(LIB_DIR))/$(LIB_NAME).lib
LIB_PATH_D = $(subst /,\,$(LIB_DIR))\$(LIB_NAME).lib

DLL_PATH_U = $(subst \,/,$(LIB_DIR))/$(LIB_NAME).dll

HEADERS_U = $(subst \,/,$(HEADERS))
HEADERS_D = $(subst /,\,$(HEADERS))
EXT_HEADERS_U = $(subst \,/,$(EXT_HEADERS))
EXT_HEADERS_D = $(subst /,\,$(EXT_HEADERS))
EXT_HEADERS_PATH_U = $(subst \,/,$(EXT_HEADERS_PATH))
EXT_HEADERS_PATH_D = $(subst /,\,$(EXT_HEADERS_PATH))

INCLUDE_PATHS = $(addprefix -I, $(INCLUDE_DIR))

SOURCE = $(C_SOURCE) $(WIN_SOURCE)
OBJECTS = $(addprefix $(OBJ_DIR_U)/, $(addsuffix .obj, $(basename $(notdir $(SOURCE)))))
EXAMPLES = $(addsuffix .exe, $(basename $(addprefix $(EXAMPLE_DIR)/, $(EXAMP_SOURCE))))

COMPILER_LINK_LIB = $(addsuffix .lib, $(LINK_LIB)) user32.lib gdi32.lib glu32.lib opengl32.lib

ifdef STATICALLEGRO
COMPILER_LINK_LIB += dsound.lib dinput.lib ddraw.lib winmm.lib dxguid.lib ole32.lib kernel32.lib
endif

COMPILER_LIB_DIR_U = $(DMCDIR_U)/lib
COMPILER_LIB_DIR_D = $(DMCDIR_D)\lib
COMPILER_INCLUDE_DIR_U = $(DMCDIR_U)/include
COMPILER_INCLUDE_DIR_D = $(DMCDIR_D)\include


#--------------------------------------#
#-- Check for environment variables ---#

.PHONY: badming

ifdef DMCDIR
  DMCDIR_U = $(subst \,/,$(DMCDIR))
  DMCDIR_D = $(subst /,\,$(DMCDIR))
else
badming:
	@echo Please specify your dmc directory via DMCDIR=.
	@echo Example: make DMCDIR=c:/dmc
endif


lib: $(LIB_PATH_U)
dll: $(DLL_PATH_U)
examples: $(EXAMPLES)

#----------------------------#
#---- Various targets -------#

include make/makefile.all


$(OBJ_DIR_U)/%.obj: $(SRC_DIR_U)/%.c $(addprefix include/,$(C_DEPEND)) $(EXT_HEADERS_U)
	$(CC) -c $< -o$@ $(FLAGS) $(INCLUDE_PATHS)

$(LIB_PATH_U): $(OBJECTS) $(HEADERS_U)
	$(AR) -c -p64 $@ $(OBJECTS)

$(DLL_PATH_U): $(OBJECTS) $(HEADERS_U)
	$(CC) -shared -o$@ $(OBJECTS) $(COMPILER_LINK_LIB)
	
$(EXAMPLE_DIR)/%.exe: $(EXAMPLE_DIR)/%.c $(HEADERS_U) $(LIB_PATH_U)
	$(CC) $< -o$(subst /,\,$@) -WA $(FLAGS) $(INCLUDE_PATHS) $(LIB_PATH_D) $(COMPILER_LINK_LIB) -L/EXETYPE:NT -L/SUBSYSTEM:WINDOWS

