build: split legacy image building code out of image.mk