-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
46 lines (36 loc) · 965 Bytes
/
Makefile
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
# Functions
define find_files
$(shell find $(1) -type f -name '$(2)')
endef
# Variables
DIR_INC = include
DIR_SRC = src
DIR_BUILD = build
INC_C = $(call find_files,$(DIR_INC),*.h)
INC_CPP = $(call find_files,$(DIR_INC),*.hpp)
SRC_C = $(call find_files,$(DIR_SRC),*.c)
SRC_CPP = $(call find_files,$(DIR_SRC),*.cpp)
OBJ_C = $(SRC_C:$(DIR_SRC)/%.c=$(DIR_BUILD)/%.o)
OBJ_CPP = $(SRC_CPP:$(DIR_SRC)/%.cpp=$(DIR_BUILD)/%.o)
TARGET = bin/project
# Flags
CC = gcc
CXX = g++
CFLAGS = -I$(DIR_INC) -O1 -Wall
CXXFLAGS = -I$(DIR_INC) -O1 -Wall
LDFLAGS = -lm
# Rules
all: $(TARGET)
$(TARGET): $(OBJ_C) $(OBJ_CPP)
$(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJ_C) $(OBJ_CPP) $(LDFLAGS)
$(DIR_BUILD)/%.o: $(DIR_SRC)/%.c | $(DIR_BUILD)/%.d
$(CC) $(CFLAGS) -c $< -o $@
$(DIR_BUILD)/%.o: $(DIR_SRC)/%.cpp | $(DIR_BUILD)/%.d
$(CXX) $(CXXFLAGS) -c $< -o $@
$(DIR_BUILD)/%.d:
mkdir -p $(dir $@)
run: all
@./$(TARGET)
clean:
$(RM) -r $(DIR_BUILD) $(TARGET)
.PHONY: all clean run