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