Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
makefile: only update rom list when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
frazz committed Jan 3, 2021
1 parent 909d60f commit f3669c5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
ECHO = echo
BASH ?= /bin/bash
FIND = find

#######################################
# CFLAGS
Expand Down Expand Up @@ -254,16 +255,18 @@ endef
# generate all object prerequisite rules
$(eval $(foreach obj,$(SDK_C_SOURCES) $(SDK_ASM_SOURCES),$(call sdk_obj_prereq_gen,$(obj))))

FORCE:

# Run parse_roms.py to generate information about the roms
Core/Src/retro-go/gb_roms.c Core/Src/retro-go/nes_roms.c $(BUILD_DIR)/saveflash.ld &: parse_roms.py | $(BUILD_DIR)
$(BUILD_DIR)/rom_hashes.txt: FORCE | $(BUILD_DIR)
$(V)$(ECHO) [ Checking roms ROMS ]
$(V)./update_rom_hashes.sh build/rom_hashes.txt roms/nes/ roms/gb

$(BUILD_DIR)/saveflash.ld: $(BUILD_DIR)/rom_hashes.txt parse_roms.py | $(BUILD_DIR)
$(V)$(ECHO) [ PYTHON3 ] $(notdir $<)
$(V)$(BASH) -c " \
cp -f $(BUILD_DIR)/rom_hashes.txt $(BUILD_DIR)/rom_hashes_old.txt 2> /dev/null; \
find ./roms -type f -exec sha1sum {} \; > $(BUILD_DIR)/rom_hashes.txt && \
diff $(BUILD_DIR)/rom_hashes.txt $(BUILD_DIR)/rom_hashes_old.txt 2> /dev/null || $(PYTHON3) parse_roms.py --flash-size $(EXTFLASH_SIZE) && \
rm -f $(BUILD_DIR)/rom_hashes_old.txt; \
"
.PHONY: Core/Src/retro-go/gb_roms.c Core/Src/retro-go/nes_roms.c $(BUILD_DIR)/saveflash.ld
$(V)$(PYTHON3) parse_roms.py --flash-size $(EXTFLASH_SIZE)

Core/Src/retro-go/gb_roms.c Core/Src/retro-go/nes_roms.c: $(BUILD_DIR)/saveflash.ld | $(BUILD_DIR)

# TODO: Hard-coded dependencies. Possible to solve in a nicer way?
Core/Src/retro-go/rom_manager.c: Core/Src/retro-go/gb_roms.c Core/Src/retro-go/nes_roms.c
Expand Down
44 changes: 44 additions & 0 deletions update_rom_hashes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash -e

if [ -z $2 ]; then
echo "Usage: `basename $0` <hash file> <rom directory> [<rom directory>] ..."
exit 1
fi

hashfile="$1"

update_needed=0

if [ ! -f $hashfile ]; then
update_needed=1
else
# Any file updated or removed?
while read line; do
file=`echo $line | sed 's/[^ ]* *//'`
hash=`echo $line | sed 's/\([^ ]*\) .*/\1/'`

if [ ! -f $file ]; then
# File removed
update_needed=1
else
h=`sha1sum $file | sed 's/\([^ ]*\) .*/\1/'`

if [ "$h" != "$hash" ]; then
# File updated
update_needed=1
fi
fi
done < "$hashfile"

# Any new files?
for dir in ${@:2}; do
while read file; do
grep $file\$ $hashfile > /dev/null || update_needed=1
done <<< `find $dir -type f`
done
fi
if [ $update_needed -ne 0 ]; then
echo "Updating hash file"
find ${@:2} -type f -exec sha1sum {} \; > $hashfile 2> /dev/null
fi

0 comments on commit f3669c5

Please sign in to comment.