-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
49 lines (35 loc) · 960 Bytes
/
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
CARGO_TARGET = debug
CFLAGS = -O2 -g -fPIE
CARGO_BUILD_OPTS =
CARGO_TEST_OPTS =
PROGRAMS = main
STATICLIBS = libfoo.a
CARGO_LIBS = foo
CARGO_SOURCES = src/foo.rs src/lib.rs \
src/bindgen/mod.rs src/bindgen/foo.rs
CARGO_STATICLIBS = $(CARGO_LIBS:%=target/$(CARGO_TARGET)/lib%.a)
ifeq ($(CARGO_TARGET), release)
CARGO_BUILD_OPTS += --release
endif
.PHONY: all
all: main
main: src/main.o $(STATICLIBS) $(CARGO_STATICLIBS)
$(CC) -o $@ $^
libfoo.a: src/foo.o
$(AR) cru $@ $^
%.o: %.c
$(CC) -o $@ -c $< $(CFLAGS)
src/main.o: src/main.c src/foo.h
src/foo.o: src/foo.c src/foo.h
src/bindgen/foo.rs: src/foo.h
bindgen --no-rustfmt-bindings $< > $@
.PHONY: $(CARGO_STATICLIBS) cargo-build-lib
$(CARGO_STATICLIBS): cargo-build-lib
cargo-build-lib: $(CARGO_SOURCES)
cargo build --lib $(CARGO_BUILD_OPTS)
clean:
rm -f $(PROGRAMS) $(STATICLIBS)
find . -name "*.o" | xargs rm -f --
cargo clean
check:
cargo test $(CARGO_BUILD_OPTS) $(CARGO_TEST_OPTS)