summaryrefslogtreecommitdiffstats
path: root/Makefile.repo-git
blob: 949ffa04c5538e291750e0254dada8211ce04dca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# -*- Makefile -*-
#
# Common Makefile for building RPMs
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
# Copyright (C) 2004-2005 Red Hat, Inc.
# Copyright (C) 2005 Fedora Foundation
#
# $Id: Makefile.common,v 1.105 2008/07/03 19:15:27 notting Exp $

# Branch and disttag definitions
# These need to happen first.
ifndef HEAD_BRANCH
HEAD_BRANCH := fedora-devel
endif
# While we use BRANCH for looking up our build target in common/branches, we
# use GIT_BRANCH for passing to koji as our specific branch we are building
# from and it must match our working branch, so no futzing around with it
# like they did with BRANCH
BRANCH:=$(shell git branch | awk '/^\* /{ print $$2 }' )
GIT_BRANCH:=$(shell git branch | awk '/^\* /{ print $$2 }' )
# check to see if this is an early branched package; we should make this more
# generic in the future
# Eh?  It wasn't clear to me what this did when I converted it from cvs to git,
# but the best I could figure out was that if the previous release branch
# didn't exist, then devel stayed devel, but if it did exist, then devel
# meant previous branch + 1
ifeq ($(BRANCH),fedora-devel)
BRANCH:=$(shell tmpbranch=`git branch | grep 'f[[:digit:]]\+' | cut -f 2 -d 'f' | sort -n | tail -1`; [ -z "$$tmpbranch" ] && echo "fedora-devel" || echo f$$(($$tmpbranch + 1)))
endif
BRANCHINFO = $(shell grep ^$(BRANCH): $(COMMON_DIR)/branches | cut -d: --output-delimiter=" " -f2-)
TARGET := $(word 1, $(BRANCHINFO))
DIST = $(word 2, $(BRANCHINFO))
DISTVAR = $(word 3, $(BRANCHINFO))
DISTVAL = $(word 4, $(BRANCHINFO))
DIST_DEFINES = --define "dist $(DIST)" --define "$(DISTVAR) $(DISTVAL)"

BUILD_FLAGS ?= $(KOJI_FLAGS)

## a base directory where we'll put as much temporary working stuff as we can
ifndef WORKDIR
WORKDIR := $(shell pwd)
endif
## of course all this can also be overridden in your RPM macros file,
## but this way you can separate your normal RPM setup from your repo
## setup. Override RPM_WITH_DIRS in ~/.fedora-repo-rc to avoid the usage of
## these variables.
SRCRPMDIR ?= $(WORKDIR)/distropkg/rpm/SRPMS
BUILDDIR ?= $(WORKDIR)/distropkg/rpm/BUILD
REPODIR ?= $(shell dirname `pwd`)
RPMDIR ?= $(WORKDIR)/distropkg/rpm/RPMS
MOCKDIR ?= $(WORKDIR)/distropkg/rpm/MOCK
ifeq ($(DISTVAR),epel)
DISTVAR := rhel
MOCKCFG ?= fedora-$(DISTVAL)-$(BUILDARCH)-epel
else
MOCKCFG ?= fedora-$(DISTVAL)-$(BUILDARCH)
## Devel builds use -devel mock config
ifeq ($(BRANCH),devel)
MOCKCFG = fedora-devel-$(BUILDARCH)
endif
endif

## SOURCEDIR is special in a dist layout, in an exploded repo layout it should
## be rarely, if ever, used.  However, for the purposes of creating srpms from
## exploded source repos by outputing commits as patches, this is where we
## want all that stuff to go.
ifndef SOURCEDIR
SOURCEDIR := $(shell pwd)/distropkg/rpm/SOURCES
endif
ifndef SPECDIR
SPECDIR := $(shell pwd)/distropkg
endif

ifndef SRPM_RPM_DEFINES
SRPM_RPM_DEFINES = --define "_sourcedir $(SOURCEDIR)" \
		--define "_specdir $(SPECDIR)" \
		--define "_builddir $(BUILDDIR)" \
		--define "_srcrpmdir $(SRCRPMDIR)" \
		--define "_rpmdir $(RPMDIR)" \
                $(DIST_DEFINES)
endif
ifndef REPO_RPM_DEFINES
REPO_RPM_DEFINES = --define "_sourcedir $(SPECDIR)" \
		--define "_specdir $(SPECDIR)" \
		--define "_builddir $(REPODIR)" \
		--define "_srcrpmdir $(SRCRPMDIR)" \
		--define "_rpmdir $(RPMDIR)" \
		$(DIST_DEFINES)
endif

# Initialize the variables that we need, but are not defined
# the version of the package
ifndef NAME
$(error "You can not run this Makefile without having NAME defined")
endif
ifndef VERSION
VERSION := $(shell rpm $(RPM_DEFINES) $(DIST_DEFINES) -q --qf "%{VERSION}\n" --specfile $(SPECFILE)| head -1)
endif
# the release of the package
ifndef RELEASE
RELEASE := $(shell rpm $(RPM_DEFINES) $(DIST_DEFINES) -q --qf "%{RELEASE}\n" --specfile $(SPECFILE)| head -1)
endif
NVR := $(NAME)-$(VERSION)-$(RELEASE)

## for secondary arch only packages we cant build on the primary hub
## we need to go direct to the secondary arch hub
define secondary-arch 
for name in silo prtconf lssbus afbinit xorg-x11-drv-sunbw2 xorg-x11-drv-suncg14 xorg-x11-drv-suncg3 xorg-x11-drv-suncg6 xorg-x11-drv-sunffb xorg-x11-drv-sunleo xorg-x11-drv-suntcx ; \
do if [ "$$name" = "$(NAME)" ]; then echo "-c ~/.koji/sparc-config"; fi \
done 
endef
# if we have defineded SECONDARY_CONFIG trust the user is doing it for a reason
ifndef SECONDARY_CONFIG
SECONDARY_CONFIG := $(shell $(secondary-arch))
endif

# user specific configuration
FEDORA_REPO_RC	:= $(shell if test -f $(HOME)/.fedora-repo-rc ; then echo $(HOME)/.fedora-repo-rc ; fi)
ifdef FEDORA_REPO_RC
include $(FEDORA_REPO_RC)
endif

# The repository and the clients we use for the files
REPOSITORY ?= $(shell rpm $(RPM_DEFINES) $(DIST_DEFINES) -q --qf "%{SCMType}+%{SCMURL}?%{SCMModule}\n" --specfile $(SPECFILE)| head -1)

BUILD_CLIENT ?= $(shell which koji 2>/dev/null)
BODHI_CLIENT ?= $(shell which bodhi 2>/dev/null)

# RPM with all the overrides in place; you can override this in your
# .cvspkgsrc also, to use a default rpm setup
# the rpm build command line
ifndef RPM
RPM := rpmbuild
endif
ifndef RPM_WITH_REPO_DIRS
RPM_WITH_REPO_DIRS = $(RPM) $(REPO_RPM_DEFINES)
endif
ifndef RPM_WITH_SRPM_DIRS
RPM_WITH_SRPM_DIRS = $(RPM) $(SRPM_RPM_DEFINES)
endif

# tag to export, defaulting to current tag in the spec file if it exists, HEAD
# otherwise
TAG?=$(shell if [ -z `git tag | grep $(NVR)` ]; then echo HEAD; else echo $(NVR); fi)

URL	:= $(REPOSITORY)\#$(GIT_BRANCH)\#$(TAG)

# allow overriding buildarch so you can do, say, an i386 build on x86_64
ifndef BUILDARCH
BUILDARCH := $(shell rpm --eval "%{_arch}")
endif

# list the possible arches usable during building or prepping
ARCHES = noarch i386 i586 i686 x86_64 ia64 s390 s390x ppc ppc64 pseries ppc64pseries iseries ppc64iseries athlon alpha alphaev6 sparc sparc64 sparcv9 sparcv9v sparc64v i164 mac sh mips geode

## ===================================================
## Here ends variable setting and starts build targets
## ===================================================

## list all our bogus targets, both hidden and public
.PHONY : bp bp-% bc bc-% bi bi-% bb bb-% commit-check distrohelp fedora-default mockbuild new notag-check repourl repo-push rpmclean scratch-build scratch-build-% tag-check tarball verrel

# The first target in the Makefile is always the default.  Generally, we won't
# have to worry about ever being first because the upstream make targets will
# come first and we will be included after them.  However, should upstream
# include us before their own make targets, we include this do nothing default
# so we don't go around doing things by accident.
fedora-default: 

# Now the rest of our make targets
bp :
	$(RPM_WITH_REPO_DIRS) -bp $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bp-% :
	$(RPM_WITH_REPO_DIRS) --target=$* -bp $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bc :
	$(RPM_WITH_REPO_DIRS) -bc $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bc-% :
	$(RPM_WITH_REPO_DIRS) --target=$* -bc $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bc-short :
	$(RPM_WITH_REPO_DIRS) -bc --short-circuit $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bc-short-% :
	$(RPM_WITH_REPO_DIRS) --target=$* -bc --short-circuit $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bi :
	$(RPM_WITH_REPO_DIRS) -bi $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bi-% :
	$(RPM_WITH_REPO_DIRS) --target=$* -bi $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bi-short :
	$(RPM_WITH_REPO_DIRS) -bi --short-circuit $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bi-short-% :
	$(RPM_WITH_REPO_DIRS) --target=$* -bi --short-circuit $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bb :
	$(RPM_WITH_REPO_DIRS) -bb $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

bb-% :
	$(RPM_WITH_REPO_DIRS) --target $* -bb $(SPECFILE) 2>&1 | tee .build-$(VERSION)-$(RELEASE).log ; exit $${PIPESTATUS[0]}

# build whatever's appropriate for the local architecture
local: $(if $(shell grep -i '^BuildArch:.*noarch' $(SPECFILE)), noarch, bb-$(shell uname -m))

## create a tarball export of either $(TAG) or head of branch
tarball:
	git-archive --format=tar --prefix=$(NVR)/ $(TAG) | bzip2 -9 > $(SRCRPMDIR)/$(NVR).tar.bz2

commit-check:
	git status | grep "nothing to commit" && { echo "Working directory is in need of a commit"; exit 1 }

repo-push:
	git push fedora && { echo "Failure pushing repo to fedora"; exit 1 }

# test build in mock
mockbuild : tarball
	mock $(MOCKARGS) -r $(MOCKCFG) --resultdir=$(MOCKDIR)/$(NVR) rebuild $(SRCRPMDIR)/$(NVR).tar.bz2

verrel:
	@echo $(NVR)

## We submit new builds as one of two types: fresh, in which case no tag
## exists and the build system builds the HEAD of our branch and tags it
## for us on successful completion, or a tagged build in which case we are
## rebuilding something that had been built before.  This means that before
## we do certain things that assume the build has completed with the tag
## specified, such as a bhodi update, we should check to see if the build
## actually succeeded and if we have a tag.
tag-check:
	git fetch fedora
	git checkout -f `git branch | awk '/^\* /{ print $2 }'`
	git tag | grep $(NVR) && { echo "The current tag has not been successfully built through the build system"; exit 1 }

notag-check:
	git fetch fedora
	git checkout -f `git branch | awk '/^\* /{ print $2 }'`
	git tag | grep $(NVR) || { echo "The current tag has already been successfully built through the build system"; exit 1 }

koji-build: commit-check repo-push $(COMMON_DIR)/branches
	@if [ ! -x "$(BUILD_CLIENT)" ]; then echo "Must have koji installed - see http://fedoraproject.org/wiki/BuildSystemClientSetup"; exit 1; fi
	$(BUILD_CLIENT) $(SECONDARY_CONFIG) build $(BUILD_FLAGS) $(TARGET) '$(URL)'

koji-scratch: commit-check repo-push $(COMMON_DIR)/branches
	@if [ ! -x "$(BUILD_CLIENT)" ]; then echo "Must have koji installed - see http://fedoraproject.org/wiki/BuildSystemClientSetup"; exit 1; fi
	$(BUILD_CLIENT) $(SECONDARY_CONFIG) build --scratch $(BUILD_FLAGS) $(TARGET) '$(URL)'


koji-scratch-%: commit-check repo-push $(COMMON_DIR)/branches
	@if [ ! -x "$(BUILD_CLIENT)" ]; then echo "Must have koji installed - see http://fedoraproject.org/wiki/BuildSystemClientSetup"; exit 1; fi
	$(BUILD_CLIENT) $(SECONDARY_CONFIG) build --scratch --arch-override=$* $(BUILD_FLAGS) $(TARGET) '$(URL)'

repourl:
	@echo '$(URL)'

# mop up, printing out exactly what was mopped.
rpmclean ::
	@echo "Running the %clean script of the rpmbuild..."
	-@$(RPM_WITH_REPO_DIRS) --clean --nodeps $(SPECFILE)
	@echo "Removing tarballs..."
	@find $(SRCRPMDIR) -type f -a ! -name .gitignore -printf '%f\n' -delete
	@echo "Removing patches..."
	@find $(SOURCEDIR) -type f -a ! -name .gitignore -printf '%f\n' -delete
	@echo "Removing build dirs..."
	@find $(BUILDDIR) -mindepth 1 -maxdepth 1 -type d -printf '%f\n' -exec rm -rf \{\} \;
	@echo "Removing mock dirs..."
	@find $(MOCKDIR) -mindepth 1 -maxdepth 1 -type d -printf '%f\n' -exec rm -rf \{\} \;
	@rm -fv *~ clog
	@echo "Leaving any prebuilt binary RPMs in $(RPMDIR)"
	@echo "Fully clean!"

distrohelp:
	@echo "Usage: make <target>"
	@echo "Available targets are:"
	@echo "	distrohelp		Show this text"
	@echo "	bp[-arch]		Local test rpmbuild prep"
	@echo "	bc[-arch]		Local test rpmbuild compile"
	@echo "	bc-short[-arch]		Local test rpmbuild short-circuit compile"
	@echo "	bi[-arch]		Local test rpmbuild install"
	@echo "	bi-short[-arch]		Local test rpmbuild short-circuit install"
	@echo "	bb[-arch]		Local test rpmbuild binary"
	@echo "	local			Local test rpmbuild binary"
	@echo "	tarball			Create clean tarball in \$$(SRCRPMDIR)"
	@echo "	koji-build		Initiate koji build of \$$(BRANCH)#HEAD in"
	@echo "				\$$(TARGET)"
	@echo "	scratch-build		Scratch version of make build"
	@echo "	scratch-build-<arches>	Scratch build, specifying arches"
	@echo "		examples:		make scratch-build-i386,ppc64"
	@echo "		 			make scratch-build-x86_64"
	@echo "	mockbuild		Local test build using mock"
	@echo "	verrel			Print \$$(NAME)-\$$(VERSION)-\$$(RELEASE) as found"
	@echo "				in the spec file"
	@echo "	gimmespec		Print the name of the specfile"
	@echo "	repo-push		Push repo changes to remote fedora repo"
	@echo "	rpmclean		Do a very thorough clean, including rpm cruft"

gimmespec:
	@echo "$(SPECFILE)"