rules 10.6 KB
Newer Older
Riku Voipio's avatar
Riku Voipio committed
1
#!/usr/bin/make -f
Michael Tokarev's avatar
Michael Tokarev committed
2
SHELL = /bin/sh -e
Riku Voipio's avatar
Riku Voipio committed
3

4
# get DEB_VERSION
5
include /usr/share/dpkg/pkg-info.mk
6
# get DEB_HOST_ARCH DEB_HOST_ARCH_OS DEB_HOST_GNU_TYPE DEB_HOST_MULTIARCH DEB_BUILD_GNU_TYPE
7
include /usr/share/dpkg/architecture.mk
8
9
# get CFLAGS LDFLAGS etc
include /usr/share/dpkg/buildflags.mk
10

11
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
Michael Tokarev's avatar
Michael Tokarev committed
12
VENDOR := UBUNTU
13
14
DEB_BUILD_PARALLEL = yes
else
Michael Tokarev's avatar
Michael Tokarev committed
15
VENDOR := DEBIAN
16
endif
17

18
# support parallel build using DEB_BUILD_OPTIONS=parallel=N
19
20
21
22
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
  MAKEFLAGS += -j$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

23
24
# verbose build
V ?= 1
Riku Voipio's avatar
Riku Voipio committed
25

26
# list of packages we're supposed to build
27
BUILD_PACKAGES = $(call dpkg_late_eval,BUILD_PACKAGES,dh_listpackages)
Riku Voipio's avatar
Riku Voipio committed
28

29
enable_system = $(if $(filter qemu-system,${BUILD_PACKAGES}),enable,disable)
30
31
enable_linux_user = $(if $(filter qemu-user,${BUILD_PACKAGES}),enable,disable)

32
FIRMWAREPATH = /usr/share/qemu:/usr/share/seabios:/usr/lib/ipxe/qemu
33

34
# we add another set of configure options from debian/control
Michael Tokarev's avatar
Michael Tokarev committed
35
36
common_configure_opts = \
	--with-pkgversion="Debian $(DEB_VERSION)" \
37
	--extra-cflags="$(CFLAGS) $(CPPFLAGS)" --extra-ldflags="$(LDFLAGS) -Wl,--as-needed" \
Michael Tokarev's avatar
Michael Tokarev committed
38
39
	--prefix=/usr \
	--sysconfdir=/etc \
40
	--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
41
	--libexecdir=/usr/lib/qemu \
42
	--firmwarepath=${FIRMWAREPATH} \
43
	--localstatedir=/var \
Michael Tokarev's avatar
Michael Tokarev committed
44
45
	--disable-blobs \
	--disable-strip \
46
	--interp-prefix=/etc/qemu-binfmt/%M \
Michael Tokarev's avatar
Michael Tokarev committed
47
	--localstatedir=/var \
Michael Tokarev's avatar
Michael Tokarev committed
48

49
50
51
52
53
# Cross compiling support
ifneq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
common_configure_opts  += --cross-prefix=$(DEB_HOST_GNU_TYPE)-
endif

54
55
ifeq (${enable_system},enable)

56
57
# list of system (softmmu) targets, from ./configure
system_targets = \
58
59
60
 i386 x86_64 alpha aarch64 arm cris lm32 hppa m68k microblaze microblazeel \
 mips mipsel mips64 mips64el moxie nios2 or1k ppc ppcemb ppc64 riscv32 riscv64 \
 sh4 sh4eb sparc sparc64 s390x tricore xtensa xtensaeb unicore32
61

Michael Tokarev's avatar
Michael Tokarev committed
62
# qemu-system subpackages, from d/control
63
64
sys_systems = arm mips ppc sparc x86
systems = ${sys_systems} misc
65
sysarch_arm   = $(filter aarch64 arm,${system_targets})
66
67
68
69
70
71
sysarch_mips  = $(filter mips mipsel mips64 mips64el,${system_targets})
sysarch_ppc   = $(filter ppc ppc64 ppcemb,${system_targets})
sysarch_sparc = $(filter sparc sparc64,${system_targets})
sysarch_x86   = $(filter i386 x86_64,${system_targets})
sysarch_misc  = $(filter-out $(foreach s,${sys_systems},${sysarch_$s}),${system_targets})

72
73
74
75
76
77
else

systems =

endif # enable_system

78
ifeq (${enable_linux_user},enable)
79
80
81

# list of linux-user targets, from ./configure
user_targets = \
82
 i386 x86_64 alpha aarch64 aarch64_be arm armeb cris hppa m68k microblaze microblazeel \
83
 mips mipsel mips64 mips64el mipsn32 mipsn32el nios2 or1k \
84
85
 ppc ppc64 ppc64abi32 ppc64le riscv32 riscv64 sh4 sh4eb sparc sparc64 sparc32plus \
 s390x tilegx xtensa xtensaeb
86

87
endif	# enable_linux_user
88

89
configure-stamp: configure
Riku Voipio's avatar
Riku Voipio committed
90
91
	dh_testdir

Aurelien Jarno's avatar
Aurelien Jarno committed
92
	# system build
93
94
95
	rm -rf qemu-build; mkdir qemu-build
	cd qemu-build && \
	    ../configure ${common_configure_opts} --disable-user \
96
97
		--${enable_system}-system \
		--${enable_linux_user}-linux-user \
98
		--enable-modules \
99
100
		$(shell sh debian/extract-config-opts \
		    $(DEB_HOST_ARCH_OS)-$(DEB_HOST_ARCH) debian/control) \
101
102
		$(QEMU_CONFIGURE_OPTIONS) || \
	 { echo ===== CONFIGURE FAILED ===; tail -n 50 config.log; exit 1; }
103

104
105
106
107
# switch UI and audio modules back to be built-ins, for now
	sed -i -r 's/(CONFIG_(CURSES|GTK|SDL|AUDIO_.*))=m/\1=y/' \
		qemu-build/config-host.mak

108
ifeq ($(enable_linux_user),enable)
109
110
# do not use debian/configure-opts here, all optional stuff will be enabled
# automatically, dependencies are already verified in the main build
111
112
113
114
115
	rm -rf user-static-build; mkdir user-static-build
	cd user-static-build && \
	    ../configure ${common_configure_opts} \
		--static --disable-system \
		--target-list="$(addsuffix -linux-user,${user_targets})"
Aurelien Jarno's avatar
Aurelien Jarno committed
116
117
endif
	touch $@
Riku Voipio's avatar
Riku Voipio committed
118

119
120
121
build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
Aurelien Jarno's avatar
Aurelien Jarno committed
122
build-stamp: configure-stamp
Riku Voipio's avatar
Riku Voipio committed
123
	dh_testdir
Michael Tokarev's avatar
Michael Tokarev committed
124

125
	# system and utils build
126
	$(MAKE) -C qemu-build V=${V}
127
ifeq (${enable_system},enable)
128
	dtc -o qemu-build/pc-bios/bamboo.dtb pc-bios/bamboo.dts
129
endif
Aurelien Jarno's avatar
Aurelien Jarno committed
130

131
ifeq ($(enable_linux_user),enable)
132
	# user-static build
133
	# we use this invocation to build just the binaries
Michael Tokarev's avatar
Michael Tokarev committed
134
	$(MAKE) -C user-static-build V=${V} $(foreach t,${user_targets},subdir-${t}-linux-user)
Aurelien Jarno's avatar
Aurelien Jarno committed
135
136
endif
	touch $@
Riku Voipio's avatar
Riku Voipio committed
137

138
clean:	debian/control
Riku Voipio's avatar
Riku Voipio committed
139
	dh_testdir
140
141
	rm -rf qemu-build user-static-build
	rm -f configure-stamp build-stamp
Michael Tokarev's avatar
Michael Tokarev committed
142
	find scripts/ -name '*.pyc' -delete || :
Riku Voipio's avatar
Riku Voipio committed
143
144
	dh_clean

145
146
147
148
149
150
151
152
# define ${ai} variable to be one of -i (indep), -a (arch) or nothing (both)
ai :=
binary-indep: ai := -i
binary-indep: install
binary-arch: ai := -a
binary-arch: install
binary: install

153
154
155
156
define inst-system
	mkdir -p debian/qemu-system-$1/usr/share/man/man1 debian/qemu-system-$1/usr/bin
	for t in ${sysarch_$1}; do \
	    mv debian/tmp/usr/bin/qemu-system-$$t debian/qemu-system-$1/usr/bin/; \
Michael Tokarev's avatar
Michael Tokarev committed
157
	    echo ".so man1/qemu-system.1" > debian/qemu-system-$1/usr/share/man/man1/qemu-system-$$t.1; \
158
	done
159
160
161
162
163
	echo sysarch:$1=\
$(if $(wordlist 10,20,${sysarch_$1}),\
$(wordlist 1,8,${sysarch_$1})\$${Newline}   $(wordlist 9,20,${sysarch_$1}),\
${sysarch_$1}) \
> debian/qemu-system-$1.substvars
164
165
	echo sysprovides:$1=${addprefix qemu-system-,${filter-out $1,${sysarch_$1}}} | \
	  sed -e 's/ /, /g' -e 'y/_/-/' >> debian/qemu-system-$1.substvars
Michael Tokarev's avatar
Michael Tokarev committed
166
	dh_link -pqemu-system-$1 usr/share/doc/qemu-system-common usr/share/doc/qemu-system-$1/common
167
168
169
170

endef

install: build-stamp
Riku Voipio's avatar
Riku Voipio committed
171
172
	dh_testdir
	dh_testroot
173
	dh_prep
Riku Voipio's avatar
Riku Voipio committed
174
	dh_installdirs -a
Michael Tokarev's avatar
Michael Tokarev committed
175

Michael Tokarev's avatar
Michael Tokarev committed
176
177
	# system and utils install
	$(MAKE) -C qemu-build DESTDIR=$(CURDIR)/debian/tmp install
Riku Voipio's avatar
Riku Voipio committed
178

179
180
ifeq (${enable_system},enable)

181
	# qemu-system subpackages
Michael Tokarev's avatar
Michael Tokarev committed
182
	mv debian/tmp/usr/share/man/man1/qemu.1 debian/tmp/usr/share/man/man1/qemu-system.1
183
	$(foreach s,${systems},$(call inst-system,$s))
184

185
186
187
188
189
ifneq ($(filter $(DEB_HOST_ARCH),amd64 i386),)
# We used to load kvm module on x86 using an initscript,
# but modern kernels do that automatically.  Remove the initscript.
# Remove this fragment for stretch+1.
	for x in preinst postinst postrm; do \
190
	  echo 'dpkg-maintscript-helper rm_conffile /etc/init.d/qemu-system-x86 1:2.2+dfsg-3~ -- "$$@"' \
191
192
	    >> debian/qemu-system-x86.$$x.debhelper ; \
	done
193
# there's no need to restore the links b/c kernel autoloads our modules
194
	echo 'if [ configure = "$$1" ] && dpkg --compare-versions "$$2" le-nl 1:2.2+dfsg-3~; then update-rc.d qemu-system-x86 remove >/dev/null; fi' \
195
196
197
	  >> debian/qemu-system-x86.postinst.debhelper
endif

198
# remove now-unused target-x86_64.conf (and /etc/qemu dir too, see #797608)
199
200
201
	for x in preinst postinst postrm; do \
	  echo 'dpkg-maintscript-helper rm_conffile /etc/qemu/target-x86_64.conf 1:2.4+dfsg-1~ -- "$$@"' \
            >> debian/qemu-system-x86.$$x.debhelper ; \
202
203
	  echo '[ -d /etc/qemu ] && rmdir /etc/qemu 2>/dev/null || :' \
	    >> debian/qemu-system-x86.$$x.debhelper; \
204
205
	done

Aurelien Jarno's avatar
Aurelien Jarno committed
206
ifeq ($(DEB_HOST_ARCH_OS),linux)
207
208
209
210

# /usr/bin/kvm compat script.  This needs some more work for other arches
# How about a manpage for it?
ifneq ($(filter $(DEB_HOST_ARCH),amd64 i386),)
211
212
	dh_install -pqemu-kvm debian/kvm /usr/bin/
	dh_install -pqemu-kvm debian/kvm.1 /usr/share/man/man1/
Michael Tokarev's avatar
Michael Tokarev committed
213
ifeq ($(VENDOR),UBUNTU)
214
215
216
217
# on ubuntu there was kvm-spice package/binary which was used in libvirt xml
	dh_link -pqemu-kvm usr/bin/kvm usr/bin/kvm-spice \
		usr/bin/qemu-system-x86_64 usr/bin/qemu-system-x86_64-spice
endif
218
endif
Michael Tokarev's avatar
Michael Tokarev committed
219
ifeq ($(VENDOR),UBUNTU)
220
221
222
223
# apport hook is ubuntu-specific
	dh_install -pqemu-system-common debian/source_qemu.py \
		usr/share/apport/package-hooks/
endif
224

225
# virtfs-proxy-helper and qemu-bridge-helper are linux-specific
226
	for f in usr/bin/virtfs-proxy-helper \
227
	         usr/share/man/man1/virtfs-proxy-helper.1 \
228
		 usr/lib/qemu/qemu-bridge-helper \
229
	; do \
230
	  mkdir -p debian/qemu-system-common/$${f%/*} ; \
231
	  mv debian/tmp/$$f debian/qemu-system-common/$$f ; \
232
	done
233
234
235
236

endif # linux

endif # enable_system
237

238
ifeq ($(enable_linux_user),enable)
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
	# qemu-user
	mkdir -p debian/qemu-user/usr/bin debian/qemu-user/usr/share/man/man1
	for t in ${user_targets}; do \
	    mv debian/tmp/usr/bin/qemu-$$t \
		debian/qemu-user/usr/bin ; \
	    ln -s qemu-user.1 \
		debian/qemu-user/usr/share/man/man1/qemu-$$t.1 ; \
	done

	# qemu-user-static
	mkdir -p debian/qemu-user-static/usr/bin debian/qemu-user-static/usr/share/man/man1
	for t in ${user_targets}; do \
	    cp -p user-static-build/$$t-linux-user/qemu-$$t \
		debian/qemu-user-static/usr/bin/qemu-$$t-static ; \
	    ln -s qemu-user-static.1 \
		    debian/qemu-user-static/usr/share/man/man1/qemu-$$t-static.1 ; \
Aurelien Jarno's avatar
Aurelien Jarno committed
255
256
	done

257
	# binfmt support
258
	for x in postinst prerm; do \
259
	    sed -e s/@SUFFIX@/-static/ -e s/@PACKAGE@/qemu-user-static/ -e "s/@FIX_BINARY@/--fix-binary yes/" \
260
		debian/binfmt-update-in >> debian/qemu-user-static.$$x.debhelper ; \
261
	    sed -e s/@SUFFIX@// -e s/@PACKAGE@/qemu-user-binfmt/ -e s/@FIX_BINARY@// \
262
		debian/binfmt-update-in >> debian/qemu-user-binfmt.$$x.debhelper ; \
263
	done
264

265
endif	# enable_linux_user
266

267
# install whole thing so --list-missing works right
268
	dh_install --list-missing
269
# install the rest for arch/indep as needed
270
	dh_installdocs ${ai} -Nqemu-user-binfmt
271
	dh_installchangelogs ${ai} -Nqemu-user-binfmt
272
	dh_installdocs ${ai} -pqemu-user-binfmt --link-doc=qemu-user
273
274
275
	dh_installman ${ai}
	dh_installudev ${ai}
ifneq (${ai},-i)	# do not run this for binary-indep
276
277
278
279
ifeq (${enable_system},enable)
# qemu-ifup is arch-specific
	install -D debian/qemu-ifup.$(DEB_HOST_ARCH_OS) \
		debian/qemu-system-common/etc/qemu-ifup
280
endif
281
	dh_installinit -pqemu-guest-agent
282
283
284
285
286
287
endif
	dh_link ${ai}
	dh_strip ${ai}
	dh_compress ${ai}
	dh_fixperms ${ai}
	dh_shlibdeps ${ai}
288
	dh_installdeb ${ai}
289
290
291
ifeq ($(enable_linux_user),enable)
# after shlibdeps finished, grab ${shlibs:Depends} from -user package
# and transform it into Built-Using field for -user-static.
292
293
294
295
296
297
298
299
# See also dpkg-query bug #588505
	if [ -f debian/qemu-user.substvars ]; then \
	  pkgs=$$(sed -n -e's/([^)]*)//g' -e's/,//g' -e's/^shlibs:Depends=//p' debian/qemu-user.substvars); \
	  srcs=; for p in $$pkgs; do \
	    srcs="$$srcs $$(dpkg-query -f '$${source:Package} (= $${source:Version}),' -W $$p)"; \
	  done ; \
	  echo "built-using=$$srcs" >> debian/qemu-user-static.substvars ; \
	fi
300
endif
301
302
303
	dh_gencontrol ${ai}
	dh_md5sums ${ai}
	dh_builddeb ${ai}
Riku Voipio's avatar
Riku Voipio committed
304

305
306
307
ifneq (,$(wildcard debian/control-in))
# only include rules for debian/control if debian/control-in is present
debian/control: debian/control-in debian/rules
308
	echo '# autogenerated file, please edit debian/control-in' > $@.tmp
Michael Tokarev's avatar
Michael Tokarev committed
309
	sed -e 's/^:$(shell echo ${VENDOR} | tr '[A-Z]' '[a-z]')://' \
310
		-e '/^:[a-z]*:/D' $< >> $@.tmp
311
	mv -f $@.tmp $@
312
	chmod -w $@
313
endif
314

315
316
317
318
get-orig-source:
	./debian/get-orig-source.sh ${DEB_VERSION}

.PHONY: build clean binary-indep binary-arch binary install get-orig-source
Riku Voipio's avatar
Riku Voipio committed
319