Makefile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. HOST := $(firstword $(shell ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' -m 1 | cut -d: -f2))
  2. PORT := 8000
  3. NPROCS := 1
  4. OS := $(shell uname -s)
  5. ifeq ($(OS),Linux)
  6. NPROCS := $(shell grep -c ^processor /proc/cpuinfo)
  7. endif
  8. HTTPD_DIR = httpd-2.4.3
  9. APR_DIR = apr-1.4.6
  10. APRUTIL_DIR = apr-util-1.5.1
  11. PHP_DIR = php-5.6.6
  12. INSTALL_DIR = $(PWD)/obj
  13. SRC_DIRS = $(HTTPD_DIR) $(APR_DIR) $(APRUTIL_DIR) $(PHP_DIR)
  14. HTDOC=$(INSTALL_DIR)/htdocs
  15. TARGET = $(INSTALL_DIR)/bin/httpd $(INSTALL_DIR)/modules/libphp5.so \
  16. $(INSTALL_DIR)/modules/mod_auth_basic_sandbox.so \
  17. conf httpd.manifest test-data
  18. all: $(TARGET)
  19. debug: MAKE_FLAGS=CC="gcc -g"
  20. debug: APXS_FLAGS=-S CC="gcc -g"
  21. debug: $(TARGET)
  22. %: %.tar.gz
  23. tar -xzf $<
  24. %: %.tar.bz2
  25. tar -xjf $<
  26. $(INSTALL_DIR)/lib/libapr-1.so.0: $(APR_DIR)
  27. #cd $< && patch -p1 < ../disable-epoll.patch
  28. cd $< && ./configure --prefix=$(INSTALL_DIR)
  29. cd $< && make -j$(NPROCS) $(MAKE_FLAGS)
  30. cd $< && make install
  31. $(INSTALL_DIR)/lib/libaprutil-1.so.0: $(APRUTIL_DIR) $(INSTALL_DIR)/lib/libapr-1.so.0
  32. cd $< && ./configure --prefix=$(INSTALL_DIR) --with-apr=$(INSTALL_DIR)
  33. cd $< && make -j$(NPROCS) $(MAKE_FLAGS)
  34. cd $< && make install
  35. $(INSTALL_DIR)/bin/httpd $(INSTALL_DIR)/bin/apxs: $(INSTALL_DIR)/lib/libapr-1.so.0 $(INSTALL_DIR)/lib/libaprutil-1.so.0
  36. [ -d $(HTTPD_DIR) ] || tar -xzf $(HTTPD_DIR).tar.gz
  37. [ -f $(HTTPD_DIR)/Makefile ] || \
  38. cd $(HTTPD_DIR) && ./configure --prefix=$(INSTALL_DIR) --with-apr=$(INSTALL_DIR) \
  39. --with-apr-util=$(INSTALL_DIR) --with-mpm=prefork
  40. cd $(HTTPD_DIR) && make -j$(NPROCS) $(MAKE_FLAGS)
  41. cd $(HTTPD_DIR) && make install
  42. $(INSTALL_DIR)/modules/libphp5.so: $(PHP_DIR) $(INSTALL_DIR)/bin/apxs
  43. cd $< && ./configure --prefix=$(INSTALL_DIR) --with-apxs2=$(INSTALL_DIR)/bin/apxs \
  44. --disable-cgi --disable-cli --disable-soap
  45. cd $< && make -j$(NPROCS) $(MAKE_FLAGS)
  46. cd $< && make install
  47. .PHONY: modules
  48. modules: $(INSTALL_DIR)/modules/mod_auth_basic_sandbox.so
  49. $(INSTALL_DIR)/modules/mod_auth_basic_sandbox.so: mod_auth_basic_sandbox.c $(INSTALL_DIR)/bin/apxs
  50. $(INSTALL_DIR)/bin/apxs $(APXS_FLAGS) \
  51. -S CFLAGS="-I../../../include" \
  52. -S LDFLAGS="-L../../../../build/libos -llibos" -c -i -A $<
  53. %.manifest: %.manifest.template
  54. make -C .. apache/$@ appdir=apache/ \
  55. extra_rules="-e 's:\\\$$\$$(HOST):$(HOST):g' -e 's:\\\$$\$$(PORT):$(PORT):g'"
  56. conf:
  57. cd $(INSTALL_DIR)/conf && ([ -f httpd.conf.old ] || mv httpd.conf httpd.conf.old)
  58. cd $(INSTALL_DIR)/conf && \
  59. sed -e "s/Listen 80/Listen $(HOST):$(PORT)/g" \
  60. -e "s/User daemon/#User root/g" \
  61. -e "s/Group daemon/#Group root/g" \
  62. -e "s/#EnableMMAP off/EnableMMAP off/g" \
  63. -e "s/#EnableSendfile on/EnableSendfile on/g" \
  64. -e "s/DirectoryIndex index.html/DirectoryIndex index.html index.php/g" \
  65. -e "s/^[ ]*CustomLog/#CustomLog/g" \
  66. httpd.conf.old > httpd.conf.new
  67. cd $(INSTALL_DIR)/conf && \
  68. echo "\n\
  69. <IfModule mpm_prefork_module>\n\
  70. StartServers 4\n\
  71. MinSpareServers 1\n\
  72. MaxSpareServers 4\n\
  73. MaxConnectionsPerChild 0\n\
  74. </IfModule>\n" >> httpd.conf.new
  75. cd $(INSTALL_DIR)/conf && ln -sf httpd.conf.new httpd.conf
  76. start-native-server:
  77. $(PREFIX) $(INSTALL_DIR)/bin/httpd -D FOREGROUND
  78. start-graphene-server:
  79. rm -rf $(INSTALL_DIR)/logs/httpd.pid
  80. $(PREFIX) ./httpd.manifest -D FOREGROUND
  81. random-data = $(foreach n,1 2 3 4 5 6 7 8 9 10,2K.$n.html) \
  82. $(foreach n,1 2 3 4 5,10K.$n.html) \
  83. $(foreach n,1 2 3 4 5,100K.$n.html) \
  84. $(foreach n,1 2 3,1M.$n.html) \
  85. $(foreach n,1 2 3,10M.$n.html) \
  86. $(foreach n,1 2 3,100.$n.html)
  87. test-data = $(HTDOC)/oscar-web $(HTDOC)/oscar-web-static \
  88. $(addprefix $(HTDOC)/random/,$(random-data)) \
  89. $(HTDOC)/auth/secret.html $(HTDOC)/auth/.htaccess
  90. $(HTDOC)/%: $(PWD)/../web-data/%.tar.gz
  91. [ -d "$@" ] || (mkdir -p $@ && cd $(HTDOC) && tar -xzf $^)
  92. $(HTDOC)/random/%.html:
  93. [ -d $(HTDOC)/random ] || mkdir -p $(HTDOC)/random
  94. dd if=/dev/urandom of=$@ count=1 bs=$(basename $(basename $(notdir $@)))
  95. $(HTDOC)/auth:
  96. mkdir -p $@
  97. $(HTDOC)/auth/secret.html: $(HTDOC)/auth
  98. echo "This is the secret" > $@
  99. $(HTDOC)/auth/.htpasswd: $(INSTALL_DIR)/bin/htpasswd $(HTDOC)/auth
  100. $< -b -c $@ test test
  101. $(HTDOC)/auth/.htaccess: $(HTDOC)/auth/.htpasswd
  102. echo "AuthName \"Login\"\n\
  103. AuthType Basic\n\
  104. AuthUserFile $(HTDOC)/auth/.htpasswd\n\
  105. AuthGroupFile /dev/null\n\
  106. require user test" > $@
  107. test-data: $(test-data)
  108. distclean: clean
  109. rm -rf $(INSTALL_DIR) $(SRC_DIRS)
  110. clean:
  111. rm -rf httpd.manifest $(test-data) \
  112. $(addprefix mod_auth_basic_sandbox.,la lo o slo)