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?= AZURE \ 19 GCE \ 20 OPENSTACK 21AZURE_FORMAT= vhdf 22AZURE_DESC= Microsoft Azure platform image 23GCE_FORMAT= raw 24GCE_DESC= Google Compute Engine image 25OPENSTACK_FORMAT=qcow2 26OPENSTACK_DESC= OpenStack platform image 27 28.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 29. for _CW in ${CLOUDWARE} 30CLOUDTARGETS+= vm-${_CW:tl} 31CLEANDIRS+= vm-${_CW:tl} 32CLEANFILES+= ${_CW:tl}.img \ 33 ${_CW:tl}.${${_CW:tu}_FORMAT} \ 34 ${_CW:tl}.${${_CW:tu}_FORMAT}.raw 35${_CW:tu}IMAGE= ${_CW:tl}.${${_CW:tu}_FORMAT} 36. if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF) 37${_CW:tu}CONF?= ${.CURDIR}/tools/${_CW:tl}.conf 38. endif 39 40vm-${_CW:tl}: 41 mkdir -p ${.OBJDIR}/${.TARGET} 42 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ 43 ${.CURDIR}/scripts/mk-vmimage.sh \ 44 -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \ 45 -i ${.OBJDIR}/${_CW:tl}.img -s ${VMSIZE} -f ${${_CW}_FORMAT} \ 46 -S ${WORLDDIR} -o ${.OBJDIR}/${${_CW}IMAGE} -c ${${_CW}CONF} 47 touch ${.TARGET} 48. endfor 49.endif 50 51.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 52CLEANDIRS+= ${VMTARGETS} 53. for FORMAT in ${VMFORMATS} 54CLEANFILES+= ${FORMAT}.img 55CLEANFILES+= ${VMBASE}.${FORMAT} 56. endfor 57.endif 58 59vm-base: vm-image 60 61vm-image: 62.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 63. for FORMAT in ${VMFORMATS} 64 mkdir -p ${.OBJDIR}/${.TARGET} 65 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ 66 ${.CURDIR}/scripts/mk-vmimage.sh \ 67 -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \ 68 -i ${.OBJDIR}/${FORMAT}.img -s ${VMSIZE} -f ${FORMAT} \ 69 -S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FORMAT} 70. endfor 71.endif 72 touch ${.TARGET} 73 74vm-cloudware: ${CLOUDTARGETS} 75 76list-vmtargets: list-cloudware 77 @${ECHO} 78 @${ECHO} "Supported virtual machine disk image formats:" 79.for FORMAT in ${VMFORMATS:tu} 80 @${ECHO} " ${FORMAT:tl}: ${${FORMAT}_DESC}" 81.endfor 82 83list-cloudware: 84.if !empty(CLOUDWARE) 85 @${ECHO} 86 @${ECHO} "Supported cloud hosting provider images:" 87. for _CW in ${CLOUDWARE} 88 @${ECHO} " ${_CW:tu}: ${${_CW:tu}_DESC}" 89. endfor 90.endif 91 92vm-install: 93.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 94 mkdir -p ${DESTDIR}/vmimages 95. for FORMAT in ${VMFORMATS} 96 cp -p ${VMBASE}.${FORMAT} \ 97 ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT} 98. endfor 99. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 100# This is very time consuming, so defer it after the images are moved to 101# the DESTDIR. 102. for FORMAT in ${VMFORMATS} 103 # Don't keep the originals. There is a copy in ${.OBJDIR} if needed. 104 ${XZCMD} ${XZ_FLAGS} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT} 105. endfor 106. endif 107 cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \ 108 ${DESTDIR}/vmimages/CHECKSUM.SHA256 109 cd ${DESTDIR}/vmimages && md5 ${OSRELEASE}* > \ 110 ${DESTDIR}/vmimages/CHECKSUM.MD5 111.endif 112 113vm-release: 114.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 115 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS} 116.endif 117 118cloudware-release: 119.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 120 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS} 121.endif 122