|
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 |
25 | 114 |
|
26 | 115 | ebb_request_parser.c: ebb_request_parser.rl
|
27 | 116 | ragel -s -G2 $< -o $@
|
28 | 117 |
|
29 |
| -# |
30 |
| -# Test programs |
31 |
| -# |
| 118 | +clean: |
| 119 | + rm -f *.o *.lo *.la *.so *.dylib *.a test_rbtree test_request_parser examples/hello_world |
32 | 120 |
|
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 |
35 | 123 |
|
36 |
| -test_rbtree: test_rbtree.c rbtree.o |
37 |
| - gcc ${CFLAGS} $^ -o $@ # -lefence |
| 124 | +.PHONY: clean clobber |
38 | 125 |
|
39 | 126 | test: test_request_parser test_rbtree
|
40 | 127 | ./test_request_parser
|
41 | 128 | ./test_rbtree
|
42 | 129 |
|
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 |
46 | 137 |
|
47 | 138 | examples: examples/hello_world
|
48 | 139 |
|
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) |
51 | 142 |
|
52 |
| -# |
53 |
| -# Other |
54 |
| -# |
| 143 | +.PHONY: examples |
55 | 144 |
|
56 | 145 | tags: *.c *.h *.rl examples/*.c
|
57 | 146 | ctags $^
|
58 | 147 |
|
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) |
63 | 149 | install -d -m755 ${prefix}/lib
|
64 | 150 | install -d -m755 ${prefix}/include
|
65 |
| - install -m644 libebb.so ${prefix}/lib |
| 151 | + install -m644 $(OUTPUT_A) ${prefix}/lib |
66 | 152 | install -m644 ebb.h ebb_request_parser.h ${prefix}/include
|
67 | 153 |
|
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 |
0 commit comments