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