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