-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
71 lines (51 loc) · 1.51 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
# In case the user uses a global build cache for rust
CARGO_TARGET_DIR = ./target/
CC = clang
CXX = clang++
#CC = gcc
#CXX = g++
CFLAGS := -std=c89 -Wall -Werror -pedantic
CXXFLAGS := -std=c++11 -Wall -Werror -pedantic
ifneq ($(findstring optimized,$(MAKECMDGOALS)),)
CFLAGS := -O2 $(CFLAGS)
CXXFLAGS := -O2 $(CXXFLAGS)
RUST_LIB := target/release/libintsorter.a
else
CFLAGS := -g $(CFLAGS)
CXXFLAGS := -g $(CXXFLAGS)
RUST_LIB := target/debug/libintsorter.a
endif
ifeq ($(shell uname),Darwin)
LDFLAGS := -Wl,-dead_strip
else
LDFLAGS := -Wl,--gc-sections -lpthread -ldl
endif
all: target/hgc target/hgcpp
######## Testing from C
target/hgc
######## Testing from C++
target/hgcpp
target:
mkdir -p $@
target/hgc: target/main_c.o $(RUST_LIB)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
target/hgcpp: target/main_cpp.o $(RUST_LIB)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
target/hgcpp_debug: target/main_cpp.o target/debug/libintsorter.a
$(CXX) $(CXXFLAGS) -fsanitize=undefined -fsanitize=leak -fsanitize=memory -fno-omit-frame-pointer -o $@ $^ $(LDFLAGS)
target/debug/libintsorter.a: src/lib.rs Cargo.toml
cargo build $(CARGOFLAGS)
target/release/libintsorter.a: src/lib.rs Cargo.toml
cargo build --release
target/main_c.o: src/main.c | target
$(CC) $(CFLAGS) -o $@ -c $<
target/main_cpp.o: src/main.cpp | target
$(CXX) $(CXXFLAGS) -o $@ -c $<
clean:
rm -rf target
optimized: all
# enables optimization
help:
# enable optimization by adding the optimized-target
# clean target
# all target compile and run tests