1 # Copyright Joyent, Inc. and other Node contributors. All rights reserved.
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to
5 # deal in the Software without restriction, including without limitation the
6 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 # sell copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
22 SONAME ?= libhttp_parser.so.2.5.2
31 CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1
32 CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA)
33 CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0
34 CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA)
35 CPPFLAGS_BENCH = $(CPPFLAGS_FAST)
37 CFLAGS += -Wall -Wextra -Werror
38 CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA)
39 CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA)
40 CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter
41 CFLAGS_LIB = $(CFLAGS_FAST) -fPIC
43 LDFLAGS_LIB = $(LDFLAGS) -shared
46 PREFIX ?= $(DESTDIR)/usr/local
47 LIBDIR = $(PREFIX)/lib
48 INCLUDEDIR = $(PREFIX)/include
50 ifneq (darwin,$(PLATFORM))
51 # TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname...
52 LDFLAGS_LIB += -Wl,-soname=$(SONAME)
55 test: test_g test_fast
59 test_g: http_parser_g.o test_g.o
60 $(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@
62 test_g.o: test.c http_parser.h Makefile
63 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c test.c -o $@
65 http_parser_g.o: http_parser.c http_parser.h Makefile
66 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c http_parser.c -o $@
68 test_fast: http_parser.o test.o http_parser.h
69 $(CC) $(CFLAGS_FAST) $(LDFLAGS) http_parser.o test.o -o $@
71 test.o: test.c http_parser.h Makefile
72 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@
74 bench: http_parser.o bench.o
75 $(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@
77 bench.o: bench.c http_parser.h Makefile
78 $(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@
80 http_parser.o: http_parser.c http_parser.h Makefile
81 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c
83 test-run-timed: test_fast
84 while(true) do time ./test_fast > /dev/null; done
89 libhttp_parser.o: http_parser.c http_parser.h Makefile
90 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_LIB) -c http_parser.c -o libhttp_parser.o
92 library: libhttp_parser.o
93 $(CC) $(LDFLAGS_LIB) -o $(SONAME) $<
95 package: http_parser.o
96 $(AR) rcs libhttp_parser.a http_parser.o
98 url_parser: http_parser.o contrib/url_parser.c
99 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o $@
101 url_parser_g: http_parser_g.o contrib/url_parser.c
102 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@
104 parsertrace: http_parser.o contrib/parsertrace.c
105 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace
107 parsertrace_g: http_parser_g.o contrib/parsertrace.c
108 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g
110 tags: http_parser.c http_parser.h test.c
114 $(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
115 $(INSTALL) -D $(SONAME) $(LIBDIR)/$(SONAME)
116 ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
118 install-strip: library
119 $(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
120 $(INSTALL) -D -s $(SONAME) $(LIBDIR)/$(SONAME)
121 ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
124 rm $(INCLUDEDIR)/http_parser.h
125 rm $(LIBDIR)/$(SONAME)
126 rm $(LIBDIR)/libhttp_parser.so
129 rm -f *.o *.a tags test test_fast test_g \
130 http_parser.tar libhttp_parser.so.* \
131 url_parser url_parser_g parsertrace parsertrace_g
133 contrib/url_parser.c: http_parser.h
134 contrib/parsertrace.c: http_parser.h
136 .PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall