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