Imported patches from patch-queue
Adapt to the new build method