Ben Noordhuis | 6df37aa | 2013-06-13 19:06:41 +0200 | [diff] [blame] | 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]"') |
Andrew Udvare | b36c2a9 | 2015-07-11 23:56:25 -0700 | [diff] [blame] | 22 | HELPER ?= |
| 23 | BINEXT ?= |
Fabian Groffen | 8ea9532 | 2017-03-14 18:59:47 +0100 | [diff] [blame] | 24 | SOLIBNAME = libhttp_parser |
| 25 | SOMAJOR = 2 |
Ben Noordhuis | 0d0a24e | 2018-12-28 08:28:50 +0100 | [diff] [blame] | 26 | SOMINOR = 9 |
Fedor Indutny | a0c034c | 2020-02-06 10:04:53 +0100 | [diff] [blame^] | 27 | SOREV = 3 |
Guo Xiao | 2896229 | 2015-05-19 11:11:07 +0800 | [diff] [blame] | 28 | ifeq (darwin,$(PLATFORM)) |
Guo Xiao | 2896229 | 2015-05-19 11:11:07 +0800 | [diff] [blame] | 29 | SOEXT ?= dylib |
Fabian Groffen | 8ea9532 | 2017-03-14 18:59:47 +0100 | [diff] [blame] | 30 | SONAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOEXT) |
| 31 | LIBNAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOREV).$(SOEXT) |
Andrew Udvare | b36c2a9 | 2015-07-11 23:56:25 -0700 | [diff] [blame] | 32 | else ifeq (wine,$(PLATFORM)) |
| 33 | CC = winegcc |
| 34 | BINEXT = .exe.so |
| 35 | HELPER = wine |
Guo Xiao | 2896229 | 2015-05-19 11:11:07 +0800 | [diff] [blame] | 36 | else |
Guo Xiao | 2896229 | 2015-05-19 11:11:07 +0800 | [diff] [blame] | 37 | SOEXT ?= so |
Fabian Groffen | 8ea9532 | 2017-03-14 18:59:47 +0100 | [diff] [blame] | 38 | SONAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR) |
| 39 | LIBNAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR).$(SOREV) |
Guo Xiao | 2896229 | 2015-05-19 11:11:07 +0800 | [diff] [blame] | 40 | endif |
Andrew Udvare | b36c2a9 | 2015-07-11 23:56:25 -0700 | [diff] [blame] | 41 | |
Ryan Dahl | c1d48fd | 2010-07-31 14:31:29 -0700 | [diff] [blame] | 42 | CC?=gcc |
Salman | fb23d15 | 2011-05-19 18:37:58 -0400 | [diff] [blame] | 43 | AR?=ar |
Ryan Dahl | c1d48fd | 2010-07-31 14:31:29 -0700 | [diff] [blame] | 44 | |
Fedor Indutny | 36f107f | 2015-01-14 15:59:25 +0300 | [diff] [blame] | 45 | CPPFLAGS ?= |
| 46 | LDFLAGS ?= |
| 47 | |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 48 | CPPFLAGS += -I. |
Ben Noordhuis | 245f6f0 | 2012-11-10 23:32:20 +0100 | [diff] [blame] | 49 | CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1 |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 50 | CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA) |
Ben Noordhuis | 245f6f0 | 2012-11-10 23:32:20 +0100 | [diff] [blame] | 51 | CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0 |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 52 | CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA) |
Fedor Indutny | 3f1a05a | 2014-11-28 21:40:27 +0300 | [diff] [blame] | 53 | CPPFLAGS_BENCH = $(CPPFLAGS_FAST) |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 54 | |
| 55 | CFLAGS += -Wall -Wextra -Werror |
| 56 | CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA) |
| 57 | CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA) |
Fedor Indutny | 3f1a05a | 2014-11-28 21:40:27 +0300 | [diff] [blame] | 58 | CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter |
LE ROUX Thomas | f1fe50e | 2012-02-09 22:24:26 +0100 | [diff] [blame] | 59 | CFLAGS_LIB = $(CFLAGS_FAST) -fPIC |
Ryan | 97d4572 | 2009-04-25 13:33:16 +0200 | [diff] [blame] | 60 | |
Ben Noordhuis | 6df37aa | 2013-06-13 19:06:41 +0200 | [diff] [blame] | 61 | LDFLAGS_LIB = $(LDFLAGS) -shared |
| 62 | |
Umorrian | 5d414fc | 2015-03-07 20:33:06 +0100 | [diff] [blame] | 63 | INSTALL ?= install |
ShaRose | 4cefc0f | 2017-10-15 19:25:02 -0230 | [diff] [blame] | 64 | PREFIX ?= /usr/local |
Umorrian | 5d414fc | 2015-03-07 20:33:06 +0100 | [diff] [blame] | 65 | LIBDIR = $(PREFIX)/lib |
| 66 | INCLUDEDIR = $(PREFIX)/include |
| 67 | |
Fabian Groffen | fd3850c | 2017-03-14 18:36:38 +0100 | [diff] [blame] | 68 | ifeq (darwin,$(PLATFORM)) |
| 69 | LDFLAGS_LIB += -Wl,-install_name,$(LIBDIR)/$(SONAME) |
| 70 | else |
Ben Noordhuis | 6df37aa | 2013-06-13 19:06:41 +0200 | [diff] [blame] | 71 | # TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname... |
| 72 | LDFLAGS_LIB += -Wl,-soname=$(SONAME) |
| 73 | endif |
| 74 | |
Peter Griess | 3bd18a7 | 2011-05-27 20:24:07 -0700 | [diff] [blame] | 75 | test: test_g test_fast |
Andrew Udvare | b36c2a9 | 2015-07-11 23:56:25 -0700 | [diff] [blame] | 76 | $(HELPER) ./test_g$(BINEXT) |
| 77 | $(HELPER) ./test_fast$(BINEXT) |
Ryan Dahl | fb6dc67 | 2009-11-20 14:24:05 +0100 | [diff] [blame] | 78 | |
Ryan Dahl | 443a6ea | 2010-04-28 23:23:01 -0700 | [diff] [blame] | 79 | test_g: http_parser_g.o test_g.o |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 80 | $(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@ |
Ryan Dahl | 4536312 | 2009-11-20 15:47:46 +0100 | [diff] [blame] | 81 | |
Cliff Frey | 83b2a52 | 2010-05-11 11:32:43 -0700 | [diff] [blame] | 82 | test_g.o: test.c http_parser.h Makefile |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 83 | $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c test.c -o $@ |
Ryan Dahl | 443a6ea | 2010-04-28 23:23:01 -0700 | [diff] [blame] | 84 | |
| 85 | http_parser_g.o: http_parser.c http_parser.h Makefile |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 86 | $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c http_parser.c -o $@ |
Ryan Dahl | 443a6ea | 2010-04-28 23:23:01 -0700 | [diff] [blame] | 87 | |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 88 | test_fast: http_parser.o test.o http_parser.h |
| 89 | $(CC) $(CFLAGS_FAST) $(LDFLAGS) http_parser.o test.o -o $@ |
| 90 | |
| 91 | test.o: test.c http_parser.h Makefile |
| 92 | $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@ |
Ryan Dahl | fb6dc67 | 2009-11-20 14:24:05 +0100 | [diff] [blame] | 93 | |
Fedor Indutny | 3f1a05a | 2014-11-28 21:40:27 +0300 | [diff] [blame] | 94 | bench: http_parser.o bench.o |
| 95 | $(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@ |
| 96 | |
| 97 | bench.o: bench.c http_parser.h Makefile |
| 98 | $(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@ |
| 99 | |
Ryan | 97d4572 | 2009-04-25 13:33:16 +0200 | [diff] [blame] | 100 | http_parser.o: http_parser.c http_parser.h Makefile |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 101 | $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c |
Ryan Dahl | 4536312 | 2009-11-20 15:47:46 +0100 | [diff] [blame] | 102 | |
Ryan Dahl | 51e9ff0 | 2009-11-21 21:48:53 +0100 | [diff] [blame] | 103 | test-run-timed: test_fast |
Andrew Udvare | b36c2a9 | 2015-07-11 23:56:25 -0700 | [diff] [blame] | 104 | while(true) do time $(HELPER) ./test_fast$(BINEXT) > /dev/null; done |
Ryan Dahl | 4536312 | 2009-11-20 15:47:46 +0100 | [diff] [blame] | 105 | |
Peter Griess | 8e83445 | 2011-06-19 14:08:26 -0500 | [diff] [blame] | 106 | test-valgrind: test_g |
| 107 | valgrind ./test_g |
| 108 | |
LE ROUX Thomas | f1fe50e | 2012-02-09 22:24:26 +0100 | [diff] [blame] | 109 | libhttp_parser.o: http_parser.c http_parser.h Makefile |
| 110 | $(CC) $(CPPFLAGS_FAST) $(CFLAGS_LIB) -c http_parser.c -o libhttp_parser.o |
| 111 | |
| 112 | library: libhttp_parser.o |
Fabian Groffen | 8ea9532 | 2017-03-14 18:59:47 +0100 | [diff] [blame] | 113 | $(CC) $(LDFLAGS_LIB) -o $(LIBNAME) $< |
LE ROUX Thomas | f1fe50e | 2012-02-09 22:24:26 +0100 | [diff] [blame] | 114 | |
Salman | fb23d15 | 2011-05-19 18:37:58 -0400 | [diff] [blame] | 115 | package: http_parser.o |
| 116 | $(AR) rcs libhttp_parser.a http_parser.o |
Ryan | 97d4572 | 2009-04-25 13:33:16 +0200 | [diff] [blame] | 117 | |
Ben Noordhuis | 120a2c5 | 2012-12-19 14:34:52 +0100 | [diff] [blame] | 118 | url_parser: http_parser.o contrib/url_parser.c |
| 119 | $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o $@ |
Corey Richardson | 798eb90 | 2012-12-12 17:23:06 -0500 | [diff] [blame] | 120 | |
Ben Noordhuis | 120a2c5 | 2012-12-19 14:34:52 +0100 | [diff] [blame] | 121 | url_parser_g: http_parser_g.o contrib/url_parser.c |
| 122 | $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@ |
| 123 | |
| 124 | parsertrace: http_parser.o contrib/parsertrace.c |
Andrew Udvare | b36c2a9 | 2015-07-11 23:56:25 -0700 | [diff] [blame] | 125 | $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace$(BINEXT) |
Ben Noordhuis | 120a2c5 | 2012-12-19 14:34:52 +0100 | [diff] [blame] | 126 | |
| 127 | parsertrace_g: http_parser_g.o contrib/parsertrace.c |
Andrew Udvare | b36c2a9 | 2015-07-11 23:56:25 -0700 | [diff] [blame] | 128 | $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g$(BINEXT) |
Corey Richardson | 798eb90 | 2012-12-12 17:23:06 -0500 | [diff] [blame] | 129 | |
Ryan Dahl | 433202d | 2009-11-17 18:42:15 +0100 | [diff] [blame] | 130 | tags: http_parser.c http_parser.h test.c |
Ryan | 7476612 | 2009-04-26 12:37:06 +0200 | [diff] [blame] | 131 | ctags $^ |
| 132 | |
Umorrian | 5d414fc | 2015-03-07 20:33:06 +0100 | [diff] [blame] | 133 | install: library |
ShaRose | 4cefc0f | 2017-10-15 19:25:02 -0230 | [diff] [blame] | 134 | $(INSTALL) -D http_parser.h $(DESTDIR)$(INCLUDEDIR)/http_parser.h |
| 135 | $(INSTALL) -D $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME) |
Fabrice Fontaine | 28f3c35 | 2019-09-24 19:44:29 +0200 | [diff] [blame] | 136 | ln -sf $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME) |
| 137 | ln -sf $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT) |
Umorrian | 5d414fc | 2015-03-07 20:33:06 +0100 | [diff] [blame] | 138 | |
| 139 | install-strip: library |
ShaRose | 4cefc0f | 2017-10-15 19:25:02 -0230 | [diff] [blame] | 140 | $(INSTALL) -D http_parser.h $(DESTDIR)$(INCLUDEDIR)/http_parser.h |
| 141 | $(INSTALL) -D -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME) |
Fabrice Fontaine | 28f3c35 | 2019-09-24 19:44:29 +0200 | [diff] [blame] | 142 | ln -sf $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME) |
| 143 | ln -sf $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT) |
Umorrian | 5d414fc | 2015-03-07 20:33:06 +0100 | [diff] [blame] | 144 | |
| 145 | uninstall: |
ShaRose | 4cefc0f | 2017-10-15 19:25:02 -0230 | [diff] [blame] | 146 | rm $(DESTDIR)$(INCLUDEDIR)/http_parser.h |
ShaRose | 652b015 | 2017-10-15 19:41:19 -0230 | [diff] [blame] | 147 | rm $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT) |
ShaRose | 4cefc0f | 2017-10-15 19:25:02 -0230 | [diff] [blame] | 148 | rm $(DESTDIR)$(LIBDIR)/$(SONAME) |
ShaRose | 652b015 | 2017-10-15 19:41:19 -0230 | [diff] [blame] | 149 | rm $(DESTDIR)$(LIBDIR)/$(LIBNAME) |
Umorrian | 5d414fc | 2015-03-07 20:33:06 +0100 | [diff] [blame] | 150 | |
Ryan | 97d4572 | 2009-04-25 13:33:16 +0200 | [diff] [blame] | 151 | clean: |
Ben Noordhuis | 120a2c5 | 2012-12-19 14:34:52 +0100 | [diff] [blame] | 152 | rm -f *.o *.a tags test test_fast test_g \ |
Ben Noordhuis | 6df37aa | 2013-06-13 19:06:41 +0200 | [diff] [blame] | 153 | http_parser.tar libhttp_parser.so.* \ |
Andrew Udvare | b36c2a9 | 2015-07-11 23:56:25 -0700 | [diff] [blame] | 154 | url_parser url_parser_g parsertrace parsertrace_g \ |
| 155 | *.exe *.exe.so |
Ben Noordhuis | 120a2c5 | 2012-12-19 14:34:52 +0100 | [diff] [blame] | 156 | |
| 157 | contrib/url_parser.c: http_parser.h |
| 158 | contrib/parsertrace.c: http_parser.h |
Ryan | 6669225 | 2009-04-27 16:49:40 +0200 | [diff] [blame] | 159 | |
Umorrian | 5d414fc | 2015-03-07 20:33:06 +0100 | [diff] [blame] | 160 | .PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall |