-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (78 loc) · 2.02 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#
# 'make' build executable file 'main'
# 'make clean' removes all .o and executable files
#
# Debug mode is disabled by default. To build in debug, use `make DEBUG=1`
DEBUG=
# CXX compiler to use
CXX = g++
LIBRARIES := libcurl
CFLAGS_DEBUG=-g
CFLAGS_RELEASE=-O3
CXXFLAGS_COMMON := `pkg-config --cflags $(LIBRARIES)` -std=c++20 -Wall -Wextra
CXXFLAGS_DEBUG := $(CXXFLAGS_COMMON) $(CFLAGS_DEBUG)
CXXFLAGS_RELEASE := $(CXXFLAGS_COMMON) $(CFLAGS_RELEASE)
LFLAGS = `pkg-config --libs $(LIBRARIES)`
OUTPUT := output
SRC := src
INCLUDE := include
LIB := lib
ifneq ($(SYSTEM),)
ifeq ($(SYSTEM),imperial)
CXXFLAGS += -DIMPERIAL
else ifeq ($(SYSTEM),metric)
CXXFLAGS += -DMETRIC
else
$(error Invalid system specified: $(SYSTEM))
endif
else
CXXFLAGS += -DMETRIC
endif
ifeq ($(OS),Windows_NT)
MAIN := main.exe
SOURCEDIRS := $(SRC)
INCLUDEDIRS := $(INCLUDE)
LIBDIRS := $(LIB)
FIXPATH = $(subst /,\,$1)
RM := del /q /f
MD := mkdir
else
MAIN := main
SOURCEDIRS := $(shell find $(SRC) -type d)
INCLUDEDIRS := $(shell find $(INCLUDE) -type d)
LIBDIRS := $(shell find $(LIB) -type d)
FIXPATH = $1
RM = rm -f
MD := mkdir -p
endif
INCLUDES := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))
LIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))
SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS)))
OBJECTS := $(SOURCES:.cpp=.o)
DEPS := $(OBJECTS:.o=.d)
OUTPUTMAIN := $(call FIXPATH,$(OUTPUT)/$(MAIN))
ifeq ($(DEBUG), 1)
CXXFLAGS:=$(CXXFLAGS) $(CXXFLAGS_DEBUG)
MODESTR := Debug
else
CXXFLAGS:=$(CXXFLAGS) $(CXXFLAGS_RELEASE)
MODESTR := Release
endif
all: $(OUTPUT) $(MAIN)
$(info Building in $(MODESTR) mode)
@echo Executing 'all' complete!
$(OUTPUT):
$(MD) $(OUTPUT)
$(MAIN): $(OBJECTS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(OUTPUTMAIN) $(OBJECTS) $(LFLAGS) $(LIBS)
-include $(DEPS)
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -MMD $< -o $@
.PHONY: clean run
clean:
$(RM) $(OUTPUTMAIN)
$(RM) $(call FIXPATH,$(OBJECTS))
$(RM) $(call FIXPATH,$(DEPS))
@echo Cleanup complete!
run: all
@./$(OUTPUTMAIN)