Makefile 4.7 KB

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