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