16513e474SGlen Barber# 26513e474SGlen Barber# 36513e474SGlen Barber# 46513e474SGlen Barber# Makefile for building virtual machine and cloud provider disk images. 56513e474SGlen Barber# 66513e474SGlen Barber 71e7c1f17SGlen BarberVMTARGETS= vm-image 86513e474SGlen BarberVMFORMATS?= vhd vmdk qcow2 raw 91dfcff29SGlen BarberVMSIZE?= 5120m 1089585511SMark JohnstonVMFS?= ufs 1132ae9a6bSColin PercivalVMFSLIST?= ufs zfs 12fa04db47SGlen BarberSWAPSIZE?= 1g 136513e474SGlen BarberVMBASE?= vm 14d08ce983SGlen Barber 1585311c29SGlen BarberVHD_DESC= Azure, VirtualPC, Hyper-V, Xen disk image 1685311c29SGlen BarberVMDK_DESC= VMWare, VirtualBox disk image 1785311c29SGlen BarberQCOW2_DESC= Qemu, KVM disk image 1885311c29SGlen BarberRAW_DESC= Unformatted raw disk image 1985311c29SGlen Barber 20e6eeac9bSColin PercivalCLOUDWARE_TYPES?= BASIC-CI \ 21ea070051SEmmanuel Vadot EC2 \ 225f87b8f5SGlen Barber GCE \ 230af49f00SDave Cottlehuber OCI \ 24e6eeac9bSColin Percival VAGRANT 25f27438c7SGlen BarberAZURE_FORMAT= vhdf 2678f901dcSLi-Wen HsuAZURE_FSLIST= ufs zfs 2799e908c9SGlen BarberAZURE_DESC= Microsoft Azure platform image 28ea070051SEmmanuel VadotBASIC-CI_FORMAT= raw 298dec4738SColin PercivalBASIC-CI_FSLIST= ufs 30ea070051SEmmanuel VadotBASIC-CI_DESC= Image for CI 31f65557efSColin PercivalEC2_FORMAT= raw 32219caac6SColin PercivalEC2_FSLIST= ufs zfs 331f4ce7a3SColin PercivalEC2_FLAVOURS= BASE CLOUD-INIT 341f4ce7a3SColin PercivalEC2-BASE_DESC= Amazon EC2 image 351f4ce7a3SColin PercivalEC2-CLOUD-INIT_DESC= Amazon EC2 Cloud-Init image 365f87b8f5SGlen BarberGCE_FORMAT= raw 371b10bdf0SLi-Wen HsuGCE_FSLIST= ufs zfs 385f87b8f5SGlen BarberGCE_DESC= Google Compute Engine image 390af49f00SDave CottlehuberOCI_FORMAT= qcow2 408dec4738SColin PercivalOCI_FSLIST= ufs 410af49f00SDave CottlehuberOCI_DESC= Oracle Cloud Infrastructure image 42573e7ccaSGlen BarberOPENSTACK_FORMAT=qcow2 438dec4738SColin PercivalOPENSTACK_FSLIST= ufs 4499e908c9SGlen BarberOPENSTACK_DESC= OpenStack platform image 45e6eeac9bSColin PercivalVAGRANT_FORMAT= vmdk 46e6eeac9bSColin PercivalVAGRANT_FSLIST= ufs 47e6eeac9bSColin PercivalVAGRANT_FLAVOURS= VIRTUALBOX VMWARE 48a54bd595SBrad DavisVAGRANT-VIRTUALBOX_DESC= Vagrant Image for VirtualBox 49a54bd595SBrad DavisVAGRANT-VMWARE_DESC= Vagrant Image for VMWare 50d08ce983SGlen Barber 51e6eeac9bSColin Percival.for _CWT in ${CLOUDWARE_TYPES} 52e6eeac9bSColin Percival. if defined(${_CWT}_FLAVOURS) 53e6eeac9bSColin Percival. for _CWF in ${${_CWT}_FLAVOURS} 54e6eeac9bSColin PercivalCLOUDWARE_GEN+= ${_CWT}-${_CWF} 55e6eeac9bSColin Percival${_CWT}-${_CWF}_FORMAT?= ${${_CWT}_FORMAT} 56e6eeac9bSColin Percival${_CWT}-${_CWF}_FSLIST?= ${${_CWT}_FSLIST} 57e6eeac9bSColin Percival${_CWT}-${_CWF}_DESC?= ${${_CWT}_DESC} 58e6eeac9bSColin Percival. endfor 59e6eeac9bSColin Percival. else 60e6eeac9bSColin PercivalCLOUDWARE_GEN+= ${_CWT} 61e6eeac9bSColin Percival. endif 62e6eeac9bSColin Percival.endfor 63e6eeac9bSColin PercivalCLOUDWARE?= ${CLOUDWARE_GEN} 64e6eeac9bSColin Percival 65e2827b51SGlen Barber.for _V in TYPE BRANCH REVISION 66e2827b51SGlen Barber. if !defined(${_V}) || empty(${_V}) 67e2827b51SGlen Barber${_V}!= eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V} 68e2827b51SGlen Barber. endif 69e2827b51SGlen Barber.endfor 70e2827b51SGlen Barber 711ecaa3f7SColin Percivalemulator-portinstall: 721ecaa3f7SColin Percival.if ${TARGET_ARCH} != ${MACHINE_ARCH} 731ecaa3f7SColin Percival.if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" ) 741ecaa3f7SColin Percival.if !exists(/usr/local/bin/qemu-${TARGET_ARCH}-static) 751ecaa3f7SColin Percival.if exists(${PORTSDIR}/emulators/qemu-user-static/Makefile) 760be274d3SGlen Barber env - UNAME_r=${UNAME_r} PATH=$$PATH make -C ${PORTSDIR}/emulators/qemu-user-static BATCH=1 all install clean 771ecaa3f7SColin Percival.else 781ecaa3f7SColin Percival.if !exists(/usr/local/sbin/pkg-static) 791ecaa3f7SColin Percival env ASSUME_ALWAYS_YES=yes pkg bootstrap -y 801ecaa3f7SColin Percival.endif 811ecaa3f7SColin Percival env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static 821ecaa3f7SColin Percival.endif 831ecaa3f7SColin Percival.endif 84*97bd53efSColin Percival touch ${.TARGET} 851ecaa3f7SColin Percival 861ecaa3f7SColin PercivalQEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static 871ecaa3f7SColin Percival.endif 881ecaa3f7SColin Percival.endif 891ecaa3f7SColin Percival 90d08ce983SGlen Barber.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 91d08ce983SGlen Barber. for _CW in ${CLOUDWARE} 92d08ce983SGlen Barber. if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF) 93d08ce983SGlen Barber${_CW:tu}CONF?= ${.CURDIR}/tools/${_CW:tl}.conf 94d08ce983SGlen Barber. endif 958dec4738SColin Percival. for _FS in ${${_CW:tu}_FSLIST} 968dec4738SColin PercivalCLOUDTARGETS+= cw-${_CW:tl}-${_FS} 978dec4738SColin PercivalCLEANDIRS+= cw-${_CW:tl}-${_FS} 988dec4738SColin PercivalCLEANFILES+= ${_CW:tl}.${_FS}.img \ 998dec4738SColin Percival ${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT} \ 100fcbeeb5fSColin Percival ${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT}.raw 1018dec4738SColin Percival${_CW:tu}${_FS:tu}IMAGE= ${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT} 10248096f81SColin Percival 1038dec4738SColin Percivalcw-${_CW:tl}-${_FS}: emulator-portinstall 10448096f81SColin Percival mkdir -p ${.OBJDIR}/${.TARGET} 105ea18fc2fSGlen Barber env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \ 1061ecaa3f7SColin Percival QEMUSTATIC=${QEMUSTATIC} \ 10748096f81SColin Percival ${.CURDIR}/scripts/mk-vmimage.sh \ 1088dec4738SColin Percival -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${_FS} \ 1098dec4738SColin Percival -i ${.OBJDIR}/${_CW:tl}.${_FS}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \ 1108dec4738SColin Percival -S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}${_FS:tu}IMAGE} -c ${${_CW:tu}CONF} 11148096f81SColin Percival touch ${.TARGET} 1128dec4738SColin Percival. endfor 1138dec4738SColin Percival 1148dec4738SColin Percival# Hardlinks from "foo.bar" to "foo-${VMFS}.bar". These can go away once all 1158dec4738SColin Percival# of the cloudware code knows how to handle multiple filesystem images (or 1168dec4738SColin Percival# at least knows the name of the UFS image). 1178dec4738SColin PercivalCLOUDTARGETS+= cw-${_CW:tl} 1188dec4738SColin PercivalCLEANFILES+= ${_CW:tl}.${${_CW:tu}_FORMAT} 1198dec4738SColin Percival${_CW:tu}IMAGE= ${_CW:tl}.${${_CW:tu}_FORMAT} 1208dec4738SColin Percivalcw-${_CW:tl}: cw-${_CW:tl}-${VMFS} 1218dec4738SColin Percival ln -f ${${_CW:tu}${VMFS:tu}IMAGE} ${${_CW:tu}IMAGE} 122d08ce983SGlen Barber. endfor 123d08ce983SGlen Barber.endif 1246513e474SGlen Barber 1256513e474SGlen Barber.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 1266513e474SGlen BarberCLEANDIRS+= ${VMTARGETS} 1276513e474SGlen Barber. for FORMAT in ${VMFORMATS} 12832ae9a6bSColin Percival. for FS in ${VMFSLIST} 12932ae9a6bSColin PercivalCLEANFILES+= ${FORMAT}.${FS}.img 13032ae9a6bSColin PercivalCLEANFILES+= ${VMBASE}.${FS}.${FORMAT} 13132ae9a6bSColin Percival. endfor 1326513e474SGlen Barber. endfor 1336513e474SGlen Barber.endif 1346513e474SGlen Barber 1351e7c1f17SGlen Barbervm-base: vm-image 1366513e474SGlen Barber 1371e7c1f17SGlen Barbervm-image: 1386513e474SGlen Barber.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 1396513e474SGlen Barber. for FORMAT in ${VMFORMATS} 14032ae9a6bSColin Percival. for FS in ${VMFSLIST} 141*97bd53efSColin Percival mkdir -p ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS} 142240e2395SGlen Barber env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \ 14326bb2a60SGlen Barber ${.CURDIR}/scripts/mk-vmimage.sh \ 144*97bd53efSColin Percival -C ${.CURDIR}/tools/vmimage.subr \ 145*97bd53efSColin Percival -d ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS} -F ${FS} \ 14632ae9a6bSColin Percival -i ${.OBJDIR}/${FORMAT}.${FS}.img -s ${VMSIZE} -f ${FORMAT} \ 14732ae9a6bSColin Percival -S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FS}.${FORMAT} 14832ae9a6bSColin Percival. endfor 1496513e474SGlen Barber. endfor 1506513e474SGlen Barber.endif 1516513e474SGlen Barber touch ${.TARGET} 1526513e474SGlen Barber 1537d2ef961SGlen Barbervm-cloudware: ${CLOUDTARGETS} 15499e908c9SGlen Barber 15585311c29SGlen Barberlist-vmtargets: list-cloudware 15685311c29SGlen Barber @${ECHO} 15785311c29SGlen Barber @${ECHO} "Supported virtual machine disk image formats:" 15885311c29SGlen Barber.for FORMAT in ${VMFORMATS:tu} 15985311c29SGlen Barber @${ECHO} " ${FORMAT:tl}: ${${FORMAT}_DESC}" 16085311c29SGlen Barber.endfor 16185311c29SGlen Barber 16299e908c9SGlen Barberlist-cloudware: 16399e908c9SGlen Barber.if !empty(CLOUDWARE) 16485311c29SGlen Barber @${ECHO} 16585311c29SGlen Barber @${ECHO} "Supported cloud hosting provider images:" 16699e908c9SGlen Barber. for _CW in ${CLOUDWARE} 16799e908c9SGlen Barber @${ECHO} " ${_CW:tu}: ${${_CW:tu}_DESC}" 16899e908c9SGlen Barber. endfor 16999e908c9SGlen Barber.endif 1702d4ff62fSGlen Barber 1712d4ff62fSGlen Barbervm-install: 1722d4ff62fSGlen Barber.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 1732d4ff62fSGlen Barber mkdir -p ${DESTDIR}/vmimages 1742d4ff62fSGlen Barber. for FORMAT in ${VMFORMATS} 17532ae9a6bSColin Percival. for FS in ${VMFSLIST} 17632ae9a6bSColin Percival cp -p ${VMBASE}.${FS}.${FORMAT} \ 17732ae9a6bSColin Percival ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT} 17832ae9a6bSColin Percival. endfor 1792d4ff62fSGlen Barber. endfor 1802d4ff62fSGlen Barber. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 1812d4ff62fSGlen Barber. for FORMAT in ${VMFORMATS} 18232ae9a6bSColin Percival. for FS in ${VMFSLIST} 1832d4ff62fSGlen Barber # Don't keep the originals. There is a copy in ${.OBJDIR} if needed. 18432ae9a6bSColin Percival ${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT} 18532ae9a6bSColin Percival. endfor 1862d4ff62fSGlen Barber. endfor 1872d4ff62fSGlen Barber. endif 18832ae9a6bSColin Percival # Compatibility hardlinks from "foo.bar" to "foo-${VMFS}.bar". 18932ae9a6bSColin Percival. for FORMAT in ${VMFORMATS} 19032ae9a6bSColin Percival. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES) 19132ae9a6bSColin Percival ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT}.xz ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}.xz 19232ae9a6bSColin Percival. else 19332ae9a6bSColin Percival ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT} 19432ae9a6bSColin Percival. endif 19532ae9a6bSColin Percival. endfor 19634187a08SGlen Barber cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \ 19734187a08SGlen Barber ${DESTDIR}/vmimages/CHECKSUM.SHA512 1982d4ff62fSGlen Barber cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \ 1992d4ff62fSGlen Barber ${DESTDIR}/vmimages/CHECKSUM.SHA256 2002d4ff62fSGlen Barber.endif 2014afe7cf5SGlen Barber 2024afe7cf5SGlen Barbervm-release: 2034afe7cf5SGlen Barber.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES) 2044afe7cf5SGlen Barber ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS} 2054afe7cf5SGlen Barber.endif 2064afe7cf5SGlen Barber 2074afe7cf5SGlen Barbercloudware-release: 2084afe7cf5SGlen Barber.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE) 2094afe7cf5SGlen Barber ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS} 2104afe7cf5SGlen Barber.endif 2110e44fa6cSGlen Barber 212873fc703SGlen Barber.include "${.CURDIR}/Makefile.azure" 213fbece760SLi-Wen Hsu.include "${.CURDIR}/Makefile.ec2" 2147acb5381SColin Percival.include "${.CURDIR}/Makefile.firecracker" 215eb64cd58SGlen Barber.include "${.CURDIR}/Makefile.gce" 21641f7db3aSBrad Davis.include "${.CURDIR}/Makefile.vagrant" 217c883b6fdSGlen Barber.include "${.CURDIR}/Makefile.inc1" 218