Makefile.common (4024B)
1 2CXX = g++ 3#CXX = clang++ 4 5EXE = gearboy 6 7GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always --tags)" 8 9EMULATOR_SRC=../../src 10EMULATOR_DESKTOP_SHARED_SRC=../desktop-shared 11EMULATOR_AUDIO_SRC=$(EMULATOR_SRC)/audio 12EMULATOR_AUDIO_SHARED_SRC=../audio-shared 13IMGUI_SRC=$(EMULATOR_DESKTOP_SHARED_SRC)/imgui 14IMGUI_FILEBROWSER_SRC=$(EMULATOR_DESKTOP_SHARED_SRC)/FileBrowser 15 16SOURCES = $(EMULATOR_DESKTOP_SHARED_SRC)/main.cpp $(EMULATOR_DESKTOP_SHARED_SRC)/emu.cpp $(EMULATOR_DESKTOP_SHARED_SRC)/gui.cpp $ (EMULATOR_DESKTOP_SHARED_SRC)/gui_debug.cpp $ (EMULATOR_DESKTOP_SHARED_SRC)/application.cpp $(EMULATOR_DESKTOP_SHARED_SRC)/config.cpp $(EMULATOR_DESKTOP_SHARED_SRC)/renderer.cpp 17 18SOURCES += $(IMGUI_SRC)/imgui_impl_sdl.cpp $(IMGUI_SRC)/imgui_impl_opengl2.cpp $(IMGUI_SRC)/imgui.cpp $(IMGUI_SRC)/imgui_demo.cpp $(IMGUI_SRC)/imgui_draw.cpp $(IMGUI_SRC)/imgui_widgets.cpp $(IMGUI_FILEBROWSER_SRC)/ImGuiFileBrowser.cpp 19 20SOURCES += $(EMULATOR_SRC)/Audio.cpp $(EMULATOR_SRC)/Cartridge.cpp $(EMULATOR_SRC)/CommonMemoryRule.cpp $(EMULATOR_SRC)/GearboyCore.cpp $(EMULATOR_SRC)/Input.cpp $(EMULATOR_SRC)/IORegistersMemoryRule.cpp $(EMULATOR_SRC)/MBC1MemoryRule.cpp $(EMULATOR_SRC)/MBC2MemoryRule.cpp $(EMULATOR_SRC)/MBC3MemoryRule.cpp $(EMULATOR_SRC)/MBC5MemoryRule.cpp $(EMULATOR_SRC)/Memory.cpp $(EMULATOR_SRC)/MemoryRule.cpp $(EMULATOR_SRC)/MultiMBC1MemoryRule.cpp $(EMULATOR_SRC)/opcodes.cpp $(EMULATOR_SRC)/opcodes_cb.cpp $(EMULATOR_SRC)/Processor.cpp $(EMULATOR_SRC)/RomOnlyMemoryRule.cpp $(EMULATOR_SRC)/Video.cpp 21 22SOURCES += $(EMULATOR_AUDIO_SRC)/Blip_Buffer.cpp $(EMULATOR_AUDIO_SRC)/Effects_Buffer.cpp $(EMULATOR_AUDIO_SRC)/Gb_Apu.cpp $(EMULATOR_AUDIO_SRC)/Gb_Apu_State.cpp $(EMULATOR_AUDIO_SRC)/Gb_Oscs.cpp $(EMULATOR_AUDIO_SRC)/Multi_Buffer.cpp 23 24SOURCES += $(EMULATOR_AUDIO_SHARED_SRC)/Sound_Queue.cpp 25 26OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) 27 28UNAME_S := $(shell uname -s) 29 30CXXFLAGS = -I../ -I../../ -g 31CXXFLAGS += -Wall -Wextra -Wformat -std=c++11 -DEMULATOR_BUILD=\"$(GIT_VERSION)\" 32LIBS = 33 34DEBUG ?= 0 35ifeq ($(DEBUG), 1) 36 CXXFLAGS +=-DDEBUG -g3 37else 38 CXXFLAGS +=-DNDEBUG -O3 -flto 39endif 40 41SANITIZE ?= 0 42ifeq ($(SANITIZE), 1) 43 CXXFLAGS +=-fsanitize=address 44 LIBS += -lasan 45endif 46 47##--------------------------------------------------------------------- 48## BUILD FLAGS PER PLATFORM 49##--------------------------------------------------------------------- 50 51ifeq ($(UNAME_S), Linux) #LINUX 52 ECHO_MESSAGE = "Linux" 53 LIBS += -lGL -lGLEW -ldl `sdl2-config --libs` 54 55 CXXFLAGS += `sdl2-config --cflags` 56 CFLAGS += $(CXXFLAGS) 57else ifeq ($(UNAME_S), Darwin) #APPLE 58 ECHO_MESSAGE = "macOS" 59 LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs` 60 LIBS += -L/usr/local/lib 61 62 CXXFLAGS += `sdl2-config --cflags` 63 CXXFLAGS += -I/usr/local/include -I/opt/local/include 64 CFLAGS += $(CXXFLAGS) 65else ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) 66 ECHO_MESSAGE = "MinGW" 67 LIBS += -lgdi32 -lopengl32 -lglew32 -limm32 `pkg-config --static --libs sdl2` 68 69 CXXFLAGS += `pkg-config --cflags sdl2` 70 CFLAGS += $(CXXFLAGS) 71else 72 ECHO_MESSAGE = "Generic Unix-like/BSD" 73 LIBS += `sdl2-config --libs` -lSDL2 74 LIBS += `pkg-config --libs glew` -lGLEW 75 76 CXXFLAGS += -std=gnu++11 77 CXXFLAGS += `sdl2-config --cflags` 78 CXXFLAGS += `pkg-config --cflags glew` 79 CFLAGS += $(CXXFLAGS) 80endif 81 82##--------------------------------------------------------------------- 83## BUILD RULES 84##--------------------------------------------------------------------- 85 86%.o:$(IMGUI_SRC)/%.cpp 87 $(CXX) $(CXXFLAGS) -c -o $@ $< 88 89%.o:$(IMGUI_FILEBROWSER_SRC)/%.cpp 90 $(CXX) $(CXXFLAGS) -c -o $@ $< 91 92%.o:$(EMULATOR_SRC)/%.cpp 93 $(CXX) $(CXXFLAGS) -c -o $@ $< 94 95%.o:$(EMULATOR_DESKTOP_SHARED_SRC)/%.cpp 96 $(CXX) $(CXXFLAGS) -c -o $@ $< 97 98%.o:$(EMULATOR_AUDIO_SRC)/%.cpp 99 $(CXX) $(CXXFLAGS) -c -o $@ $< 100 101%.o:$(EMULATOR_AUDIO_SHARED_SRC)/%.cpp 102 $(CXX) $(CXXFLAGS) -c -o $@ $< 103 104all: $(EXE) 105 @echo Build complete for $(ECHO_MESSAGE) 106 107$(EXE): $(OBJS) 108 $(CXX) -o $@ $^ $(LDFLAGS) $(LIBS) 109 110clean: 111 rm -f $(EXE) $(OBJS)