INCFLAGS += \
	-I$(CORE_DIR)/src \
	-I$(CORE_DIR)/deps/dirent \
	-I$(CORE_DIR)/deps/gdb_server \
	-I$(CORE_DIR)/deps/inih \
	-I$(CORE_DIR)/deps/libretro/include \
	-I$(CORE_DIR)/deps/xbyak \
	-I$(LIBRETRO_DIR)

SOURCES_C := $(CORE_DIR)/src/core/assert.c \
	$(CORE_DIR)/src/file/trace.c \
	$(CORE_DIR)/src/core/filesystem.c \
	$(CORE_DIR)/src/core/interval_tree.c \
	$(CORE_DIR)/src/core/exception_handler.c \
	$(CORE_DIR)/src/core/list.c \
	$(CORE_DIR)/src/core/log.c \
	$(CORE_DIR)/src/core/md5.c \
	$(CORE_DIR)/src/core/ringbuf.c \
	$(CORE_DIR)/src/core/rb_tree.c \
	$(CORE_DIR)/src/core/sort.c \
	$(CORE_DIR)/src/core/profiler.c \
	$(CORE_DIR)/src/core/string.c \
	$(CORE_DIR)/src/guest/bios/bios.c \
	$(CORE_DIR)/src/guest/bios/flash.c \
	$(CORE_DIR)/src/guest/bios/syscalls.c \
	$(CORE_DIR)/src/guest/gdrom/cdi.c \
	$(CORE_DIR)/src/guest/gdrom/chd.c \
	$(CORE_DIR)/src/guest/gdrom/disc.c \
	$(CORE_DIR)/src/guest/gdrom/gdi.c \
	$(CORE_DIR)/src/guest/gdrom/gdrom.c \
	$(CORE_DIR)/src/guest/holly/holly.c \
	$(CORE_DIR)/src/guest/maple/controller.c \
	$(CORE_DIR)/src/guest/maple/maple.c \
	$(CORE_DIR)/src/guest/maple/vmu.c \
	$(CORE_DIR)/src/guest/pvr/pvr.c \
	$(CORE_DIR)/src/guest/pvr/ta.c \
	$(CORE_DIR)/src/guest/pvr/tex.c \
	$(CORE_DIR)/src/guest/pvr/tr.c \
	$(CORE_DIR)/src/guest/aica/aica.c \
	$(CORE_DIR)/src/guest/arm7/arm7.c \
	$(CORE_DIR)/src/guest/rom/boot.c \
	$(CORE_DIR)/src/guest/rom/flash.c \
	$(CORE_DIR)/src/guest/serial/serial.c \
	$(CORE_DIR)/src/guest/sh4/sh4.c \
	$(CORE_DIR)/src/guest/sh4/sh4_ccn.c \
	$(CORE_DIR)/src/guest/sh4/sh4_dbg.c \
	$(CORE_DIR)/src/guest/sh4/sh4_dmac.c \
	$(CORE_DIR)/src/guest/sh4/sh4_intc.c \
	$(CORE_DIR)/src/guest/sh4/sh4_mem.c \
	$(CORE_DIR)/src/guest/sh4/sh4_mmu.c \
	$(CORE_DIR)/src/guest/sh4/sh4_tmu.c \
	$(CORE_DIR)/src/guest/sh4/sh4_scif.c \
	$(CORE_DIR)/src/guest/debugger.c \
	$(CORE_DIR)/src/guest/dreamcast.c \
	$(CORE_DIR)/src/guest/memory.c \
	$(CORE_DIR)/src/guest/scheduler.c \
	$(CORE_DIR)/src/core/option.c \
	$(CORE_DIR)/src/core/memory.c \
	$(CORE_DIR)/src/host/keycode.c \
	$(CORE_DIR)/src/jit/backend/interp/interp_backend.c \
	$(CORE_DIR)/src/jit/frontend/armv3/armv3_context.c \
	$(CORE_DIR)/src/jit/frontend/armv3/armv3_disasm.c \
	$(CORE_DIR)/src/jit/frontend/armv3/armv3_fallback.c \
	$(CORE_DIR)/src/jit/frontend/armv3/armv3_frontend.c \
	$(CORE_DIR)/src/jit/frontend/sh4/sh4_disasm.c \
	$(CORE_DIR)/src/jit/frontend/sh4/sh4_fallback.c \
	$(CORE_DIR)/src/jit/frontend/sh4/sh4_frontend.c \
	$(CORE_DIR)/src/jit/frontend/sh4/sh4_translate.c \
	$(CORE_DIR)/src/jit/ir/ir.c \
	$(CORE_DIR)/src/jit/ir/ir_read.c \
	$(CORE_DIR)/src/jit/ir/ir_write.c \
	$(CORE_DIR)/src/jit/passes/constant_propagation_pass.c \
	$(CORE_DIR)/src/jit/passes/control_flow_analysis_pass.c \
	$(CORE_DIR)/src/jit/passes/conversion_elimination_pass.c \
	$(CORE_DIR)/src/jit/passes/dead_code_elimination_pass.c \
	$(CORE_DIR)/src/jit/passes/expression_simplification_pass.c \
	$(CORE_DIR)/src/jit/passes/load_store_elimination_pass.c \
	$(CORE_DIR)/src/jit/passes/register_allocation_pass.c \
	$(CORE_DIR)/src/jit/jit.c \
	$(CORE_DIR)/src/jit/pass_stats.c \
	$(CORE_DIR)/src/host/retro_host.c \
	$(CORE_DIR)/src/render/gl_backend.c \
	$(CORE_DIR)/src/emulator.c \
	$(CORE_DIR)/src/options.c \
	$(CORE_DIR)/src/stats.c

SOURCES_CXX := $(CORE_DIR)/src/imgui.cc

SOURCES_CPP :=

COREFLAGS += -DHAVE_FASTMEM

#==--------------------------------------------------------------------------==#
# inih
#==--------------------------------------------------------------------------==#
SOURCES_C += $(CORE_DIR)/deps/inih/ini.c \

#==--------------------------------------------------------------------------==#
# capstone
#==--------------------------------------------------------------------------==#
INCFLAGS += -I$(CORE_DIR)/deps/capstone/include
SOURCES_C += $(CORE_DIR)/deps/capstone/cs.c \
	$(CORE_DIR)/deps/capstone/utils.c \
	$(CORE_DIR)/deps/capstone/MCInst.c \
	$(CORE_DIR)/deps/capstone/MCInstrDesc.c \
	$(CORE_DIR)/deps/capstone/MCRegisterInfo.c \
	$(CORE_DIR)/deps/capstone/SStream.c \

ifeq ($(CAPSTONE_HAS_ARM), 1)
SOURCES_C += $(CORE_DIR)/deps/capstone/arch/ARM/ARMDisassembler.c \
	$(CORE_DIR)/deps/capstone/arch/ARM/ARMInstPrinter.c \
	$(CORE_DIR)/deps/capstone/arch/ARM/ARMMapping.c \
	$(CORE_DIR)/deps/capstone/arch/ARM/ARMModule.c
endif

ifeq ($(CAPSTONE_HAS_ARM64), 1)
SOURCES_C += $(CORE_DIR)/deps/capstone/arch/AArch64/AArch64Disassembler.c \
	$(CORE_DIR)/deps/capstone/arch/AArch64/AArch64InstPrinter.c \
	$(CORE_DIR)/deps/capstone/arch/AArch64/AArch64Mapping.c \
	$(CORE_DIR)/deps/capstone/arch/AArch64/AArch64BaseInfo.c \
	$(CORE_DIR)/deps/capstone/arch/AArch64/AArch64Module.c
endif

SOURCES_C += $(CORE_DIR)/deps/capstone/arch/X86/X86Disassembler.c \
	$(CORE_DIR)/deps/capstone/arch/X86/X86DisassemblerDecoder.c \
	$(CORE_DIR)/deps/capstone/arch/X86/X86ATTInstPrinter.c \
	$(CORE_DIR)/deps/capstone/arch/X86/X86IntelInstPrinter.c \
	$(CORE_DIR)/deps/capstone/arch/X86/X86Mapping.c \
	$(CORE_DIR)/deps/capstone/arch/X86/X86Module.c

#==--------------------------------------------------------------------------==#
# glad
#==--------------------------------------------------------------------------==#
INCFLAGS += -I$(CORE_DIR)/deps/glad/include \

# work around glad using dlopen, etc. which are actually unused
ifneq ($(findstring Darwin,$(shell uname -a)),)
LDFLAGS += -undefined dynamic_lookup
else
LDFLAGS += -Wl,--unresolved-symbols=ignore-all
endif

SOURCES_C += $(CORE_DIR)/deps/glad/src/glad.c

#==--------------------------------------------------------------------------==#
# imgui
#==--------------------------------------------------------------------------==#
ifeq ($(HAVE_IMGUI), 1)
INCFLAGS += -I$(CORE_DIR)/deps/cimgui
SOURCES_CPP += $(CORE_DIR)/deps/cimgui/cimgui/cimgui.cpp
endif

#==--------------------------------------------------------------------------==#
# libchdr
#==--------------------------------------------------------------------------==#
INCFLAGS += -I$(CORE_DIR)/deps/chdr/deps/crypto \
	-I$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/include \
	-I$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/include \
	-I$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C \
	-I$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11 \
	-I$(CORE_DIR)/deps/chdr/src
COREFLAGS += -D_7ZIP_ST -DPACKAGE_VERSION=\"1.3.2\" -DFLAC_API_EXPORTS -DFLAC__HAS_OGG=0 -DHAVE_LROUND -DHAVE_STDINT_H -DHAVE_STDLIB_H -DHAVE_SYS_PARAM_H

ifeq ($(HAVE_WINDOWS), 1)
COREFLAGS += -DHAVE_FSEEKO
endif

SOURCES_C += $(CORE_DIR)/deps/chdr/deps/crypto/md5.c \
	$(CORE_DIR)/deps/chdr/deps/crypto/sha1.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/bitmath.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/bitreader.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/cpu.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/crc.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/fixed.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/fixed_intrin_sse2.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/fixed_intrin_ssse3.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/float.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/format.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/lpc.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/lpc_intrin_avx2.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/lpc_intrin_sse2.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/lpc_intrin_sse41.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/lpc_intrin_sse.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/md5.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/memory.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/metadata_iterators.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/metadata_object.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/stream_decoder.c \
	$(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/window.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/Alloc.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/Bra86.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/Bra.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/BraIA64.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/CpuArch.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/Delta.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/LzFind.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/Lzma86Dec.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/Lzma86Enc.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/LzmaDec.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/LzmaEnc.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/LzmaLib.c \
	$(CORE_DIR)/deps/chdr/deps/lzma-16.04/C/Sort.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/adler32.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/compress.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/crc32.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/deflate.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/gzclose.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/gzlib.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/gzread.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/gzwrite.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/inffast.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/inflate.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/inftrees.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/trees.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/uncompr.c \
	$(CORE_DIR)/deps/chdr/deps/zlib-1.2.11/zutil.c \
	$(CORE_DIR)/deps/chdr/src/bitstream.c \
	$(CORE_DIR)/deps/chdr/src/cdrom.c \
	$(CORE_DIR)/deps/chdr/src/chd.c \
	$(CORE_DIR)/deps/chdr/src/flac.c \
	$(CORE_DIR)/deps/chdr/src/huffman.c 

ifeq ($(HAVE_WINDOWS), 1)
SOURCES_C += $(CORE_DIR)/deps/chdr/deps/flac-1.3.2/src/libFLAC/windows_unicode_filenames.c
endif

#==--------------------------------------------------------------------------==#
# platform-specific
#==--------------------------------------------------------------------------==#
ifeq ($(HAVE_LINUX), 1)
SOURCES_C += $(CORE_DIR)/src/core/exception_handler_linux.c  \
	$(CORE_DIR)/src/core/time_linux.c
endif

ifeq ($(HAVE_MAC), 1)
SOURCES_C += $(CORE_DIR)/src/core/exception_handler_mac.c  \
	 $(CORE_DIR)/src/core/time_mac.c
endif

ifeq ($(HAVE_WINDOWS), 1)
SOURCES_C += $(CORE_DIR)/src/core/exception_handler_win.c  \
	$(CORE_DIR)/src/core/time_win.c
endif

ifeq ($(HAVE_POSIX), 1)
SOURCES_C += $(CORE_DIR)/src/core/filesystem_posix.c \
	$(CORE_DIR)/src/core/memory_posix.c \
	$(CORE_DIR)/src/core/thread_posix.c
endif

ifeq ($(HAVE_WINDOWS), 1)
SOURCES_C += $(CORE_DIR)/src/core/filesystem_win.c \
	$(CORE_DIR)/src/core/memory_win.c \
	$(CORE_DIR)/src/core/thread_win.c
endif

#==--------------------------------------------------------------------------==#
# dynarec
#==--------------------------------------------------------------------------==#
ifdef WITH_DYNAREC

ifeq ($(WITH_DYNAREC), arm)
DYNAFLAGS += -DNEW_DYNAREC=3
endif

ifeq ($(WITH_DYNAREC), $(filter $(WITH_DYNAREC), x86_64 x64))
DYNAREC_USED = 1
COREFLAGS += -DARCH_X64=1
CPUFLAGS += -msse -msse2
DYNAFLAGS += -D_M_X64
SOURCES_CXX += \
	$(CORE_DIR)/src/jit/backend/x64/x64_backend.cc \
	$(CORE_DIR)/src/jit/backend/x64/x64_dispatch.cc \
	$(CORE_DIR)/src/jit/backend/x64/x64_emitters.cc
SOURCES_C += $(CORE_DIR)/src/jit/backend/x64/x64_disassembler.c
endif

endif
