-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.old
103 lines (77 loc) · 2.85 KB
/
Makefile.old
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
102
#============================================================================#
# BobEngine #
#============================================================================#
# Compiler and common flags
CXX = g++
# Specific flags for different build profiles
COMMON_CFLAGS = -Wall -fdiagnostics-color=auto -Iinclude
LIBS = -lglfw -lGLEW -lGLU -lGL
# Just a normal thingy
CFLAGS_NORMAL = $(COMMON_CFLAGS) -O2
# For debugging
CFLAGS_DEBUG = $(COMMON_CFLAGS) -Og -g -fstack-protector
# Optimized for release
CFLAGS_RELEASE = $(COMMON_CFLAGS) -O3 -fno-math-errno -fomit-frame-pointer -fno-strict-aliasing \
-flto -fuse-linker-plugin
# Fast but unstable for release
CFLAGS_FAST = $(COMMON_CFLAGS) -Ofast -march=native -fno-math-errno -fomit-frame-pointer -fno-strict-aliasing \
-flto -fuse-linker-plugin -fprefetch-loop-arrays -ftree-vectorize
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
#=============================================================================
# Source files and executable
SRC_DIR := src
OBJ_DIR := obj
BIN_DIR := bin
SRC := $(wildcard $(SRC_DIR)/*.cpp)
OBJ := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC))
EXECUTABLE := $(BIN_DIR)/main
#=============================================================================
# Default target rule
default: run-debug
.PHONY: default
# Build all
all: normal debug fast release
.PHONY: all
#=============================================================================
# Build target rules
define build_rule
$(1): $(BIN_DIR) $(OBJ_DIR) $$(OBJ)
$$(CXX) $($(2)) -o $(EXECUTABLE)_$(1) $$(OBJ) $$(LIBS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$$(CXX) -c $$< -o $$@
endef
$(foreach target, normal debug fast release, $(eval $(call build_rule,$(target),CFLAGS_$(shell echo $(target) | tr '[:lower:]' '[:upper:]'))))
#=============================================================================
# Run target rules
define run_rule
run-$(1): $(1)
./$$(EXECUTABLE)_$(1)
endef
$(foreach target, normal debug fast release, $(eval $(call run_rule,$(target))))
.PHONY: run-normal run-debug run-fast run-release
# Run aliases
r: run-debug
run: run-normal
rund: run-debug
runf: run-fast
runr: run-release
.PHONY: r run rund runf runr
#=============================================================================
# Clean rules
define clean_rule
clean-$(1):
rm -f $$(EXECUTABLE)_$(1)
endef
$(foreach target, normal debug fast release, $(eval $(call clean_rule,$(target))))
clean:
rm -rf $(BIN_DIR) $(OBJ_DIR)
.PHONY: clean clean-normal clean-debug clean-fast clean-release
#=============================================================================
# Directory creation
$(BIN_DIR):
mkdir -p $(BIN_DIR)
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)