Since around March pacman’s git repo has a new tool called makepkg-template created by Florian Pritz. Below is a description from man makepkg-template: makepkg-template is a script to ease the work of maintaining multiple similar PKGBUILDs.
It allows you to move most of the code from the PKGBUILD into a template file and uses markers to allow in-place updating of existing PKGBUILDs if the template has been changed.
With makepkg-template you can define a template file, which can replace parts of a PKGBUILD and keep them consistent.
Now you can use this .template file by saving it as “$template_name-$version.template”, then you create a symlink to “$template_name.template”
After saving the template and symlinking, you edit the PKGBUILD to use the template.
Now we can run makepkg-template on the PKGBUILD and it will replace the contents between the template’s start and end definition with the template file’s contents.
With templates for Perl, Python and other packages we can make sure they all use the same build() and package() functions. The creation of new packages should be easier with these templates too. Currently makepkg-template is only available in pacman-git.