5 # Makefile for building virtual machine and cloud provider disk images.
9 VMFORMATS?= vhd vmdk qcow2 raw
15 VHD_DESC= Azure, VirtualPC, Hyper-V, Xen disk image
16 VMDK_DESC= VMWare, VirtualBox disk image
17 QCOW2_DESC= Qemu, KVM disk image
18 RAW_DESC= Unformatted raw disk image
20 CLOUDWARE?= BASIC-CI \
27 AZURE_DESC= Microsoft Azure platform image
28 AZURE_DISK= ${OSRELEASE}.${AZURE_FORMAT}
30 BASIC-CI_DESC= Image for CI
31 BASIC-CI_DISK= ${OSRELEASE}.${BASIC-CI_FORMAT}
33 EC2_DESC= Amazon EC2 image
34 EC2_DISK= ${OSRELEASE}.${EC2_FORMAT}
36 GCE_DESC= Google Compute Engine image
37 GCE_DISK= disk.${GCE_FORMAT}
39 OCI_DESC= Oracle Cloud Infrastructure image
40 OCI_DISK= ${OSRELEASE}.${OCI_FORMAT}
41 OPENSTACK_FORMAT=qcow2
42 OPENSTACK_DESC= OpenStack platform image
43 OPENSTACK_DISK= ${OSRELEASE}.${OPENSTACK_FORMAT}
44 VAGRANT-VIRTUALBOX_FORMAT= vmdk
45 VAGRANT-VIRTUALBOX_DESC= Vagrant Image for VirtualBox
46 VAGRANT-VIRTUALBOX_DISK= ${OSRELEASE}.vbox.${VAGRANT_FORMAT}
47 VAGRANT-VMWARE_FORMAT= vmdk
48 VAGRANT-VMWARE_DESC= Vagrant Image for VMWare
49 VAGRANT-VMWARE_DISK= ${OSRELEASE}.vmware.${VAGRANT_FORMAT}
51 .for _V in TYPE BRANCH REVISION
52 . if !defined(${_V}) || empty(${_V})
53 ${_V}!= eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V}
58 .if ${TARGET_ARCH} != ${MACHINE_ARCH}
59 .if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" )
60 .if !exists(/usr/local/bin/qemu-${TARGET_ARCH}-static)
61 .if exists(${PORTSDIR}/emulators/qemu-user-static/Makefile)
62 env - UNAME_r=${UNAME_r} PATH=$$PATH make -C ${PORTSDIR}/emulators/qemu-user-static BATCH=1 all install clean
64 .if !exists(/usr/local/sbin/pkg-static)
65 env ASSUME_ALWAYS_YES=yes pkg bootstrap -y
67 env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static
71 QEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static
75 .if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
76 . for _CW in ${CLOUDWARE}
77 CLOUDTARGETS+= cw-${_CW:tl}
78 CLEANDIRS+= cw-${_CW:tl}
79 CLEANFILES+= ${_CW:tl}.img \
80 ${_CW:tl}.${${_CW:tu}_FORMAT} \
81 ${_CW:tl}.${${_CW:tu}_FORMAT}.raw \
83 CLOUDPACKAGE+= cw${_CW:tl}-package
84 ${_CW:tu}IMAGE= ${_CW:tl}.${${_CW:tu}_FORMAT}
85 . if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF)
86 ${_CW:tu}CONF?= ${.CURDIR}/tools/${_CW:tl}.conf
89 cw-${_CW:tl}: emulator-portinstall
90 mkdir -p ${.OBJDIR}/${.TARGET}
91 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
92 QEMUSTATIC=${QEMUSTATIC} \
93 ${.CURDIR}/scripts/mk-vmimage.sh \
94 -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${VMFS} \
95 -i ${.OBJDIR}/${_CW:tl}.img -s ${VMSIZE} -f ${${_CW:tu}_FORMAT} \
96 -S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}IMAGE} -c ${${_CW:tu}CONF}
100 @# Special target to handle packaging cloud images in the formats
101 @# specific to each hosting provider.
102 .if exists(${.CURDIR}/tools/${_CW:tl}-package.sh)
103 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
104 ${.CURDIR}/tools/${_CW:tl}-package.sh \
105 -D ${DESTDIR} -I ${${_CW}_DISK} -S ${WORLDDIR}
112 .if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
113 CLEANDIRS+= ${VMTARGETS}
114 . for FORMAT in ${VMFORMATS}
115 CLEANFILES+= ${FORMAT}.img
116 CLEANFILES+= ${VMBASE}.${FORMAT}
123 .if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
124 . for FORMAT in ${VMFORMATS}
125 mkdir -p ${.OBJDIR}/${.TARGET}
126 env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
127 ${.CURDIR}/scripts/mk-vmimage.sh \
128 -C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${VMFS} \
129 -i ${.OBJDIR}/${FORMAT}.img -s ${VMSIZE} -f ${FORMAT} \
130 -S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FORMAT}
135 vm-cloudware: ${CLOUDTARGETS}
137 list-vmtargets: list-cloudware
139 @${ECHO} "Supported virtual machine disk image formats:"
140 .for FORMAT in ${VMFORMATS:tu}
141 @${ECHO} " ${FORMAT:tl}: ${${FORMAT}_DESC}"
145 .if !empty(CLOUDWARE)
147 @${ECHO} "Supported cloud hosting provider images:"
148 . for _CW in ${CLOUDWARE}
149 @${ECHO} " ${_CW:tu}: ${${_CW:tu}_DESC}"
154 .if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
155 mkdir -p ${DESTDIR}/vmimages
156 . for FORMAT in ${VMFORMATS}
157 cp -p ${VMBASE}.${FORMAT} \
158 ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
160 . if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
161 . for FORMAT in ${VMFORMATS}
162 # Don't keep the originals. There is a copy in ${.OBJDIR} if needed.
163 ${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
166 cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \
167 ${DESTDIR}/vmimages/CHECKSUM.SHA512
168 cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \
169 ${DESTDIR}/vmimages/CHECKSUM.SHA256
173 .if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
174 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS}
178 .if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
179 ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS}
182 .include "${.CURDIR}/Makefile.azure"
183 .include "${.CURDIR}/Makefile.ec2"
184 .include "${.CURDIR}/Makefile.firecracker"
185 .include "${.CURDIR}/Makefile.gce"
186 .include "${.CURDIR}/Makefile.vagrant"
187 .include "${.CURDIR}/Makefile.inc1"