Makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_HTML_FILES := $(wildcard src/*.html)
  14. SRC_JS_FILES := $(wildcard src/*.js)
  15. SRC_ICO_FILES := $(wildcard src/*.ico)
  16. EXAMPLE_FILES := $(wildcard examples/*.html) $(wildcard examples/*.lua)
  17. DIST := dist
  18. DIST_FILES = $(wildcard $(DIST)/*.gz) $(wildcard $(DIST)/*.lua)
  19. # Print usage
  20. usage:
  21. @echo "make upload FILE:=<file> to upload a specific file (i.e make upload FILE:=init.lua)"
  22. @echo "make upload_webide to upload webide"
  23. @echo "make upload_examples to upload examples"
  24. @echo "make upload_server to upload the server code and init.lua"
  25. @echo "make upload_all to upload all"
  26. @echo $(TEST)
  27. help: usage
  28. prepare: httpserver/Makefile patchserver
  29. # make sure that the submodules are fetch
  30. httpserver/Makefile:
  31. @echo Preparing submodules...
  32. @git submodule init
  33. @git submodule update
  34. # Patch httpserver makefile for upload and init
  35. patchserver: httpserver/makefile.patched httpserver/init.patched httpserver/httpserver.patched
  36. httpserver/makefile.patched: patchs/httpserver_makefile.patch httpserver/Makefile
  37. @echo Patching httpserver makefile...
  38. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  39. @patch -p1 < $?
  40. @touch ${@}
  41. httpserver/init.patched: patchs/httpserver_init.patch httpserver/httpserver-compile.lua
  42. @echo Patching httpserver compile scripts...
  43. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  44. @patch -p1 < $?
  45. @touch ${@}
  46. httpserver/httpserver.patched: patchs/httpserver_httpserver.patch httpserver/httpserver.lua
  47. @echo Patching httpserver.lua ...
  48. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  49. @patch -p1 < $?
  50. @touch ${@}
  51. httpserver/httpserver-start.lua:
  52. @echo Replace httpserver init.lua by ${@}
  53. @mv httpserver/init.lua ${@}
  54. install: compress copy_lua
  55. # Compress files
  56. compress: compress_html compress_js compress_ico
  57. compress_html: $(SRC_HTML_FILES)
  58. @echo Compression HTML files
  59. @cp $^ $(DIST)/
  60. @gzip -9 -f $(DIST)/*.html
  61. compress_js: $(SRC_JS_FILES)
  62. @echo Compression JS files
  63. cp $^ $(DIST)/
  64. gzip -9 -f $(DIST)/*.js
  65. compress_ico: $(SRC_ICO_FILES)
  66. @echo Compression ICO files
  67. cp $^ $(DIST)/
  68. gzip -9 -f $(DIST)/*.ico
  69. copy_lua: $(SRC_LUA_FILES)
  70. cp $^ $(DIST)/
  71. venv: prepare venv/bin/activate
  72. venv/bin/activate: uploader/test_requirements.txt
  73. @test -d venv || virtualenv venv --python=python3
  74. @venv/bin/pip install -Ur $<
  75. @touch venv/bin/activate
  76. # Upload one files only
  77. upload: prepare venv
  78. @$(PYTHON) $(NODEMCU-COMMAND) $(FILE)
  79. # Upload webide
  80. upload_webide: $(DIST_FILES) prepare venv install
  81. @$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
  82. # Upload examples files
  83. upload_examples: $(EXAMPLES_FILES) prepare venv
  84. @$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
  85. # Upload httpserver lua files (init and server module)
  86. upload_server: prepare patchserver venv httpserver/Makefile
  87. @make -C httpserver upload_server
  88. # Upload all
  89. upload_all: upload_server upload_webide upload_examples