-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
60 lines (47 loc) · 1.03 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
# C API sample file build for Unix (Linux and macOS)
.FAKE : test run all clean
CC=cc
CFLAGS=-g
LDFLAGS=-L./build -lmtpng
CARGO=cargo
PROFILE=release
RUSTLIBDIR=target/$(PROFILE)
# This is all hacky and not gonna help with cross-compiling. :D
ifeq ($(OS),Windows_NT)
EXE_EXT=.exe
CDYLIB_EXT=.dll
CDYLIB_PATHVAR=
else
UNAME_S=$(shell uname -s)
ifeq ($(UNAME_S),Linux)
EXE_EXT=
CDYLIB_EXT=.so
CDYLIB_PATHVAR=LD_LIBRARY_PATH=build
endif
ifeq ($(UNAME_S),Darwin)
EXE_EXT=
CDYLIB_EXT=.dylib
CDYLIB_PATHVAR=
endif
endif
RUSTLIB=$(RUSTLIBDIR)/libmtpng$(CDYLIB_EXT)
SOURCES=c/sample.c
HEADERS=c/mtpng.h
EXE=build/sample$(EXE_EXT)
LIB=build/libmtpng$(CDYLIB_EXT)
all : $(EXE)
clean :
rm -f $(EXE)
rm -f $(LIB)
cargo clean
run : all
mkdir -p out
$(CDYLIB_PATHVAR) ./$(EXE)
test : run
$(EXE) : $(SOURCES) $(HEADERS) $(LIB)
$(CC) $(CFLAGS) -o $(EXE) $(SOURCES) $(LDFLAGS)
$(LIB) : $(RUSTLIB)
mkdir -p build && \
cp $(RUSTLIB) $(LIB)
$(RUSTLIB) : Cargo.toml src/*.rs
$(CARGO) build --release --features capi