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 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.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 43. for _CW in ${CLOUDWARE} 44CLOUDTARGETS+= cw-${_CW:tl} 45CLEANDIRS+= cw-${_CW:tl} 46CLEANFILES+= ${_CW:tl}.img \ 47 ${_CW:tl}.${${_CW:tu}_FORMAT} \ 48 ${_CW:tl}.${${_CW:tu}_FORMAT}.raw \ 49 cw${_CW:tl}-package 50CLOUDPACKAGE+= cw${_CW:tl}-package 51${_CW:tu}IMAGE= ${_CW:tl}.${${_CW:tu}_FORMAT} 52. if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF) 53${_CW:tu}CONF?= ${.CURDIR}/tools/${_CW:tl}.conf 54. endif 55 56cw-${_CW:tl}: 57 mkdir -p ${.OBJDIR}/${.TARGET} 58 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \ 59 ${.CURDIR}/scripts/mk-vmimage.sh \ 60 -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \ 61 -i ${.OBJDIR}/${_CW:tl}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \ 62 -S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}IMAGE} -c ${${_CW:tu}CONF} 63 touch ${.TARGET} 64 65cw${_CW:tl}-package: 66 @# Special target to handle packaging cloud images in the formats 67 @# specific to each hosting provider. 68.if exists(${.CURDIR}/tools/${_CW:tl}-package.sh) 69 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ 70 ${.CURDIR}/tools/${_CW:tl}-package.sh \ 71 -D ${DESTDIR} -I ${${_CW}_DISK} -S ${WORLDDIR} 72.endif 73 touch ${.TARGET} 74 75. endfor 76.endif 77 78.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 79CLEANDIRS+= ${VMTARGETS} 80. for FORMAT in ${VMFORMATS} 81CLEANFILES+= ${FORMAT}.img 82CLEANFILES+= ${VMBASE}.${FORMAT} 83. endfor 84.endif 85 86vm-base: vm-image 87 88vm-image: 89.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 90. for FORMAT in ${VMFORMATS} 91 mkdir -p ${.OBJDIR}/${.TARGET} 92 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \ 93 ${.CURDIR}/scripts/mk-vmimage.sh \ 94 -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} \ 95 -i ${.OBJDIR}/${FORMAT}.img -s ${VMSIZE} -f ${FORMAT} \ 96 -S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FORMAT} 97. endfor 98.endif 99 touch ${.TARGET} 100 101vm-cloudware: ${CLOUDTARGETS} 102 103list-vmtargets: list-cloudware 104 @${ECHO} 105 @${ECHO} "Supported virtual machine disk image formats:" 106.for FORMAT in ${VMFORMATS:tu} 107 @${ECHO} " ${FORMAT:tl}: ${${FORMAT}_DESC}" 108.endfor 109 110list-cloudware: 111.if !empty(CLOUDWARE) 112 @${ECHO} 113 @${ECHO} "Supported cloud hosting provider images:" 114. for _CW in ${CLOUDWARE} 115 @${ECHO} " ${_CW:tu}: ${${_CW:tu}_DESC}" 116. endfor 117.endif 118 119vm-install: 120.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 121 mkdir -p ${DESTDIR}/vmimages 122. for FORMAT in ${VMFORMATS} 123 cp -p ${VMBASE}.${FORMAT} \ 124 ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT} 125. endfor 126. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 127. for FORMAT in ${VMFORMATS} 128 # Don't keep the originals. There is a copy in ${.OBJDIR} if needed. 129 ${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT} 130. endfor 131. endif 132 cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \ 133 ${DESTDIR}/vmimages/CHECKSUM.SHA512 134 cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \ 135 ${DESTDIR}/vmimages/CHECKSUM.SHA256 136.endif 137 138vm-release: 139.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 140 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS} 141.endif 142 143cloudware-release: 144.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 145 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS} 146.endif 147 148.include "${.CURDIR}/Makefile.ec2" 149.include "${.CURDIR}/Makefile.azure" 150.include "${.CURDIR}/Makefile.gce" 151.include "${.CURDIR}/Makefile.vagrant" 152