mirror of
https://github.com/LIV2/a4091-logic.git
synced 2025-12-06 06:22:43 +00:00
Clean up JED file generation
In order to track versioning of individual JED files better, add a better time stamp to each of them: - If a JED files is checked into git already and no changes to the file occured, use the timestamp of the last change to this file. (Default) - If a JED files is checked into git already and changes to the file occured, use the timestamp of the file's last modification. - If a JED files is NOT checked into git already, also use the timestamp of the file's last modification. In addition, recalculate the file checksum (not the same as the data checksum) after this change, just in case.
This commit is contained in:
parent
ae50265da8
commit
4448352575
13
Makefile
13
Makefile
@ -8,12 +8,17 @@ OPT = 1
|
||||
|
||||
all: $(JED)
|
||||
|
||||
clean:
|
||||
rm -f $(JED)
|
||||
|
||||
jedec/%.jed: source/%.pld Makefile
|
||||
jedec/%.jed: source/%.pld Makefile util/jedcrc
|
||||
$(CUPL) -jm$(OPT) $(LIBCUPL) $<
|
||||
mv $(<:source/u%.pld=source/U%.jed) $(<:source/%.pld=jedec/%.jed)
|
||||
util/fixup_jed.sh $< $(<:source/%.pld=jedec/%.jed)
|
||||
|
||||
jedec/u305.jed : OPT=3 # U305 says: COMPILE -M3
|
||||
|
||||
util/jedcrc : util/jedcrc.c
|
||||
|
||||
clean:
|
||||
rm -f util/jedcrc
|
||||
distclean: clean
|
||||
rm -f $(JED)
|
||||
|
||||
|
||||
46
util/date.sh
Executable file
46
util/date.sh
Executable file
@ -0,0 +1,46 @@
|
||||
#
|
||||
# Script to find "best" time stamp of a file
|
||||
# - If file is checked into git and unchanged, use git check-in date
|
||||
# - If file is checked into git and changed, use file modification date
|
||||
# - If file is not checked into git, use file modification date
|
||||
#
|
||||
|
||||
change_date() {
|
||||
case $(uname) in
|
||||
NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin)
|
||||
eval $(stat -s $1)
|
||||
echo $st_mtime
|
||||
;;
|
||||
*)
|
||||
stat -c %Y $1
|
||||
esac
|
||||
}
|
||||
|
||||
FILE=$1
|
||||
|
||||
if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
|
||||
|
||||
if ! git diff --quiet $FILE; then
|
||||
TIMESOURCE="file date"
|
||||
DATE=$(change_date "$FILE")
|
||||
else
|
||||
|
||||
TIMESOURCE=git
|
||||
DATE=$(LANG= git log --no-show-signature -1 --format="format:%ct" $FILE 2>/dev/null || \
|
||||
LANG= git log -1 --format="format:%ct" $FILE)
|
||||
fi
|
||||
else
|
||||
TIMESOURCE="file date"
|
||||
DATE=$(change_date $FILE)
|
||||
fi
|
||||
|
||||
# echo $TIMESOURCE
|
||||
|
||||
case $(uname) in
|
||||
NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin)
|
||||
LANG= date -r $DATE +"%a %b %d %T %Y"
|
||||
;;
|
||||
*)
|
||||
LANG= date +"%a %b %d %T %Y" -d @$DATE
|
||||
esac
|
||||
|
||||
12
util/fixup_jed.sh
Executable file
12
util/fixup_jed.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
PLD=$1
|
||||
JED=$2
|
||||
|
||||
DATE=$( util/date.sh $PLD )
|
||||
perl -pi -e "s/^Created.*/Created $DATE
/" $JED
|
||||
|
||||
CHECKSUM=$( LANG= util/jedcrc $JED| sed "s/Checksum: //" |tr -d "\r")
|
||||
perl -pi -e "s/\\003..../\\003$CHECKSUM/" $JED
|
||||
|
||||
echo "Fixed up $JED ($DATE, CHK=$CHECKSUM)"
|
||||
66
util/jedcrc.c
Normal file
66
util/jedcrc.c
Normal file
@ -0,0 +1,66 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define STX 0x02
|
||||
#define ETX 0x03
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
FILE* src = NULL;
|
||||
uint16_t sum = 0;
|
||||
int c;
|
||||
bool start = false;
|
||||
bool end = false;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"usage: %s PATH\n\n"
|
||||
"Calculate the checksum of the data in a JEDEC .jed file.\n"
|
||||
"If PATH is -, read from stdin instead.\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(argv[1]) == 1 && argv[1][0] == '-') {
|
||||
src = stdin;
|
||||
} else {
|
||||
src = fopen(argv[1], "rb");
|
||||
if (!src) {
|
||||
perror(argv[1]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
while (!((c = fgetc(src)) & ~0x7F)) {
|
||||
if (!start && c == STX) {
|
||||
start = true;
|
||||
}
|
||||
|
||||
if (start && !end) {
|
||||
sum += (uint16_t)c;
|
||||
}
|
||||
|
||||
if (!end && c == ETX) {
|
||||
end = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (src != stdin) {
|
||||
fclose(src);
|
||||
}
|
||||
|
||||
if (start && end) {
|
||||
printf("Checksum: %04hX\n", sum);
|
||||
} else if (!start) {
|
||||
fprintf(stderr, "No STX byte found\n");
|
||||
return 1;
|
||||
} else if (!end) {
|
||||
fprintf(stderr, "No ETX byte found\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user