xref: /freebsd/release/Makefile.vm (revision f81cdf24ba5436367377f7c8e8f51f6df2a75ca7)
1#
2#
3#
4# Makefile for building virtual machine and cloud provider disk images.
5#
6
7VMTARGETS=	vm-image
8VMFORMATS?=	vhd vmdk qcow2 raw
9VMSIZE?=	5120m
10VMFS?=		ufs
11VMFSLIST?=	ufs zfs
12SWAPSIZE?=	1g
13VMBASE?=	vm
14
15VHD_DESC=	Azure, VirtualPC, Hyper-V, Xen disk image
16VMDK_DESC=	VMWare, VirtualBox disk image
17QCOW2_DESC=	Qemu, KVM disk image
18RAW_DESC=	Unformatted raw disk image
19
20CLOUDWARE_TYPES?= AZURE \
21		BASIC-CI \
22		EC2 \
23		GCE \
24		OCI \
25		VAGRANT
26AZURE_FORMAT=	vhdf
27AZURE_FSLIST?=	ufs zfs
28AZURE_DESC=	Microsoft Azure platform image
29BASIC-CI_FORMAT=	raw
30BASIC-CI_FSLIST?=	ufs
31BASIC-CI_DESC=		Image for CI
32EC2_FORMAT=	raw
33EC2_FSLIST?=	ufs zfs
34EC2_FLAVOURS?=	BASE CLOUD-INIT
35EC2-BASE_DESC=	Amazon EC2 image
36EC2-CLOUD-INIT_DESC=	Amazon EC2 Cloud-Init image
37GCE_FORMAT=	raw
38GCE_FSLIST?=	ufs zfs
39GCE_DESC=	Google Compute Engine image
40OCI_FORMAT=	qcow2
41OCI_FSLIST?=	ufs
42OCI_DESC=	Oracle Cloud Infrastructure image
43OPENSTACK_FORMAT=qcow2
44OPENSTACK_FSLIST?=	ufs
45OPENSTACK_DESC=	OpenStack platform image
46VAGRANT_FORMAT=	vmdk
47VAGRANT_FSLIST?=	ufs
48VAGRANT_FLAVOURS?=	VIRTUALBOX VMWARE
49VAGRANT-VIRTUALBOX_DESC=	Vagrant Image for VirtualBox
50VAGRANT-VMWARE_DESC=	Vagrant Image for VMWare
51
52.for _CWT in ${CLOUDWARE_TYPES}
53. if defined(${_CWT}_FLAVOURS)
54.  for _CWF in ${${_CWT}_FLAVOURS}
55CLOUDWARE_GEN+=	${_CWT}-${_CWF}
56${_CWT}-${_CWF}_FORMAT?=	${${_CWT}_FORMAT}
57${_CWT}-${_CWF}_FSLIST?=	${${_CWT}_FSLIST}
58${_CWT}-${_CWF}_DESC?=	${${_CWT}_DESC}
59.  endfor
60. else
61CLOUDWARE_GEN+=	${_CWT}
62. endif
63.endfor
64CLOUDWARE?=	${CLOUDWARE_GEN}
65
66.for _V in TYPE BRANCH REVISION
67. if !defined(${_V}) || empty(${_V})
68${_V}!=	eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V}
69. endif
70.endfor
71
72emulator-portinstall:
73.if !exists(/usr/local/bin/qemu-${TARGET_ARCH}-static)
74.if exists(${PORTSDIR}/emulators/qemu-user-static/Makefile)
75	env - UNAME_r=${UNAME_r} PATH=$$PATH make -C ${PORTSDIR}/emulators/qemu-user-static BATCH=1 all install clean
76.else
77.if !exists(/usr/local/sbin/pkg-static)
78	env ASSUME_ALWAYS_YES=yes pkg bootstrap -y
79.endif
80	env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static
81.endif
82.endif
83	touch ${.TARGET}
84
85.if ${TARGET_ARCH} != ${MACHINE_ARCH}
86.if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" )
87QEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static
88QEMUTGT=emulator-portinstall
89.endif
90.endif
91QEMUTGT?=
92
93.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
94. for _CW in ${CLOUDWARE}
95.  if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF)
96${_CW:tu}CONF?=	${.CURDIR}/tools/${_CW:tl}.conf
97.  endif
98.  for _FS in ${${_CW:tu}_FSLIST}
99CLOUDTARGETS+=	cw-${_CW:tl}-${_FS}
100CLEANDIRS+=	cw-${_CW:tl}-${_FS}
101CLEANFILES+=	${_CW:tl}.${_FS}.img \
102		${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT} \
103		${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT}.raw
104${_CW:tu}${_FS:tu}IMAGE=	${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT}
105
106cw-${_CW:tl}-${_FS}: ${QEMUTGT}
107	mkdir -p ${.OBJDIR}/${.TARGET}
108	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
109		QEMUSTATIC=${QEMUSTATIC} \
110		${.CURDIR}/scripts/mk-vmimage.sh \
111		-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${_FS} \
112		-i ${.OBJDIR}/${_CW:tl}.${_FS}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \
113		-S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}${_FS:tu}IMAGE} -c ${${_CW:tu}CONF}
114	touch ${.TARGET}
115.  endfor
116
117# Hardlinks from "foo.bar" to "foo-${VMFS}.bar".  These can go away once all
118# of the cloudware code knows how to handle multiple filesystem images (or
119# at least knows the name of the UFS image).
120CLOUDTARGETS+=	cw-${_CW:tl}
121CLEANFILES+=	${_CW:tl}.${${_CW:tu}_FORMAT}
122${_CW:tu}IMAGE=	${_CW:tl}.${${_CW:tu}_FORMAT}
123cw-${_CW:tl}: cw-${_CW:tl}-${VMFS}
124	ln -f ${${_CW:tu}${VMFS:tu}IMAGE} ${${_CW:tu}IMAGE}
125. endfor
126.endif
127
128.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
129CLEANDIRS+=	${VMTARGETS}
130. for FORMAT in ${VMFORMATS}
131.  for FS in ${VMFSLIST}
132CLEANFILES+=	${FORMAT}.${FS}.img
133CLEANFILES+=	${VMBASE}.${FS}.${FORMAT}
134.  endfor
135. endfor
136.endif
137
138vm-base:	vm-image
139
140vm-image:
141.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
142. for FORMAT in ${VMFORMATS}
143.  for FS in ${VMFSLIST}
144	mkdir -p ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS}
145	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
146		${.CURDIR}/scripts/mk-vmimage.sh \
147		-C ${.CURDIR}/tools/vmimage.subr \
148		-d ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS} -F ${FS} \
149		-i ${.OBJDIR}/${FORMAT}.${FS}.img -s ${VMSIZE} -f ${FORMAT} \
150		-S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FS}.${FORMAT}
151.  endfor
152. endfor
153.endif
154	touch ${.TARGET}
155
156vm-cloudware:	${CLOUDTARGETS}
157
158list-vmtargets:	list-cloudware
159	@${ECHO}
160	@${ECHO} "Supported virtual machine disk image formats:"
161.for FORMAT in ${VMFORMATS:tu}
162	@${ECHO} "  ${FORMAT:tl}: ${${FORMAT}_DESC}"
163.endfor
164
165list-cloudware:
166.if !empty(CLOUDWARE)
167	@${ECHO}
168	@${ECHO} "Supported cloud hosting provider images:"
169. for _CW in ${CLOUDWARE}
170	@${ECHO} "  ${_CW:tu}: ${${_CW:tu}_DESC}"
171. endfor
172.endif
173
174vm-install:
175.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
176	mkdir -p ${DESTDIR}/vmimages
177. for FORMAT in ${VMFORMATS}
178.  for FS in ${VMFSLIST}
179	cp -p ${VMBASE}.${FS}.${FORMAT} \
180		${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT}
181.  endfor
182. endfor
183. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
184.  for FORMAT in ${VMFORMATS}
185.   for FS in ${VMFSLIST}
186	# Don't keep the originals.  There is a copy in ${.OBJDIR} if needed.
187	${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT}
188.   endfor
189.  endfor
190. endif
191	# Compatibility hardlinks from "foo.bar" to "foo-${VMFS}.bar".
192. for FORMAT in ${VMFORMATS}
193.  if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
194	ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT}.xz ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}.xz
195.  else
196	ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
197.  endif
198. endfor
199	cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \
200		${DESTDIR}/vmimages/CHECKSUM.SHA512
201	cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \
202		${DESTDIR}/vmimages/CHECKSUM.SHA256
203.endif
204
205vm-release:
206.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
207	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS}
208.endif
209
210cloudware-release:
211.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
212	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS}
213.endif
214
215.include "${.CURDIR}/Makefile.azure"
216.include "${.CURDIR}/Makefile.ec2"
217.include "${.CURDIR}/Makefile.firecracker"
218.include "${.CURDIR}/Makefile.gce"
219.include "${.CURDIR}/Makefile.vagrant"
220.include "${.CURDIR}/Makefile.inc1"
221