1
0

Makefile 5.2 KB

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