Blame Makefile

23b01e
# Makefile for constructing RPMs.
23b01e
23b01e
SHELL := bash
23b01e
.SHELLFLAGS := -eu -o pipefail -c
23b01e
NAME = cephadm
23b01e
DIST ?= el8
23b01e
BASE := "https://github.com/ceph/ceph"
23b01e
BRANCH := $(shell git rev-parse --abbrev-ref HEAD | cut -d'-' -f5)
23b01e
LAST_VERSION ?= $(shell cat SPECS/cephadm.spec.in | awk '/Version/ { print $$2}')
23b01e
LAST_RELEASE ?= $(shell cat SPECS/cephadm.spec.in | awk '/Release/ {print $$2}' | cut -d'%' -f1)
23b01e
LOCALHASH := $(shell cat SPECS/cephadm.spec.in | awk '/Source0/ { print $$2}' | cut -d'/' -f7)
23b01e
SPECTOOL :=$(shell which spectool)
23b01e
RPMBUILD :=$(shell which rpmbuild)
23b01e
RELEASE := $(if $(RELEASE),$(RELEASE),$(LAST_RELEASE))
23b01e
VERSION := $(if $(VERSION),$(VERSION),$(LAST_VERSION))
23b01e
23b01e
23b01e
all: spec src srpm
23b01e
23b01e
pre: ## Get the last remote hash for the specified branch
23b01e
	$(eval REMOTEHASH := $(shell git ls-remote $(BASE) $(BRANCH) | awk '{print $$1}'))
23b01e
	$(eval RELEASE=$(shell echo $$(($(RELEASE)+1))))
8d8c85
	$(eval NVR=$(shell echo $(NAME)-$(VERSION)-$(RELEASE).$(DIST)))
23b01e
23b01e
echo: pre  ## Print the passed (or computed) parameters
23b01e
	@echo PWD $(PWD)/SOURCES
23b01e
	@echo BASE $(BASE)
23b01e
	@echo BRANCH $(BRANCH)
23b01e
	@echo CURRENT VERSION $(LAST_VERSION)
23b01e
	@echo NEXT VERSION $(VERSION)
23b01e
	@echo REMOTE HASH $(REMOTEHASH)
23b01e
	@echo LOCAL HASH $(LOCALHASH)
23b01e
	@echo RELEASE $(RELEASE)
23b01e
6f0600
patch: pre ## Build the latest patch
6f0600
	 git diff $(PWD)/SOURCES/cephadm > $(PWD)/SOURCES/cephadm-$(VERSION)-$(RELEASE).patch
6f0600
23b01e
spec: pre  ## Patch and build the cephadm spec file
23b01e
	sed SPECS/cephadm.spec.in \
23b01e
	  -e "s/$(LOCALHASH)/$(REMOTEHASH)/" \
23b01e
	  -e 's/Version: $(LAST_VERSION)/Version: $(VERSION)/' \
23b01e
	  -e 's/Release: $(LAST_RELEASE)/Release: $(RELEASE)/' \
23b01e
	 > SPECS/cephadm.spec
23b01e
	cp SPECS/cephadm.spec SPECS/cephadm.spec.in
23b01e
23b01e
src: 	## Download the cephadm sources according to the last hash
23b01e
	$(SPECTOOL) -g SPECS/cephadm.spec -C SOURCES -f
23b01e
23b01e
srpm:	## Build the srpm
23b01e
	$(RPMBUILD) -bs $(PWD)/SPECS/cephadm.spec \
23b01e
	  --define "_sourcedir $(PWD)/SOURCES" \
23b01e
	  --define "_srcrpmdir $(PWD)" \
23b01e
	  --define "dist .$(DIST)"
8d8c85
	mv $(NVR).src.rpm $(PWD)/SRPMS/
23b01e
23b01e
clean:  ## Clean the workdir
23b01e
	rm -f *.src.rpm
8d8c85
	rm -f SRPMS/*.src.rpm
23b01e
	rm -f SPECS/cephadm.spec
23b01e
23b01e
help:	## Print the Help
23b01e
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile  | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
23b01e
23b01e
.PHONY: all