####################################################
#                                                  #
#     JGMOD makefile by Guan Foo Wah               #
#                                                  #
####################################################

LIBDEST = $(DJDIR)/lib
INCDEST = $(DJDIR)/include
CPLIBDEST = $(subst /,\,$(DJDIR)/lib)
CPINCDEST = $(subst /,\,$(DJDIR)/include)

OBJ_DIR = ../obj/djgpp

LIB_DIR = ../lib/djgpp
LIB_NAME = $(LIB_DIR)/libjgmod.a

include makefile.lst

CFLAGS = -O3 -W -Wno-unused -Wall -mcpu=pentium -ffast-math -fomit-frame-pointer -funroll-loops

#detect if UPX or DJP exe compressor is present
ifneq ($(wildcard $(DJDIR)/bin/upx.exe),)
DJP = $(DJDIR)/bin/upx.exe
else
ifneq ($(wildcard $(DJDIR)/bin/djp.exe),)
DJP = $(DJDIR)/bin/djp.exe -s
endif
endif


all : $(OBJ_LIST) $(LIB_NAME) jgmod.exe jgm.exe
	copy $(subst /,\,$(LIB_DIR)/libjgmod.a) $(CPLIBDEST)
	copy jgmod.h $(CPINCDEST)
	@echo Done. 
	@echo To compress the exes, type make compress
	@echo Please read readme.txt


include ../obj/djgpp/makefile.dep


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


$(LIB_NAME) : $(OBJ_LIST)
	ar rs $(LIB_NAME) $(OBJ_LIST)
	
jgmod.exe : jgmod.c jgmod.h $(LIB_NAME)
	gcc jgmod.c -o jgmod.exe -s $(LIB_NAME) -lalleg

jgm.exe : jgm.c jgmod.h port.h $(LIB_NAME)
	gcc jgm.c -o jgm.exe -s $(LIB_NAME) -lalleg


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


veryclean :
	del $(subst /,\,$(OBJ_DIR)/*.o)
	del $(subst /,\,$(LIB_NAME))
	del jgmod.exe 
	del jgm.exe
	del $(CPLIBDEST)\libjgmod.a 
	del $(CPINCDEST)\jgmod.h


compress: jgmod.exe jgm.exe
    ifneq ($(DJP),)
	@$(DJP) jgmod.exe jgm.exe
    else
	@echo No executable compressor found! This target requires either the
	@echo DJP or UPX utilities to be installed in your djgpp bin directory.
    endif
