Jelajahi Sumber

Makefile: create version file with the latest git commit info

H. Peter Anvin 2 tahun lalu
induk
melakukan
5cc202c10c
2 mengubah file dengan 37 tambahan dan 4 penghapusan
  1. 2 0
      .gitignore
  2. 35 4
      Makefile

+ 2 - 0
.gitignore

@@ -26,7 +26,9 @@ greybox_tmp/
 *.stamp
 *.ild
 .*.d
+*.tmp
 *.build/
 fpga/output_files/*.htm
 fpga/output_files/*.htm_files/
 tools/gnu/
+version.*

+ 35 - 4
Makefile

@@ -1,7 +1,10 @@
 MAKEFLAGS += -R -r
 
+PROJECT   := max80
 SUBDIRS   := esp32 tools rv32 fpga
-REVISIONS := v1 v2
+REVISIONS := v1 v2 bypass
+
+GIT_DIR   ?= .git
 
 all clean spotless :
 	$(MAKE) local.$@ $(SUBDIRS) goal=$@
@@ -16,16 +19,39 @@ $(REVISIONS): prefpga
 $(SUBDIRS):
 	$(MAKE) -C $@ $(goal)
 
-rv32: | tools
+.PHONY: version.mk
+version.mk:
+	if [ -d '$(GIT_DIR)' ]; then \
+	    TZ=UTC0 git log -n 1 --date=local --abbrev=8 \
+		--pretty='format:COMMIT_VERSION=$(PROJECT)-%(describe:abbrev=6)%nCOMMIT_ID=%H%nCOMMIT_MAGIC=0x%h%nCOMMIT_DATE=%cd UTC%n' > $@.tmp ; \
+		if cmp -q '$@' '$@.tmp' 2>/dev/null; then \
+			rm -f $@.tmp; else mv -f $@.tmp $@; fi \
+	fi
+
+version.h: version.mk
+	sed -e 's/^/#define /' -e 's/=/ "/' -e 's/$$/"/' \
+		-e '/ COMMIT_MAGIC /s/"//g' < $< > $@
+
+version.vh: version.mk
+	sed -e 's/^/`define /' -e 's/=/ "/' -e 's/$$/"/' \
+		-e '/ COMMIT_MAGIC /s/"//g' < $< > $@
+
+$(SUBDIRS): version.mk
 
-fpga: | rv32 esp32
+esp32: version.h
+
+rv32: version.h | tools
+
+fpga: version.vh | rv32 esp32
 
 local.all:
 
 local.clean:
-	rm -f *~ ./\#* \# *.bak
+	rm -f *~ ./\#* \# *.bak *.tmp
 
 local.spotless: local.clean
+	rm -f version.h version.vh
+	if [ -d .git ]; then rm -f version.mk; fi
 
 # Obsolete target, need version
 program flash:
@@ -35,3 +61,8 @@ program flash:
 # FPGA-specific targets
 program-% flash-%: prefpga
 	$(MAKE) -C fpga $@
+
+# ESP update by USB or serial port
+upload-esp:
+	$(MAKE) -C esp32 upload
+