include ../../mkfile/common/RebuildTarget.mk
JABY_ENGINE_DIR = ../../

ARTIFACT  = libJabyEngine_$(PSX_TV_FORMAT)

SPLASH_IMAGE      = src/BootLoader/splash_image_pal_boot.hpp
SPLASH_IMAGE_NTSC = src/BootLoader/splash_image_ntsc_boot.hpp

CCFLAGS += -I../../include -D__friends=public
CCFLAGS += -save-temps=obj

include ../../mkfile/common/CustomConfigHelper.mk
CONFIG_NAME = $(PLATFORM)-$(BUILD_PROFILE)/$(CUSTOM_CONFIG)

include ../../mkfile/common/Wildcard.mk
SRCS = $(call rwildcard, src, c cpp s)

include ../../mkfile/Makefile
LIB_DIR = ../../lib/$(CONFIG_NAME)

MAIN_LIB_OBJS = $(filter-out $(MAIN_BOOT_OBJ) $(OVERLAY_BOOT_OBJ),$(OBJS))

#$(info $$var  is [${MAIN_BOOT_OBJ}])
#$(info $$var2 is [${MAIN_LIB_OBJS}])

#Linking rule
$(TARGET).a: $(MAIN_LIB_OBJS) $(SPLASH_IMAGE)
	@mkdir -p $(dir $@)
	$(AR) rcs $(TARGET).a $(MAIN_LIB_OBJS)

#Copy rules
$(LIB_DIR)/$(ARTIFACT).a: $(TARGET).a
	@mkdir -p $(LIB_DIR)
	cp $(TARGET).a $(LIB_DIR)/$(ARTIFACT).a

# rule to make the boot image
$(SPLASH_IMAGE): ressources/Splash.png
	psxfileconv --lz4 $< simple-tim full16 | cpp_out --name SplashScreen -o $@	

$(SPLASH_IMAGE_NTSC): ressources/Splash_ntsc.png
	psxfileconv --lz4 $< simple-tim full16 | cpp_out --name SplashScreen -o $@	

#Rules section for default compilation and linking
all: $(SPLASH_IMAGE) $(SPLASH_IMAGE_NTSC) $(LIB_DIR)/$(ARTIFACT).a 

clean:
	rm -fr $(SPLASH_IMAGE)
	rm -fr $(SPLASH_IMAGE_NTSC)
	rm -fr $(OUTPUT_DIR)
	rm -fr gcm.cache
	rm -fr $(LIB_DIR)/$(ARTIFACT).a