Blame SOURCES/Makefile

1e8b1a
VERSION := $(shell rpm --specfile *.spec --qf '%{VERSION}\n' | head -1)
1e8b1a
RELEASE := $(shell rpm --specfile *.spec --qf '%{RELEASE}\n' | head -1 | cut -d. -f1)
1bbbef
1e8b1a
NAME       := grafana-pcp
1e8b1a
RPM_NAME   := $(NAME)
1e8b1a
SOURCE_DIR := $(NAME)-$(VERSION)
1e8b1a
SOURCE_TAR := $(NAME)-$(VERSION).tar.gz
1e8b1a
VENDOR_TAR := $(RPM_NAME)-vendor-$(VERSION)-$(RELEASE).tar.xz
1e8b1a
WEBPACK_TAR := $(RPM_NAME)-webpack-$(VERSION)-$(RELEASE).tar.gz
db3ad6
1e8b1a
# patches which must be applied before creating the vendor tarball, for example:
1e8b1a
# - changes in dependency versions
1e8b1a
# - changes in Go module imports (which affect the vendored Go modules)
1e8b1a
PATCHES_PRE_VENDOR := \
1e8b1a
	001-remove-unused-frontend-crypto.patch
db3ad6
1e8b1a
# patches which must be applied before creating the webpack, for example:
1e8b1a
# - changes in Node.js sources or vendored dependencies
1e8b1a
PATCHES_PRE_WEBPACK := \
1e8b1a
	001-remove-unused-frontend-crypto.patch
1bbbef
1e8b1a
1e8b1a
all: $(SOURCE_TAR) $(VENDOR_TAR) $(WEBPACK_TAR)
1e8b1a
1e8b1a
$(SOURCE_TAR):
1e8b1a
	spectool -g $(RPM_NAME).spec
1e8b1a
1e8b1a
$(VENDOR_TAR): $(SOURCE_TAR)
1e8b1a
	# start with a clean state
1e8b1a
	rm -rf $(SOURCE_DIR)
1e8b1a
	tar xf $(SOURCE_TAR)
1e8b1a
1e8b1a
	# Patches to apply before vendoring
1e8b1a
	for patch in $(PATCHES_PRE_VENDOR); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
db3ad6
1bbbef
	# Go
1e8b1a
	cd $(SOURCE_DIR) && go mod vendor -v
1e8b1a
	awk '$$2~/^v/ && $$4 != "indirect" {print "Provides: bundled(golang(" $$1 ")) = " substr($$2, 2)}' $(SOURCE_DIR)/go.mod | \
1bbbef
		sed -E 's/=(.*)-(.*)-(.*)/=\1-\2.\3/g' > $@.manifest
1bbbef
1bbbef
	# Node.js
1e8b1a
	cd $(SOURCE_DIR) && yarn install --pure-lockfile
1bbbef
	# Remove files with licensing issues
1e8b1a
	find $(SOURCE_DIR) -type d -name 'node-notifier' -prune -exec rm -r {} \;
1e8b1a
	find $(SOURCE_DIR) -type f -name '*.exe' -delete
1bbbef
	# Remove not required packages
1e8b1a
	rm -r $(SOURCE_DIR)/node_modules/puppeteer
1e8b1a
	./list_bundled_nodejs_packages.py $(SOURCE_DIR) >> $@.manifest
1bbbef
1bbbef
	# Jsonnet
1e8b1a
	cd $(SOURCE_DIR) && jb --jsonnetpkg-home=vendor_jsonnet install
1bbbef
1bbbef
	# Create tarball
1e8b1a
	XZ_OPT=-9 time -p tar cJf $@ \
1e8b1a
		$(SOURCE_DIR)/vendor \
1e8b1a
		$(SOURCE_DIR)/node_modules \
1e8b1a
		$(SOURCE_DIR)/vendor_jsonnet
1e8b1a
1e8b1a
$(WEBPACK_TAR): $(VENDOR_TAR)
1e8b1a
	# start with a clean state
1e8b1a
	rm -rf $(SOURCE_DIR)
1e8b1a
	tar xf $(SOURCE_TAR)
1e8b1a
	tar xf $(VENDOR_TAR)
1e8b1a
1e8b1a
	# Patches to apply before creating the webpack
1e8b1a
	for patch in $(PATCHES_PRE_WEBPACK); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
1bbbef
1e8b1a
	cd $(SOURCE_DIR) && \
db3ad6
		../build_frontend.sh
1bbbef
1e8b1a
	tar cfz $@ $(SOURCE_DIR)/dist
1bbbef
1bbbef
clean:
1e8b1a
	rm -rf *.tar.gz *.tar.xz *.manifest *.rpm $(NAME)-*/