####################################################
#                                                  #
#     JGMOD makefile by Henrik Stokseth            #
#                                                  #
####################################################

CPLIBDEST = $(subst /,\,$(MINGDIR)/lib)
CPINCDEST = $(subst /,\,$(MINGDIR)/include)

OBJ_DIR = ../obj/mingw32

LIB_DIR = ../lib/mingw32
LIB_FILE = libjgmod.a
LIB_NAME = $(LIB_DIR)/$(LIB_FILE)

#check if MingW32 enviroment string is set
ifdef MINGDIR
MINGDIR_U = $(subst \,/,$(MINGDIR))
MINGDIR_D = $(subst /,\,$(MINGDIR))
else
badming:
	@echo Your MINGDIR environment variable is not set!
endif

NULLSTRING :=
SPACE := $(NULLSTRING) # special magic to get an isolated space character

ifneq ($(findstring $(SPACE),$(MINGDIR)),)
badspaces:
	@echo There are spaces in your MINGDIR environment variables:
	@echo please change these to the 8.3 short filename version,
	@echo or move your compiler to a different directory.
endif


include makefile.lst

CFLAGS = -O3 -W -Wno-unused -Wall -m486 -ffast-math -fomit-frame-pointer -funroll-loops
LFLAGS = -s


all : $(OBJ_LIST) $(LIB_NAME) winjgmod.exe winjgm.exe
	copy $(subst /,\,$(LIB_NAME)) $(MINGDIR_D)\lib
	copy jgmod.h $(MINGDIR_D)\include
	@echo Done. 
	@echo Please read readme.txt


include ..\obj\mingw32\makefile.dep

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

$(LIB_NAME) : $(OBJ_LIST)
	ar rs $(LIB_NAME) $(OBJ_LIST)

winjgmod.exe: jgmod.c jgmod.h $(LIB_NAME)
	gcc $(LFLAGS) jgmod.c -o winjgmod.exe $(LIB_NAME) -lalleg

winjgm.exe: jgm.c jgmod.h $(LIB_NAME)
	gcc $(LFLAGS) jgm.c -o winjgm.exe $(LIB_NAME) -lalleg


clean :
	del $(subst /,\,$(OBJ_DIR)/*.o)
	del $(subst /,\,$(LIB_NAME))
	del winjgmod.exe 
	del winjgm.exe


veryclean :
	del $(subst /,\,$(OBJ_DIR)/*.o)
	del $(subst /,\,$(LIB_NAME))
	del winjgmod.exe 
	del winjgm.exe
	del $(MINGDIR_D)\lib\$(LIB_FILE)
	del $(MINGDIR_D)\include\jgmod.h
