ClassiCube/Makefile

318 lines
7.8 KiB
Makefile
Raw Normal View History

SOURCE_DIR = src
BUILD_DIR = build
C_SOURCES = $(wildcard $(SOURCE_DIR)/*.c)
C_OBJECTS = $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.o, $(C_SOURCES))
OBJECTS = $(C_OBJECTS)
2024-08-17 01:19:10 -04:00
# Flags passed to the C compiler
CFLAGS = -pipe -fno-math-errno -Werror -Wno-error=missing-braces -Wno-error=strict-aliasing
# Flags passed to the linker
LDFLAGS = -g -rdynamic
2024-08-17 01:19:10 -04:00
# Name of the main executable
ENAME = ClassiCube
# Name of the final target file
# (usually this is the executable, but e.g. is app bundle on macOS)
TARGET := $(ENAME)
2018-10-14 02:31:13 -04:00
ifndef RM
# No prefined RM variable, try to guess OS default
ifeq ($(OS),Windows_NT)
RM = del
else
RM = rm -f
endif
endif
# Enables dependency tracking (https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/)
# This ensures that changing a .h file automatically results in the .c files using it being auto recompiled when next running make
# On older systems the required GCC options may not be supported - in which case just change TRACK_DEPENDENCIES to 0
TRACK_DEPENDENCIES=1
2019-04-06 03:44:53 -04:00
ifndef $(PLAT)
ifeq ($(OS),Windows_NT)
PLAT = mingw
else
PLAT = $(shell uname -s | tr '[:upper:]' '[:lower:]')
endif
2019-04-05 14:52:01 -04:00
endif
2018-10-14 02:31:13 -04:00
ifeq ($(PLAT),web)
CC = emcc
OEXT = .html
CFLAGS = -g
LDFLAGS = -g -s WASM=1 -s NO_EXIT_RUNTIME=1 -s ABORTING_MALLOC=0 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=256Kb --js-library $(SOURCE_DIR)/interop_web.js
BUILD_DIR = build-web
endif
2019-04-05 14:52:01 -04:00
ifeq ($(PLAT),mingw)
CC = gcc
OEXT = .exe
CFLAGS += -DUNICODE
LDFLAGS = -g
LIBS = -mwindows -lwinmm
BUILD_DIR = build-win
endif
2019-04-05 14:52:01 -04:00
ifeq ($(PLAT),linux)
CFLAGS += -DCC_BUILD_ICON
LIBS = -lX11 -lXi -lpthread -lGL -ldl
BUILD_DIR = build-linux
endif
ifeq ($(PLAT),sunos)
CFLAGS += -DCC_BUILD_ICON
LIBS = -lsocket -lX11 -lXi -lGL
BUILD_DIR = build-solaris
endif
2019-04-06 03:44:53 -04:00
2024-10-13 20:32:34 -04:00
ifeq ($(PLAT),hp-ux)
2024-10-13 21:46:22 -04:00
CC = gcc
2024-10-13 20:32:34 -04:00
CFLAGS = -DCC_BUILD_ICON
LDFLAGS =
2024-10-13 21:46:22 -04:00
LIBS = -lm -lX11 -lXi -lXext -L/opt/graphics/OpenGL/lib -lGL -lpthread
2024-10-13 20:32:34 -04:00
BUILD_DIR = build-hpux
endif
ifeq ($(PLAT),darwin)
OBJECTS += $(BUILD_DIR)/Window_cocoa.o
CFLAGS += -DCC_BUILD_ICON
LIBS =
LDFLAGS = -rdynamic -framework Cocoa -framework OpenGL -framework IOKit -lobjc
BUILD_DIR = build-macos
2024-08-17 06:09:23 -04:00
TARGET = $(ENAME).app
endif
ifeq ($(PLAT),freebsd)
CFLAGS += -I /usr/local/include -DCC_BUILD_ICON
LDFLAGS = -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
BUILD_DIR = build-freebsd
endif
2019-04-06 03:44:53 -04:00
ifeq ($(PLAT),openbsd)
CFLAGS += -I /usr/X11R6/include -I /usr/local/include -DCC_BUILD_ICON
LDFLAGS = -L /usr/X11R6/lib -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
BUILD_DIR = build-openbsd
endif
2019-04-06 03:44:53 -04:00
ifeq ($(PLAT),netbsd)
CFLAGS += -I /usr/X11R7/include -I /usr/pkg/include -DCC_BUILD_ICON
LDFLAGS = -L /usr/X11R7/lib -L /usr/pkg/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
BUILD_DIR = build-netbsd
endif
ifeq ($(PLAT),dragonfly)
CFLAGS += -I /usr/local/include -DCC_BUILD_ICON
LDFLAGS = -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
BUILD_DIR = build-flybsd
endif
2019-11-11 02:23:50 -05:00
ifeq ($(PLAT),haiku)
OBJECTS += $(BUILD_DIR)/Platform_BeOS.o $(BUILD_DIR)/Window_BeOS.o
2024-08-10 08:39:39 -04:00
CFLAGS = -pipe -fno-math-errno
LDFLAGS = -g
2024-10-31 05:01:31 -04:00
LINK = $(CXX)
LIBS = -lGL -lnetwork -lbe -lgame -ltracker
BUILD_DIR = build-haiku
2019-11-11 02:23:50 -05:00
endif
2023-06-29 05:45:27 -04:00
ifeq ($(PLAT),beos)
OBJECTS += $(BUILD_DIR)/Platform_BeOS.o $(BUILD_DIR)/Window_BeOS.o
2024-08-10 08:39:39 -04:00
CFLAGS = -pipe
LDFLAGS = -g
2024-10-31 05:01:31 -04:00
LINK = $(CXX)
LIBS = -lGL -lnetwork -lbe -lgame -ltracker
BUILD_DIR = build-beos
TRACK_DEPENDENCIES=0
2023-06-29 05:45:27 -04:00
endif
2022-10-18 06:27:16 -04:00
ifeq ($(PLAT),serenityos)
LIBS = -lgl -lSDL2
BUILD_DIR = build-serenity
2022-10-18 06:27:16 -04:00
endif
ifeq ($(PLAT),irix)
CC = gcc
LIBS = -lGL -lX11 -lXi -lpthread -ldl
BUILD_DIR = build-irix
endif
2024-09-27 18:30:45 -04:00
ifeq ($(PLAT),dos)
CC = i586-pc-msdosdjgpp-gcc
LIBS =
LDFLAGS = -g
OEXT = .exe
BUILD_DIR = build-dos
2024-09-27 18:30:45 -04:00
endif
ifdef SDL2
CFLAGS += -DCC_WIN_BACKEND=CC_WIN_BACKEND_SDL2
LIBS += -lSDL2
endif
ifdef SDL3
CFLAGS += -DCC_WIN_BACKEND=CC_WIN_BACKEND_SDL3
LIBS += -lSDL3
endif
ifdef TERMINAL
CFLAGS += -DCC_WIN_BACKEND=CC_WIN_BACKEND_TERMINAL -DCC_GFX_BACKEND=CC_GFX_BACKEND_SOFTGPU
LIBS := $(subst mwindows,mconsole,$(LIBS))
endif
2024-08-10 08:39:39 -04:00
ifdef BEARSSL
BEARSSL_SOURCES = $(wildcard third_party/bearssl/src/*.c)
BEARSSL_OBJECTS = $(patsubst third_party/bearssl/src/%.c, $(BUILD_DIR)/%.o, $(BEARSSL_SOURCES))
OBJECTS += $(BEARSSL_OBJECTS)
CFLAGS += -Ithird_party/bearssl/inc -DCC_SSL_BACKEND=CC_SSL_BACKEND_BEARSSL -DCC_NET_BACKEND=CC_NET_BACKEND_BUILTIN
endif
2024-08-02 21:07:45 -04:00
ifdef RELEASE
CFLAGS += -O1
2024-08-10 08:39:39 -04:00
else
CFLAGS += -g
2024-08-02 21:07:45 -04:00
endif
# link with CC by default
LINK ?= $(CC)
2019-04-05 14:52:01 -04:00
default: $(PLAT)
web:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=web
2019-04-05 14:52:01 -04:00
linux:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=linux
2019-04-05 14:52:01 -04:00
mingw:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=mingw
sunos:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=sunos
2024-10-13 20:32:34 -04:00
hp-ux:
$(MAKE) $(TARGET) PLAT=hp-ux
darwin:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=darwin
2019-04-06 03:44:53 -04:00
freebsd:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=freebsd
2019-04-06 03:44:53 -04:00
openbsd:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=openbsd
2019-04-06 03:44:53 -04:00
netbsd:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=netbsd
dragonfly:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=dragonfly
haiku:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=haiku
2023-06-29 05:45:27 -04:00
beos:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=beos
2022-10-18 06:27:16 -04:00
serenityos:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=serenityos
irix:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) PLAT=irix
2024-09-27 18:30:45 -04:00
dos:
$(MAKE) $(TARGET) PLAT=dos
# Default overrides
sdl2:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) SDL2=1
sdl3:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) SDL3=1
terminal:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) TERMINAL=1
2024-08-02 21:07:45 -04:00
release:
2024-08-17 06:09:23 -04:00
$(MAKE) $(TARGET) RELEASE=1
2024-04-01 13:23:30 -04:00
2024-06-02 06:17:21 -04:00
# Some builds require more complex handling, so are moved to
2023-08-19 19:28:49 -04:00
# separate makefiles to avoid having one giant messy makefile
2024-12-27 20:58:14 -05:00
32x:
$(MAKE) -f misc/32x/Makefile
2024-04-18 05:18:05 -04:00
saturn:
$(MAKE) -f misc/saturn/Makefile
2024-12-27 20:58:14 -05:00
dreamcast:
$(MAKE) -f misc/dreamcast/Makefile
psp:
$(MAKE) -f misc/psp/Makefile
vita:
$(MAKE) -f misc/vita/Makefile
2024-03-27 01:31:01 -04:00
ps1:
cmake --preset default misc/ps1
cmake --build misc/ps1/build
2023-11-22 04:56:11 -05:00
ps2:
$(MAKE) -f misc/ps2/Makefile
ps3:
$(MAKE) -f misc/ps3/Makefile
xbox:
$(MAKE) -f misc/xbox/Makefile
xbox360:
$(MAKE) -f misc/xbox360/Makefile
2023-10-28 07:07:22 -04:00
n64:
$(MAKE) -f misc/n64/Makefile
ds:
$(MAKE) -f misc/ds/Makefile
2024-03-14 17:44:05 -04:00
3ds:
$(MAKE) -f misc/3ds/Makefile
2024-03-14 17:44:05 -04:00
gamecube:
$(MAKE) -f misc/gc/Makefile
wii:
$(MAKE) -f misc/wii/Makefile
2024-03-14 17:44:05 -04:00
wiiu:
$(MAKE) -f misc/wiiu/Makefile
2024-03-08 10:53:48 -05:00
switch:
$(MAKE) -f misc/switch/Makefile
2024-04-01 13:23:30 -04:00
os/2:
$(MAKE) -f misc/os2/Makefile
macclassic_68k:
$(MAKE) -f misc/macclassic/Makefile_68k
macclassic_ppc:
$(MAKE) -f misc/macclassic/Makefile_ppc
2024-10-20 01:20:51 -04:00
amiga_68k:
$(MAKE) -f misc/amiga/Makefile_68k
amiga_ppc:
$(MAKE) -f misc/amiga/Makefile_ppc
2018-10-14 02:31:13 -04:00
clean:
$(RM) $(OBJECTS)
2019-04-05 14:52:01 -04:00
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
2024-08-17 06:09:23 -04:00
$(ENAME): $(BUILD_DIR) $(OBJECTS)
$(LINK) $(LDFLAGS) -o $@$(OEXT) $(OBJECTS) $(EXTRA_LIBS) $(LIBS)
2024-08-17 06:09:23 -04:00
# macOS app bundle
$(ENAME).app : $(ENAME)
2024-08-17 07:22:18 -04:00
mkdir -p $(TARGET)/Contents/MacOS
mkdir -p $(TARGET)/Contents/Resources
2024-08-17 06:09:23 -04:00
cp $(ENAME) $(TARGET)/Contents/MacOS/$(ENAME)
2024-08-17 07:22:18 -04:00
cp misc/macOS/Info.plist $(TARGET)/Contents/Info.plist
2024-08-17 06:09:23 -04:00
cp misc/macOS/appicon.icns $(TARGET)/Contents/Resources/appicon.icns
2019-04-05 14:52:01 -04:00
# === Compiling with dependency tracking ===
# NOTE: Tracking dependencies might not work on older systems - disable this if so
ifeq ($(TRACK_DEPENDENCIES), 1)
DEPFLAGS = -MT $@ -MMD -MP -MF $(BUILD_DIR)/$*.d
DEPFILES := $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.d, $(C_SOURCES))
$(DEPFILES):
$(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c $(BUILD_DIR)/%.d
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(DEPFLAGS) -c $< -o $@
include $(wildcard $(DEPFILES))
# === Compiling WITHOUT dependency tracking ===
else
$(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
endif
# === Platform specific file compiling ===
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.m
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.cpp
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
2024-08-10 08:39:39 -04:00
$(BUILD_DIR)/%.o: third_party/bearssl/src/%.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
2024-06-26 08:40:11 -04:00
# EXTRA_CFLAGS and EXTRA_LIBS are not defined in the makefile intentionally -
2024-06-26 08:40:11 -04:00
# define them on the command line as a simple way of adding CFLAGS/LIBS