forked from DVSwitch/md380tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile_orig
63 lines (49 loc) · 2.48 KB
/
Makefile_orig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# This Makefile grabs firmware from the web, then decompresses it.
# We used to download from VA3XPR, but since they started requiring
# a newsletter subscription to access newer files, we have migrated
# to using the Internet Archive.
# Previously, we used to check the MD5 hashes of each file, but this
# caused portability issues and we're not too concerned about VA3XPR
# messing with our firmware sources, so for now we just check filesize
# to identify accidental corruption. Anyone causing intentional
# corruption is politely asked to ensure that their joke is funny.
include ../curl.mak
DLDIR = dl
BINDIR = bin
UNWRAPDIR = unwrapped
DLFILES := $(addprefix $(DLDIR)/,$(shell grep -v '^\#' firmware_files.txt | awk '{print $$1}'))
BINARIES := $(addprefix $(BINDIR)/,$(patsubst %.zip,%.bin,$(notdir $(DLFILES))))
UNWRAPPEDFILES := $(addprefix $(UNWRAPDIR)/,$(patsubst %.bin,%.img,$(notdir $(BINARIES))))
FIRMWARE_FILENAME = $$(cat firmware_files.txt | grep "^$(notdir $@)" | cut -f1)
FIRMWARE_URL = $$(cat firmware_files.txt | grep "^$(notdir $@)" | cut -f2)
FIRMWARE_ZIPPATH = $$(cat firmware_files.txt | grep "^$(basename $(notdir $@))" | cut -f3)
FIRMWARE_FILESIZE = $$(cat firmware_files.txt | grep "^$(basename $(notdir $@))" | cut -f4)
FIRMWARE_SHA256 = $$(cat firmware_files.txt | grep "^$(basename $(notdir $@))" | cut -f5)
.PHONY: all binary unwrap clean
all: download binary unwrap
download: $(DLFILES)
binary: $(BINARIES)
unwrap: $(UNWRAPPEDFILES)
clean:
rm -rf $(BINDIR) $(UNWRAPDIR) $(DLDIR)
$(DLDIR):
mkdir -p $@
$(BINDIR):
mkdir -p $@
$(UNWRAPDIR):
mkdir -p $@
$(UNWRAPDIR)/%.img: $(BINDIR)/%.bin | $(UNWRAPDIR)
../md380-fw --unwrap $< $@
$(BINDIR)/%.bin: $(DLDIR)/%.zip | $(BINDIR)
unzip -p $< "$(FIRMWARE_ZIPPATH)" >$@
@test $$(find $@ -size $(FIRMWARE_FILESIZE)c) || (rm -f $@ && echo "$@: filesize mismatch" && false)
@test $$(shasum -a 256 $@ | awk '{print $$1}') "=" $(FIRMWARE_SHA256) || (rm -f $@ && echo "$@: SHA256 mismatch" && false)
$(BINDIR)/%.bin: $(DLDIR)/%.bin | $(BINDIR)
cp $< $@
@test $$(find $@ -size $(FIRMWARE_FILESIZE)c) || (rm -f $@ && echo "$@: filesize mismatch" && false)
@test $$(shasum -a 256 $@ | awk '{print $$1}') "=" $(FIRMWARE_SHA256) || (rm -f $@ && echo "$@: SHA256 mismatch" && false)
$(DLDIR)/%: | $(DLDIR)
@which curl >>/dev/null #Check that we have curl.
@-echo $(FIRMWARE_URL) \=\> $@
@curl $(CURL_FLAGS) $(FIRMWARE_URL) -o $@
@test $$(find $@ -size +0c) || (rm -f $@ && echo "FATAL ERROR: $@ downloaded as a zero byte file" && false)