grafana/Makefile

102 lines
3.5 KiB
Makefile
Raw Normal View History

2021-09-30 12:16:39 +00:00
VERSION := $(shell rpm --specfile *.spec --qf '%{VERSION}\n' | head -1)
RELEASE := $(shell rpm --specfile *.spec --qf '%{RELEASE}\n' | head -1 | cut -d. -f1)
CHANGELOGTIME := $(shell rpm --specfile *.spec --qf '%{CHANGELOGTIME}\n' | head -1)
SOURCE_DATE_EPOCH := $(shell echo $$(( $(CHANGELOGTIME) - $(CHANGELOGTIME) % 86400 )))
NAME := grafana
RPM_NAME := $(NAME)
2021-09-30 12:16:39 +00:00
SOURCE_DIR := $(NAME)-$(VERSION)
SOURCE_TAR := $(NAME)-$(VERSION).tar.gz
VENDOR_TAR := $(RPM_NAME)-vendor-$(VERSION)-$(RELEASE).tar.xz
WEBPACK_TAR := $(RPM_NAME)-webpack-$(VERSION)-$(RELEASE).tar.gz
2021-05-20 14:57:43 +00:00
2021-10-08 14:53:45 +00:00
# patches which must be applied before creating the vendor tarball, for example:
# - changes in dependency versions
# - changes in Go module imports (which affect the vendored Go modules)
PATCHES_PRE_VENDOR := \
2022-07-06 10:57:30 +00:00
0004-remove-unused-backend-dependencies.patch \
0005-remove-unused-frontend-crypto.patch \
0007-disable-husky-git-hook.patch \
2021-10-08 14:53:45 +00:00
# patches which must be applied before creating the webpack, for example:
# - changes in Node.js sources or vendored dependencies
PATCHES_PRE_WEBPACK := \
2022-07-06 10:57:30 +00:00
0005-remove-unused-frontend-crypto.patch \
2021-10-08 14:53:45 +00:00
all: $(SOURCE_TAR) $(VENDOR_TAR) $(WEBPACK_TAR)
$(SOURCE_TAR):
spectool -g $(RPM_NAME).spec
$(VENDOR_TAR): $(SOURCE_TAR)
# Start with a clean state
2021-09-30 12:16:39 +00:00
rm -rf $(SOURCE_DIR)
tar pxf $(SOURCE_TAR)
2021-05-20 14:57:43 +00:00
2021-09-30 12:16:39 +00:00
# Patches to apply before vendoring
2021-10-08 14:53:45 +00:00
for patch in $(PATCHES_PRE_VENDOR); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
2020-07-30 15:52:28 +00:00
2020-11-25 17:55:36 +00:00
# Go
2021-09-30 12:16:39 +00:00
cd $(SOURCE_DIR) && go mod vendor -v
2022-06-22 17:13:29 +00:00
# Generate Go files
cd $(SOURCE_DIR) && make gen-go
# Remove unused crypto
2022-07-06 10:57:30 +00:00
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/bcrypt
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/blowfish
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/cast5
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/elgamal
rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/packet/ocfb.go
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/pkcs12/internal/rc2
2021-09-30 12:16:39 +00:00
awk '$$2~/^v/ && $$4 != "indirect" {print "Provides: bundled(golang(" $$1 ")) = " substr($$2, 2)}' $(SOURCE_DIR)/go.mod | \
2020-11-25 17:55:36 +00:00
sed -E 's/=(.*)-(.*)-(.*)/=\1-\2.\3/g' > $@.manifest
2020-11-25 17:55:36 +00:00
# Node.js
cd $(SOURCE_DIR) && yarn install --frozen-lockfile
# Remove files with licensing issues
2022-06-22 17:13:29 +00:00
find $(SOURCE_DIR)/.yarn -name 'node-notifier' -prune -exec rm -r {} \;
find $(SOURCE_DIR)/.yarn -name 'nodemon' -prune -exec rm -r {} \;
#rm -r $(SOURCE_DIR)/node_modules/visjs-network/examples
2021-09-30 12:16:39 +00:00
./list_bundled_nodejs_packages.py $(SOURCE_DIR) >> $@.manifest
2020-11-25 17:55:36 +00:00
# Create tarball
XZ_OPT=-9 tar \
--sort=name \
--mtime="@$(SOURCE_DATE_EPOCH)" --clamp-mtime \
--owner=0 --group=0 --numeric-owner \
-cJf $@ \
2021-09-30 12:16:39 +00:00
$(SOURCE_DIR)/vendor \
2022-06-22 17:13:29 +00:00
$$(find $(SOURCE_DIR) -type f -name "wire_gen.go" | LC_ALL=C sort) \
$(SOURCE_DIR)/.pnp.cjs \
$(SOURCE_DIR)/.yarn/cache \
$(SOURCE_DIR)/.yarn/unplugged
$(WEBPACK_TAR): $(VENDOR_TAR)
# Start with a clean state
2021-10-08 14:53:45 +00:00
rm -rf $(SOURCE_DIR)
tar pxf $(SOURCE_TAR)
tar pxf $(VENDOR_TAR)
2021-10-08 14:53:45 +00:00
# Patches to apply before creating the webpack
for patch in $(PATCHES_PRE_WEBPACK); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
# Build frontend
2021-09-30 12:16:39 +00:00
cd $(SOURCE_DIR) && \
2020-11-25 17:55:36 +00:00
../build_frontend.sh
2020-07-30 15:52:28 +00:00
# Create tarball
tar \
--sort=name \
--mtime="@$(SOURCE_DATE_EPOCH)" --clamp-mtime \
--owner=0 --group=0 --numeric-owner \
-czf $@ \
2022-06-22 17:13:29 +00:00
$(SOURCE_DIR)/plugins-bundled \
$(SOURCE_DIR)/public/build \
2022-06-22 17:13:29 +00:00
$(SOURCE_DIR)/public/img \
$(SOURCE_DIR)/public/lib \
2022-07-06 10:57:30 +00:00
$(SOURCE_DIR)/public/locales \
2022-06-22 17:13:29 +00:00
$(SOURCE_DIR)/public/views
2020-07-30 15:52:28 +00:00
clean:
rm -rf *.tar.gz *.tar.xz *.manifest *.rpm $(NAME)-*/