-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
75 lines (54 loc) · 1.46 KB
/
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
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
# Compiler
CC = gcc
CXX = g++
# Compiler flags
CFLAGS = -std=c11 -Wall -Wextra
CXXFLAGS = -std=c++20 -Wall -Wextra
# Include directories
INCLUDES = -Iinclude
# Libraries
CLIBS =
CXXLIBS =
# Source files
CSRCS = $(wildcard src/*.c)
CXXSRCS = $(wildcard src/*.cpp)
# Object files
COBJS = $(CSRCS:.c=.o)
COBJS := $(addprefix build/, $(COBJS))
CXXOBJS = $(CXXSRCS:.cpp=.o)
CXXOBJS := $(addprefix build/, $(CXXOBJS))
# Executable name
MAIN = main
.PHONY: default all debug clean depend
default: all
all: $(MAIN)
@echo "Project has been compiled"
debug: CFLAGS += -g -DDEBUG -D_DEBUG
debug: CXXFLAGS += -g -DDEBUG -D_DEBUG
debug: $(MAIN)
@echo "Project has been compiled in debug mode"
### Choose one of the following for C or C++ compilation -------------------
# $(MAIN): $(COBJS)
# @mkdir -p build/bin
# $(CC) $(CFLAGS) $(INCLUDES) -o build/bin/$(MAIN) $(COBJS) $(CLIBS)
$(MAIN): $(CXXOBJS)
@mkdir -p build/bin
$(CXX) $(CXXFLAGS) $(INCLUDES) -o build/bin/$(MAIN) $(CXXOBJS) $(CXXLIBS)
# build/%.o: %.c
# @mkdir -p $(@D)
# $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
build/%.o: %.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
# depend: $(CSRCS)
# makedepend $(INCLUDES) $^
depend: $(CXXSRCS)
makedepend $(INCLUDES) $^
### -----------------------------------------------------------------------
clean:
$(RM) build/src/*.o *~ $(MAIN)
$(RM) build/bin/$(MAIN)
$(RM) build/lib/*.a
# Include dependency files
-include $(SRCS:.c=.d)
-include $(SRCS:.cpp=.d)