Blob Blame History Raw
# Makefile for constructing RPMs.

SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
NAME = cephadm
DIST ?= el8
BASE := "https://github.com/ceph/ceph"
BRANCH := "octopus"
VERSION ?= $(shell cat SPECS/cephadm.spec.in | awk '/Version/ { print $$2}')
LOCALHASH := $(shell cat SPECS/cephadm.spec.in | awk '/Source0/ { print $$2}' | cut -d'/' -f7)
RELEASE ?= $(shell cat SPECS/cephadm.spec.in | awk '/Release/ {print $$2}' | cut -d'%' -f1)
SPECTOOL :=$(shell which spectool)
RPMBUILD :=$(shell which rpmbuild)

NVR := $(NAME)-$(VERSION)-$(RELEASE).$(DIST)

all: spec src srpm

pre: ## Get the last remote hash for the specified branch
	$(eval REMOTEHASH := $(shell git ls-remote $(BASE) $(BRANCH) | awk '{print $$1}'))

echo: pre  ## Print the passed (or computed) parameters
	@echo PWD $(PWD)/SOURCES
	@echo BASE $(BASE)
	@echo BRANCH $(BRANCH)
	@echo CURRENT VERSION $(VERSION)
	@echo REMOTE HASH $(REMOTEHASH)
	@echo LOCAL HASH $(LOCALHASH)
	$(eval RELEASE=$(shell echo $$(($(RELEASE)+1))))
	@echo RELEASE $(RELEASE)

spec: pre  ## Patch and build the cephadm spec file
	sed SPECS/cephadm.spec.in \
	  -e "s/$(LOCALHASH)/$(REMOTEHASH)/" \
	  -e 's/@VERSION@/$(VERSION)/' \
	  -e 's/@RELEASE@/$(RELEASE)/' \
	 > SPECS/cephadm.spec
	cp SPECS/cephadm.spec SPECS/cephadm.spec.in

src: 	## Download the cephadm sources according to the last hash
	$(SPECTOOL) -g SPECS/cephadm.spec -C SOURCES -f

srpm:	## Build the srpm
	rpmbuild -bs $(PWD)/SPECS/cephadm.spec \
	  --define "_sourcedir $(PWD)/SOURCES" \
	  --define "_srcrpmdir $(PWD)" \
	  --define "dist .$(DIST)"

clean:  ## Clean the workdir
	rm -f $(NVR).src.rpm
	rm -f SPECS/cephadm.spec

help:	## Print the Help
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile  | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: all