Makefile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ######################################################################
  2. # Makefile user configuration
  3. ######################################################################
  4. # Path to nodemcu-uploader (https://github.com/kmpm/nodemcu-uploader)
  5. export NODEMCU-UPLOADER=$(CURDIR)/uploader/nodemcu-uploader.py
  6. # Serial port
  7. export PORT=/dev/ttyUSB0
  8. export SPEED=115200
  9. export NODEMCU-COMMAND=$(NODEMCU-UPLOADER) -b $(SPEED) --start_baud $(SPEED) -p $(PORT) upload
  10. export PYTHON=$(CURDIR)/venv/bin/python
  11. ######################################################################
  12. SRC_LUA_FILES := $(wildcard src/*.lua)
  13. SRC_HTTP_FILES = $(wildcard src/http/*.html) $(wildcard src/http/*.js) $(wildcard src/http/*.lua) $(wildcard src/http/*.ico)
  14. EXAMPLE_FILES := $(wildcard examples/*.html) $(wildcard examples/*.lua)
  15. DIST := dist
  16. SRC_DIST_FILES = $(wildcard $(DIST)/*.lua) $(wildcard $(DIST)/http/*.gz) $(wildcard $(DIST)/http/*.lua)
  17. DIST_FILES = $(patsubst $(DIST)/%, %, $(SRC_DIST_FILES))
  18. # Print usage
  19. usage:
  20. @echo "make upload FILE:=<file> to upload a specific file (i.e make upload FILE:=init.lua)"
  21. @echo "make upload_webide to upload webide"
  22. @echo "make upload_examples to upload examples"
  23. @echo "make upload_server to upload the server code and init.lua"
  24. @echo "make upload_all to upload all"
  25. @echo $(TEST)
  26. help: usage
  27. prepare: httpserver/Makefile patchserver
  28. clean:
  29. @git submodule deinit -f .
  30. @rm -f $(DIST)/*.gz
  31. @rm -f $(DIST)/*.lua
  32. @rm -Rf $(DIST)/http
  33. # make sure that the submodules are fetch
  34. httpserver/Makefile:
  35. @echo Preparing submodules...
  36. @git submodule init
  37. @git submodule update
  38. # Patch httpserver makefile for upload and init
  39. patchserver: httpserver/makefile.patched httpserver/init.patched httpserver/httpserver.patched httpserver/httpserver-start.lua
  40. httpserver/makefile.patched: patchs/httpserver_makefile.patch httpserver/Makefile
  41. @echo Patching httpserver makefile...
  42. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  43. @patch -p1 < $?
  44. @touch ${@}
  45. httpserver/init.patched: patchs/httpserver_init.patch httpserver/httpserver-compile.lua
  46. @echo Patching httpserver compile scripts...
  47. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  48. @patch -p1 < $?
  49. @touch ${@}
  50. httpserver/httpserver.patched: patchs/httpserver_httpserver.patch httpserver/httpserver.lua
  51. @echo Patching httpserver.lua ...
  52. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  53. @patch -p1 < $?
  54. @touch ${@}
  55. httpserver/httpserver-start.lua:
  56. @echo Replace httpserver init.lua by ${@}
  57. @mv httpserver/init.lua ${@}
  58. install: compress copy_lua
  59. # Compress files
  60. compress: $(SRC_HTTP_FILES)
  61. @echo Compression HTTP files
  62. @install -d $(DIST)/http/
  63. @install $^ $(DIST)/http/
  64. @gzip -9 -f $(DIST)/http/*.html
  65. @gzip -9 -f $(DIST)/http/*.js
  66. @gzip -9 -f $(DIST)/http/*.ico
  67. copy_lua: $(SRC_LUA_FILES)
  68. @cp $^ $(DIST)/
  69. venv: prepare venv/bin/activate
  70. venv/bin/activate: uploader/test_requirements.txt
  71. @test -d venv || virtualenv venv --python=python3
  72. @venv/bin/pip install -Ur $<
  73. @touch venv/bin/activate
  74. # Upload one files only
  75. upload: prepare venv
  76. @$(PYTHON) $(NODEMCU-COMMAND) $(FILE)
  77. # Upload webide
  78. upload_webide: prepare venv install
  79. @cd $(DIST) && $(PYTHON) $(NODEMCU-COMMAND) $(DIST_FILES)
  80. # Upload examples files
  81. upload_examples: $(EXAMPLES_FILES) prepare venv copy_example upload_webide
  82. copy_example:
  83. @cp $(EXAMPLE_FILES) $(DIST)/http
  84. # Upload httpserver lua files (init and server module)
  85. upload_server: prepare patchserver venv httpserver/Makefile
  86. @make -C httpserver upload_server
  87. # Upload all
  88. upload_all: upload_server upload_webide upload_examples