Commit 9eab3b88 authored by Hugo Grostabussiat's avatar Hugo Grostabussiat
Browse files

Clean up Makefile

Prepare the Makefile for producing more than one image, and fix small
issues along the way.

- Rename 'IMAGE' to 'IMAGES', and generate COMPRESSED from IMAGES (the
  '.xz' suffix is appended to every filename in IMAGE).
- Fix the image being rebuilt every time even when no change occurred by
  making the '' prerequisite order-only.
- Make CHECKSUM depend on COMPRESSED so that the checksum file is
  updated if the images changed.
- Use variable STAMPFILE instead of repeating 'tmp/$(IMAGE).stamp'.
- Remove all .tmp file in the 'clean' target. This also eliminates a
  potentially dangerous 'rm -rf *'.
parent 6b76e241
# SPDX-License-Identifier: GPL-3.0+ # SPDX-License-Identifier: GPL-3.0+
BOARD=imx6 BOARD ?= imx6
TYPE=unstable TYPE ?= unstable
IMAGE=$(BOARD).img DIST ?= buster+ci
CHECKSUM=sha256sums STAMPFILE := tmp/$(BOARD).img.stamp
DIST=buster+ci IMAGES := $(BOARD).img
COMPRESSED := $(addsuffix .xz,$(IMAGES))
CHECKSUM := sha256sums
build-image \ build-image \ \ \
...@@ -18,24 +20,28 @@ SHELLCHECK_SCRIPTS=\ ...@@ -18,24 +20,28 @@ SHELLCHECK_SCRIPTS=\
build/ \ build/ \
.PHONY: all
$(IMAGE): tmp/$(IMAGE).stamp $(IMAGES): $(STAMPFILE)
tmp/$(IMAGE).stamp: $(DEPS)
# Use an order-only dependency to prevent rebuilding $(STAMPFILE) every time
# is out of date (it is always out of date because of .PHONY).
./build-image -b $(BOARD) -T $(TYPE) -d $(DIST) ./build-image -b $(BOARD) -T $(TYPE) -d $(DIST)
touch tmp/$(IMAGE).stamp touch $@
%.img.xz: %.img tmp/%.img.stamp %.img.xz: %.img
xz -T0 --stdout $< > $@.tmp xz -T0 --stdout $< > $@.tmp
mv $@.tmp $@ mv $@.tmp $@
sha256sum $(COMPRESSED) > $@.tmp sha256sum $(COMPRESSED) > $@.tmp
mv $@.tmp $@ mv $@.tmp $@
clean: clean:
rm -rf files/ tmp/ $(IMAGE) $(COMPRESSED) $(CHECKSUM)* rm -rf files/ tmp/ $(IMAGES) $(COMPRESSED) $(CHECKSUM) *.tmp
check: check:
shellcheck -x $(SHELLCHECK_SCRIPTS) shellcheck -x $(SHELLCHECK_SCRIPTS)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment