Makefile 3.5 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_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_webide 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. prepare: httpserver/Makefile patchserver
  28. # make sure that the submodules are fetch
  29. httpserver/Makefile:
  30. @echo Preparing submodules...
  31. @git submodule init
  32. @git submodule update
  33. # Patch httpserver makefile for upload and init
  34. patchserver: httpserver/makefile.patched httpserver/init.patched httpserver/httpserver.patched
  35. httpserver/makefile.patched: patchs/httpserver_makefile.patch httpserver/Makefile
  36. @echo Patching httpserver makefile...
  37. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  38. @patch -p1 < $?
  39. @touch ${@}
  40. httpserver/init.patched: patchs/httpserver_init.patch httpserver/httpserver-compile.lua
  41. @echo Patching httpserver compile scripts...
  42. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  43. @patch -p1 < $?
  44. @touch ${@}
  45. httpserver/httpserver.patched: patchs/httpserver_httpserver.patch httpserver/httpserver.lua
  46. @echo Patching httpserver.lua ...
  47. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  48. @patch -p1 < $?
  49. @touch ${@}
  50. httpserver/httpserver-start.lua:
  51. @echo Replace httpserver init.lua by ${@}
  52. @mv httpserver/init.lua ${@}
  53. install: compress copy_lua
  54. # Compress files
  55. compress: compress_html compress_js compress_ico
  56. compress_html: $(SRC_HTML_FILES)
  57. @echo Compression HTML files
  58. @cp $^ $(DIST)/
  59. @gzip -9 -f $(DIST)/*.html
  60. compress_js: $(SRC_JS_FILES)
  61. @echo Compression JS files
  62. cp $^ $(DIST)/
  63. gzip -9 -f $(DIST)/*.js
  64. compress_ico: $(SRC_ICO_FILES)
  65. @echo Compression ICO files
  66. cp $^ $(DIST)/
  67. gzip -9 -f $(DIST)/*.ico
  68. copy_lua: $(SRC_LUA_FILES)
  69. cp $^ $(DIST)/
  70. venv: prepare venv/bin/activate
  71. venv/bin/activate: uploader/test_requirements.txt
  72. @test -d venv || virtualenv venv --python=python3
  73. @venv/bin/pip install -Ur $<
  74. @touch venv/bin/activate
  75. # Upload one files only
  76. upload: prepare venv
  77. @$(PYTHON) $(NODEMCU-COMMAND) $(FILE)
  78. # Upload webide
  79. upload_webide: $(DIST_FILES) prepare venv install
  80. @$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
  81. # Upload examples files
  82. upload_examples: $(EXAMPLES_FILES) prepare venv
  83. @$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
  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