target := qt
binary := application
build := performance
openmp := true
flags += -I. -I../higan -I..

nall.path := ../nall
include $(nall.path)/GNUmakefile

ifeq ($(platform),windows)
  ifeq ($(arch),x86)
    flags += -m32
    link += -m32
  endif
  ifeq ($(binary),application)
    link += -luuid -lkernel32 -luser32 -lgdi32 -lcomctl32 -lcomdlg32 -lshell32
    link += -Wl,-enable-auto-import
    link += -Wl,-enable-runtime-pseudo-reloc
  else ifeq ($(binary),library)
    link += -shared
  endif
else ifeq ($(platform),macos)
  ifeq ($(binary),application)
  else ifeq ($(binary),library)
    flags += -fPIC
    link += -dynamiclib
  endif
else ifneq ($(filter $(platform),linux bsd),)
  ifeq ($(binary),application)
    flags += -march=native
    link += -Wl,-export-dynamic
    link += -lX11 -lXext
  else ifeq ($(binary),library)
    flags += -fPIC
    link += -shared
  endif
else
  $(error "unsupported platform")
endif

objects := libco emulator audio video resource resource-fastppu

obj/libco.o: ../libco/libco.c
obj/emulator.o: ../higan/emulator/emulator.cpp
obj/audio.o: ../higan/audio/audio.cpp
obj/video.o: ../higan/video/video.cpp
obj/resource.o: ../higan/resource/resource.cpp
obj/resource-fastppu.o: resource/resource.cpp

profile := accuracy

ifeq ($(target),qt)
  cores := sfc gb
  ifeq ($(profile),performance)
    double_vram := false
  else
    double_vram := true
  endif
else
  double_vram := true
endif

ifeq ($(double_vram),true)
  flags += -DDOUBLE_VRAM
endif

ifeq ($(profile),compatibility)
  override profile = accuracy
endif

ifneq ($(filter $(cores),sfc),)
  ifeq ($(profile),performance)
    flags += -DPROFILE_PERFORMANCE
    include sfc-performance/GNUmakefile
  else
    include sfc/GNUmakefile
  endif
endif

ifneq ($(filter $(cores),gb),)
  include gb/GNUmakefile
endif

include processor/GNUmakefile

flags += $(foreach c,$(call strupper,$(cores)),-DCORE_$c)
ui := target-$(target)
include $(ui)/GNUmakefile
-include obj/*.d

clean:
	$(call delete,obj/*)
	$(call delete,out/*)
