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