Makefile 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. CXX = clang++
  2. CXXFLAGS = -g -std=c++11 -I. -Wall -Wextra -Wtype-limits -Wconversion -Wshadow # -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 CoreFoundation -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. TEST_ARGS = gtest/gtest-all.cc gtest/gtest_main.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT) $(BROTLI_SUPPORT) -pthread -lcurl
  16. # By default, use standalone_fuzz_target_runner.
  17. # This runner does no fuzzing, but simply executes the inputs
  18. # provided via parameters.
  19. # Run e.g. "make all LIB_FUZZING_ENGINE=/path/to/libFuzzer.a"
  20. # to link the fuzzer(s) against a real fuzzing engine.
  21. # OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE.
  22. LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o
  23. all : test test_split
  24. ./test
  25. proxy : test_proxy
  26. ./test_proxy
  27. test : test.cc include_httplib.cc ../httplib.h Makefile cert.pem
  28. $(CXX) -o $@ -I.. $(CXXFLAGS) test.cc include_httplib.cc $(TEST_ARGS)
  29. # Note: The intention of test_split is to verify that it works to compile and
  30. # link the split httplib.h, so there is normally no need to execute it.
  31. test_split : test.cc ../httplib.h httplib.cc Makefile cert.pem
  32. $(CXX) -o $@ $(CXXFLAGS) test.cc httplib.cc $(TEST_ARGS)
  33. test_proxy : test_proxy.cc ../httplib.h Makefile cert.pem
  34. $(CXX) -o $@ -I.. $(CXXFLAGS) test_proxy.cc $(TEST_ARGS)
  35. # Runs server_fuzzer.cc based on value of $(LIB_FUZZING_ENGINE).
  36. # Usage: make fuzz_test LIB_FUZZING_ENGINE=/path/to/libFuzzer
  37. fuzz_test: server_fuzzer
  38. ./server_fuzzer fuzzing/corpus/*
  39. # Fuzz target, so that you can choose which $(LIB_FUZZING_ENGINE) to use.
  40. server_fuzzer : fuzzing/server_fuzzer.cc ../httplib.h standalone_fuzz_target_runner.o
  41. $(CXX) -o $@ -I.. $(CXXFLAGS) $< $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT) $(BROTLI_SUPPORT) $(LIB_FUZZING_ENGINE) -pthread
  42. # Standalone fuzz runner, which just reads inputs from fuzzing/corpus/ dir and
  43. # feeds it to server_fuzzer.
  44. standalone_fuzz_target_runner.o : fuzzing/standalone_fuzz_target_runner.cpp
  45. $(CXX) -o $@ -I.. $(CXXFLAGS) -c $<
  46. httplib.cc : ../httplib.h
  47. python3 ../split.py -o .
  48. cert.pem:
  49. openssl genrsa 2048 > key.pem
  50. openssl req -new -batch -config test.conf -key key.pem | openssl x509 -days 3650 -req -signkey key.pem > cert.pem
  51. openssl req -x509 -config test.conf -key key.pem -sha256 -days 3650 -nodes -out cert2.pem -extensions SAN
  52. openssl genrsa 2048 > rootCA.key.pem
  53. openssl req -x509 -new -batch -config test.rootCA.conf -key rootCA.key.pem -days 1024 > rootCA.cert.pem
  54. openssl genrsa 2048 > client.key.pem
  55. openssl req -new -batch -config test.conf -key client.key.pem | openssl x509 -days 370 -req -CA rootCA.cert.pem -CAkey rootCA.key.pem -CAcreateserial > client.cert.pem
  56. openssl genrsa -passout pass:test123! 2048 > key_encrypted.pem
  57. openssl req -new -batch -config test.conf -key key_encrypted.pem | openssl x509 -days 3650 -req -signkey key_encrypted.pem > cert_encrypted.pem
  58. openssl genrsa -aes256 -passout pass:test012! 2048 > client_encrypted.key.pem
  59. openssl req -new -batch -config test.conf -key client_encrypted.key.pem -passin pass:test012! | openssl x509 -days 370 -req -CA rootCA.cert.pem -CAkey rootCA.key.pem -CAcreateserial > client_encrypted.cert.pem
  60. #c_rehash .
  61. clean:
  62. rm -f test test_split test_proxy server_fuzzer *.pem *.0 *.o *.1 *.srl httplib.h httplib.cc