Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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
  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 scripts...
  42. @if [ -e $@ ]; then patch -p1 -R < $?; fi
  43. @patch -p1 < $?
  44. @touch ${@}
  45. httpserver/httpserver-start.lua:
  46. @echo Replace httpserver init.lua by ${@}
  47. @mv httpserver/init.lua ${@}
  48. install: compress copy_lua
  49. # Compress files
  50. compress: compress_html compress_js compress_ico
  51. compress_html: $(SRC_HTML_FILES)
  52. @echo Compression HTML files
  53. @cp $^ $(DIST)/
  54. @gzip -9 -f $(DIST)/*.html
  55. compress_js: $(SRC_JS_FILES)
  56. @echo Compression JS files
  57. cp $^ $(DIST)/
  58. gzip -9 -f $(DIST)/*.js
  59. compress_ico: $(SRC_ICO_FILES)
  60. @echo Compression ICO files
  61. cp $^ $(DIST)/
  62. gzip -9 -f $(DIST)/*.ico
  63. copy_lua: $(SRC_LUA_FILES)
  64. cp $^ $(DIST)/
  65. venv: prepare venv/bin/activate
  66. venv/bin/activate: uploader/test_requirements.txt
  67. @test -d venv || virtualenv venv --python=python3
  68. @venv/bin/pip install -Ur $<
  69. @touch venv/bin/activate
  70. # Upload one files only
  71. upload: prepare venv
  72. @$(PYTHON) $(NODEMCU-COMMAND) $(FILE)
  73. # Upload webide
  74. upload_webide: $(DIST_FILES) prepare venv install
  75. @$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
  76. # Upload examples files
  77. upload_examples: $(EXAMPLES_FILES) prepare venv
  78. @$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
  79. # Upload httpserver lua files (init and server module)
  80. upload_server: prepare patchserver venv httpserver/Makefile
  81. @make -C httpserver upload_server
  82. # Upload all
  83. upload_all: upload_server upload_webide upload_examples