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