Makefile 4.9 KB

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