deps: upgrade to npm 2.14.18
[platform/upstream/nodejs.git] / deps / http_parser / Makefile
1 # Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2 #
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:
9 #
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
12 #
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
19 # IN THE SOFTWARE.
20
21 PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
22 SONAME ?= libhttp_parser.so.2.5.2
23
24 CC?=gcc
25 AR?=ar
26
27 CPPFLAGS ?=
28 LDFLAGS ?=
29
30 CPPFLAGS += -I.
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)
36
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
42
43 LDFLAGS_LIB = $(LDFLAGS) -shared
44
45 INSTALL ?= install
46 PREFIX ?= $(DESTDIR)/usr/local
47 LIBDIR = $(PREFIX)/lib
48 INCLUDEDIR = $(PREFIX)/include
49
50 ifneq (darwin,$(PLATFORM))
51 # TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname...
52 LDFLAGS_LIB += -Wl,-soname=$(SONAME)
53 endif
54
55 test: test_g test_fast
56         ./test_g
57         ./test_fast
58
59 test_g: http_parser_g.o test_g.o
60         $(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@
61
62 test_g.o: test.c http_parser.h Makefile
63         $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c test.c -o $@
64
65 http_parser_g.o: http_parser.c http_parser.h Makefile
66         $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c http_parser.c -o $@
67
68 test_fast: http_parser.o test.o http_parser.h
69         $(CC) $(CFLAGS_FAST) $(LDFLAGS) http_parser.o test.o -o $@
70
71 test.o: test.c http_parser.h Makefile
72         $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@
73
74 bench: http_parser.o bench.o
75         $(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@
76
77 bench.o: bench.c http_parser.h Makefile
78         $(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@
79
80 http_parser.o: http_parser.c http_parser.h Makefile
81         $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c
82
83 test-run-timed: test_fast
84         while(true) do time ./test_fast > /dev/null; done
85
86 test-valgrind: test_g
87         valgrind ./test_g
88
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
91
92 library: libhttp_parser.o
93         $(CC) $(LDFLAGS_LIB) -o $(SONAME) $<
94
95 package: http_parser.o
96         $(AR) rcs libhttp_parser.a http_parser.o
97
98 url_parser: http_parser.o contrib/url_parser.c
99         $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o $@
100
101 url_parser_g: http_parser_g.o contrib/url_parser.c
102         $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@
103
104 parsertrace: http_parser.o contrib/parsertrace.c
105         $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace
106
107 parsertrace_g: http_parser_g.o contrib/parsertrace.c
108         $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g
109
110 tags: http_parser.c http_parser.h test.c
111         ctags $^
112
113 install: library
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
117
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
122
123 uninstall:
124         rm $(INCLUDEDIR)/http_parser.h
125         rm $(LIBDIR)/$(SONAME)
126         rm $(LIBDIR)/libhttp_parser.so
127
128 clean:
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
132
133 contrib/url_parser.c:   http_parser.h
134 contrib/parsertrace.c:  http_parser.h
135
136 .PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall