Skip to content

Commit

Permalink
Improve makefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 13, 2024
1 parent 6aeb837 commit 8ef188f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 85 deletions.
1 change: 1 addition & 0 deletions platforms/bsd/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include ../desktop-shared/Makefile.sources
include ../desktop-shared/Makefile.common
130 changes: 46 additions & 84 deletions platforms/desktop-shared/Makefile.common
Original file line number Diff line number Diff line change
@@ -1,111 +1,73 @@

CXX = g++
CC = gcc
#CXX = clang++
#CC = clang

EXE = gearcoleco

TARGET_NAME = gearcoleco
GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always --tags)"

EMULATOR_SRC=../../src
EMULATOR_DESKTOP_SHARED_SRC=../desktop-shared
EMULATOR_AUDIO_SRC=$(EMULATOR_SRC)/audio
EMULATOR_AUDIO_SHARED_SRC=../audio-shared
IMGUI_SRC=$(EMULATOR_DESKTOP_SHARED_SRC)/imgui
IMGUI_FILEBROWSER_SRC=$(EMULATOR_DESKTOP_SHARED_SRC)/FileBrowser

SOURCES = $(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

SOURCES += $(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

SOURCES += $(EMULATOR_SRC)/Audio.cpp $(EMULATOR_SRC)/Cartridge.cpp $(EMULATOR_SRC)/GearcolecoCore.cpp $(EMULATOR_SRC)/Input.cpp $(EMULATOR_SRC)/Memory.cpp $(EMULATOR_SRC)/opcodes.cpp $(EMULATOR_SRC)/opcodes_cb.cpp $(EMULATOR_SRC)/opcodes_ed.cpp $(EMULATOR_SRC)/Processor.cpp $(EMULATOR_SRC)/ColecoVisionIOPorts.cpp $(EMULATOR_SRC)/Video.cpp $(EMULATOR_SRC)/AY8910.cpp

SOURCES += $(EMULATOR_AUDIO_SRC)/Blip_Buffer.cpp $(EMULATOR_AUDIO_SRC)/Effects_Buffer.cpp $(EMULATOR_AUDIO_SRC)/Sms_Apu.cpp $(EMULATOR_AUDIO_SRC)/Multi_Buffer.cpp

SOURCES += $(EMULATOR_AUDIO_SHARED_SRC)/Sound_Queue.cpp

OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))

UNAME_S := $(shell uname -s)
PLATFORM = "undefined"

OBJECTS := $(SOURCES_C:.c=.o) $(SOURCES_CXX:.cpp=.o)

CXXFLAGS = -I../ -I../../
CXXFLAGS += -Wall -Wextra -Wformat -std=c++11 -DEMULATOR_BUILD=\"$(GIT_VERSION)\"
LIBS =
CPPFLAGS = -I../ -I../../
CPPFLAGS += -Wall -Wextra -Wformat -DEMULATOR_BUILD=\"$(GIT_VERSION)\"
CXXFLAGS += -std=c++11
CFLAGS += -std=c99
LDFLAGS =

DEBUG ?= 0
ifeq ($(DEBUG), 1)
CXXFLAGS +=-DDEBUG -g3
CPPFLAGS +=-DDEBUG -g3
else
CXXFLAGS +=-DNDEBUG -O3 -flto=auto
CPPFLAGS +=-DNDEBUG -O3 -flto=auto
LDFLAGS += -flto=auto
endif

SANITIZE ?= 0
ifeq ($(SANITIZE), 1)
CXXFLAGS +=-fsanitize=address
LIBS += -lasan
CPPFLAGS +=-fsanitize=address
LDFLAGS += -lasan
endif

##---------------------------------------------------------------------
## BUILD FLAGS PER PLATFORM
##---------------------------------------------------------------------

ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
LIBS += -lGL -lGLEW -ldl `sdl2-config --libs`

CXXFLAGS += `sdl2-config --cflags`
CFLAGS += $(CXXFLAGS)
PLATFORM = "Linux"
LDFLAGS += -lGL -lGLEW -ldl `sdl2-config --libs`
CPPFLAGS += `sdl2-config --cflags`
TARGET := $(TARGET_NAME)
else ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "macOS"
LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs`
LIBS += -L/usr/local/lib

CXXFLAGS += `sdl2-config --cflags`
CXXFLAGS += -I/usr/local/include -I/opt/local/include
CFLAGS += $(CXXFLAGS)
PLATFORM = "macOS"
LDFLAGS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs`
LDFLAGS += -L/usr/local/lib
CPPFLAGS += `sdl2-config --cflags`
CPPFLAGS += -I/usr/local/include -I/opt/local/include
TARGET := $(TARGET_NAME)
else ifeq ($(findstring MINGW,$(UNAME_S)),MINGW)
ECHO_MESSAGE = "MinGW"
LIBS += -lgdi32 -lopengl32 -lglew32 -limm32 `pkg-config --static --libs sdl2`

CXXFLAGS += `pkg-config --cflags sdl2`
CFLAGS += $(CXXFLAGS)
PLATFORM = "MinGW"
LDFLAGS += -lgdi32 -lopengl32 -lglew32 -limm32 `pkg-config --static --libs sdl2`
CPPFLAGS += `pkg-config --cflags sdl2`
TARGET := $(TARGET_NAME).exe
else
ECHO_MESSAGE = "Generic Unix-like/BSD"
LIBS += `sdl2-config --libs` -lSDL2
LIBS += `pkg-config --libs glew` -lGLEW

CXXFLAGS += -std=gnu++11
CXXFLAGS += `sdl2-config --cflags`
CXXFLAGS += `pkg-config --cflags glew`
CFLAGS += $(CXXFLAGS)
PLATFORM = "Generic Unix-like/BSD"
LDFLAGS += `sdl2-config --libs` -lSDL2
LDFLAGS += `pkg-config --libs glew` -lGLEW
CXXFLAGS += -std=gnu++11
CPPFLAGS += `sdl2-config --cflags`
CPPFLAGS += `pkg-config --cflags glew`
TARGET := $(TARGET_NAME)
endif

##---------------------------------------------------------------------
## BUILD RULES
##---------------------------------------------------------------------

%.o:$(IMGUI_SRC)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o:$(IMGUI_FILEBROWSER_SRC)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o:$(EMULATOR_SRC)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o:$(EMULATOR_DESKTOP_SHARED_SRC)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

%.o:$(EMULATOR_AUDIO_SRC)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
all: $(TARGET)
@echo Build complete for $(PLATFORM)

%.o:$(EMULATOR_AUDIO_SHARED_SRC)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(TARGET): $(OBJECTS)
$(CXX) -o $@ $(OBJECTS) $(LDFLAGS)

all: $(EXE)
@echo Build complete for $(ECHO_MESSAGE)
%.o: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<

$(EXE): $(OBJS)
$(CXX) -o $@ $^ $(LDFLAGS) $(LIBS)
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

clean:
rm -f $(EXE) $(OBJS)
rm -f $(OBJECTS) $(TARGET)
37 changes: 37 additions & 0 deletions platforms/desktop-shared/Makefile.sources
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
SRC_DIR = ../../src
DESKTOP_SRC_DIR=../desktop-shared
AUDIO_SRC_DIR=../audio-shared

SOURCES_C :=

SOURCES_CXX := \
$(DESKTOP_SRC_DIR)/main.cpp \
$(DESKTOP_SRC_DIR)/emu.cpp \
$(DESKTOP_SRC_DIR)/gui.cpp \
$(DESKTOP_SRC_DIR)/gui_debug.cpp \
$(DESKTOP_SRC_DIR)/application.cpp \
$(DESKTOP_SRC_DIR)/config.cpp \
$(DESKTOP_SRC_DIR)/renderer.cpp \
$(DESKTOP_SRC_DIR)/imgui/imgui_impl_sdl.cpp \
$(DESKTOP_SRC_DIR)/imgui/imgui_impl_opengl2.cpp \
$(DESKTOP_SRC_DIR)/imgui/imgui.cpp \
$(DESKTOP_SRC_DIR)/imgui/imgui_draw.cpp \
$(DESKTOP_SRC_DIR)/imgui/imgui_widgets.cpp \
$(DESKTOP_SRC_DIR)/FileBrowser/ImGuiFileBrowser.cpp \
$(AUDIO_SRC_DIR)/Sound_Queue.cpp \
$(SRC_DIR)/Audio.cpp \
$(SRC_DIR)/AY8910.cpp \
$(SRC_DIR)/Cartridge.cpp \
$(SRC_DIR)/ColecoVisionIOPorts.cpp \
$(SRC_DIR)/GearcolecoCore.cpp \
$(SRC_DIR)/Input.cpp \
$(SRC_DIR)/Memory.cpp \
$(SRC_DIR)/opcodes.cpp \
$(SRC_DIR)/opcodes_cb.cpp \
$(SRC_DIR)/opcodes_ed.cpp \
$(SRC_DIR)/Processor.cpp \
$(SRC_DIR)/Video.cpp \
$(SRC_DIR)/audio/Blip_Buffer.cpp \
$(SRC_DIR)/audio/Effects_Buffer.cpp \
$(SRC_DIR)/audio/Sms_Apu.cpp \
$(SRC_DIR)/audio/Multi_Buffer.cpp \
1 change: 1 addition & 0 deletions platforms/linux/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include ../desktop-shared/Makefile.sources
include ../desktop-shared/Makefile.common
3 changes: 2 additions & 1 deletion platforms/macos/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include ../desktop-shared/Makefile.sources
include ../desktop-shared/Makefile.common

DYLIB_PATH=/usr/local/opt/sdl2/lib
Expand All @@ -10,7 +11,7 @@ bundle:
cp Info.plist $(APP_NAME).app/Contents/
cp $(DYLIB_PATH)/$(SDL_DYLIB) $(APP_NAME).app/Contents/Frameworks/
cp iconfile.icns $(APP_NAME).app/Contents/Resources/
cp $(EXE) $(APP_NAME).app/Contents/MacOS/
cp $(TARGET) $(APP_NAME).app/Contents/MacOS/
cp run.sh $(APP_NAME).app/Contents/MacOS/
cp gamecontrollerdb.txt $(APP_NAME).app/Contents/MacOS/
install_name_tool -change $(DYLIB_PATH)/$(SDL_DYLIB) @$(APP_NAME).app/Contents/MacOS/$(SDL_DYLIB) $(APP_NAME).app/Contents/MacOS/$(APP_NAME)
Expand Down
1 change: 1 addition & 0 deletions platforms/windows/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include ../desktop-shared/Makefile.sources
include ../desktop-shared/Makefile.common

0 comments on commit 8ef188f

Please sign in to comment.