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 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 make -C ${PORTSDIR}/emulators/qemu-user-static BATCH=1 all install clean 80.else 81.if !exists(/usr/local/sbin/pkg-static) 82 env ASSUME_ALWAYS_YES=yes pkg bootstrap -y 83.endif 84 env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static 85.endif 86.endif 87 touch ${.TARGET} 88 89.if ${TARGET_ARCH} != ${MACHINE_ARCH} 90.if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" ) 91QEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static 92QEMUTGT=emulator-portinstall 93.endif 94.endif 95QEMUTGT?= 96 97.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 98. for _CW in ${CLOUDWARE} 99. if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF) 100${_CW:tu}CONF?= ${.CURDIR}/tools/${_CW:tl}.conf 101. endif 102. for _FS in ${${_CW:tu}_FSLIST} 103CLOUDTARGETS+= cw-${_CW:tl}-${_FS} 104CLEANDIRS+= cw-${_CW:tl}-${_FS} 105CLEANFILES+= ${_CW:tl}.${_FS}.img \ 106 ${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT} \ 107 ${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT}.raw 108${_CW:tu}${_FS:tu}IMAGE= ${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT} 109 110cw-${_CW:tl}-${_FS}: ${QEMUTGT} 111 mkdir -p ${.OBJDIR}/${.TARGET} 112 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \ 113 QEMUSTATIC=${QEMUSTATIC} \ 114 ${.CURDIR}/scripts/mk-vmimage.sh \ 115 -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${_FS} \ 116 -i ${.OBJDIR}/${_CW:tl}.${_FS}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \ 117 -S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}${_FS:tu}IMAGE} -c ${${_CW:tu}CONF} 118 touch ${.TARGET} 119. endfor 120 121# Hardlinks from "foo.bar" to "foo-${VMFS}.bar". These can go away once all 122# of the cloudware code knows how to handle multiple filesystem images (or 123# at least knows the name of the UFS image). 124CLOUDTARGETS+= cw-${_CW:tl} 125CLEANFILES+= ${_CW:tl}.${${_CW:tu}_FORMAT} 126${_CW:tu}IMAGE= ${_CW:tl}.${${_CW:tu}_FORMAT} 127cw-${_CW:tl}: cw-${_CW:tl}-${VMFS} 128 ln -f ${${_CW:tu}${VMFS:tu}IMAGE} ${${_CW:tu}IMAGE} 129. endfor 130.endif 131 132.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 133CLEANDIRS+= ${VMTARGETS} 134. for FORMAT in ${VMFORMATS} 135. for FS in ${VMFSLIST} 136CLEANFILES+= ${FORMAT}.${FS}.img 137CLEANFILES+= ${VMBASE}.${FS}.${FORMAT} 138. endfor 139. endfor 140.endif 141 142vm-base: vm-image 143 144vm-image: 145.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 146. for FORMAT in ${VMFORMATS} 147. for FS in ${VMFSLIST} 148 mkdir -p ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS} 149 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \ 150 ${.CURDIR}/scripts/mk-vmimage.sh \ 151 -C ${.CURDIR}/tools/vmimage.subr \ 152 -d ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS} -F ${FS} \ 153 -i ${.OBJDIR}/${FORMAT}.${FS}.img -s ${VMSIZE} -f ${FORMAT} \ 154 -S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FS}.${FORMAT} 155. endfor 156. endfor 157.endif 158 touch ${.TARGET} 159 160vm-cloudware: ${CLOUDTARGETS} 161 162list-vmtargets: list-cloudware 163 @${ECHO} 164 @${ECHO} "Supported virtual machine disk image formats:" 165.for FORMAT in ${VMFORMATS:tu} 166 @${ECHO} " ${FORMAT:tl}: ${${FORMAT}_DESC}" 167.endfor 168 169list-cloudware: 170.if !empty(CLOUDWARE) 171 @${ECHO} 172 @${ECHO} "Supported cloud hosting provider images:" 173. for _CW in ${CLOUDWARE} 174 @${ECHO} " ${_CW:tu}: ${${_CW:tu}_DESC}" 175. endfor 176.endif 177 178vm-install: 179.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 180 mkdir -p ${DESTDIR}/vmimages 181. for FORMAT in ${VMFORMATS} 182. for FS in ${VMFSLIST} 183 cp -p ${VMBASE}.${FS}.${FORMAT} \ 184 ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT} 185. endfor 186. endfor 187. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 188. for FORMAT in ${VMFORMATS} 189. for FS in ${VMFSLIST} 190 # Don't keep the originals. There is a copy in ${.OBJDIR} if needed. 191 ${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT} 192. endfor 193. endfor 194. endif 195 # Compatibility hardlinks from "foo.bar" to "foo-${VMFS}.bar". 196. for FORMAT in ${VMFORMATS} 197. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 198 ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT}.xz ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}.xz 199. else 200 ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT} 201. endif 202. endfor 203 cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \ 204 ${DESTDIR}/vmimages/CHECKSUM.SHA512 205 cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \ 206 ${DESTDIR}/vmimages/CHECKSUM.SHA256 207.endif 208 209vm-release: 210.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 211 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS} 212.endif 213 214cloudware-release: 215.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 216 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS} 217.endif 218 219.include "${.CURDIR}/Makefile.azure" 220.include "${.CURDIR}/Makefile.ec2" 221.include "${.CURDIR}/Makefile.firecracker" 222.include "${.CURDIR}/Makefile.gce" 223.include "${.CURDIR}/Makefile.vagrant" 224.include "${.CURDIR}/Makefile.inc1" 225