Blame SOURCES/Makefile

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