This is roughly based on https://github.com/FooBarWidget/debian-packaging-for-the-modern-developer/tree/master/tutorial-3.
What’s worth noting is that we are going to package a C application using the GNU standard build procedure. It makes heavy use of GCC, glibc, bash, GNU Make, and more.
To make it simple, create a directory “chello” at /tmp
:
mkdir /tmp/chello
cd /tmp/chello
Then create a file called “hello.c”:
#include <stdio.h>
int main() {
printf("Hello world! 1.0.0\n");
return 0;
}
Then create a Makefile:
CC ?= gcc
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/share/man
.PHONY: all clean install
all: hello
hello: hello.c
gcc -Wall -g hello.c -o chello
clean:
rm -f chello
install:
mkdir -p $(DESTDIR)/$(BINDIR)
install -c chello $(DESTDIR)/$(BINDIR)/chello
Done.
Tar and gzip the application directory.
cd /tmp
tar -czf chello-1.0.0.tar.gz chello
Compute the guix hash.
guix hash chello-1.0.0.tar.gz chello
Done.
We shall make use of the previous guixpkgtut.scm
file by appending a new package definition to it:
(define-public chello
(package
(name "chello")
(version "1.0.0")
(source (origin
(method url-fetch)
(uri (string-append "file:///tmp/chello-" version ".tar.gz"))
(sha256
(base32 "0crvmzy9mr2w6mflmlg3g3r8ka06b593qzsivypaf8maav3wmx7y"))))
(build-system gnu-build-system)
(arguments
`(#:make-flags
(list (string-append "CC=" ,(cc-for-target))
(string-append "PREFIX=" (assoc-ref %outputs "out")))
#:phases
(modify-phases %standard-phases
(delete 'configure) ; no configure script
(delete 'check)))) ; no make check target
(home-page #f)
(synopsis "My compiled hello package.")
(description "A package to learn packaging a compiled C application that says hello.")
(license license:bsd-2)))
Again, we can check our package definition by searching it with guix:
guix search chello
then build it:
guix build chello
Try running in shell:
guix environment --ad-hoc chello -- chello
Done. You’ve successfully package a compiled application.