Makefile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. CXX = clang++
  2. CXXFLAGS = -g -std=c++11 -I. -Wall -Wextra -Wtype-limits -Wconversion -Wshadow $(EXTRA_CXXFLAGS) -DCPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO # -fno-exceptions -DCPPHTTPLIB_NO_EXCEPTIONS -fsanitize=address
  3. PREFIX ?= $(shell brew --prefix)
  4. OPENSSL_DIR = $(PREFIX)/opt/openssl@3
  5. OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR)/include -L$(OPENSSL_DIR)/lib -lssl -lcrypto
  6. ifneq ($(OS), Windows_NT)
  7. UNAME_S := $(shell uname -s)
  8. ifeq ($(UNAME_S), Darwin)
  9. OPENSSL_SUPPORT += -DCPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN -framework Security
  10. endif
  11. endif
  12. ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
  13. BROTLI_DIR = $(PREFIX)/opt/brotli
  14. BROTLI_SUPPORT = -DCPPHTTPLIB_BROTLI_SUPPORT -I$(BROTLI_DIR)/include -L$(BROTLI_DIR)/lib -lbrotlicommon -lbrotlienc -lbrotlidec
  15. ZSTD_DIR = $(PREFIX)/opt/zstd
  16. ZSTD_SUPPORT = -DCPPHTTPLIB_ZSTD_SUPPORT -I$(ZSTD_DIR)/include -L$(ZSTD_DIR)/lib -lzstd
  17. LIBS = -lpthread -lcurl
  18. ifneq ($(OS), Windows_NT)
  19. UNAME_S := $(shell uname -s)
  20. ifeq ($(UNAME_S), Darwin)
  21. LIBS += -framework CoreFoundation -framework CFNetwork
  22. endif
  23. ifneq ($(UNAME_S), Darwin)
  24. LIBS += -lanl
  25. endif
  26. endif
  27. TEST_ARGS = gtest/src/gtest-all.cc gtest/src/gtest_main.cc -Igtest -Igtest/include $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT) $(BROTLI_SUPPORT) $(ZSTD_SUPPORT) $(LIBS)
  28. # By default, use standalone_fuzz_target_runner.
  29. # This runner does no fuzzing, but simply executes the inputs
  30. # provided via parameters.
  31. # Run e.g. "make all LIB_FUZZING_ENGINE=/path/to/libFuzzer.a"
  32. # to link the fuzzer(s) against a real fuzzing engine.
  33. # OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE.
  34. LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o
  35. CLANG_FORMAT = clang-format
  36. REALPATH = $(shell which grealpath 2>/dev/null || which realpath 2>/dev/null)
  37. STYLE_CHECK_FILES = $(filter-out httplib.h httplib.cc, \
  38. $(wildcard example/*.h example/*.cc fuzzing/*.h fuzzing/*.cc *.h *.cc ../httplib.h))
  39. all : test test_split
  40. ./test
  41. proxy : test_proxy
  42. @echo "Starting proxy server..."
  43. cd proxy && \
  44. docker compose up -d
  45. @echo "Waiting for proxy to be ready..."
  46. @until nc -z localhost 3128 && nc -z localhost 3129; do sleep 1; done
  47. @echo "Proxy servers are ready, waiting additional 5 seconds for full startup..."
  48. @sleep 5
  49. @echo "Checking proxy server status..."
  50. @cd proxy && docker compose ps
  51. @echo "Checking proxy server logs..."
  52. @cd proxy && docker compose logs --tail=20
  53. @echo "Running proxy tests..."
  54. ./test_proxy; \
  55. exit_code=$$?; \
  56. echo "Stopping proxy server..."; \
  57. cd proxy && docker compose down; \
  58. exit $$exit_code
  59. test : test.cc include_httplib.cc ../httplib.h Makefile cert.pem
  60. $(CXX) -o $@ -I.. $(CXXFLAGS) test.cc include_httplib.cc $(TEST_ARGS)
  61. @file $@
  62. # Note: The intention of test_split is to verify that it works to compile and
  63. # link the split httplib.h, so there is normally no need to execute it.
  64. test_split : test.cc ../httplib.h httplib.cc Makefile cert.pem
  65. $(CXX) -o $@ $(CXXFLAGS) test.cc httplib.cc $(TEST_ARGS)
  66. check_abi:
  67. @./check-shared-library-abi-compatibility.sh
  68. .PHONY: style_check
  69. style_check: $(STYLE_CHECK_FILES)
  70. @for file in $(STYLE_CHECK_FILES); do \
  71. $(CLANG_FORMAT) $$file > $$file.formatted; \
  72. if ! diff -u $$file $$file.formatted; then \
  73. file2=$$($(REALPATH) --relative-to=.. $$file); \
  74. printf "\n%*s\n" 80 | tr ' ' '#'; \
  75. printf "##%*s##\n" 76; \
  76. printf "## %-70s ##\n" "$$file2 not properly formatted. Please run clang-format."; \
  77. printf "##%*s##\n" 76; \
  78. printf "%*s\n\n" 80 | tr ' ' '#'; \
  79. failed=1; \
  80. fi; \
  81. rm -f $$file.formatted; \
  82. done; \
  83. if [ -n "$$failed" ]; then \
  84. echo "Style check failed for one or more files. See above for details."; \
  85. false; \
  86. else \
  87. echo "All files are properly formatted."; \
  88. fi
  89. test_proxy : test_proxy.cc ../httplib.h Makefile cert.pem
  90. $(CXX) -o $@ -I.. $(CXXFLAGS) test_proxy.cc $(TEST_ARGS)
  91. # Runs server_fuzzer.cc based on value of $(LIB_FUZZING_ENGINE).
  92. # Usage: make fuzz_test LIB_FUZZING_ENGINE=/path/to/libFuzzer
  93. fuzz_test: server_fuzzer
  94. ./server_fuzzer fuzzing/corpus/*
  95. # Fuzz target, so that you can choose which $(LIB_FUZZING_ENGINE) to use.
  96. server_fuzzer : fuzzing/server_fuzzer.cc ../httplib.h standalone_fuzz_target_runner.o
  97. $(CXX) -o $@ -I.. $(CXXFLAGS) $< $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT) $(BROTLI_SUPPORT) $(LIB_FUZZING_ENGINE) $(ZSTD_SUPPORT) $(LIBS)
  98. @file $@
  99. # Standalone fuzz runner, which just reads inputs from fuzzing/corpus/ dir and
  100. # feeds it to server_fuzzer.
  101. standalone_fuzz_target_runner.o : fuzzing/standalone_fuzz_target_runner.cpp
  102. $(CXX) -o $@ -I.. $(CXXFLAGS) -c $<
  103. httplib.cc : ../httplib.h
  104. python3 ../split.py -o .
  105. cert.pem:
  106. ./gen-certs.sh
  107. clean:
  108. rm -rf test test_split test_proxy server_fuzzer *.pem *.0 *.o *.1 *.srl httplib.h httplib.cc _build* *.dSYM