diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2009-01-25 05:52:05 +0100 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2009-01-25 05:52:05 +0100 |
commit | dfadebb69134c80b78504bbf39998e462f5ca055 (patch) | |
tree | 2e325ce5398461f09eed44b5f229fa482b16e13b | |
download | git-rpm-dfadebb69134c80b78504bbf39998e462f5ca055.tar.gz git-rpm-dfadebb69134c80b78504bbf39998e462f5ca055.tar.xz git-rpm-dfadebb69134c80b78504bbf39998e462f5ca055.zip |
Initial commit
-rw-r--r-- | git-rpm.mk | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/git-rpm.mk b/git-rpm.mk new file mode 100644 index 0000000..4356ad1 --- /dev/null +++ b/git-rpm.mk @@ -0,0 +1,216 @@ +# How to use this file: +# 0. run "git init" +# 1. copy this file as git-rpm.mk +# 2. create GNUmakefile with contents like +# NAME = mypkg +# include git-rpm.mk +# 3. write mypkg.spec, and fill in at least the Summary: line +# 4. run "make setup" to created the upload directory to the server +# 5. write mypkg.spec, patches, Source: files, etc. +# 6. run "make" for a test build of the rpm files +# 7. if you do not like the result, go to 5 +# 8. make sure NVR and %changelog are updated +# 9. Make sure you have "git commit"ed all your changes before +# 10. run "make tag" tag the current release +# 11. run "make upload" to upload the built rpm files to the server +# +# Settings best defined in ~/.git-rpm-settings.mk, but with potentially +# useful defaults: +# 1. RSYNC_USER and RSYNC_HOST or RSYNC_USHO +# 2. RSYNC_ROOT +# +# The path setups etc. work for fedorapeople.org accounts. Other systems +# will probably need adaptation. +# +# Benefits: +# 1. Reproducible local rpm builds: +# $ make +# 2. Automatic generation of text reports (rpmlint, rpm content list): +# $ make check +# 3. Easy versioning of NVRs using git tags +# $ make tag +# 4. Easy upload via rsync/ssh to NVR specific places on a web server, +# and to a git repository (nice for package review) +# $ make upload + +RPMDIRS = rpm-build rpm-dist +UPLOAD_FILES = + +OPTS = +OPTS += --define "_sourcedir $${PWD}" +OPTS += --define "_builddir $${PWD}/rpm-build" +OPTS += --define "_srcrpmdir $${PWD}/rpm-dist" --define "_rpmdir $${PWD}/rpm-dist" + +NAME ?= packagename-to-be-defined + +SPEC = $(NAME).spec + +RPM_SUMMARY = $(shell rpm -q --specfile $(SPEC) --queryformat '[%{SUMMARY}\n]' | sed '1q') +RPM_URL = $(shell rpm -q --specfile $(SPEC) --queryformat '[%{URL}\n]' | sed '1q') + +RPM_VERSION := $(shell rpm -q --specfile $(SPEC) --queryformat '[%{VERSION}\n]' | sed '1q') +RPM_RELEASE := $(shell rpm -q --specfile $(SPEC) --queryformat '[%{RELEASE}\n]' | sed '1q') +RPM_ARCH := $(shell rpm -q --specfile $(SPEC) --queryformat '[%{ARCH}\n]' | sed '1q') + +NVR = $(NAME)-$(RPM_VERSION)-$(RPM_RELEASE) + +SRPM = rpm-dist/$(NVR).src.rpm +BRPM = rpm-dist/$(RPM_ARCH)/$(NVR).$(RPM_ARCH).rpm + +-include $(HOME)/.git-rpm-settings.mk +RSYNC_USER ?= $(USER) +RSYNC_HOST ?= fedorapeople.org +RSYNC_USHO ?= $(RSYNC_USER)@$(RSYNC_HOST) +RSYNC_ROOT ?= public_html/packages +RSYNC_DIR = $(RSYNC_ROOT)/$(NAME)/$(RPM_VERSION)-$(RPM_RELEASE) + +SOURCE_FILES = $(shell spectool --lf $(SPEC) | cut -d' ' -f2 | xargs -l basename) + +.PHONY: all +all: build +build: rpm check + +.PHONY: sources +sources: + spectool -g $(SPEC) + +.PHONY: srpm +srpm: $(SRPM) + +clog: $(SPEC) + rpm -q --specfile $(SPEC) --changelog | sed '1n; /^\*/,$$d' > $@ + cat $@ + +UPLOAD_FILES += $(NVR)/$(NVR).src.rpm +$(SRPM): $(SPEC) $(SOURCE_FILES) + mkdir -p $(RPMDIRS) + rpmbuild $(OPTS) -bs $(SPEC) +$(NVR)/$(NVR).src.rpm: $(SRPM) + mkdir -p $(NVR) + cp -p $< $@ + +.PHONY: rpm +rpm: $(BRPM) + +UPLOAD_FILES += $(NVR)/build.log +$(BRPM) rpm-build/$(NVR).buildlog: $(SPEC) $(SOURCE_FILES) + mkdir -p $(RPMDIRS) + rpmbuild $(OPTS) -ba $(SPEC) 2>&1 | tee rpm-build/$(NVR).buildlog + +$(NVR)/build.log: rpm-build/$(NVR).buildlog + mkdir -p $(NVR) + sed "s|$(USER)|build|g" < $< > $@ + +.PHONY: check +check: $(NVR)/rpmlint.txt $(NVR)/filelist.txt + +UPLOAD_FILES += $(NVR)/rpmlint.txt +$(NVR)/rpmlint.txt: $(BRPM) + mkdir -p $(NVR) + rpmlint -i $(SPEC) $(SRPM) $(BRPM) 2>&1 | tee $@ + +UPLOAD_FILES += $(NVR)/filelist.txt +$(NVR)/filelist.txt: rpm-build/$(NVR).buildlog + mkdir -p $(NVR) + for pkg in rpm-dist/$(NVR).src.rpm rpm-dist/$(RPM_ARCH)/$(NAME)*-$(RPM_VERSION)-$(RPM_RELEASE).$(RPM_ARCH).rpm; do \ + echo "## $$(basename "$$pkg")"; \ + rpm -qpl --scripts "$$pkg"; \ + echo; \ + done > $@.new + cp $@.new $@ && rm -f $@.new + +REPODIR = $(NAME)-package.git +.PHONY: setup +setup: + ssh $(RSYNC_USHO) mkdir -p $(RSYNC_ROOT)/$(NAME) public_git + ssh $(RSYNC_USHO) "test -d public_git/$(REPODIR) || env GIT_DIR=public_git/$(REPODIR) git --bare init" + ssh $(RSYNC_USHO) "echo 'git://fedorapeople.org/~$(RSYNC_USER)/$(REPODIR)' > public_git/$(REPODIR)/cloneurl" + ssh $(RSYNC_USHO) "touch public_git/$(REPODIR)/git-daemon-export-ok" + ssh $(RSYNC_USHO) "echo 'RPM package for $(NAME): $(RPM_SUMMARY)' > public_git/$(REPODIR)/description" + ssh $(RSYNC_USHO) "echo '<p>RPM package for <a href=\"$(RPM_URL)\">$(NAME)</a>: $(RPM_SUMMARY)</p><p>See also the finished <a href=\"http://$(RSYNC_USER).$(RSYNC_HOST)/packages/$(NAME)/\">$(NAME) rpm packages</a>.</p>' > public_git/$(REPODIR)/README.html" + ssh $(RSYNC_USHO) "echo '<p>RPM package for <a href=\"$(RPM_URL)\">$(NAME)</a>: $(RPM_SUMMARY)</p><p>See also the <a href=\"http://$(RSYNC_HOST)/gitweb?p=$(RSYNC_USER)/public_git/$(REPODIR);a=summary\">$(NAME) rpm package git repository</a>.</p>' > $(RSYNC_ROOT)/$(NAME)/99README.html" + +STUFF_TO_PUSH = +STUFF_TO_PUSH += refs/heads/master:refs/heads/master +STUFF_TO_PUSH += refs/tags/$(NVR):refs/tags/$(NVR) +.PHONY: push +push: + git push "ssh://$(RSYNC_USER)@$(RSYNC_HOST)/~/public_git/$(REPODIR)" $(STUFF_TO_PUSH) + +.PHONY: upload +upload: $(NVR) tag push + +UPLOAD_FILES += $(NVR)/$(SPEC) +$(NVR)/$(SPEC): $(SPEC) + mkdir -p $(NVR) + cp -p $< $@ + +UPLOAD_FILES += $(foreach p, $(SOURCE_FILES), $(NVR)/$(p)) +$(NVR)/%: % + mkdir -p $(NVR) + cp -p $< $@ + +$(NVR): $(UPLOAD_FILES) + mkdir -p $(NVR) + rsync -avz --delete $(NVR)/ $(RSYNC_USHO):$(RSYNC_DIR)/ + touch $@ + +.PHONY: clean +clean: + rm -rf $(RPMDIRS) + +.PHONY: tag +tag: clog + @echo "List of git tags:"; git tag -n20 -l '$(NAME)*' + if tag_sha=`git rev-list tags/$(NVR) | sed 1q` && test -n "$$tag_sha"; then \ + head_sha=`git rev-list HEAD | sed 1q`; \ + if test "x$$tag_sha" = "x$$head_sha"; then \ + echo "Tag $(NVR) already exists and equal to HEAD."; \ + else \ + echo "Error: Tag $(NVR) already exists but not equal to HEAD."; \ + exit 13; \ + fi; \ + else \ + echo "Really add git tag $(NVR)? Ctrl-C to abort, Enter to continue"; \ + read; \ + echo git tag -a -F clog $(NVR); \ + git tag -a -F clog $(NVR); \ + fi + +WORKDIR ?= $(PWD) +MOCKDIR ?= $(WORKDIR) +MOCKCFG ?= fedora-$(shell echo $(RPM_RELEASE) | sed -n 's/.*\.fc\([1-9][0-9]*\)$$/\1/p')-$(RPM_ARCH) +MOCKRESULTDIR ?= $(MOCKDIR)/$(NVR).mock + +SCRATCHBUILD_KOJI_TAG = dist-f10 + +.PHONY: scratch-build +scratch-build: $(SRPM) + /usr/bin/koji build --scratch $(SCRATCHBUILD_KOJI_TAG) $(SRPM) + +.PHONY: mock-build +mock-build: $(MOCKRESULTDIR) + +$(MOCKRESULTDIR): $(SRPM) + mock $(MOCKARGS) -r $(MOCKCFG) --resultdir=$(MOCKRESULTDIR) rebuild $(SRPM) + +.PHONY: help +help: + @echo "NVR: $(NVR)" + @echo "Summary: $(RPM_SUMMARY)" + @echo "Mock config: $(MOCKCFG)" + @echo "Mock result dir: $(MOCKRESULTDIR)" + @echo "Source RPM: $(SRPM)" + @echo "Targets:" + @echo " build build the RPM package(s) locally" + @echo " scratch-build build scratch RPM via Fedora's koji" + @echo " mock-build build RPM in local mock chroot" + @echo " sources download all source files" + @echo " srpm build SRPM package locally" + +# Package specific rules, best put into package specific GNUmakefile + +#$(NAME)-$(RPM_VERSION)-buildfixes.patch: $(wildcard $(NAME)-$(RPM_VERSION)/* $(NAME)-$(RPM_VERSION)-buildfixes/*) +# diff -ru $(NAME)-$(RPM_VERSION) $(NAME)-$(RPM_VERSION)-buildfixes > $@;: + +# End of file. |