-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
140 lines (106 loc) · 4.37 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
.PHONY: clean fmt check_fmt valgrind compile_rust deps_macos build_collections_lib docker_build docker_run docker_test_and_format docker_clean docker_build_collections_lib docker_valgrind
TARGET=cairo_vm
TEST_TARGET=cairo_vm_test
CC=cc
CXX=g++
SANITIZER_FLAGS=-fsanitize=address -fno-omit-frame-pointer
CFLAGS=-std=c11 -Wall -Wextra -Wimplicit-fallthrough -Werror -pedantic -g -O0
CXX_FLAGS=-std=c++14 -Wall -Wextra -Wimplicit-fallthrough -Werror -pedantic -g -O0
CFLAGS_TEST=-I./src
LN_FLAGS=-L./lambdaworks/lib/lambdaworks/target/release/ -Bstatic -llambdaworks -lcollectc -ldl -lpthread -lm
BUILD_DIR=./build
SRC_DIR=./src
TEST_DIR=./test
LIB_DIR=./lib
SOURCE = $(wildcard $(SRC_DIR)/*.c)
SOURCE := $(filter-out %main.c, $(SOURCE))
SOURCE_CPP = $(wildcard $(SRC_DIR)/*.cpp)
LIB_SOURCE_CPP = $(wildcard $(LIB_DIR)/*.cpp)
TEST_SOURCE = $(wildcard $(TEST_DIR)/*.c)
TEST_SOURCE_CPP = $(wildcard $(TEST_DIR)/*.cpp) $(wildcard $(SRC_DIR)/*.cpp)
HEADERS = $(wildcard $(SRC_DIR)/*.h)
TEST_HEADERS = $(wildcard $(TEST_DIR)/*.h)
OBJECTS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SOURCE))
OBJECTS_CPP = $(patsubst $(SRC_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(SOURCE_CPP))
TEST_OBJECTS = $(patsubst $(TEST_DIR)/%.c, $(BUILD_DIR)/%.o, $(TEST_SOURCE))
LIB_OBJECTS_CPP = $(patsubst $(LIB_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(LIB_SOURCE_CPP))
COLLECTIONS_LIB_DIR= Collections-C
$(COLLECTIONS_LIB_DIR):
git clone https://github.com/srdja/Collections-C.git
cd Collections-C && \
mkdir build && \
cd build && \
cmake .. && \
make && \
sudo make install
# Gcc/Clang will create these .d files containing dependencies.
DEP = $(OBJECTS:%.o=%.d)
default: compile_rust $(TARGET)
$(TARGET): $(BUILD_DIR)/$(TARGET)
$(BUILD_DIR)/$(TARGET): $(OBJECTS) $(OBJECTS_CPP) $(LIB_OBJECTS_CPP) $(BUILD_DIR)/main.o
$(CXX) $(CXX_FLAGS) $(SANITIZER_FLAGS) $^ -o $@ $(LN_FLAGS)
$(TEST_TARGET): $(BUILD_DIR)/$(TEST_TARGET)
$(BUILD_DIR)/$(TEST_TARGET): $(OBJECTS) $(OBJECTS_CPP) $(LIB_OBJECTS_CPP) $(TEST_OBJECTS)
$(CXX) $(CXX_FLAGS) $(CFLAGS_TEST) $(SANITIZER_FLAGS) $^ -o $@ $(LN_FLAGS)
-include $(DEP)
# The potential dependency on header files is covered
# by calling `-include $(DEP)`.
# The -MMD flags additionaly creates a .d file with
# the same name as the .o file.
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(SANITIZER_FLAGS) -MMD -c $< -o $@
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(@D)
$(CXX) $(CXX_FLAGS) $(SANITIZER_FLAGS) -MMD -c $< -o $@
$(BUILD_DIR)/%.o: $(TEST_DIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(CFLAGS_TEST) $(SANITIZER_FLAGS) -MMD -c $< -o $@
$(BUILD_DIR)/%.o: $(LIB_DIR)/%.cpp
@mkdir -p $(@D)
$(CXX) $(CXX_FLAGS) $(SANITIZER_FLAGS) -MMD -c $< -o $@
$(BUILD_DIR)/%.o: $(SRC_DIR)/%main.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(SANITIZER_FLAGS) -MMD -c $< -o $@
deps_macos:
brew install clang-format
run: default
$(BUILD_DIR)/$(TARGET)
test: compile_rust build_collections_lib $(TEST_TARGET)
$(BUILD_DIR)/$(TEST_TARGET)
clean:
rm -rf $(BUILD_DIR) && \
rm -rf $(COLLECTIONS_LIB_DIR) && \
cd lambdaworks/lib/lambdaworks && cargo clean
fmt:
clang-format --style=file -i $(SOURCE) $(TEST_SOURCE) $(HEADERS) $(TEST_HEADERS)
check_fmt:
clang-format --style=file -Werror -n $(SOURCE) $(TEST_SOURCE) $(HEADERS) $(TEST_HEADERS)
valgrind: clean compile_rust build_collections_lib $(TEST_TARGET)
valgrind --leak-check=full --show-reachable=yes --show-leak-kinds=all --track-origins=yes --error-exitcode=1 ./build/cairo_vm_test
compile_rust:
cd lambdaworks/lib/lambdaworks && cargo build --release
build_collections_lib: | $(COLLECTIONS_LIB_DIR)
docker_build:
docker build . -t cairo-vm_in_c
docker_run:
docker run --rm -it -v `pwd`:/usr/cairo-vm_in_C cairo-vm_in_c
docker_test_and_format:
docker create --name test -t -v `pwd`:/usr/cairo-vm_in_C cairo-vm_in_c
docker start test
docker exec -t test bash -c "make clean && make docker_build_collections_lib && make test && make SANITIZER_FLAGS=-fno-omit-frame-pointer docker_valgrind"
docker stop test
docker rm test
docker_clean:
docker rmi cairo-vm_in_c
docker_build_collections_lib:
git clone https://github.com/srdja/Collections-C.git
cd Collections-C && \
mkdir build && \
cd build && \
cmake .. && \
make && \
make install && \
ldconfig
docker_valgrind: clean compile_rust docker_build_collections_lib $(TEST_TARGET)
valgrind --leak-check=full --show-reachable=yes --show-leak-kinds=all --track-origins=yes --error-exitcode=1 ./build/cairo_vm_test