@@ -36,15 +36,33 @@ SCIMARK2_SHA1 := de278c5b8cef84ab6dda41855052c7bfef919e36
3636
3737SHELL_HACK := $(shell mkdir -p $(BIN_DIR ) /linux-x86-softfp $(BIN_DIR ) /riscv32 $(BIN_DIR ) /linux-image)
3838
39+ # $(1): tag of GitHub releases
40+ # $(2): name of GitHub releases
41+ # $(3): name showing in terminal
42+ define fetch-releases-tag
43+ $(if $(wildcard $(BIN_DIR ) /$(2 ) ) , \
44+ $(info $(3 ) is found. Skipping downloading.) , \
45+ $(eval LATEST_RELEASE := $(shell wget -q https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases -O- \
46+ | grep '"tag_name"' \
47+ | grep "$(1 ) " \
48+ | head -n 1 \
49+ | sed -E 's/.* "tag_name": "([^"]+) ".* /\1/') ) \
50+ $(if $(LATEST_RELEASE ) ,, \
51+ $(error Fetching tag of latest releases failed) \
52+ ) \
53+ )
54+ endef
55+
3956ifeq ($(call has, PREBUILT) , 1)
40- ifeq ($(call has, SYSTEM) , 1)
41- LATEST_RELEASE := $(shell wget -q https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases -O- | grep '"tag_name"' | grep "Linux-Image" | head -n 1 | sed -E 's/.* "tag_name": "([^"]+) ".*/\1/')
42- else ifeq ($(call has, ARCH_TEST), 1)
43- LATEST_RELEASE := $(shell wget -q https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases -O- | grep '"tag_name"' | grep "sail" | head -n 1 | sed -E 's/.* "tag_name": "([^"]+) ".*/\1/')
44- else
45- LATEST_RELEASE := $(shell wget -q https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases -O- | grep '"tag_name"' | grep "ELF" | head -n 1 | sed -E 's/.* "tag_name": "([^"]+) ".*/\1/')
46- endif
47- PREBUILT_BLOB_URL = https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE )
57+ ifeq ($(call has, SYSTEM), 1)
58+ $(call fetch-releases-tag,Linux-Image,rv32emu-linux-image-prebuilt.tar.gz,Linux image)
59+ else ifeq ($(call has, ARCH_TEST), 1)
60+ $(call fetch-releases-tag,sail,rv32emu-prebuilt-sail-$(HOST_PLATFORM),Sail model)
61+ else
62+ $(call fetch-releases-tag,ELF,rv32emu-prebuilt.tar.gz,Prebuilt benchmark)
63+ endif
64+
65+ PREBUILT_BLOB_URL = https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE )
4866else
4967 # Since rv32emu only supports the dynamic binary translation of integer instruction in tiered compilation currently,
5068 # we disable the hardware floating-point and the related SIMD operation of x86.
@@ -95,14 +113,15 @@ endif
95113ifeq ($(call has, ARCH_TEST) , 1)
96114 $(Q)if [ "$(RES)" = "1" ]; then \
97115 $(PRINTF) "\n$(YELLOW)SHA-1 verification failed! Re-fetching prebuilt binaries from \"rv32emu-prebuilt\" ...\n$(NO_COLOR)"; \
98- wget -q --show-progress $(PREBUILT_BLOB_URL)/$(RV32EMU_PREBUILT_TARBALL) -O build/$(RV32EMU_PREBUILT_TARBALL);\
116+ wget -q --show-progress $(PREBUILT_BLOB_URL)/$(RV32EMU_PREBUILT_TARBALL) -O build/$(RV32EMU_PREBUILT_TARBALL); \
99117 else \
100118 $(call notice, [OK]); \
101119 fi
102120else
103121 $(Q)if [ "$(RES)" = "1" ]; then \
104122 $(PRINTF) "\n$(YELLOW)SHA-1 verification failed! Re-fetching prebuilt binaries from \"rv32emu-prebuilt\" ...\n$(NO_COLOR)"; \
105- wget -q --show-progress $(PREBUILT_BLOB_URL)/$(RV32EMU_PREBUILT_TARBALL) -O- | tar -C build --strip-components=1 -xz; \
123+ wget -q --show-progress $(PREBUILT_BLOB_URL)/$(RV32EMU_PREBUILT_TARBALL) -O build/$(RV32EMU_PREBUILT_TARBALL); \
124+ tar --strip-components=1 -zxf build/$(RV32EMU_PREBUILT_TARBALL) -C build; \
106125 else \
107126 $(call notice, [OK]); \
108127 fi
@@ -147,16 +166,29 @@ endif
147166
148167fetch-checksum :
149168ifeq ($(call has, PREBUILT) , 1)
150- $(Q)$(PRINTF) "Fetching SHA-1 of prebuilt binaries ...\n "
169+ $(Q)$(PRINTF) "Fetching SHA-1 of prebuilt binaries ... "
151170ifeq ($(call has, SYSTEM) , 1)
152- $(Q)wget -q -O $(BIN_DIR)/sha1sum-linux-image $(PREBUILT_BLOB_URL)/sha1sum-linux-image
153- $(Q)$(call notice, [OK])
171+ ifeq ($(wildcard $(BIN_DIR)/rv32emu-linux-image-prebuilt.tar.gz),)
172+ $(Q)wget -q -O $(BIN_DIR)/sha1sum-linux-image $(PREBUILT_BLOB_URL)/sha1sum-linux-image
173+ $(Q)$(call notice, [OK])
174+ else
175+ $(Q)$(PRINTF) "Skipped\n"
176+ endif
154177else ifeq ($(call has, ARCH_TEST), 1)
155- $(Q)wget -q -O $(BIN_DIR)/rv32emu-prebuilt-sail-$(HOST_PLATFORM).sha $(PREBUILT_BLOB_URL)/rv32emu-prebuilt-sail-$(HOST_PLATFORM).sha
178+ ifeq ($(wildcard $(BIN_DIR)/rv32emu-prebuilt-sail-$(HOST_PLATFORM)),)
179+ $(Q)wget -q -O $(BIN_DIR)/rv32emu-prebuilt-sail-$(HOST_PLATFORM).sha $(PREBUILT_BLOB_URL)/rv32emu-prebuilt-sail-$(HOST_PLATFORM).sha
180+ $(Q)$(call notice, [OK])
181+ else
182+ $(Q)$(PRINTF) "Skipped\n"
183+ endif
156184else
157- $(Q)wget -q -O $(BIN_DIR)/sha1sum-linux-x86-softfp $(PREBUILT_BLOB_URL)/sha1sum-linux-x86-softfp
158- $(Q)wget -q -O $(BIN_DIR)/sha1sum-riscv32 $(PREBUILT_BLOB_URL)/sha1sum-riscv32
159- $(Q)$(call notice, [OK])
185+ ifeq ($(wildcard $(BIN_DIR)/rv32emu-prebuilt.tar.gz),)
186+ $(Q)wget -q -O $(BIN_DIR)/sha1sum-linux-x86-softfp $(PREBUILT_BLOB_URL)/sha1sum-linux-x86-softfp
187+ $(Q)wget -q -O $(BIN_DIR)/sha1sum-riscv32 $(PREBUILT_BLOB_URL)/sha1sum-riscv32
188+ $(Q)$(call notice, [OK])
189+ else
190+ $(Q)$(PRINTF) "Skipped\n"
191+ endif
160192endif
161193endif
162194
0 commit comments