-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
125 lines (100 loc) · 3.53 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
###############################################################################
## SETTINGS ##
###############################################################################
OS = $(shell uname)
ARCH = $(shell uname -m)
PLATFORM = $(OS)-$(ARCH)
CFLAGS = -std=gnu99 -g -Wall -fPIC -O3
CFLAGS += -fno-common -fno-strict-aliasing
CFLAGS += -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_GNU_SOURCE
CFLAGS += -I/usr/local/include
LDFLAGS =
ifeq ($(OS),Darwin)
CFLAGS += -D_DARWIN_UNLIMITED_SELECT
ifneq ($(wildcard /opt/homebrew/include),)
# Mac new homebrew external include path
CFLAGS += -I/opt/homebrew/include
else ifneq ($(wildcard /usr/local/opt/libevent/include),)
# Mac old homebrew libevent include path
CFLAGS += -I/usr/local/opt/libevent/include
endif
ifneq ($(wildcard /opt/homebrew/opt/openssl/include),)
# Mac new homebrew openssl include path
CFLAGS += -I/opt/homebrew/opt/openssl/include
else ifneq ($(wildcard /usr/local/opt/openssl/include),)
# Mac old homebrew openssl include path
CFLAGS += -I/usr/local/opt/openssl/include
else ifneq ($(wildcard /opt/local/include/openssl),)
# macports openssl include path
CFLAGS += -I/opt/local/include
endif
LDFLAGS += /usr/local/lib/libaerospike.a
ifneq ($(wildcard /opt/homebrew/lib),)
# Mac new homebrew external lib path
LDFLAGS += -L/opt/homebrew/lib
else
# Mac old homebrew external lib path
LDFLAGS += -L/usr/local/lib
ifeq ($(EVENT_LIB),libevent)
LDFLAGS += -L/usr/local/opt/libevent/lib
endif
endif
ifneq ($(wildcard /opt/homebrew/opt/openssl/lib),)
# Mac new homebrew openssl lib path
LDFLAGS += -L/opt/homebrew/opt/openssl/lib
else
# Mac old homebrew openssl lib path
LDFLAGS += -L/usr/local/opt/openssl/lib
endif
else ifeq ($(OS),FreeBSD)
CFLAGS += -finline-functions
LDFLAGS += /usr/lib/libaerospike.a
else
CFLAGS += -finline-functions -rdynamic
LDFLAGS += /usr/lib/libaerospike.a
ifneq ($(wildcard /etc/alpine-release),)
CFLAGS += -DAS_ALPINE
endif
endif
ifeq ($(EVENT_LIB),libuv)
CFLAGS += -DAS_USE_LIBUV
LDFLAGS += -L/usr/local/lib -luv
TARGETS = target/single_thread_libuv
else ifeq ($(EVENT_LIB),libevent)
CFLAGS += -DAS_USE_LIBEVENT
LDFLAGS += -L/usr/local/lib -levent_core -levent_pthreads
TARGETS = target/single_thread_libevent
else
CFLAGS += -DAS_USE_LIBEV
LDFLAGS += -L/usr/local/lib -lev
TARGETS = target/single_thread_libev
endif
LDFLAGS += -lssl -lcrypto -lpthread -lm -lz
ifneq ($(OS),Darwin)
LDFLAGS += -lrt -ldl
endif
###############################################################################
## OBJECTS ##
###############################################################################
OBJECTS = async_tutorial.o
###############################################################################
## MAIN TARGETS ##
###############################################################################
all: build
.PHONY: build
build: target/async_tutorial $(TARGETS)
.PHONY: clean
clean:
@rm -rf target
target:
mkdir $@
target/%.o: %.c | target
cc $(CFLAGS) -o $@ -c $^
target/async_tutorial: $(addprefix target/,$(OBJECTS)) | target
cc -o $@ $^ $(LDFLAGS)
target/single_thread_libuv: $(addprefix target/,$(OBJECTS)) | target
cc -o $@ $^ $(LDFLAGS)
target/single_thread_libevent: $(addprefix target/,$(OBJECTS)) | target
cc -o $@ $^ $(LDFLAGS)
target/single_thread_libev: $(addprefix target/,$(OBJECTS)) | target
cc -o $@ $^ $(LDFLAGS)