xref: /freebsd/release/Makefile.vm (revision da477bcdc0c335171bb0ed3813f570026de6df85)
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?=	4096M
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
42.for _V in TYPE BRANCH REVISION
43. if !defined(${_V}) || empty(${_V})
44${_V}!=	eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V}
45. endif
46.endfor
47
48emulator-portinstall:
49.if ${TARGET_ARCH} != ${MACHINE_ARCH}
50.if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" )
51.if !exists(/usr/local/bin/qemu-${TARGET_ARCH}-static)
52.if exists(${PORTSDIR}/emulators/qemu-user-static/Makefile)
53	env - PATH=$$PATH make -C ${PORTSDIR}/emulators/qemu-user-static BATCH=1 all install clean
54.else
55.if !exists(/usr/local/sbin/pkg-static)
56	env ASSUME_ALWAYS_YES=yes pkg bootstrap -y
57.endif
58	env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static
59.endif
60.endif
61
62QEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static
63.endif
64.endif
65
66.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
67. for _CW in ${CLOUDWARE}
68CLOUDTARGETS+=	cw-${_CW:tl}
69CLEANDIRS+=	cw-${_CW:tl}
70CLEANFILES+=	${_CW:tl}.img \
71		${_CW:tl}.${${_CW:tu}_FORMAT} \
72		${_CW:tl}.${${_CW:tu}_FORMAT}.raw \
73		cw${_CW:tl}-package
74CLOUDPACKAGE+=	cw${_CW:tl}-package
75${_CW:tu}IMAGE=	${_CW:tl}.${${_CW:tu}_FORMAT}
76.  if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF)
77${_CW:tu}CONF?=	${.CURDIR}/tools/${_CW:tl}.conf
78.  endif
79
80cw-${_CW:tl}: emulator-portinstall
81	mkdir -p ${.OBJDIR}/${.TARGET}
82	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
83		QEMUSTATIC=${QEMUSTATIC} \
84		${.CURDIR}/scripts/mk-vmimage.sh \
85		-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \
86		-i ${.OBJDIR}/${_CW:tl}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \
87		-S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}IMAGE} -c ${${_CW:tu}CONF}
88	touch ${.TARGET}
89
90cw${_CW:tl}-package:
91	@# Special target to handle packaging cloud images in the formats
92	@# specific to each hosting provider.
93.if exists(${.CURDIR}/tools/${_CW:tl}-package.sh)
94	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
95		${.CURDIR}/tools/${_CW:tl}-package.sh \
96		-D ${DESTDIR} -I ${${_CW}_DISK} -S ${WORLDDIR}
97.endif
98	touch ${.TARGET}
99
100. endfor
101.endif
102
103.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
104CLEANDIRS+=	${VMTARGETS}
105. for FORMAT in ${VMFORMATS}
106CLEANFILES+=	${FORMAT}.img
107CLEANFILES+=	${VMBASE}.${FORMAT}
108. endfor
109.endif
110
111vm-base:	vm-image
112
113vm-image:
114.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
115. for FORMAT in ${VMFORMATS}
116	mkdir -p ${.OBJDIR}/${.TARGET}
117	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
118		${.CURDIR}/scripts/mk-vmimage.sh \
119		-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \
120		-i ${.OBJDIR}/${FORMAT}.img -s ${VMSIZE} -f ${FORMAT} \
121		-S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FORMAT}
122. endfor
123.endif
124	touch ${.TARGET}
125
126vm-cloudware:	${CLOUDTARGETS}
127
128list-vmtargets:	list-cloudware
129	@${ECHO}
130	@${ECHO} "Supported virtual machine disk image formats:"
131.for FORMAT in ${VMFORMATS:tu}
132	@${ECHO} "  ${FORMAT:tl}: ${${FORMAT}_DESC}"
133.endfor
134
135list-cloudware:
136.if !empty(CLOUDWARE)
137	@${ECHO}
138	@${ECHO} "Supported cloud hosting provider images:"
139. for _CW in ${CLOUDWARE}
140	@${ECHO} "  ${_CW:tu}: ${${_CW:tu}_DESC}"
141. endfor
142.endif
143
144vm-install:
145.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
146	mkdir -p ${DESTDIR}/vmimages
147. for FORMAT in ${VMFORMATS}
148	cp -p ${VMBASE}.${FORMAT} \
149		${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
150. endfor
151. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
152.  for FORMAT in ${VMFORMATS}
153	# Don't keep the originals.  There is a copy in ${.OBJDIR} if needed.
154	${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
155.  endfor
156. endif
157	cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \
158		${DESTDIR}/vmimages/CHECKSUM.SHA512
159	cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \
160		${DESTDIR}/vmimages/CHECKSUM.SHA256
161.endif
162
163vm-release:
164.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
165	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS}
166.endif
167
168cloudware-release:
169.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
170	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS}
171.endif
172
173.include "${.CURDIR}/Makefile.ec2"
174.include "${.CURDIR}/Makefile.azure"
175.include "${.CURDIR}/Makefile.gce"
176.include "${.CURDIR}/Makefile.vagrant"
177