-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
49 lines (38 loc) · 1.13 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
# important directories
SRC = src
BIN = bin
OBJ = obj
INCLUDE = include
# compilation related parameters
CXX = g++
CXXFLAGS = -std=c++17
CC = gcc
CFLAGS =
LDFLAGS = $(shell pkg-config --libs \
libnetfilter_queue)
# identify sources and create object file targets
SOURCES_CPP = $(wildcard $(SRC)/*.cpp)
SOURCES_C = $(wildcard $(SRC)/*.c)
OBJECTS = $(patsubst $(SRC)/%.cpp, $(OBJ)/%.o, $(SOURCES_CPP)) \
$(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SOURCES_C))
# directive to prevent (attempted) itermediary file/directory deletion
.PRECIOUS: $(BIN)/ $(OBJ)/
# top level rule (specifies final binary)
build: $(BIN)/ops-inject
# generate compile_Commands.json for clangd (or other language servers)
bear:
bear -- $(MAKE) build
# non-persistent directory creation rule
%/:
@mkdir -p $@
# final binary generation rule
$(BIN)/ops-inject: $(OBJECTS) | $(BIN)/
$(CXX) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# object generation rule
$(OBJ)/%.o: $(SRC)/%.cpp | $(OBJ)/
$(CXX) -c -I $(INCLUDE) $(CXXFLAGS) -o $@ $<
$(OBJ)/%.o: $(SRC)/%.c | $(OBJ)/
$(CC) -c -I $(INCLUDE) $(CFLAGS) -o $@ $<
# clean rule
clean:
@rm -rf $(BIN) $(OBJ)