SOURCEDIR := $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword \
	$(MAKEFILE_LIST))))))

NAME := picodrive
JGNAME := $(NAME)-jg

CFLAGS ?= -O1

FLAGS := -std=gnu99 -falign-functions=2
DEFS += -DEMU_F68K -D_USE_CZ80 -DNDEBUG
WARNINGS := -Wall

SRCDIR := $(SOURCEDIR)/..

INCLUDES = -I$(SRCDIR)

LINKER = $(CC)

LIBS = -lm
LIBS_STATIC =

LIBS_REQUIRES :=

DOCS := ../AUTHORS ../COPYING README

# Object dirs
MKDIRS := cpu/cz80 \
	cpu/drc \
	cpu/fame \
	cpu/sh2/mame \
	pico/32x \
	pico/carthw/svp \
	pico/cd \
	pico/pico \
	pico/sound \
	platform/common \
	unzip

override INSTALL_DATA := 0
override INSTALL_EXAMPLE := 0
override INSTALL_SHARED := 0

include $(SOURCEDIR)/version.h
include $(SOURCEDIR)/mk/jg.mk

EXT := c

INCLUDES += $(CFLAGS_ZLIB)
LIBS += $(LIBS_ZLIB)

override REQUIRES_PRIVATE += $(PKGCONF_ZLIB)

CSRCS := cpu/cz80/cz80.c \
	cpu/drc/cmn.c \
	cpu/fame/famec.c \
	cpu/sh2/mame/sh2pico.c \
	cpu/sh2/sh2.c \
	pico/32x/32x.c \
	pico/32x/draw.c \
	pico/32x/memory.c \
	pico/32x/pwm.c \
	pico/32x/sh2soc.c \
	pico/carthw/carthw.c \
	pico/carthw/eeprom_spi.c \
	pico/carthw/svp/memory.c \
	pico/carthw/svp/ssp16.c \
	pico/carthw/svp/svp.c \
	pico/cd/cd_image.c \
	pico/cd/cdc.c \
	pico/cd/cdd.c \
	pico/cd/cue.c \
	pico/cd/gfx.c \
	pico/cd/gfx_dma.c \
	pico/cd/mcd.c \
	pico/cd/memory.c \
	pico/cd/misc.c \
	pico/cd/pcm.c \
	pico/cd/sek.c \
	pico/pico/memory.c \
	pico/pico/pico.c \
	pico/pico/xpcm.c \
	pico/sound/mix.c \
	pico/sound/sn76496.c \
	pico/sound/sound.c \
	pico/sound/ym2612.c \
	pico/cart.c \
	pico/debug.c \
	pico/draw.c \
	pico/draw2.c \
	pico/eeprom.c \
	pico/media.c \
	pico/memory.c \
	pico/misc.c \
	pico/mode4.c \
	pico/patch.c \
	pico/pico.c \
	pico/sek.c \
	pico/sms.c \
	pico/state.c \
	pico/videoport.c \
	pico/z80if.c \
	platform/common/mp3.c \
	platform/common/mp3_dummy.c \
	unzip/unzip.c

JGSRCS := jg.c

# List of object files
OBJS := $(patsubst %,$(OBJDIR)/%,$(CSRCS:.c=.o))
OBJS_JG := $(patsubst %,$(OBJDIR)/%,$(JGSRCS:.c=.o))

# Core commands
BUILD_JG = $(call COMPILE_C, $(FLAGS) $(WARNINGS) $(DEFS) $(INCLUDES) \
	$(CFLAGS_JG))
BUILD_MAIN = $(call COMPILE_C, $(FLAGS) $(WARNINGS) $(DEFS) $(INCLUDES))

.PHONY: $(PHONY)

all: $(TARGET)

# Core rules
$(OBJDIR)/%.o: $(SRCDIR)/%.$(EXT) $(PREREQ)
	$(call COMPILE_INFO,$(BUILD_MAIN))
	@$(BUILD_MAIN)

include $(SOURCEDIR)/mk/rules.mk
