Skip to content

Commit f888e6b

Browse files
committed
changes for usage with osx and mess with makefile
1 parent 3063242 commit f888e6b

File tree

3 files changed

+156
-65
lines changed

3 files changed

+156
-65
lines changed

Makefile

+137-53
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,160 @@
1-
LIBEVDIR = ${HOME}/local/libev
2-
3-
# where to install to.
4-
# will create ${prefix}/include and ${prefix}/lib
5-
prefix = ${HOME}/local/libebb
6-
7-
CFLAGS = -g -Wall -fPIC -O3
8-
LIBS = -L${LIBEVDIR}/lib -lev `pkg-config --libs gnutls`
9-
10-
#
11-
# libebb.so
12-
#
13-
14-
libebb.so: ebb.o ebb_request_parser.o rbtree.o
15-
gcc -shared -o $@ $^
16-
17-
ebb.o: ebb.c ebb.h
18-
gcc ${CFLAGS} -I${LIBEVDIR}/include `pkg-config --cflags gnutls` -c $< -o $@
19-
20-
rbtree.o: rbtree.c rbtree.h
21-
gcc ${CFLAGS} -c $< -o $@
22-
23-
ebb_request_parser.o: ebb_request_parser.c ebb_request_parser.h
24-
gcc ${CFLAGS} -c $< -o $@
1+
#based on the makefiles in rubinius
2+
3+
# Respect the environment
4+
ifeq ($(CC),)
5+
CC=gcc
6+
endif
7+
8+
UNAME=$(shell uname)
9+
CPU=$(shell uname -p)
10+
MARCH=$(shell uname -m)
11+
OSVER=$(shell uname -r)
12+
13+
WARNINGS = -Wall
14+
DEBUG = -g -ggdb3
15+
16+
CFLAGS = -I. $(WARNINGS) $(DEBUG)
17+
18+
19+
20+
COMP=$(CC)
21+
ifeq ($(UNAME),Darwin)
22+
LDOPT=-dynamiclib
23+
SUFFIX=dylib
24+
SONAME=-current_version $(VERSION) -compatibility_version $(VERSION)
25+
else
26+
LDOPT=-shared
27+
SUFFIX=so
28+
ifneq ($(UNAME),SunOS)
29+
SONAME=-Wl,-soname,libptr_array-$(VERSION).$(SUFFIX)
30+
endif
31+
endif
32+
33+
BIN_RPATH=
34+
LINKER=$(CC) $(LDOPT)
35+
RANLIB = ranlib
36+
37+
ifndef VERBOSE
38+
COMP=@echo CC $@;$(CC)
39+
LINKER=@echo LINK $@;$(CC) $(LDOPT)
40+
endif
41+
42+
VERSION=0.1
43+
44+
NAME=libebb
45+
OUTPUT_LIB=$(NAME).$(VERSION).$(SUFFIX)
46+
OUTPUT_A=$(NAME).a
47+
48+
ifeq ($(UNAME),Darwin)
49+
SINGLE_MODULE=-Wl,-single_module
50+
ifeq ($(OSVER),9.1.0)
51+
export MACOSX_DEPLOYMENT_TARGET=10.5
52+
else
53+
export MACOSX_DEPLOYMENT_TARGET=10.4
54+
endif
55+
else
56+
SINGLE_MODULE=
57+
endif
58+
59+
ifeq ($(UNAME),SunOS)
60+
CFLAGS+=-D__C99FEATURES__
61+
endif
62+
63+
ifdef DEV
64+
OPTIMIZATIONS=
65+
else
66+
INLINE_OPTS=
67+
OPTIMIZATIONS=-O2 -funroll-loops -finline-functions $(INLINE_OPTS)
68+
endif
69+
70+
ifeq ($(CPU), powerpc)
71+
OPTIMIZATIONS+=-falign-loops=16
72+
endif
73+
74+
CFLAGS += -fPIC $(CPPFLAGS)
75+
DEPS = ebb.h ebb_request_parser.h rbtree.h
76+
LIBS = -lev
77+
78+
GNUTLS_EXISTS = $(shell pkg-config --silence-errors --exists gnutls || echo "no")
79+
ifneq (GNUTLS_EXISTS,no)
80+
CFLAGS += $(shell pkg-config --cflags gnutls) -DHAVE_GNUTLS=1
81+
LIBS += $(shell pkg-config --libs gnutls)
82+
USING_GNUTLS = "yes"
83+
else
84+
USING_GNUTLS = "no"
85+
endif
86+
87+
SOURCES=ebb.c ebb_request_parser.c rbtree.c
88+
OBJS=$(SOURCES:.c=.o)
89+
90+
%.o: %.c
91+
$(COMP) $(CFLAGS) $(OPTIMIZATIONS) -c $< -o $@
92+
93+
%.o: %.S
94+
$(COMP) $(CFLAGS) $(OPTIMIZATIONS) -c $< -o $@
95+
96+
.%.d: %.c $(DEPS)
97+
@echo DEP $<
98+
@set -e; rm -f $@; \
99+
$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
100+
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
101+
rm -f $@.$$$$
102+
103+
library: $(OUTPUT_LIB) $(OUTPUT_A)
104+
@echo "using GnuTLS... ${USING_GNUTLS}"
105+
106+
$(OUTPUT_LIB): $(DEPS) $(OBJS)
107+
$(LINKER) -o $(OUTPUT_LIB) $(OBJS) $(SONAME) $(LIBS)
108+
109+
$(OUTPUT_A): $(DEPS) $(OBJS)
110+
$(AR) cru $(OUTPUT_A) $(OBJS)
111+
$(RANLIB) $(OUTPUT_A)
112+
113+
.PHONY: library
25114

26115
ebb_request_parser.c: ebb_request_parser.rl
27116
ragel -s -G2 $< -o $@
28117

29-
#
30-
# Test programs
31-
#
118+
clean:
119+
rm -f *.o *.lo *.la *.so *.dylib *.a test_rbtree test_request_parser examples/hello_world
32120

33-
test_request_parser: test_request_parser.c ebb_request_parser.o
34-
gcc ${CFLAGS} $^ -o $@ # -lefence
121+
clobber: clean
122+
rm -f ebb_request_parser.c
35123

36-
test_rbtree: test_rbtree.c rbtree.o
37-
gcc ${CFLAGS} $^ -o $@ # -lefence
124+
.PHONY: clean clobber
38125

39126
test: test_request_parser test_rbtree
40127
./test_request_parser
41128
./test_rbtree
42129

43-
#
44-
# Example programs
45-
#
130+
test_rbtree: test_rbtree.o $(OUTPUT_A)
131+
$(CC) -o $@ $< $(OUTPUT_A)
132+
133+
test_request_parser: test_request_parser.o $(OUTPUT_A)
134+
$(CC) -o $@ $< $(OUTPUT_A)
135+
136+
.PHONY: test
46137

47138
examples: examples/hello_world
48139

49-
examples/hello_world: examples/hello_world.c ebb.o ebb_request_parser.o rbtree.o
50-
gcc ${CFLAGS} ${LIBS} -lefence $^ -o $@
140+
examples/hello_world: examples/hello_world.o $(OUTPUT_A)
141+
$(CC) -lev -o $@ $< $(OUTPUT_A)
51142

52-
#
53-
# Other
54-
#
143+
.PHONY: examples
55144

56145
tags: *.c *.h *.rl examples/*.c
57146
ctags $^
58147

59-
upload_website:
60-
scp -r doc/index.html doc/icon.png rydahl@tinyclouds.org:~/web/public/libebb
61-
62-
install: libebb.so
148+
install: $(OUTPUT_A)
63149
install -d -m755 ${prefix}/lib
64150
install -d -m755 ${prefix}/include
65-
install -m644 libebb.so ${prefix}/lib
151+
install -m644 $(OUTPUT_A) ${prefix}/lib
66152
install -m644 ebb.h ebb_request_parser.h ${prefix}/include
67153

68-
clean:
69-
-rm -f *.o
70-
-rm -f test_request_parser
71-
-rm -f test_rbtree
72-
-rm -f examples/hello_world
73-
-rm -f libebb.so
74-
75-
clobber: clean
76-
-rm -f ebb_request_parser.c
154+
upload_website:
155+
scp -r doc/index.html doc/icon.png rydahl@tinyclouds.org:~/web/public/libebb
156+
157+
158+
ifneq ($(MAKECMDGOALS),clean)
159+
-include $(SOURCES:%.c=.%.d)
160+
endif

ebb.c

+18-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <netinet/in.h> /* inet_ntoa */
1515
#include <arpa/inet.h> /* inet_ntoa */
1616
#include <unistd.h>
17-
#include <error.h>
1817
#include <stdio.h> /* perror */
1918
#include <errno.h> /* perror */
2019
#include <stdlib.h> /* for the default methods */
@@ -27,9 +26,17 @@
2726
# include "rbtree.h" /* for session_cache */
2827
#endif
2928

30-
#define TRUE 1
31-
#define FALSE 0
32-
#define MIN(a,b) (a < b ? a : b)
29+
#ifndef TRUE
30+
# define TRUE 1
31+
#endif
32+
#ifndef FALSE
33+
# define FALSE 0
34+
#endif
35+
#ifndef MIN
36+
# define MIN(a,b) (a < b ? a : b)
37+
#endif
38+
39+
#define error(FORMAT, ...) fprintf(stderr, "error: " FORMAT "\n", ##__VA_ARGS__)
3340

3441
#define CONNECTION_HAS_SOMETHING_TO_WRITE (connection->to_write != NULL)
3542

@@ -64,7 +71,7 @@ close_connection(ebb_connection *connection)
6471
ev_timer_stop(connection->server->loop, &connection->timeout_watcher);
6572

6673
if(0 > close(connection->fd))
67-
error(0, 0, "problem closing connection fd");
74+
error("problem closing connection fd");
6875

6976
connection->open = FALSE;
7077

@@ -191,7 +198,7 @@ on_handshake(struct ev_loop *loop ,ev_io *watcher, int revents)
191198
assert(!ev_is_active(&connection->write_watcher));
192199

193200
if(EV_ERROR & revents) {
194-
error(0, 0, "on_handshake() got error event, closing connection.\n");
201+
error("on_handshake() got error event, closing connection.n");
195202
goto error;
196203
}
197204

@@ -265,7 +272,7 @@ on_readable(struct ev_loop *loop, ev_io *watcher, int revents)
265272
assert(watcher == &connection->read_watcher);
266273

267274
if(EV_ERROR & revents) {
268-
error(0, 0, "on_readable() got error event, closing connection.\n");
275+
error("on_readable() got error event, closing connection.");
269276
goto error;
270277
}
271278

@@ -377,7 +384,7 @@ on_writable(struct ev_loop *loop, ev_io *watcher, int revents)
377384
}
378385
return;
379386
error:
380-
error(0, 0, "close connection on write.\n");
387+
error("close connection on write.");
381388
ebb_connection_schedule_close(connection);
382389
}
383390

@@ -390,7 +397,7 @@ on_goodbye_tls(struct ev_loop *loop, ev_io *watcher, int revents)
390397
assert(watcher == &connection->goodbye_tls_watcher);
391398

392399
if(EV_ERROR & revents) {
393-
error(0, 0, "on_goodbye() got error event, closing connection.\n");
400+
error("on_goodbye() got error event, closing connection.");
394401
goto die;
395402
}
396403

@@ -447,7 +454,7 @@ on_connection(struct ev_loop *loop, ev_io *watcher, int revents)
447454
assert(&server->connection_watcher == watcher);
448455

449456
if(EV_ERROR & revents) {
450-
error(0, 0, "on_connection() got error event, closing server.\n");
457+
error("on_connection() got error event, closing server.");
451458
ebb_server_unlisten(server);
452459
return;
453460
}
@@ -671,7 +678,7 @@ ebb_server_set_secure (ebb_server *server, const char *cert_file, const char *ke
671678
, GNUTLS_X509_FMT_PEM
672679
);
673680
if(r < 0) {
674-
error(0, 0, "error loading certificates");
681+
error("loading certificates");
675682
return -1;
676683
}
677684
return 1;

examples/hello_world.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <assert.h>
66

77
#include <ev.h>
8-
#include <ebb.h>
8+
#include "ebb.h"
99

1010
#define MSG ("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 12\r\n\r\nhello world\n")
1111
static int c = 0;

0 commit comments

Comments
 (0)