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