-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathmakefile
121 lines (98 loc) · 2.86 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
ifneq ($(OS_NAME),)
TARGET_OS = $(OS_NAME)
else
ifeq ($(OS),Windows_NT)
TARGET_OS = Windows
else ifeq ($(PLATFORM),iPhoneOS)
TARGET_OS = iPhoneOS
else ifeq ($(PLATFORM),iPhoneSimulator)
TARGET_OS = iPhoneSimulator
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
TARGET_OS = Mac
else
TARGET_OS = Linux
endif
endif
endif
ifeq ($(TARGET_OS),Windows)
LIBRARY = binn-3.0.dll
else ifeq ($(TARGET_OS),iPhoneOS)
LIBRARY = libbinn.dylib
CFLAGS += -fPIC
else ifeq ($(TARGET_OS),iPhoneSimulator)
LIBRARY = libbinn.dylib
CFLAGS += -fPIC
else
ifeq ($(TARGET_OS),Mac)
LIBRARY = libbinn.3.dylib
LINK1 = libbinn.dylib
else
LIBRARY = libbinn.so.3.0
LINK1 = libbinn.so.3
LINK2 = libbinn.so
endif
CFLAGS += -fPIC
endif
SHORT = binn
PREFIX ?= /usr/local
ifneq ($(HOST),)
CROSS_PREFIX := $(HOST)-
endif
CC ?= $(CROSS_PREFIX)gcc
STRIP ?= $(CROSS_PREFIX)strip
.PHONY: test
all: $(LIBRARY)
static: libbinn.a
ios: libbinn.a libbinn.dylib
libbinn.so.3.0: binn.o
$(CC) -shared -Wl,-soname,$(LINK1) -o $@ $^
$(STRIP) $@
libbinn.3.dylib: binn.o
$(CC) -dynamiclib -install_name "$(DESTDIR)$(PREFIX)/lib/$@" -current_version 3.0.0 -compatibility_version 3.0 -o $@ $^
$(STRIP) -x $@
libbinn.a: binn.o
$(AR) rcs $@ $^
libbinn.dylib: binn.o
$(CC) -dynamiclib -o $@ $^ $(LDFLAGS)
$(STRIP) -x $@
binn-3.0.dll: binn.o dllmain.o
$(CC) -shared -Wl,--out-implib,binn-3.0.lib -o $@ $^
$(STRIP) $@
binn.o: src/binn.c src/binn.h
$(CC) -Wall $(CFLAGS) -c $<
dllmain.o: src/win32/dllmain.c
$(CC) -Wall -c $<
install: binn.pc-install
ifeq ($(TARGET_OS),Windows)
$(error install not supported on Windows)
else ifeq ($(TARGET_OS),Mac)
mkdir -p $(DESTDIR)$(PREFIX)/lib
mkdir -p $(DESTDIR)$(PREFIX)/include
install -m644 $(LIBRARY) $(DESTDIR)$(PREFIX)/lib
install -m644 src/binn.h $(DESTDIR)$(PREFIX)/include
cd $(DESTDIR)$(PREFIX)/lib && ln -sf $(LIBRARY) $(LINK1)
else
mkdir -p $(DESTDIR)$(PREFIX)/lib
mkdir -p $(DESTDIR)$(PREFIX)/include
install -m644 $(LIBRARY) $(DESTDIR)$(PREFIX)/lib
install -m644 src/binn.h $(DESTDIR)$(PREFIX)/include
cd $(DESTDIR)$(PREFIX)/lib && ln -sf $(LIBRARY) $(LINK1)
cd $(DESTDIR)$(PREFIX)/lib && ln -sf $(LIBRARY) $(LINK2)
endif
.PHONY: binn.pc binn.pc-install binn.pc-clean
binn.pc:
sed "s#@prefix@#$(PREFIX)#" binn.pc.in > binn.pc
binn.pc-install: binn.pc
mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig
install -m644 binn.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
binn.pc-clean:
rm -f binn.pc
clean: binn.pc-clean
rm -f *.o $(LIBRARY) libbinn.a libbinn.dylib
uninstall:
rm -f $(PREFIX)/lib/$(LINK1) $(PREFIX)/lib/$(LINK2) $(PREFIX)/lib/$(LIBRARY) $(PREFIX)/include/binn.h
test: test/test_binn.c test/test_binn2.c src/binn.c
$(CC) -g -Wall -DDEBUG -o test/test_binn $^
cd test && ./test_binn