-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
54 lines (43 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
CC = clang
CXX = clang++
BUILD_DIR := bin
OBJ_DIR := obj
ASSEMBLY := ldcapture
EXTENSION := .so
COMPILER_FLAGS := -fPIC
INCLUDE_FLAGS := -Isrc -Ivendor -Ivendor/STC/include -Ivendor/FMOD
LINKER_FLAGS := -shared -lm -ldl -lpulse -lpthread -lavformat -lavcodec -lswresample -lswscale -lavutil -lconfig
DEFINES :=
SRC_FILES := $(shell find src -name *.c -or -name *.cpp) # .c and .cpp files
DIRECTORIES := $(shell find src -type d) # directories with .h files
OBJ_FILES := $(SRC_FILES:%=$(OBJ_DIR)/%.o) # compiled .o objects
all: scaffold compile link
debug: COMPILER_FLAGS += -g -O0
debug: LINKER_FLAGS +=
debug: DEFINES += -DDEBUG
debug: all
release: COMPILER_FLAGS += -O2
release: DEFINES += -DRELEASE
release: all
.PHONY: scaffold
scaffold: # create build directory
@echo Scaffolding folder structure...
@mkdir -p $(addprefix $(OBJ_DIR)/,$(DIRECTORIES))
@mkdir -p $(BUILD_DIR)
.PHONY: link
link: scaffold $(OBJ_FILES) # link
@echo Linking $(ASSEMBLY)...
$(CC) $(OBJ_FILES) -o $(BUILD_DIR)/$(ASSEMBLY)$(EXTENSION) $(LINKER_FLAGS)
.PHONY: compile
compile: #compile .c and .cpp files
@echo Compiling...
.PHONY: clean
clean: # clean build directory
rm -rf $(BUILD_DIR)
rm -rf $(OBJ_DIR)
$(OBJ_DIR)/%.c.o: %.c # compile .c to .o object
@echo $<...
$(CC) -std=c17 $< $(COMPILER_FLAGS) -c -o $@ $(DEFINES) $(INCLUDE_FLAGS)
$(OBJ_DIR)/%.cpp.o: %.cpp # compile .cpp to .o object
@echo $<...
$(CXX) -std=c++17 $< $(COMPILER_FLAGS) -c -o $@ $(DEFINES) $(INCLUDE_FLAGS)