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 21PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"') 22HELPER ?= 23BINEXT ?= 24SOLIBNAME = libhttp_parser 25SOMAJOR = 2 26SOMINOR = 7 27SOREV = 1 28ifeq (darwin,$(PLATFORM)) 29SOEXT ?= dylib 30SONAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOEXT) 31LIBNAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOREV).$(SOEXT) 32else ifeq (wine,$(PLATFORM)) 33CC = winegcc 34BINEXT = .exe.so 35HELPER = wine 36else 37SOEXT ?= so 38SONAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR) 39LIBNAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR).$(SOREV) 40endif 41 42CC?=gcc 43AR?=ar 44 45CPPFLAGS ?= 46LDFLAGS ?= 47 48CPPFLAGS += -I. 49CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1 50CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA) 51CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0 52CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA) 53CPPFLAGS_BENCH = $(CPPFLAGS_FAST) 54 55CFLAGS += -Wall -Wextra -Werror 56CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA) 57CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA) 58CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter 59CFLAGS_LIB = $(CFLAGS_FAST) -fPIC 60 61LDFLAGS_LIB = $(LDFLAGS) -shared 62 63INSTALL ?= install 64PREFIX ?= $(DESTDIR)/usr/local 65LIBDIR = $(PREFIX)/lib 66INCLUDEDIR = $(PREFIX)/include 67 68ifneq (darwin,$(PLATFORM)) 69# TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname... 70LDFLAGS_LIB += -Wl,-soname=$(SONAME) 71endif 72 73test: test_g test_fast 74 $(HELPER) ./test_g$(BINEXT) 75 $(HELPER) ./test_fast$(BINEXT) 76 77test_g: http_parser_g.o test_g.o 78 $(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@ 79 80test_g.o: test.c http_parser.h Makefile 81 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c test.c -o $@ 82 83http_parser_g.o: http_parser.c http_parser.h Makefile 84 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c http_parser.c -o $@ 85 86test_fast: http_parser.o test.o http_parser.h 87 $(CC) $(CFLAGS_FAST) $(LDFLAGS) http_parser.o test.o -o $@ 88 89test.o: test.c http_parser.h Makefile 90 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@ 91 92bench: http_parser.o bench.o 93 $(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@ 94 95bench.o: bench.c http_parser.h Makefile 96 $(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@ 97 98http_parser.o: http_parser.c http_parser.h Makefile 99 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c 100 101test-run-timed: test_fast 102 while(true) do time $(HELPER) ./test_fast$(BINEXT) > /dev/null; done 103 104test-valgrind: test_g 105 valgrind ./test_g 106 107libhttp_parser.o: http_parser.c http_parser.h Makefile 108 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_LIB) -c http_parser.c -o libhttp_parser.o 109 110library: libhttp_parser.o 111 $(CC) $(LDFLAGS_LIB) -o $(LIBNAME) $< 112 113package: http_parser.o 114 $(AR) rcs libhttp_parser.a http_parser.o 115 116url_parser: http_parser.o contrib/url_parser.c 117 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o $@ 118 119url_parser_g: http_parser_g.o contrib/url_parser.c 120 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@ 121 122parsertrace: http_parser.o contrib/parsertrace.c 123 $(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace$(BINEXT) 124 125parsertrace_g: http_parser_g.o contrib/parsertrace.c 126 $(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g$(BINEXT) 127 128tags: http_parser.c http_parser.h test.c 129 ctags $^ 130 131install: library 132 $(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h 133 $(INSTALL) -D $(LIBNAME) $(LIBDIR)/$(LIBNAME) 134 ln -s $(LIBDIR)/$(LIBNAME) $(LIBDIR)/$(SONAME) 135 ln -s $(LIBDIR)/$(LIBNAME) $(LIBDIR)/$(SOLIBNAME).$(SOEXT) 136 137install-strip: library 138 $(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h 139 $(INSTALL) -D -s $(LIBNAME) $(LIBDIR)/$(LIBNAME) 140 ln -s $(LIBDIR)/$(LIBNAME) $(LIBDIR)/$(SONAME) 141 ln -s $(LIBDIR)/$(LIBNAME) $(LIBDIR)/$(SOLIBNAME).$(SOEXT) 142 143uninstall: 144 rm $(INCLUDEDIR)/http_parser.h 145 rm $(LIBDIR)/$(SONAME) 146 rm $(LIBDIR)/libhttp_parser.so 147 148clean: 149 rm -f *.o *.a tags test test_fast test_g \ 150 http_parser.tar libhttp_parser.so.* \ 151 url_parser url_parser_g parsertrace parsertrace_g \ 152 *.exe *.exe.so 153 154contrib/url_parser.c: http_parser.h 155contrib/parsertrace.c: http_parser.h 156 157.PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall 158