1# 2# 3# 4# Makefile for building virtual machine and cloud provider disk images. 5# 6 7VMTARGETS= vm-image 8VMFORMATS?= vhd vmdk qcow2 raw 9VMSIZE?= 5120m 10VMFS?= ufs 11VMFSLIST?= ufs zfs 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_TYPES?= BASIC-CI \ 21 EC2 \ 22 GCE \ 23 OCI \ 24 VAGRANT 25AZURE_FORMAT= vhdf 26AZURE_FSLIST= ufs zfs 27AZURE_DESC= Microsoft Azure platform image 28BASIC-CI_FORMAT= raw 29BASIC-CI_FSLIST= ufs 30BASIC-CI_DESC= Image for CI 31EC2_FORMAT= raw 32EC2_FSLIST= ufs zfs 33EC2_FLAVOURS= BASE CLOUD-INIT 34EC2-BASE_DESC= Amazon EC2 image 35EC2-CLOUD-INIT_DESC= Amazon EC2 Cloud-Init image 36GCE_FORMAT= raw 37GCE_FSLIST= ufs zfs 38GCE_DESC= Google Compute Engine image 39OCI_FORMAT= qcow2 40OCI_FSLIST= ufs 41OCI_DESC= Oracle Cloud Infrastructure image 42OPENSTACK_FORMAT=qcow2 43OPENSTACK_FSLIST= ufs 44OPENSTACK_DESC= OpenStack platform image 45VAGRANT_FORMAT= vmdk 46VAGRANT_FSLIST= ufs 47VAGRANT_FLAVOURS= VIRTUALBOX VMWARE 48VAGRANT-VIRTUALBOX_DESC= Vagrant Image for VirtualBox 49VAGRANT-VMWARE_DESC= Vagrant Image for VMWare 50 51.for _CWT in ${CLOUDWARE_TYPES} 52. if defined(${_CWT}_FLAVOURS) 53. for _CWF in ${${_CWT}_FLAVOURS} 54CLOUDWARE_GEN+= ${_CWT}-${_CWF} 55${_CWT}-${_CWF}_FORMAT?= ${${_CWT}_FORMAT} 56${_CWT}-${_CWF}_FSLIST?= ${${_CWT}_FSLIST} 57${_CWT}-${_CWF}_DESC?= ${${_CWT}_DESC} 58. endfor 59. else 60CLOUDWARE_GEN+= ${_CWT} 61. endif 62.endfor 63CLOUDWARE?= ${CLOUDWARE_GEN} 64 65.for _V in TYPE BRANCH REVISION 66. if !defined(${_V}) || empty(${_V}) 67${_V}!= eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V} 68. endif 69.endfor 70 71emulator-portinstall: 72.if ${TARGET_ARCH} != ${MACHINE_ARCH} 73.if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" ) 74.if !exists(/usr/local/bin/qemu-${TARGET_ARCH}-static) 75.if exists(${PORTSDIR}/emulators/qemu-user-static/Makefile) 76 env - UNAME_r=${UNAME_r} PATH=$$PATH make -C ${PORTSDIR}/emulators/qemu-user-static BATCH=1 all install clean 77.else 78.if !exists(/usr/local/sbin/pkg-static) 79 env ASSUME_ALWAYS_YES=yes pkg bootstrap -y 80.endif 81 env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static 82.endif 83.endif 84 85QEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static 86.endif 87.endif 88 89.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 90. for _CW in ${CLOUDWARE} 91. if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF) 92${_CW:tu}CONF?= ${.CURDIR}/tools/${_CW:tl}.conf 93. endif 94. for _FS in ${${_CW:tu}_FSLIST} 95CLOUDTARGETS+= cw-${_CW:tl}-${_FS} 96CLEANDIRS+= cw-${_CW:tl}-${_FS} 97CLEANFILES+= ${_CW:tl}.${_FS}.img \ 98 ${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT} \ 99 ${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT}.raw 100${_CW:tu}${_FS:tu}IMAGE= ${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT} 101 102cw-${_CW:tl}-${_FS}: emulator-portinstall 103 mkdir -p ${.OBJDIR}/${.TARGET} 104 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \ 105 QEMUSTATIC=${QEMUSTATIC} \ 106 ${.CURDIR}/scripts/mk-vmimage.sh \ 107 -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${_FS} \ 108 -i ${.OBJDIR}/${_CW:tl}.${_FS}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \ 109 -S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}${_FS:tu}IMAGE} -c ${${_CW:tu}CONF} 110 touch ${.TARGET} 111. endfor 112 113# Hardlinks from "foo.bar" to "foo-${VMFS}.bar". These can go away once all 114# of the cloudware code knows how to handle multiple filesystem images (or 115# at least knows the name of the UFS image). 116CLOUDTARGETS+= cw-${_CW:tl} 117CLEANFILES+= ${_CW:tl}.${${_CW:tu}_FORMAT} 118${_CW:tu}IMAGE= ${_CW:tl}.${${_CW:tu}_FORMAT} 119cw-${_CW:tl}: cw-${_CW:tl}-${VMFS} 120 ln -f ${${_CW:tu}${VMFS:tu}IMAGE} ${${_CW:tu}IMAGE} 121. endfor 122.endif 123 124.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 125CLEANDIRS+= ${VMTARGETS} 126. for FORMAT in ${VMFORMATS} 127. for FS in ${VMFSLIST} 128CLEANFILES+= ${FORMAT}.${FS}.img 129CLEANFILES+= ${VMBASE}.${FS}.${FORMAT} 130. endfor 131. endfor 132.endif 133 134vm-base: vm-image 135 136vm-image: 137.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 138. for FORMAT in ${VMFORMATS} 139. for FS in ${VMFSLIST} 140 mkdir -p ${.OBJDIR}/${.TARGET} 141 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \ 142 ${.CURDIR}/scripts/mk-vmimage.sh \ 143 -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${FS} \ 144 -i ${.OBJDIR}/${FORMAT}.${FS}.img -s ${VMSIZE} -f ${FORMAT} \ 145 -S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FS}.${FORMAT} 146. endfor 147. endfor 148.endif 149 touch ${.TARGET} 150 151vm-cloudware: ${CLOUDTARGETS} 152 153list-vmtargets: list-cloudware 154 @${ECHO} 155 @${ECHO} "Supported virtual machine disk image formats:" 156.for FORMAT in ${VMFORMATS:tu} 157 @${ECHO} " ${FORMAT:tl}: ${${FORMAT}_DESC}" 158.endfor 159 160list-cloudware: 161.if !empty(CLOUDWARE) 162 @${ECHO} 163 @${ECHO} "Supported cloud hosting provider images:" 164. for _CW in ${CLOUDWARE} 165 @${ECHO} " ${_CW:tu}: ${${_CW:tu}_DESC}" 166. endfor 167.endif 168 169vm-install: 170.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 171 mkdir -p ${DESTDIR}/vmimages 172. for FORMAT in ${VMFORMATS} 173. for FS in ${VMFSLIST} 174 cp -p ${VMBASE}.${FS}.${FORMAT} \ 175 ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT} 176. endfor 177. endfor 178. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 179. for FORMAT in ${VMFORMATS} 180. for FS in ${VMFSLIST} 181 # Don't keep the originals. There is a copy in ${.OBJDIR} if needed. 182 ${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT} 183. endfor 184. endfor 185. endif 186 # Compatibility hardlinks from "foo.bar" to "foo-${VMFS}.bar". 187. for FORMAT in ${VMFORMATS} 188. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 189 ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT}.xz ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}.xz 190. else 191 ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT} 192. endif 193. endfor 194 cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \ 195 ${DESTDIR}/vmimages/CHECKSUM.SHA512 196 cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \ 197 ${DESTDIR}/vmimages/CHECKSUM.SHA256 198.endif 199 200vm-release: 201.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 202 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS} 203.endif 204 205cloudware-release: 206.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 207 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS} 208.endif 209 210.include "${.CURDIR}/Makefile.azure" 211.include "${.CURDIR}/Makefile.ec2" 212.include "${.CURDIR}/Makefile.firecracker" 213.include "${.CURDIR}/Makefile.gce" 214.include "${.CURDIR}/Makefile.vagrant" 215.include "${.CURDIR}/Makefile.inc1" 216