about summary refs log tree commit diff
path: root/sent
diff options
context:
space:
mode:
Diffstat (limited to 'sent')
-rw-r--r--sent/README.md5
-rw-r--r--sent/make-static.scm97
2 files changed, 102 insertions, 0 deletions
diff --git a/sent/README.md b/sent/README.md
index 924b90d..6507e00 100644
--- a/sent/README.md
+++ b/sent/README.md
@@ -15,3 +15,8 @@ Run sent on the example slides.
 ```
 $(guix build -f make.scm) slides
 ```
+
+To produce a statically linked executable, build using the `make-static.scm` file.
+```
+guix build -f make-static.scm
+```
diff --git a/sent/make-static.scm b/sent/make-static.scm
new file mode 100644
index 0000000..7d26873
--- /dev/null
+++ b/sent/make-static.scm
@@ -0,0 +1,97 @@
+;; This is the same as make.scm, except that it statically links the
+;; final executable.
+
+(use-modules (gnu packages base)
+             (gnu packages commencement)
+             (gnu packages compression)
+             (gnu packages fontutils)
+             (gnu packages image)
+             (gnu packages xml)
+             (gnu packages xorg)
+             (guix gexp)
+             (guix packages)
+             (guix utils))
+
+(define set-up-gcc-gexp
+  (with-imported-modules '((guix build utils))
+    #~(begin
+        (use-modules (guix build utils))
+
+        (set-path-environment-variable "PATH"
+                                       '("bin")
+                                       (list #$gcc-toolchain))
+        (set-path-environment-variable "C_INCLUDE_PATH"
+                                       '("include")
+                                       (list #$gcc-toolchain))
+        (set-path-environment-variable "LIBRARY_PATH"
+                                       '("lib")
+                                       (list #$gcc-toolchain)))))
+
+(define* (compile source-filename #:key (flags '()))
+  (computed-file (string-append (basename source-filename ".c")
+                                ".o")
+                 #~(begin
+                     #$set-up-gcc-gexp
+                     (invoke "gcc" "-c" #$(local-file source-filename)
+                             "-o" #$output
+                             #$@flags))))
+
+(define* (link output-filename object-files #:key (flags '()))
+  (computed-file output-filename
+                 #~(begin
+                     #$set-up-gcc-gexp
+                     (invoke "gcc" "-o" #$output
+                             #$@object-files
+                             #$@flags))))
+
+(define (static pkg)
+  (package
+    (inherit pkg)
+    (arguments
+     (substitute-keyword-arguments (package-arguments pkg)
+       ((#:configure-flags flags #~())
+        #~(cons "--enable-static"
+                (delete "--disable-static" #$flags)))))))
+
+(let ((include-dependencies
+       (directory-union "include"
+                        (list (file-append fontconfig "/include")
+                              (file-append freetype "/include/freetype2")
+                              (file-append libx11 "/include")
+                              (file-append libxft "/include")
+                              (file-append libxrender "/include")
+                              (file-append xorgproto "/include")))))
+  (link "sent"
+        (list (let ((headers `(("arg.h" ,(local-file "sent/arg.h"))
+                               ("config.h" ,(local-file "sent/config.def.h"))
+                               ("drw.h" ,(local-file "sent/drw.h"))
+                               ("util.h" ,(local-file "sent/util.h")))))
+                (compile "sent/sent.c"
+                         #:flags (list "-DVERSION=\"1\""
+                                       "-I" include-dependencies
+                                       "-I" (file-union "include" headers))))
+              (let ((headers `(("drw.h" ,(local-file "sent/drw.h"))
+                               ("util.h" ,(local-file "sent/util.h")))))
+                (compile "sent/drw.c"
+                         #:flags (list "-I" include-dependencies
+                                       "-I" (file-union "include" headers))))
+              (let ((headers `(("util.h" ,(local-file "sent/util.h")))))
+                (compile "sent/util.c"
+                         #:flags (list "-I" (file-union "include" headers)))))
+        #:flags (list "-static"
+                      "-L" #~(string-append #$bzip2:static "/lib")
+                      "-L" #~(string-append #$expat:static "/lib")
+                      "-L" (file-append (static fontconfig) "/lib")
+                      "-L" (file-append freetype "/lib")
+                      "-L" #~(string-append #$glibc:static "/lib")
+                      "-L" (file-append (static libpng) "/lib")
+                      "-L" (file-append (static libx11) "/lib")
+                      "-L" (file-append (static libxau) "/lib")
+                      "-L" (file-append (static libxcb) "/lib")
+                      "-L" (file-append (static libxdmcp) "/lib")
+                      "-L" (file-append (static libxft) "/lib")
+                      "-L" (file-append (static libxrender) "/lib")
+                      "-L" #~(string-append #$zlib:static "/lib")
+                      "-lXft" "-lfontconfig" "-lfreetype" "-lbz2"
+                      "-lexpat" "-lpng" "-lXrender" "-lX11" "-lxcb"
+                      "-lXdmcp" "-lXau" "-lz" "-lm")))