blob: 9e8c1f0371d116e8fb0903ba3674818b26f6cba6 [file] [log] [blame]
Ben Noordhuis6df37aa2013-06-13 19:06:41 +02001# 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
21PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
Andrew Udvareb36c2a92015-07-11 23:56:25 -070022HELPER ?=
23BINEXT ?=
Fabian Groffen8ea95322017-03-14 18:59:47 +010024SOLIBNAME = libhttp_parser
25SOMAJOR = 2
Ben Noordhuis0d0a24e2018-12-28 08:28:50 +010026SOMINOR = 9
Fedor Indutnya0c034c2020-02-06 10:04:53 +010027SOREV = 3
Guo Xiao28962292015-05-19 11:11:07 +080028ifeq (darwin,$(PLATFORM))
Guo Xiao28962292015-05-19 11:11:07 +080029SOEXT ?= dylib
Fabian Groffen8ea95322017-03-14 18:59:47 +010030SONAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOEXT)
31LIBNAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOREV).$(SOEXT)
Andrew Udvareb36c2a92015-07-11 23:56:25 -070032else ifeq (wine,$(PLATFORM))
33CC = winegcc
34BINEXT = .exe.so
35HELPER = wine
Guo Xiao28962292015-05-19 11:11:07 +080036else
Guo Xiao28962292015-05-19 11:11:07 +080037SOEXT ?= so
Fabian Groffen8ea95322017-03-14 18:59:47 +010038SONAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR)
39LIBNAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR).$(SOREV)
Guo Xiao28962292015-05-19 11:11:07 +080040endif
Andrew Udvareb36c2a92015-07-11 23:56:25 -070041
Ryan Dahlc1d48fd2010-07-31 14:31:29 -070042CC?=gcc
Salmanfb23d152011-05-19 18:37:58 -040043AR?=ar
Ryan Dahlc1d48fd2010-07-31 14:31:29 -070044
Fedor Indutny36f107f2015-01-14 15:59:25 +030045CPPFLAGS ?=
46LDFLAGS ?=
47
Peter Griess8e834452011-06-19 14:08:26 -050048CPPFLAGS += -I.
Ben Noordhuis245f6f02012-11-10 23:32:20 +010049CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1
Peter Griess8e834452011-06-19 14:08:26 -050050CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA)
Ben Noordhuis245f6f02012-11-10 23:32:20 +010051CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0
Peter Griess8e834452011-06-19 14:08:26 -050052CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA)
Fedor Indutny3f1a05a2014-11-28 21:40:27 +030053CPPFLAGS_BENCH = $(CPPFLAGS_FAST)
Peter Griess8e834452011-06-19 14:08:26 -050054
55CFLAGS += -Wall -Wextra -Werror
56CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA)
57CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA)
Fedor Indutny3f1a05a2014-11-28 21:40:27 +030058CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter
LE ROUX Thomasf1fe50e2012-02-09 22:24:26 +010059CFLAGS_LIB = $(CFLAGS_FAST) -fPIC
Ryan97d45722009-04-25 13:33:16 +020060
Ben Noordhuis6df37aa2013-06-13 19:06:41 +020061LDFLAGS_LIB = $(LDFLAGS) -shared
62
Umorrian5d414fc2015-03-07 20:33:06 +010063INSTALL ?= install
ShaRose4cefc0f2017-10-15 19:25:02 -023064PREFIX ?= /usr/local
Umorrian5d414fc2015-03-07 20:33:06 +010065LIBDIR = $(PREFIX)/lib
66INCLUDEDIR = $(PREFIX)/include
67
Fabian Groffenfd3850c2017-03-14 18:36:38 +010068ifeq (darwin,$(PLATFORM))
69LDFLAGS_LIB += -Wl,-install_name,$(LIBDIR)/$(SONAME)
70else
Ben Noordhuis6df37aa2013-06-13 19:06:41 +020071# TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname...
72LDFLAGS_LIB += -Wl,-soname=$(SONAME)
73endif
74
Peter Griess3bd18a72011-05-27 20:24:07 -070075test: test_g test_fast
Andrew Udvareb36c2a92015-07-11 23:56:25 -070076 $(HELPER) ./test_g$(BINEXT)
77 $(HELPER) ./test_fast$(BINEXT)
Ryan Dahlfb6dc672009-11-20 14:24:05 +010078
Ryan Dahl443a6ea2010-04-28 23:23:01 -070079test_g: http_parser_g.o test_g.o
Peter Griess8e834452011-06-19 14:08:26 -050080 $(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@
Ryan Dahl45363122009-11-20 15:47:46 +010081
Cliff Frey83b2a522010-05-11 11:32:43 -070082test_g.o: test.c http_parser.h Makefile
Peter Griess8e834452011-06-19 14:08:26 -050083 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c test.c -o $@
Ryan Dahl443a6ea2010-04-28 23:23:01 -070084
85http_parser_g.o: http_parser.c http_parser.h Makefile
Peter Griess8e834452011-06-19 14:08:26 -050086 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c http_parser.c -o $@
Ryan Dahl443a6ea2010-04-28 23:23:01 -070087
Peter Griess8e834452011-06-19 14:08:26 -050088test_fast: http_parser.o test.o http_parser.h
89 $(CC) $(CFLAGS_FAST) $(LDFLAGS) http_parser.o test.o -o $@
90
91test.o: test.c http_parser.h Makefile
92 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@
Ryan Dahlfb6dc672009-11-20 14:24:05 +010093
Fedor Indutny3f1a05a2014-11-28 21:40:27 +030094bench: http_parser.o bench.o
95 $(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@
96
97bench.o: bench.c http_parser.h Makefile
98 $(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@
99
Ryan97d45722009-04-25 13:33:16 +0200100http_parser.o: http_parser.c http_parser.h Makefile
Peter Griess8e834452011-06-19 14:08:26 -0500101 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c
Ryan Dahl45363122009-11-20 15:47:46 +0100102
Ryan Dahl51e9ff02009-11-21 21:48:53 +0100103test-run-timed: test_fast
Andrew Udvareb36c2a92015-07-11 23:56:25 -0700104 while(true) do time $(HELPER) ./test_fast$(BINEXT) > /dev/null; done
Ryan Dahl45363122009-11-20 15:47:46 +0100105
Peter Griess8e834452011-06-19 14:08:26 -0500106test-valgrind: test_g
107 valgrind ./test_g
108
LE ROUX Thomasf1fe50e2012-02-09 22:24:26 +0100109libhttp_parser.o: http_parser.c http_parser.h Makefile
110 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_LIB) -c http_parser.c -o libhttp_parser.o
111
112library: libhttp_parser.o
Fabian Groffen8ea95322017-03-14 18:59:47 +0100113 $(CC) $(LDFLAGS_LIB) -o $(LIBNAME) $<
LE ROUX Thomasf1fe50e2012-02-09 22:24:26 +0100114
Salmanfb23d152011-05-19 18:37:58 -0400115package: http_parser.o
116 $(AR) rcs libhttp_parser.a http_parser.o
Ryan97d45722009-04-25 13:33:16 +0200117
Ben Noordhuis120a2c52012-12-19 14:34:52 +0100118url_parser: http_parser.o contrib/url_parser.c
119 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o $@
Corey Richardson798eb902012-12-12 17:23:06 -0500120
Ben Noordhuis120a2c52012-12-19 14:34:52 +0100121url_parser_g: http_parser_g.o contrib/url_parser.c
122 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@
123
124parsertrace: http_parser.o contrib/parsertrace.c
Andrew Udvareb36c2a92015-07-11 23:56:25 -0700125 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace$(BINEXT)
Ben Noordhuis120a2c52012-12-19 14:34:52 +0100126
127parsertrace_g: http_parser_g.o contrib/parsertrace.c
Andrew Udvareb36c2a92015-07-11 23:56:25 -0700128 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g$(BINEXT)
Corey Richardson798eb902012-12-12 17:23:06 -0500129
Ryan Dahl433202d2009-11-17 18:42:15 +0100130tags: http_parser.c http_parser.h test.c
Ryan74766122009-04-26 12:37:06 +0200131 ctags $^
132
Umorrian5d414fc2015-03-07 20:33:06 +0100133install: library
ShaRose4cefc0f2017-10-15 19:25:02 -0230134 $(INSTALL) -D http_parser.h $(DESTDIR)$(INCLUDEDIR)/http_parser.h
135 $(INSTALL) -D $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME)
Fabrice Fontaine28f3c352019-09-24 19:44:29 +0200136 ln -sf $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME)
137 ln -sf $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT)
Umorrian5d414fc2015-03-07 20:33:06 +0100138
139install-strip: library
ShaRose4cefc0f2017-10-15 19:25:02 -0230140 $(INSTALL) -D http_parser.h $(DESTDIR)$(INCLUDEDIR)/http_parser.h
141 $(INSTALL) -D -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME)
Fabrice Fontaine28f3c352019-09-24 19:44:29 +0200142 ln -sf $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME)
143 ln -sf $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT)
Umorrian5d414fc2015-03-07 20:33:06 +0100144
145uninstall:
ShaRose4cefc0f2017-10-15 19:25:02 -0230146 rm $(DESTDIR)$(INCLUDEDIR)/http_parser.h
ShaRose652b0152017-10-15 19:41:19 -0230147 rm $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT)
ShaRose4cefc0f2017-10-15 19:25:02 -0230148 rm $(DESTDIR)$(LIBDIR)/$(SONAME)
ShaRose652b0152017-10-15 19:41:19 -0230149 rm $(DESTDIR)$(LIBDIR)/$(LIBNAME)
Umorrian5d414fc2015-03-07 20:33:06 +0100150
Ryan97d45722009-04-25 13:33:16 +0200151clean:
Ben Noordhuis120a2c52012-12-19 14:34:52 +0100152 rm -f *.o *.a tags test test_fast test_g \
Ben Noordhuis6df37aa2013-06-13 19:06:41 +0200153 http_parser.tar libhttp_parser.so.* \
Andrew Udvareb36c2a92015-07-11 23:56:25 -0700154 url_parser url_parser_g parsertrace parsertrace_g \
155 *.exe *.exe.so
Ben Noordhuis120a2c52012-12-19 14:34:52 +0100156
157contrib/url_parser.c: http_parser.h
158contrib/parsertrace.c: http_parser.h
Ryan66692252009-04-27 16:49:40 +0200159
Umorrian5d414fc2015-03-07 20:33:06 +0100160.PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall