systemtls.mak 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. CFLAGS?=-g -O2
  2. CFLAGS += -Wall -Wextra -I./src -DNDEBUG -D_FILE_OFFSET_BITS=64 -pthread
  3. LIBS+=-lzmq -ldl -lsqlite3 -lmbedtls -lmbedx509 -lmbedcrypto
  4. PREFIX?=/usr/local
  5. get_objs = $(addsuffix .o,$(basename $(wildcard $(1))))
  6. ASM=$(wildcard src/**/*.S src/*.S)
  7. RAGEL_TARGETS=src/state.c src/http11/http11_parser.c
  8. SOURCES=$(wildcard src/**/*.c src/*.c) $(RAGEL_TARGETS)
  9. OBJECTS=$(patsubst %.c,%.o,${SOURCES}) $(patsubst %.S,%.o,${ASM})
  10. OBJECTS_NOEXT=$(filter-out ${OBJECTS_EXTERNAL},${OBJECTS})
  11. LIB_SRC=$(filter-out src/mongrel2.c,${SOURCES})
  12. LIB_OBJ=$(filter-out src/mongrel2.o,${OBJECTS})
  13. TEST_SRC=$(wildcard tests/*_tests.c)
  14. TESTS=$(patsubst %.c,%,${TEST_SRC})
  15. MAKEOPTS=OPTFLAGS="${NOEXTCFLAGS} ${OPTFLAGS}" LIBS="${LIBS}" DESTDIR="${DESTDIR}" PREFIX="${PREFIX}"
  16. all: builddirs bin/mongrel2 tests m2sh procer
  17. ${OBJECTS_NOEXT}: CFLAGS += ${NOEXTCFLAGS}
  18. ${OBJECTS}:
  19. #
  20. # CFLAGS_DEFS: The $(CC) flags required to obtain C pre-processor #defines, per:
  21. #
  22. # http://nadeausoftware.com/articles/2011/12/c_c_tip_how_list_compiler_predefined_macros
  23. #
  24. # It may be appropriate to copy some of these platform-specific CFLAGS_DEFS assignments into the
  25. # appropriate platform target at the end of this file, eg:
  26. #
  27. # solaris: CFLAGS_DEF=...
  28. # solaris: all
  29. #CFLAGS_DEFS=-dM -E # Portland Group PGCC
  30. #CFLAGS_DEFS=-xdumpmacros -E # Oracle Solaris Studio
  31. #CFLAGS_DEFS=-qshowmacros -E # IBM XL C
  32. CFLAGS_DEFS=-dM -E -x c # clang, gcc, HP C, Intel icc
  33. .PHONY: builddirs
  34. builddirs:
  35. @mkdir -p build
  36. @mkdir -p bin
  37. bin/mongrel2: build/libm2.a src/mongrel2.o
  38. $(CC) $(CFLAGS) $(LDFLAGS) src/mongrel2.o -o $@ $< $(LIBS)
  39. build/libm2.a: CFLAGS += -fPIC
  40. build/libm2.a: ${LIB_OBJ}
  41. ar rcs $@ ${LIB_OBJ}
  42. ranlib $@
  43. clean:
  44. rm -rf build bin lib ${OBJECTS} ${TESTS} tests/config.sqlite
  45. rm -f tests/perf.log
  46. rm -f tests/test.pid
  47. rm -f tests/tests.log
  48. rm -f tests/empty.sqlite
  49. rm -f tools/lemon/lemon
  50. rm -f tools/m2sh/tests/tests.log
  51. rm -rf release-scripts/output
  52. find . \( -name "*.gcno" -o -name "*.gcda" \) -exec rm {} \;
  53. ${MAKE} -C tools/m2sh OPTLIB=${OPTLIB} clean
  54. ${MAKE} -C tools/filters OPTLIB=${OPTLIB} clean
  55. ${MAKE} -C tests/filters OPTLIB=${OPTLIB} clean
  56. ${MAKE} -C tools/config_modules OPTLIB=${OPTLIB} clean
  57. ${MAKE} -C tools/procer OPTLIB=${OPTLIB} clean
  58. pristine: clean
  59. sudo rm -rf examples/python/build examples/python/dist examples/python/m2py.egg-info
  60. sudo find . -name "*.pyc" -exec rm {} \;
  61. ${MAKE} -C docs/manual clean
  62. cd docs/ && ${MAKE} clean
  63. ${MAKE} -C examples/kegogi clean
  64. rm -f logs/*
  65. rm -f run/*
  66. ${MAKE} -C tools/m2sh pristine
  67. ${MAKE} -C tools/procer pristine
  68. git submodule deinit -f src/mbedtls
  69. .PHONY: tests
  70. tests: tests/config.sqlite ${TESTS} test_filters filters config_modules
  71. sh ./tests/runtests.sh
  72. tests/config.sqlite: src/config/config.sql src/config/example.sql src/config/mimetypes.sql
  73. sqlite3 $@ < src/config/config.sql
  74. sqlite3 $@ < src/config/example.sql
  75. sqlite3 $@ < src/config/mimetypes.sql
  76. $(TESTS): %: %.c build/libm2.a
  77. $(CC) $(CFLAGS) -o $@ $< build/libm2.a $(LIBS)
  78. src/state.c: src/state.rl src/state_machine.rl
  79. src/http11/http11_parser.c: src/http11/http11_parser.rl
  80. src/http11/httpclient_parser.c: src/http11/httpclient_parser.rl
  81. check:
  82. @echo Files with potentially dangerous functions.
  83. @egrep '[^_.>a-zA-Z0-9](str(n?cpy|n?cat|xfrm|n?dup|str|pbrk|tok|_)|stpn?cpy|a?sn?printf|byte_)' $(filter-out src/bstr/bsafe.c,${SOURCES})
  84. m2sh: build/libm2.a
  85. ${MAKE} ${MAKEOPTS} -C tools/m2sh all
  86. procer: build/libm2.a
  87. ${MAKE} ${MAKEOPTS} -C tools/procer all
  88. test_filters: build/libm2.a
  89. ${MAKE} ${MAKEOPTS} -C tests/filters all
  90. filters: build/libm2.a
  91. ${MAKE} ${MAKEOPTS} -C tools/filters all
  92. config_modules: build/libm2.a
  93. ${MAKE} ${MAKEOPTS} -C tools/config_modules all
  94. # Try to install first before creating target directory and trying again
  95. install: all
  96. install bin/mongrel2 $(DESTDIR)/$(PREFIX)/bin/ \
  97. || ( install -d $(DESTDIR)/$(PREFIX)/bin/ \
  98. && install bin/mongrel2 $(DESTDIR)/$(PREFIX)/bin/ )
  99. ${MAKE} ${MAKEOPTS} -C tools/m2sh install
  100. ${MAKE} ${MAKEOPTS} -C tools/config_modules install
  101. ${MAKE} ${MAKEOPTS} -C tools/filters install
  102. ${MAKE} ${MAKEOPTS} -C tools/procer install
  103. examples/python/mongrel2/sql/config.sql: src/config/config.sql src/config/mimetypes.sql
  104. cat src/config/config.sql src/config/mimetypes.sql > $@
  105. ragel:
  106. ragel -G2 src/state.rl
  107. ragel -G2 src/http11/http11_parser.rl
  108. ragel -G2 src/handler_parser.rl
  109. ragel -G2 src/http11/httpclient_parser.rl
  110. %.o: %.S
  111. $(CC) $(CFLAGS) -c $< -o $@