Blame SOURCES/Makefile

6ad68d
VERSION := $(shell rpm --specfile *.spec --qf '%{VERSION}\n' | head -1)
6ad68d
RELEASE := $(shell rpm --specfile *.spec --qf '%{RELEASE}\n' | head -1 | cut -d. -f1)
28ad2d
897738
NAME       := grafana
897738
RPM_NAME   := $(NAME)
6ad68d
SOURCE_DIR := $(NAME)-$(VERSION)
6ad68d
SOURCE_TAR := $(NAME)-$(VERSION).tar.gz
6ad68d
VENDOR_TAR := $(RPM_NAME)-vendor-$(VERSION)-$(RELEASE).tar.xz
6ad68d
WEBPACK_TAR := $(RPM_NAME)-webpack-$(VERSION)-$(RELEASE).tar.gz
6ad68d
6ad68d
# patches which must be applied before creating the vendor tarball, for example:
6ad68d
# - changes in dependency versions
6ad68d
# - changes in Go module imports (which affect the vendored Go modules)
6ad68d
PATCHES_PRE_VENDOR := \
6ad68d
	005-remove-unused-dependencies.patch \
6ad68d
	008-remove-unused-frontend-crypto.patch
6ad68d
6ad68d
# patches which must be applied before creating the webpack, for example:
6ad68d
# - changes in Node.js sources or vendored dependencies
6ad68d
PATCHES_PRE_WEBPACK :=
897738
897738
897738
all: $(SOURCE_TAR) $(VENDOR_TAR) $(WEBPACK_TAR)
897738
897738
$(SOURCE_TAR):
897738
	spectool -g $(RPM_NAME).spec
897738
897738
$(VENDOR_TAR): $(SOURCE_TAR)
6ad68d
	# start with a clean state
6ad68d
	rm -rf $(SOURCE_DIR)
6ad68d
	tar xf $(SOURCE_TAR)
28ad2d
6ad68d
	# Patches to apply before vendoring
6ad68d
	for patch in $(PATCHES_PRE_VENDOR); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
897738
28ad2d
	# Go
6ad68d
	cd $(SOURCE_DIR) && go mod vendor -v
897738
	# Remove unused crypto
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/cast5/cast5.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/ed25519/ed25519.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/const.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/edwards25519.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/elgamal/elgamal.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/packet/ocfb.go
6ad68d
	awk '$$2~/^v/ && $$4 != "indirect" {print "Provides: bundled(golang(" $$1 ")) = " substr($$2, 2)}' $(SOURCE_DIR)/go.mod | \
28ad2d
		sed -E 's/=(.*)-(.*)-(.*)/=\1-\2.\3/g' > $@.manifest
28ad2d
28ad2d
	# Node.js
6ad68d
	cd $(SOURCE_DIR) && yarn install --pure-lockfile
28ad2d
	# Remove files with licensing issues
6ad68d
	find $(SOURCE_DIR) -type d -name 'node-notifier' -prune -exec rm -r {} \;
6ad68d
	find $(SOURCE_DIR) -type d -name 'property-information' -prune -exec rm -r {} \;
6ad68d
	find $(SOURCE_DIR) -type f -name '*.exe' -delete
6ad68d
	rm -r $(SOURCE_DIR)/node_modules/visjs-network/examples
6ad68d
	./list_bundled_nodejs_packages.py $(SOURCE_DIR) >> $@.manifest
28ad2d
28ad2d
	# Create tarball
6ad68d
	XZ_OPT=-9 time -p tar cJf $@ \
6ad68d
		$(SOURCE_DIR)/vendor \
6ad68d
		$$(find $(SOURCE_DIR) -type d -name "node_modules" -prune)
28ad2d
897738
$(WEBPACK_TAR): $(VENDOR_TAR)
6ad68d
	# start with a clean state
6ad68d
	rm -rf $(SOURCE_DIR)
6ad68d
	tar xf $(SOURCE_TAR)
6ad68d
	tar xf $(VENDOR_TAR)
6ad68d
6ad68d
	# Patches to apply before creating the webpack
6ad68d
	for patch in $(PATCHES_PRE_WEBPACK); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
6ad68d
6ad68d
	cd $(SOURCE_DIR) && \
28ad2d
		../build_frontend.sh
28ad2d
6ad68d
	tar cfz $@ $(SOURCE_DIR)/public/build $(SOURCE_DIR)/public/views $(SOURCE_DIR)/plugins-bundled
28ad2d
28ad2d
clean:
897738
	rm -rf *.tar.gz *.tar.xz *.manifest *.rpm $(NAME)-*/