Makefile 5.1 KB

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