-
Notifications
You must be signed in to change notification settings - Fork 110
/
Makefile
166 lines (124 loc) · 3.3 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#based on the makefiles in rubinius
# Set this such that $(LIBEVDIR)/lib include libev.so and
# $(LIBEVDIR)/include has ev.h
LIBEVDIR=$(HOME)/local/libev
# Respect the environment
ifeq ($(CC),)
CC=gcc
endif
UNAME=$(shell uname)
CPU=$(shell uname -p)
MARCH=$(shell uname -m)
OSVER=$(shell uname -r)
WARNINGS = -Wall
DEBUG = -g -ggdb3
CFLAGS = -I. $(WARNINGS) $(DEBUG)
COMP=$(CC)
ifeq ($(UNAME),Darwin)
LDOPT=-dynamiclib
SUFFIX=dylib
SONAME=-current_version $(VERSION) -compatibility_version $(VERSION)
else
LDOPT=-shared
SUFFIX=so
ifneq ($(UNAME),SunOS)
SONAME=-Wl,-soname,libptr_array-$(VERSION).$(SUFFIX)
endif
endif
BIN_RPATH=
LINKER=$(CC) $(LDOPT)
RANLIB = ranlib
ifndef VERBOSE
COMP=@echo CC $@;$(CC)
LINKER=@echo LINK $@;$(CC) $(LDOPT)
endif
VERSION=0.1
NAME=libebb
OUTPUT_LIB=$(NAME).$(VERSION).$(SUFFIX)
OUTPUT_A=$(NAME).a
ifeq ($(UNAME),Darwin)
SINGLE_MODULE=-Wl,-single_module
ifeq ($(OSVER),9.1.0)
export MACOSX_DEPLOYMENT_TARGET=10.5
else
export MACOSX_DEPLOYMENT_TARGET=10.4
endif
else
SINGLE_MODULE=
endif
ifeq ($(UNAME),SunOS)
CFLAGS+=-D__C99FEATURES__
endif
ifdef DEV
OPTIMIZATIONS=
else
INLINE_OPTS=
OPTIMIZATIONS=-O2 -funroll-loops -finline-functions $(INLINE_OPTS)
endif
ifeq ($(CPU), powerpc)
OPTIMIZATIONS+=-falign-loops=16
endif
CFLAGS += -fPIC $(CPPFLAGS)
DEPS = ebb.h ebb_request_parser.h rbtree.h
LIBS =
GNUTLS_EXISTS = $(shell pkg-config --silence-errors --exists gnutls || echo "no")
ifeq ($(GNUTLS_EXISTS),no)
USING_GNUTLS = "no"
else
CFLAGS += $(shell pkg-config --cflags gnutls) -DHAVE_GNUTLS=1
LIBS += $(shell pkg-config --libs gnutls)
USING_GNUTLS = "yes"
endif
CFLAGS += -I$(LIBEVDIR)/include
LIBS += -L$(LIBEVDIR)/lib -lev
SOURCES=ebb.c ebb_request_parser.c rbtree.c
OBJS=$(SOURCES:.c=.o)
%.o: %.c
$(COMP) $(CFLAGS) $(OPTIMIZATIONS) -c $< -o $@
%.o: %.S
$(COMP) $(CFLAGS) $(OPTIMIZATIONS) -c $< -o $@
.%.d: %.c $(DEPS)
@echo DEP $<
@set -e; rm -f $@; \
$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
library: $(OUTPUT_LIB) $(OUTPUT_A)
@echo "using GnuTLS... ${USING_GNUTLS}"
$(OUTPUT_LIB): $(DEPS) $(OBJS)
$(LINKER) -o $(OUTPUT_LIB) $(OBJS) $(SONAME) $(LIBS)
$(OUTPUT_A): $(DEPS) $(OBJS)
$(AR) cru $(OUTPUT_A) $(OBJS)
$(RANLIB) $(OUTPUT_A)
.PHONY: library
ebb_request_parser.c: ebb_request_parser.rl
ragel -s -G2 $< -o $@
clean:
rm -f *.o *.lo *.la *.so *.dylib *.a test_rbtree test_request_parser examples/hello_world
clobber: clean
rm -f ebb_request_parser.c
.PHONY: clean clobber
test: test_request_parser test_rbtree
./test_request_parser
./test_rbtree
test_rbtree: test_rbtree.o $(OUTPUT_A)
$(CC) -o $@ $< $(OUTPUT_A)
test_request_parser: test_request_parser.o $(OUTPUT_A)
$(CC) -o $@ $< $(OUTPUT_A)
.PHONY: test
examples: examples/hello_world
examples/hello_world: examples/hello_world.o $(OUTPUT_A)
$(CC) $(CFLAGS) -lev -o $@ $< $(OUTPUT_A) $(LIBS)
.PHONY: examples
tags: *.c *.h *.rl examples/*.c
ctags $^
install: $(OUTPUT_A)
install -d -m755 ${prefix}/lib
install -d -m755 ${prefix}/include
install -m644 $(OUTPUT_A) ${prefix}/lib
install -m644 ebb.h ebb_request_parser.h ${prefix}/include
upload_website:
scp -r doc/index.html doc/icon.png [email protected]:~/web/public/libebb
ifneq ($(MAKECMDGOALS),clean)
-include $(SOURCES:%.c=.%.d)
endif