fix Build-requires when image ISO is in SRPM
[ovirt-node-image.git] / Makefile.am
blobc91c3b9997ec35019f92cd0568e31f311d36ca5d
1 # Copyright (C) 2008 Red Hat, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; version 2 of the License.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15 # MA  02110-1301, USA.  A copy of the GNU General Public License is
16 # also available at http://www.gnu.org/copyleft/gpl.html.
18 OVIRT_CACHE_DIR  ?= $(HOME)/ovirt-cache
19 OVIRT_LOCAL_REPO ?= file://$(OVIRT_CACHE_DIR)/ovirt
20 OVIRT_URL        ?= http://ovirt.org/repos/ovirt
21 SUM              ?= sha1sum
22 PKG_FMT           = iso
23 SRC_FMT          ?= tar
24 AUTH_KEYS        ?= ~/.ssh/authorized_keys
26 FEDORA_MIRROR     = http://mirrors.fedoraproject.org/mirrorlist
27 CUR_RAWHIDE       = 11
29 FEDORA            = $(shell rpm --eval '%{fedora}')
30 ARCH              = $(shell rpm --eval '%{_arch}')
32 NVR               = $(PACKAGE)-$(VERSION)-$(ARCH)
34 EXTRA_DIST =                            \
35   .gitignore                            \
36   $(PACKAGE).spec                       \
37   $(PACKAGE).spec.in                    \
38   README.krb5                           \
39   common-blacklist.ks                   \
40   common-install.ks                     \
41   common-pkgs.ks                        \
42   common-post.ks                        \
43   ovirt-flash                           \
44   $(PACKAGE).ks                         \
45   ovirt-pxe                             \
46   create-ovirt-iso-nodes                \
47   edit-livecd                           \
48   livecd-setauth
50 DISTCLEANFILES = $(PACKAGE)-$(VERSION).tar.gz \
51   $(PACKAGE).$(PKG_FMT) \
52   $(NVR).$(PKG_FMT) \
53   $(NVR).$(PKG_FMT).$(SUM) \
54   repos.ks ovirt-authorized_keys
56 # For Release: 0..., set _ovirt_dev=1 so that we get extra_release.GIT-
57 # annotated rpm version strings.
58 _ovirt_dev = \
59  $(shell grep -q '^[[:space:]]*Release:[[:space:]]*0' \
60    $(srcdir)/*.spec.in && echo 1 || :)
62 git_head    = $$(git log -1 --pretty=format:%h)
63 GIT_RELEASE = $(shell date --utc +%Y%m%d%H%M%S)git$(git_head)
64 RPMDIR      = $$(rpm --eval '%{_rpmdir}')
65 RPM_FLAGS   = --define "ovirt_cache_dir $(OVIRT_CACHE_DIR)"
66 RPM_FLAGS  += $(if $(_ovirt_dev),--define "extra_release .$(GIT_RELEASE)")
67 NODE_TMP    = $(OVIRT_CACHE_DIR)/$(PACKAGE)-$(ARCH)-tmp
68 SRC_KS      = $(NODE_TMP)/src.ks
70 repos.ks:
71         ( \
72             if [ 0$(FEDORA) == 0$(CUR_RAWHIDE) ]; then \
73                 FEDORA_REPO=rawhide ;\
74                 FEDORA_REPO_LOC="$(if $(FEDORA_URL),--baseurl=$(FEDORA_URL)/development/$(ARCH)/os,--mirrorlist=$(FEDORA_MIRROR)?repo=rawhide&arch=$(ARCH))" ;\
75                 OVIRT_DISTRO=development ;\
76             else \
77                 FEDORA_REPO=f$(FEDORA) ;\
78                 FEDORA_REPO_LOC="$(if $(FEDORA_URL),--baseurl=$(FEDORA_URL)/releases/$(FEDORA)/Everything/${ARCH}/os,--mirrorlist=$(FEDORA_MIRROR)?repo=fedora-$(FEDORA)&arch=$(ARCH))" ;\
79                 OVIRT_DISTRO=$(FEDORA) ;\
80                 UPDATE_REPO_LINE="repo --name=$${FEDORA_REPO}-updates $(if $(FEDORA_URL),--baseurl=$(FEDORA_URL)/updates/$(FEDORA)/${ARCH},--mirrorlist=$(FEDORA_MIRROR)?repo=updates-released-f$(FEDORA)&arch=$(ARCH))" ;\
81             fi ;\
82             echo "repo --name=$${FEDORA_REPO} $${FEDORA_REPO_LOC}" > $@ ;\
83             echo "repo --name=ovirt-org --baseurl=$(OVIRT_URL)/$${OVIRT_DISTRO}/$(ARCH)" >> $@ ;\
84             echo "$${UPDATE_REPO_LINE}" >> $@ ;\
85             echo "repo --name=ovirt-local --baseurl=$(OVIRT_LOCAL_REPO)" >> $@ \
86         )
88 src.ks: repos.ks
89         mkdir -p $(NODE_TMP)
90         ( \
91             cat repos.ks ;\
92             if [ 0$(FEDORA) == 0$(CUR_RAWHIDE) ]; then \
93                 FEDORA_REPO=rawhide ;\
94                 FEDORA_REPO_LOC="$(if $(FEDORA_URL),--baseurl=$(FEDORA_URL)/development/source/SRPMS,--mirrorlist=$(FEDORA_MIRROR)?repo=rawhide-source&arch=source)" ;\
95                 OVIRT_DISTRO=development ;\
96             else \
97                 FEDORA_REPO=f$(FEDORA) ;\
98                 FEDORA_REPO_LOC="$(if $(FEDORA_URL),--baseurl=$(FEDORA_URL)/releases/$(FEDORA)/Everything/source/SRPMS,--mirrorlist=$(FEDORA_MIRROR)?repo=fedora-source-$(FEDORA)&arch=source)" ;\
99                 OVIRT_DISTRO=$(FEDORA) ;\
100                 UPDATE_REPO_LINE="repo --name=$${FEDORA_REPO}-updates-source $(if $(FEDORA_URL),--baseurl=$(FEDORA_URL)/updates/$(FEDORA)/SRPMS,--mirrorlist=$(FEDORA_MIRROR)?repo=updates-released-source-f$(FEDORA)&arch=source)" ;\
101             fi ;\
102             echo "repo --name=$${FEDORA_REPO}-source $${FEDORA_REPO_LOC}" ;\
103             echo "repo --name=ovirt-org-source --baseurl=$(OVIRT_URL)/$${OVIRT_DISTRO}/src" ;\
104             echo "$${UPDATE_REPO_LINE}" ;\
105             echo "%packages --nobase" ;\
106             grep -v '^-' common-pkgs.ks ;\
107             echo "%end" ;\
108         ) > $(SRC_KS)
110 keys:
111         if [ "$(_ovirt_dev)" = 1 -a -f $(AUTH_KEYS) ]; then \
112             cp -va $(AUTH_KEYS) ovirt-authorized_keys ;\
113         fi
115 SELINUX_ENFORCING=$(shell /usr/sbin/getenforce)
116 $(NVR).$(PKG_FMT): repos.ks keys
117         mkdir -p $(NODE_TMP)
118         mkdir -p $(OVIRT_CACHE_DIR)/yum-$(ARCH)
119         ( \
120             case $(SELINUX_ENFORCING) in \
121                 Enforcing) sudo /usr/sbin/setenforce Permissive ;; \
122                 Permissive) ;; \
123                 *) if ksflatten $(PACKAGE).ks 2>/dev/null \
124                        | grep -q '^selinux --disabled'; then \
125                        echo WARNING: SELinux disabled in kickstart ;\
126                    else \
127                        echo ERROR: SELinux enabled in kickstart, \
128                        but disabled on the build machine ;\
129                        exit 1 ;\
130                    fi ;; \
131             esac ;\
132         )
133         sudo livecd-creator --skip-minimize -c $(PACKAGE).ks \
134             -f $(PACKAGE) \
135             --tmpdir='$(NODE_TMP)' \
136             --cache='$(OVIRT_CACHE_DIR)/yum-$(ARCH)'
137         sudo chown $${USER} $(PACKAGE).$(PKG_FMT)
138         ( \
139             if [ $(SELINUX_ENFORCING) = Enforcing ]; then \
140                 sudo /usr/sbin/setenforce Enforcing || exit 1 ;\
141             fi \
142         )
144         ln -nf $(PACKAGE).$(PKG_FMT) $(NVR).$(PKG_FMT)
146 $(NVR).$(PKG_FMT).$(SUM): $(NVR).$(PKG_FMT)
147         $(SUM) $(NVR).$(PKG_FMT) > $(NVR).$(PKG_FMT).$(SUM)
149 $(PACKAGE).$(PKG_FMT) node: $(NVR).$(PKG_FMT).$(SUM)
151 PUNGI = $(NODE_TMP)/tree/pungi
152 source: src.ks
153         @sudo rm -Rf $(PUNGI)
154         @mkdir -p $(PUNGI)
156         cd $(PUNGI) && \
157             sudo pungi -G --ver=$(PACKAGE) -c $(SRC_KS) \
158             --cachedir=$(OVIRT_CACHE_DIR)/yum-$(ARCH)
159         if [ "$(SRC_FMT)" == "iso" ]; then \
160             cd $(PUNGI) && \
161                 sudo pungi --sourceiso --ver=$(PACKAGE) -c $(SRC_KS) \
162                 --cachedir=$(OVIRT_CACHE_DIR)/yum-$(ARCH) ;\
163             sudo mv $(PUNGI)/$(PACKAGE)/source/iso/Fedora-$(PACKAGE)-source.iso \
164                 $(PWD)/$(PACKAGE)-source-$(VERSION).iso ;\
165         elif [ "$(SRC_FMT)" == "tar" ]; then \
166             cd $(PUNGI)/$(PACKAGE)/source && \
167                 sudo tar cf ovirt-source.tar SRPMS ;\
168             sudo mv $(PUNGI)/$(PACKAGE)/source/ovirt-source.tar \
169                 $(PWD)/$(PACKAGE)-source-$(VERSION).tar ;\
170         else \
171             echo "Invalid src format: $(SRC_FMT)" ;\
172             exit 1 ;\
173         fi
174         sudo sudo chown -R $(USER) $(PWD)/$(PACKAGE)-source-$(VERSION).$(SRC_FMT)
175         sudo sudo chown -R $(USER) $(PUNGI)
176         $(SUM) $(PWD)/$(PACKAGE)-source-$(VERSION).$(SRC_FMT) \
177             > $(PACKAGE)-source-$(VERSION).$(SRC_FMT).$(SUM)
179 rpms: dist node
180         rpmbuild $(RPM_FLAGS) -ts $(distdir).tar.gz
181         rpmbuild $(RPM_FLAGS) --define "source_iso 1" -tb $(distdir).tar.gz
183 srpms: dist
184         rpmbuild $(RPM_FLAGS) -ts $(distdir).tar.gz
185         $(MAKE) _publish
187 iso_srpms: dist
188         rpmbuild $(RPM_FLAGS) --define "source_iso 1" -ts $(distdir).tar.gz
189         $(MAKE) _publish
191 publish: rpms _publish
193 _publish:
194         mkdir -p $(OVIRT_CACHE_DIR)
195         rsync -aq $(shell rpm --eval '%{_rpmdir}')/ $(OVIRT_CACHE_DIR)/ovirt/
196         rsync -aq $(shell rpm --eval '%{_srcrpmdir}')/ $(OVIRT_CACHE_DIR)/ovirt/src
197         createrepo $(OVIRT_CACHE_DIR)/ovirt
199 .PHONY: rpms publish srpms $(NVR).$(PKG_FMT).$(SUM) $(NVR).$(PKG_FMT) \
200   $(PACKAGE).$(PKG_FMT) keys repos.ks src.ks source _publish iso_srpms