Makefile 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. MAKEFLAGS += -R -r
  2. PROJECT := max80
  3. SUBDIRS := common esp32 tools rv32 fpga
  4. REVISIONS := v1 v2 bypass
  5. GIT_DIR ?= .git
  6. TEMP ?= /tmp
  7. MAX80_IP ?= max80.local
  8. CURL = curl
  9. PERL = perl
  10. PYTHON = python
  11. ESPTOOL ?= esptool
  12. export ESPTOOL
  13. all clean spotless :
  14. $(MAKE) local.$@ $(SUBDIRS) goal=$@
  15. prefpga:
  16. $(MAKE) local.all $(filter-out fpga,$(SUBDIRS)) goal=all
  17. $(REVISIONS): prefpga
  18. $(MAKE) -C fpga $@
  19. .PHONY: $(SUBDIRS)
  20. $(SUBDIRS):
  21. $(MAKE) -C $@ $(goal)
  22. .PHONY: version.mk
  23. version.mk:
  24. if git log -n 1 --date=iso --pretty="format:\
  25. PROJECT=$(PROJECT)%n\
  26. COMMIT_VERSION=%(describe:abbrev=6)%n\
  27. COMMIT_ID=%H%nCOMMIT_MAGIC=%h%n\
  28. COMMIT_DATE=%ci%n\
  29. COMMIT_TIME=%ct%n\
  30. COMMIT_AUTHOR=%an <%ae>%n\
  31. " > '$@.tmp' 2>/dev/null && \
  32. ! cmp -s '$@' '$@.tmp' 2>/dev/null; then \
  33. mv -f '$@.tmp' '$@'; else rm -f '$@.tmp'; fi
  34. version.%: version.mk version.%.sed
  35. sed -f $@.sed $< > $@
  36. .PHONY: version
  37. version: version.mk version.h version.vh
  38. $(SUBDIRS): version.mk
  39. esp32: version.h | common
  40. rv32: version.h | common tools
  41. fpga: version.vh | rv32 esp32
  42. local.all:
  43. local.clean:
  44. rm -f *~ ./\#* \# *.bak *.tmp stamp_*.bin
  45. local.spotless: local.clean
  46. rm -f version.h version.vh
  47. if [ -d .git ]; then rm -f version.mk; fi
  48. # Obsolete target, need version
  49. program flash:
  50. @echo 'Please specify one of: $(foreach rev,$(REVISIONS),$@-$(rev))' 1>&2
  51. @false
  52. # FPGA-specific targets
  53. program-% flash-%: prefpga
  54. $(MAKE) -C fpga $@
  55. # ESP update by USB or serial port using esptool directly
  56. upload-esp:
  57. $(MAKE) -C esp32 upload
  58. ip = $(MAX80_IP)
  59. # Generic upload for newer firmware (as opposed to specifying a version)
  60. upload: upload-$(PROJECT)
  61. ifeq ($(PORT),)
  62. # --- Upload via HTTP ---
  63. upload-%:
  64. $(CURL) -v --data-binary @fpga/output/$*.fw 'http://$(ip)/sys/fwupdate'
  65. # setver is not supported via HTTP
  66. setver-%:
  67. @echo 'make $@ requires PORT= to be specified'
  68. @exit 1
  69. else
  70. # --- Upload via serial port/USB
  71. FLASHMAX = $(PERL) ./tools/flashmax.pl --port '$(PORT)' $(FLASHOPT)
  72. # Version-specific uploads for older firmware
  73. upload-%:
  74. $(FLASHMAX) fpga/output/$*.fw
  75. # Write board ID/revision to flash
  76. setver-%:
  77. $(FLASHMAX) --setver 'MAX80 $*'
  78. endif