go-makepkg
go-makepkg copied to clipboard
Generate PKGBUILD for Golang programs and run makepkg
go-makepkg
Tool for fast packaging Golang programs under the archlinux.
It will automatically generate appropriate PKGBUILD and systemd.service files.
How to use
-
go get github.com/seletskiy/go-makepkg
; -
mkdir some-directory
; -
cd some-directory
; -
mkdir -p etc/mycoolprog/
; - Copy any other required files for you program, like config files:
cp <somepath>/example.conf etc/mycoolprog/main.conf
; - Omit
-s
flag if you do not want service file:
go-makepkg -sB "my description" git://url-to-prog/repo.git **/*
; - Package is ready for install and located at
build/<blah>.tar.xz
;
Typical invocation
go-makepkg -gsB "my cool package" git://github.com/seletskiy/go-makepkg *
Will generate .gitignore, PKGBUILD and .service file for specified repo (e.g. go-makepkg) and include all files under current directory to the package.
If you do not want to build package automatically, omit -B
flag.
See go-makepkg -h
for more info.
go-makepkg
by itself can be packaged using itself:
go-makepkg -B "go-makepkg tool" git://github.com/seletskiy/go-makepkg.git
Pass package version into golang code
As you know, you can change global variables of your Golang program in the
compile time by using go build
options, like in the following example you can
change variable packageVersion
using ldflags
.
package main
import "fmt"
var blahme = "autogenerated"
func main() {
fmt.Println(blahme)
}
Value of the blahme
can be changed:
go build -ldflags="-X main.blahme=testvalue" -o test .
Run ./test
and you will see testvalue
instead of hardcoded autogenerated
string.
It's very useful opportunity, for escaping the hell of versioning your software and shift this work to the PKGBUILD.
go-makepkg
can do it for you, all you need is to specify a variable name
which holds version number using -p <var>
flag:
go-makepkg -p version "go-makepkg tool" git://github.com/seletskiy/go-makepkg.git