xref: /freebsd/release/Makefile.vm (revision f01edb6f5d55fe093f8ab9c5da2b1707af698a56)
1#
2# $FreeBSD$
3#
4#
5# Makefile for building virtual machine and cloud provider disk images.
6#
7
8VMTARGETS=	vm-image
9VMFORMATS?=	vhd vmdk qcow2 raw
10VMSIZE?=	3072M
11SWAPSIZE?=	1G
12VMBASE?=	vm
13
14VHD_DESC=	Azure, VirtualPC, Hyper-V, Xen disk image
15VMDK_DESC=	VMWare, VirtualBox disk image
16QCOW2_DESC=	Qemu, KVM disk image
17RAW_DESC=	Unformatted raw disk image
18
19CLOUDWARE?=	EC2 \
20		GCE \
21		VAGRANT-VIRTUALBOX \
22		VAGRANT-VMWARE
23AZURE_FORMAT=	vhdf
24AZURE_DESC=	Microsoft Azure platform image
25AZURE_DISK=	${OSRELEASE}.${AZURE_FORMAT}
26EC2_FORMAT=	raw
27EC2_DESC=	Amazon EC2 image
28EC2_DISK=	${OSRELEASE}.${EC2_FORMAT}
29GCE_FORMAT=	raw
30GCE_DESC=	Google Compute Engine image
31GCE_DISK=	disk.${GCE_FORMAT}
32OPENSTACK_FORMAT=qcow2
33OPENSTACK_DESC=	OpenStack platform image
34OPENSTACK_DISK=	${OSRELEASE}.${OPENSTACK_FORMAT}
35VAGRANT-VIRTUALBOX_FORMAT=	vmdk
36VAGRANT-VIRTUALBOX_DESC=	Vagrant Image for VirtualBox
37VAGRANT-VIRTUALBOX_DISK=	${OSRELEASE}.vbox.${VAGRANT_FORMAT}
38VAGRANT-VMWARE_FORMAT=	vmdk
39VAGRANT-VMWARE_DESC=	Vagrant Image for VMWare
40VAGRANT-VMWARE_DISK=	${OSRELEASE}.vmware.${VAGRANT_FORMAT}
41
42emulator-portinstall:
43.if ${TARGET_ARCH} != ${MACHINE_ARCH}
44.if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" )
45.if !exists(/usr/local/bin/qemu-${TARGET_ARCH}-static)
46.if exists(${PORTSDIR}/emulators/qemu-user-static/Makefile)
47	env - PATH=$$PATH make -C ${PORTSDIR}/emulators/qemu-user-static BATCH=1 all install clean
48.else
49.if !exists(/usr/local/sbin/pkg-static)
50	env ASSUME_ALWAYS_YES=yes pkg bootstrap -y
51.endif
52	env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static
53.endif
54.endif
55
56QEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static
57.endif
58.endif
59
60.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
61. for _CW in ${CLOUDWARE}
62CLOUDTARGETS+=	cw-${_CW:tl}
63CLEANDIRS+=	cw-${_CW:tl}
64CLEANFILES+=	${_CW:tl}.img \
65		${_CW:tl}.${${_CW:tu}_FORMAT} \
66		${_CW:tl}.${${_CW:tu}_FORMAT}.raw \
67		cw${_CW:tl}-package
68CLOUDPACKAGE+=	cw${_CW:tl}-package
69${_CW:tu}IMAGE=	${_CW:tl}.${${_CW:tu}_FORMAT}
70.  if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF)
71${_CW:tu}CONF?=	${.CURDIR}/tools/${_CW:tl}.conf
72.  endif
73
74cw-${_CW:tl}: emulator-portinstall
75	mkdir -p ${.OBJDIR}/${.TARGET}
76	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
77		QEMUSTATIC=${QEMUSTATIC} \
78		${.CURDIR}/scripts/mk-vmimage.sh \
79		-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \
80		-i ${.OBJDIR}/${_CW:tl}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \
81		-S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}IMAGE} -c ${${_CW:tu}CONF}
82	touch ${.TARGET}
83
84cw${_CW:tl}-package:
85	@# Special target to handle packaging cloud images in the formats
86	@# specific to each hosting provider.
87.if exists(${.CURDIR}/tools/${_CW:tl}-package.sh)
88	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
89		${.CURDIR}/tools/${_CW:tl}-package.sh \
90		-D ${DESTDIR} -I ${${_CW}_DISK} -S ${WORLDDIR}
91.endif
92	touch ${.TARGET}
93
94. endfor
95.endif
96
97.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
98CLEANDIRS+=	${VMTARGETS}
99. for FORMAT in ${VMFORMATS}
100CLEANFILES+=	${FORMAT}.img
101CLEANFILES+=	${VMBASE}.${FORMAT}
102. endfor
103.endif
104
105vm-base:	vm-image
106
107vm-image:
108.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
109. for FORMAT in ${VMFORMATS}
110	mkdir -p ${.OBJDIR}/${.TARGET}
111	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
112		${.CURDIR}/scripts/mk-vmimage.sh \
113		-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \
114		-i ${.OBJDIR}/${FORMAT}.img -s ${VMSIZE} -f ${FORMAT} \
115		-S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FORMAT}
116. endfor
117.endif
118	touch ${.TARGET}
119
120vm-cloudware:	${CLOUDTARGETS}
121
122list-vmtargets:	list-cloudware
123	@${ECHO}
124	@${ECHO} "Supported virtual machine disk image formats:"
125.for FORMAT in ${VMFORMATS:tu}
126	@${ECHO} "  ${FORMAT:tl}: ${${FORMAT}_DESC}"
127.endfor
128
129list-cloudware:
130.if !empty(CLOUDWARE)
131	@${ECHO}
132	@${ECHO} "Supported cloud hosting provider images:"
133. for _CW in ${CLOUDWARE}
134	@${ECHO} "  ${_CW:tu}: ${${_CW:tu}_DESC}"
135. endfor
136.endif
137
138vm-install:
139.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
140	mkdir -p ${DESTDIR}/vmimages
141. for FORMAT in ${VMFORMATS}
142	cp -p ${VMBASE}.${FORMAT} \
143		${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
144. endfor
145. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
146.  for FORMAT in ${VMFORMATS}
147	# Don't keep the originals.  There is a copy in ${.OBJDIR} if needed.
148	${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
149.  endfor
150. endif
151	cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \
152		${DESTDIR}/vmimages/CHECKSUM.SHA512
153	cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \
154		${DESTDIR}/vmimages/CHECKSUM.SHA256
155.endif
156
157vm-release:
158.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
159	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS}
160.endif
161
162cloudware-release:
163.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
164	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS}
165.endif
166
167.include "${.CURDIR}/Makefile.ec2"
168.include "${.CURDIR}/Makefile.azure"
169.include "${.CURDIR}/Makefile.gce"
170.include "${.CURDIR}/Makefile.vagrant"
171