Blame SOURCES/Makefile

456ad1
VERSION := $(shell rpm --specfile *.spec --qf '%{VERSION}\n' | head -1)
456ad1
RELEASE := $(shell rpm --specfile *.spec --qf '%{RELEASE}\n' | head -1 | cut -d. -f1)
f6686b
CHANGELOGTIME := $(shell rpm --specfile *.spec --qf '%{CHANGELOGTIME}\n' | head -1)
f6686b
SOURCE_DATE_EPOCH := $(shell echo $$(( $(CHANGELOGTIME) - $(CHANGELOGTIME) % 86400 )))
bae306
4bd38e
NAME       := grafana
4bd38e
RPM_NAME   := $(NAME)
456ad1
SOURCE_DIR := $(NAME)-$(VERSION)
456ad1
SOURCE_TAR := $(NAME)-$(VERSION).tar.gz
456ad1
VENDOR_TAR := $(RPM_NAME)-vendor-$(VERSION)-$(RELEASE).tar.xz
456ad1
WEBPACK_TAR := $(RPM_NAME)-webpack-$(VERSION)-$(RELEASE).tar.gz
456ad1
456ad1
# patches which must be applied before creating the vendor tarball, for example:
456ad1
# - changes in dependency versions
456ad1
# - changes in Go module imports (which affect the vendored Go modules)
456ad1
PATCHES_PRE_VENDOR := \
456ad1
	005-remove-unused-dependencies.patch \
f6686b
	008-remove-unused-frontend-crypto.patch \
f6686b
	012-support-go1.18.patch \
f6686b
	013-CVE-2021-23648.patch \
f6686b
	014-CVE-2022-21698.patch
456ad1
456ad1
# patches which must be applied before creating the webpack, for example:
456ad1
# - changes in Node.js sources or vendored dependencies
f6686b
PATCHES_PRE_WEBPACK := \
f6686b
	008-remove-unused-frontend-crypto.patch
4bd38e
4bd38e
4bd38e
all: $(SOURCE_TAR) $(VENDOR_TAR) $(WEBPACK_TAR)
4bd38e
4bd38e
$(SOURCE_TAR):
4bd38e
	spectool -g $(RPM_NAME).spec
4bd38e
4bd38e
$(VENDOR_TAR): $(SOURCE_TAR)
f6686b
	# Start with a clean state
456ad1
	rm -rf $(SOURCE_DIR)
f6686b
	tar pxf $(SOURCE_TAR)
bae306
456ad1
	# Patches to apply before vendoring
456ad1
	for patch in $(PATCHES_PRE_VENDOR); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
4bd38e
bae306
	# Go
456ad1
	cd $(SOURCE_DIR) && go mod vendor -v
4bd38e
	# Remove unused crypto
456ad1
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/cast5/cast5.go
456ad1
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/ed25519/ed25519.go
456ad1
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/const.go
456ad1
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/edwards25519.go
456ad1
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/elgamal/elgamal.go
456ad1
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/packet/ocfb.go
456ad1
	awk '$$2~/^v/ && $$4 != "indirect" {print "Provides: bundled(golang(" $$1 ")) = " substr($$2, 2)}' $(SOURCE_DIR)/go.mod | \
bae306
		sed -E 's/=(.*)-(.*)-(.*)/=\1-\2.\3/g' > $@.manifest
bae306
bae306
	# Node.js
f6686b
	cd $(SOURCE_DIR) && yarn install --frozen-lockfile
bae306
	# Remove files with licensing issues
456ad1
	find $(SOURCE_DIR) -type d -name 'node-notifier' -prune -exec rm -r {} \;
456ad1
	find $(SOURCE_DIR) -type d -name 'property-information' -prune -exec rm -r {} \;
456ad1
	find $(SOURCE_DIR) -type f -name '*.exe' -delete
456ad1
	rm -r $(SOURCE_DIR)/node_modules/visjs-network/examples
456ad1
	./list_bundled_nodejs_packages.py $(SOURCE_DIR) >> $@.manifest
bae306
bae306
	# Create tarball
f6686b
	XZ_OPT=-9 tar \
f6686b
		--sort=name \
f6686b
		--mtime="@$(SOURCE_DATE_EPOCH)" --clamp-mtime \
f6686b
		--owner=0 --group=0 --numeric-owner \
f6686b
		-cJf $@ \
456ad1
		$(SOURCE_DIR)/vendor \
f6686b
		$$(find $(SOURCE_DIR) -type d -name "node_modules" -prune | LC_ALL=C sort)
bae306
4bd38e
$(WEBPACK_TAR): $(VENDOR_TAR)
f6686b
	# Start with a clean state
456ad1
	rm -rf $(SOURCE_DIR)
f6686b
	tar pxf $(SOURCE_TAR)
f6686b
	tar pxf $(VENDOR_TAR)
456ad1
456ad1
	# Patches to apply before creating the webpack
456ad1
	for patch in $(PATCHES_PRE_WEBPACK); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
456ad1
f6686b
	# Build frontend
456ad1
	cd $(SOURCE_DIR) && \
bae306
		../build_frontend.sh
bae306
f6686b
	# Create tarball
f6686b
	tar \
f6686b
		--sort=name \
f6686b
		--mtime="@$(SOURCE_DATE_EPOCH)" --clamp-mtime \
f6686b
		--owner=0 --group=0 --numeric-owner \
f6686b
		-czf $@ \
f6686b
		$(SOURCE_DIR)/public/build \
f6686b
		$(SOURCE_DIR)/public/views \
f6686b
		$(SOURCE_DIR)/plugins-bundled
bae306
bae306
clean:
4bd38e
	rm -rf *.tar.gz *.tar.xz *.manifest *.rpm $(NAME)-*/