aboutsummaryrefslogtreecommitdiff
path: root/sent/make-static.scm
blob: 7d268733394842b23dadd1845f6ad6ab30634aff (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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")))