-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
73 lines (56 loc) · 1.68 KB
/
makefile
File metadata and controls
73 lines (56 loc) · 1.68 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
# Directories
SRC_DIR = src
OBJ_DIR = obj
RELEASE_DIR = release
DEBUG_DIR = debug
# Compiler and flags
CXX = g++
# Base flags
BASE_CXXFLAGS = -std=c++14 -Wall -Iinclude -Ithird_party
# Debug flags - include debug info, minimal optimization
DEBUG_CXXFLAGS = $(BASE_CXXFLAGS) -g -O1
# Release flags - full optimization, no debug info
RELEASE_CXXFLAGS = $(BASE_CXXFLAGS) -O3 -DNDEBUG
# Current mode - can be overridden by 'make MODE=release'
MODE ?= debug
# Set flags based on mode
ifeq ($(MODE),debug)
CXXFLAGS = $(DEBUG_CXXFLAGS)
TARGET_DIR = $(DEBUG_DIR)
else
CXXFLAGS = $(RELEASE_CXXFLAGS)
TARGET_DIR = $(RELEASE_DIR)
endif
FRAMEWORKS = -framework ApplicationServices
# Find all .cpp files recursively in SRC_DIR
SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
# Generate object file names in OBJ_DIR, using the base name of the source file
# Assumes no two .cpp files have the same name in different subdirectories
OBJS := $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(notdir $(SRCS)))
# Target executable
TARGET = $(TARGET_DIR)/input_simulator
# Tell make where to find source files for the pattern rule below
VPATH := $(shell find $(SRC_DIR) -type d)
# Default target
all: directories $(TARGET)
# Create necessary directories
directories:
mkdir -p $(OBJ_DIR)
mkdir -p $(RELEASE_DIR)
mkdir -p $(DEBUG_DIR)
# Link
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) $(OBJS) -o $(TARGET) $(FRAMEWORKS)
# Compile source files found via VPATH into OBJ_DIR
$(OBJ_DIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
# Clean
clean:
rm -rf $(OBJ_DIR)
rm -f $(DEBUG_DIR)/*
rm -f $(RELEASE_DIR)/*
# Targets for specific modes
debug: all
release:
$(MAKE) MODE=release all
.PHONY: all clean directories debug release