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: 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 ${.CURDIR}/scripts/mk-vmimage.sh \ 167 -C ${.CURDIR}/tools/vmimage.subr \ 168 -d ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS} -F ${FS} \ 169 -i ${.OBJDIR}/${FORMAT}.${FS}.img -s ${VMSIZE} -f ${FORMAT} \ 170 -S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FS}.${FORMAT} 171. endfor 172. endfor 173.endif 174 touch ${.TARGET} 175 176vm-cloudware: ${CLOUDTARGETS} 177 178list-vmtargets: list-cloudware 179 @${ECHO} 180 @${ECHO} "Supported virtual machine disk image formats:" 181.for FORMAT in ${VMFORMATS:tu} 182 @${ECHO} " ${FORMAT:tl}: ${${FORMAT}_DESC}" 183.endfor 184 185list-cloudware: 186.if !empty(CLOUDWARE) 187 @${ECHO} 188 @${ECHO} "Supported cloud hosting provider images:" 189. for _CW in ${CLOUDWARE} 190 @${ECHO} " ${_CW:tu}: ${${_CW:tu}_DESC}" 191. endfor 192.endif 193 194vm-install: 195.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 196 mkdir -p ${DESTDIR}/vmimages 197. for FORMAT in ${VMFORMATS} 198. for FS in ${VMFSLIST} 199 cp -p ${VMBASE}.${FS}.${FORMAT} \ 200 ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT} 201. endfor 202. endfor 203. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 204. for FORMAT in ${VMFORMATS} 205. for FS in ${VMFSLIST} 206 # Don't keep the originals. There is a copy in ${.OBJDIR} if needed. 207 ${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT} 208. endfor 209. endfor 210. endif 211 # Compatibility hardlinks from "foo.bar" to "foo-${VMFS}.bar". 212. for FORMAT in ${VMFORMATS} 213. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 214 ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT}.xz ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}.xz 215. else 216 ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT} 217. endif 218. endfor 219 cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \ 220 ${DESTDIR}/vmimages/CHECKSUM.SHA512 221 cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \ 222 ${DESTDIR}/vmimages/CHECKSUM.SHA256 223.endif 224 225vm-release: 226.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 227 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS} 228.endif 229 230cloudware-release: 231.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 232 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS} 233.endif 234 235.include "${.CURDIR}/Makefile.azure" 236.include "${.CURDIR}/Makefile.ec2" 237.include "${.CURDIR}/Makefile.firecracker" 238.include "${.CURDIR}/Makefile.gce" 239.include "${.CURDIR}/Makefile.vagrant" 240.include "${.CURDIR}/Makefile.inc1" 241