-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (78 loc) · 2.47 KB
/
Copy pathMakefile
File metadata and controls
101 lines (78 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
CC = gcc
PKG_CONFIG ?= pkg-config
rwildcard = $(foreach dir,$(wildcard $(1)/*),$(call rwildcard,$(dir),$(2))) $(filter $(subst *,%,$(2)),$(wildcard $(1)/$(2)))
SRC := $(sort $(call rwildcard,src,*.c))
OBJ := $(patsubst src/%.c,build/%.o,$(SRC))
DEP := $(OBJ:.o=.d)
BIN_DIR := bin
BUILD_DIR := build
TARGET_NAME := open-sosaria
TARGET := $(BIN_DIR)/$(TARGET_NAME)
CPPFLAGS += -Isrc
CFLAGS += -std=c99 -Wall -Wextra -Werror -MMD -MP
LDFLAGS +=
LDLIBS +=
STRIP_FLAGS := -s
GUI_LDFLAGS :=
DEBUG_CPPFLAGS := -DDEBUG
GLFW_CFLAGS := $(strip $(shell $(PKG_CONFIG) --cflags glfw3 2>/dev/null))
GLFW_LIBS := $(strip $(shell $(PKG_CONFIG) --libs glfw3 2>/dev/null))
ifeq ($(OS),Windows_NT)
TARGET := $(TARGET).exe
CPPFLAGS += -DCR_WINDOWS
GUI_LDFLAGS += -mwindows
ifneq ($(GLFW_CFLAGS)$(GLFW_LIBS),)
CPPFLAGS += $(GLFW_CFLAGS)
LDLIBS += $(GLFW_LIBS)
else
CPPFLAGS += -IC:/CLibs/include
LDFLAGS += -LC:/CLibs/libs
LDLIBS += -lglfw3
endif
LDLIBS += -lopengl32 -lgdi32 -luser32 -lkernel32
else
UNAME_S := $(shell uname -s)
CPPFLAGS += -DCR_UNIX
ifneq ($(GLFW_CFLAGS)$(GLFW_LIBS),)
CPPFLAGS += $(GLFW_CFLAGS)
LDLIBS += $(GLFW_LIBS)
endif
ifeq ($(UNAME_S),Linux)
CPPFLAGS += -D_POSIX_C_SOURCE=200809L
ifeq ($(GLFW_CFLAGS)$(GLFW_LIBS),)
LDLIBS += -lglfw
endif
LDLIBS += -lGL -lX11 -lXrandr -lXi -ldl -lm -lpthread
endif
ifeq ($(UNAME_S),Darwin)
ifeq ($(GLFW_CFLAGS)$(GLFW_LIBS),)
BREW_PREFIX := $(strip $(shell brew --prefix 2>/dev/null))
ifneq ($(BREW_PREFIX),)
CPPFLAGS += -I$(BREW_PREFIX)/include
LDFLAGS += -L$(BREW_PREFIX)/lib
endif
LDLIBS += -lglfw
endif
LDLIBS += -framework Cocoa -framework IOKit -framework CoreVideo
endif
endif
all: $(TARGET)
$(TARGET): $(OBJ)
@mkdir -p $(dir $@)
$(CC) $(OBJ) $(LDFLAGS) $(GUI_LDFLAGS) $(LDLIBS) $(STRIP_FLAGS) -o $@
# Third-party source: relax warning promotion for glad and miniaudio only.
build/dependencies/glad.o: CFLAGS := $(filter-out -Werror -pedantic-errors,$(CFLAGS)) -Wno-error -Wno-pedantic
build/dependencies/miniaudio.o: CFLAGS := $(filter-out -Werror -pedantic-errors,$(CFLAGS)) -Wno-error -Wno-pedantic
build/%.o: src/%.c
@mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
debug: CPPFLAGS += $(DEBUG_CPPFLAGS)
debug: STRIP_FLAGS :=
debug: GUI_LDFLAGS :=
debug: CFLAGS += -g
debug: $(TARGET)
clean:
rm -f $(BIN_DIR)/$(TARGET_NAME) $(BIN_DIR)/$(TARGET_NAME).exe
rm -rf $(BUILD_DIR)
.PHONY: all debug clean
-include $(DEP)