Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. CXX = clang++
  2. CXXFLAGS = -g -std=c++11 -I. -Wall -Wextra -Wtype-limits -Wconversion -Wshadow # -fno-exceptions -DCPPHTTPLIB_NO_EXCEPTIONS -fsanitize=address
  3. ifeq ($(SELECT_IMPL),select)
  4. CXXFLAGS += -DCPPHTTPLIB_USE_SELECT
  5. endif
  6. PREFIX ?= $(shell brew --prefix)
  7. OPENSSL_DIR = $(PREFIX)/opt/openssl@3
  8. OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR)/include -L$(OPENSSL_DIR)/lib -lssl -lcrypto
  9. ifneq ($(OS), Windows_NT)
  10. UNAME_S := $(shell uname -s)
  11. ifeq ($(UNAME_S), Darwin)
  12. OPENSSL_SUPPORT += -DCPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN -framework CoreFoundation -framework Security
  13. endif
  14. endif
  15. ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
  16. BROTLI_DIR = $(PREFIX)/opt/brotli
  17. BROTLI_SUPPORT = -DCPPHTTPLIB_BROTLI_SUPPORT -I$(BROTLI_DIR)/include -L$(BROTLI_DIR)/lib -lbrotlicommon -lbrotlienc -lbrotlidec
  18. TEST_ARGS = gtest/gtest-all.cc gtest/gtest_main.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT) $(BROTLI_SUPPORT) -pthread -lcurl
  19. # By default, use standalone_fuzz_target_runner.
  20. # This runner does no fuzzing, but simply executes the inputs
  21. # provided via parameters.
  22. # Run e.g. "make all LIB_FUZZING_ENGINE=/path/to/libFuzzer.a"
  23. # to link the fuzzer(s) against a real fuzzing engine.
  24. # OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE.
  25. LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o
  26. CLANG_FORMAT = clang-format
  27. REALPATH = $(shell which grealpath 2>/dev/null || which realpath 2>/dev/null)
  28. STYLE_CHECK_FILES = $(filter-out httplib.h httplib.cc, \
  29. $(wildcard example/*.h example/*.cc fuzzing/*.h fuzzing/*.cc *.h *.cc ../httplib.h))
  30. all : test test_split
  31. ./test
  32. proxy : test_proxy
  33. ./test_proxy
  34. test : test.cc include_httplib.cc ../httplib.h Makefile cert.pem
  35. $(CXX) -o $@ -I.. $(CXXFLAGS) test.cc include_httplib.cc $(TEST_ARGS)
  36. # Note: The intention of test_split is to verify that it works to compile and
  37. # link the split httplib.h, so there is normally no need to execute it.
  38. test_split : test.cc ../httplib.h httplib.cc Makefile cert.pem
  39. $(CXX) -o $@ $(CXXFLAGS) test.cc httplib.cc $(TEST_ARGS)
  40. check_abi:
  41. @./check-shared-library-abi-compatibility.sh
  42. .PHONY: style_check
  43. style_check: $(STYLE_CHECK_FILES)
  44. @for file in $(STYLE_CHECK_FILES); do \
  45. $(CLANG_FORMAT) $$file > $$file.formatted; \
  46. if ! diff -u $$file $$file.formatted; then \
  47. file2=$$($(REALPATH) --relative-to=.. $$file); \
  48. printf "\n%*s\n" 80 | tr ' ' '#'; \
  49. printf "##%*s##\n" 76; \
  50. printf "## %-70s ##\n" "$$file2 not properly formatted. Please run clang-format."; \
  51. printf "##%*s##\n" 76; \
  52. printf "%*s\n\n" 80 | tr ' ' '#'; \
  53. failed=1; \
  54. fi; \
  55. rm -f $$file.formatted; \
  56. done; \
  57. if [ -n "$$failed" ]; then \
  58. echo "Style check failed for one or more files. See above for details."; \
  59. false; \
  60. else \
  61. echo "All files are properly formatted."; \
  62. fi
  63. test_proxy : test_proxy.cc ../httplib.h Makefile cert.pem
  64. $(CXX) -o $@ -I.. $(CXXFLAGS) test_proxy.cc $(TEST_ARGS)
  65. # Runs server_fuzzer.cc based on value of $(LIB_FUZZING_ENGINE).
  66. # Usage: make fuzz_test LIB_FUZZING_ENGINE=/path/to/libFuzzer
  67. fuzz_test: server_fuzzer
  68. ./server_fuzzer fuzzing/corpus/*
  69. # Fuzz target, so that you can choose which $(LIB_FUZZING_ENGINE) to use.
  70. server_fuzzer : fuzzing/server_fuzzer.cc ../httplib.h standalone_fuzz_target_runner.o
  71. $(CXX) -o $@ -I.. $(CXXFLAGS) $< $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT) $(BROTLI_SUPPORT) $(LIB_FUZZING_ENGINE) -pthread
  72. # Standalone fuzz runner, which just reads inputs from fuzzing/corpus/ dir and
  73. # feeds it to server_fuzzer.
  74. standalone_fuzz_target_runner.o : fuzzing/standalone_fuzz_target_runner.cpp
  75. $(CXX) -o $@ -I.. $(CXXFLAGS) -c $<
  76. httplib.cc : ../httplib.h
  77. python3 ../split.py -o .
  78. cert.pem:
  79. ./gen-certs.sh
  80. clean:
  81. rm -rf test test_split test_proxy server_fuzzer *.pem *.0 *.o *.1 *.srl httplib.h httplib.cc _build* *.dSYM