File: install.zuo

package info (click to toggle)
chezscheme 10.0.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 36,908 kB
  • sloc: ansic: 24,192; sh: 1,132; makefile: 386; csh: 368; asm: 168
file content (263 lines) | stat: -rw-r--r-- 9,811 bytes parent folder | download | duplicates (2)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#lang zuo
(require "version.zuo")

(provide install)

;; Installation steps are written in a way that can run immediately
;; or that can be rendered as commands in a makefile-shaped script

(define (install at-workarea [vars (hash)] [uninstall? #f] [script-to #f])
  (define config (config-file->hash (at-workarea "Mf-config") vars))
  (define (lookup key) (hash-ref config key #f))

  (define (out-raw s)
    (fd-write script-to s))
  (define (out s)
    (out-raw (~a "\n" s)))

  (define-syntax (define-var stx)
    `(define ,(cadr stx) (let ([v (or (lookup ',(cadr stx))
                                      ,(list-ref stx 2))])
                           (cond
                             [script-to
                              (out (~a ',(cadr stx) "=" v))
                              (~a "${" ',(cadr stx) "}")]
                             [else v]))))
  (define-syntax (define-now-var stx)
    `(define ,(cadr stx) (or (lookup ',(cadr stx))
                             ,(list-ref stx 2))))

  (define m (lookup 'm))

  ;; The following variables determine where the executables, boot files,
  ;; example programs, and manual pages are installed.

  ;; executable directory
  (define-var InstallBin "/usr/bin")

  ;; library directory
  (define-var InstallLib "/usr/lib")

  ;; man page directory
  (define-var InstallMan "/usr/man/man1")

  ;; installation owner
  (define-var InstallOwner "")

  ;; installation group
  (define-var InstallGroup "")

  ;; Files are actually installed at ${TempRoot}${InstallBin},
  ;; ${TempRoot}${InstallLib}, and ${TempRoot}${InstallMan}.
  ;; This useful for testing the install process and for building
  ;; installation scripts
  (define-var TempRoot "")

  ;; compress man pages?
  (define-var GzipManPages "yes")

  ;; executable names
  (define-var InstallSchemeName "scheme")
  (define-var InstallPetiteName "petite")
  (define-var InstallScriptName "scheme-script")

  ;; Whether to install "kernel.o" or "libkernel.a"
  (define-now-var Kernel "KernelLib") ; or "KernelO"

  ;; Empty lib vars mean install libz.a and liblz4.a
  (define-now-var zlibLib "")
  (define-now-var LZ4Lib "")

  ;; Everything after here is derived from the configuration

  (define Version (let ([l (get-version)])
                    (~a "csv" (list-ref l 0) "." (list-ref l 1) "." (list-ref l 2)
                        (if (= (list-ref l 3) 0)
                            ""
                            (~a "-pre-release." (list-ref l 3))))))

  (define (build-path* . elems)
    (if script-to
        (string-join elems "/")
        (apply build-path elems)))
  
  (define (at-workarea* . elems)
    (if script-to
        (apply build-path* elems)
        (apply at-workarea elems)))

  (define (at-source* . elems)
    (if script-to
        (apply build-path* (if (glob-match? "../*" (car elems))
                               (cons (substring (car elems) 3) (cdr elems))
                               elems))
        (apply at-source elems)))

  (define (guard* a cmp b . body)
    (cond
      [script-to
       (out (~a "\tif [ \"" a "\" " cmp " \"" b "\" ] ; then \\"))
       (for-each (lambda (t)
                   (t)
                   (out-raw ";\\"))
                 body)
       (out "\t fi")]
      [else
       (when (if (string=? cmp "=")
                 (string=? a b)
               (not (string=? a b)))
         (for-each (lambda (t) (t)) body))]))

  (define Include (at-workarea* "boot" m))
  (define PetiteBoot (at-workarea* "boot" m "petite.boot"))
  (define SchemeBoot (at-workarea* "boot" m "scheme.boot"))
  (define Revision (at-workarea* "boot" m "revision"))
  (define Scheme (at-workarea* "bin" m "scheme"))
  (define InstallLibExamples (build-path* InstallLib Version "examples"))
  (define InstallLibBin (build-path* InstallLib Version m))

  (define (prefix-path prefix path)
    (cond
      [(string=? prefix "") path]
      [script-to (~a prefix path)]
      [else
       (apply build-path (cons prefix (let loop ([path path] [accum '()])
                                        (define l (split-path path))
                                        (if (not (car l))
                                            accum
                                            (loop (car l) (cons (cdr l) accum))))))]))

  (define Bin (prefix-path TempRoot InstallBin))
  (define Lib (prefix-path TempRoot (build-path InstallLib Version)))
  (define LibExamples (prefix-path TempRoot InstallLibExamples))
  (define LibBin (prefix-path TempRoot InstallLibBin))
  (define Man (prefix-path TempRoot InstallMan))
  (define PetitePath (build-path* Bin InstallPetiteName))
  (define SchemePath (build-path* Bin InstallSchemeName))
  (define SchemeScriptPath (build-path* Bin InstallScriptName))

  (struct literal (content))

  (define (shell/wait* . args)
    (let ([args (map (lambda (arg)
                       (if (literal? arg)
                           (literal-content arg)
                           (if script-to
                               arg
                               (string->shell arg))))
                     args)])
      (if script-to
          (out (~a "\t" (apply build-shell args)))
          (shell/wait (apply build-shell args)))))

  (define (quoted* s)
    (if script-to
        (~a "\"" s "\"")
        s))
  
  (define (I . args)
    (apply shell/wait*
           (list* (at-source* "./installsh")
                  "-o" (quoted* InstallOwner) "-g" (quoted* InstallGroup)
                  args)))
  (define (rm-f f)
    (shell/wait* "rm" "-f" f))
  (define (rm-rf d)
    (shell/wait* "rm" "-rf" d))
  (define (ln-f from to)
    (shell/wait* "ln" "-f" from to))
  (define (ln-s from to)
    (shell/wait* "ln" "-s" from to))

  (when (or (not uninstall?) script-to)
    (when script-to (out "\ninstall:"))
    (for-each (lambda (d)
                (I "-d" "-m" "755" d))
              (list Lib LibBin LibExamples Bin Man))

    ;; bin
    (rm-f SchemePath)
    (rm-f PetitePath)
    (rm-f SchemeScriptPath)
    (cond
      [(equal? (hash-ref config 'relativeBootFiles #f) "yes")
       (define SchemeLibPath (build-path LibBin InstallSchemeName))
       (define PetiteLibPath (build-path LibBin InstallPetiteName))
       (define ScriptLibPath (build-path LibBin InstallScriptName))
       (define (ln-s/rel from to)
         (define to-dir (car (split-path to)))
         (ln-s (find-relative-path to-dir from) to))
       (I "-m" "555" Scheme SchemeLibPath)
       (ln-f SchemeLibPath PetiteLibPath)
       (ln-f SchemeLibPath ScriptLibPath)
       (ln-s/rel SchemeLibPath SchemePath)
       (ln-s/rel PetiteLibPath PetitePath)
       (ln-s/rel ScriptLibPath SchemeScriptPath)]
      [else
       (I "-m" "555" Scheme SchemePath)
       (ln-f SchemePath PetitePath)
       (ln-f SchemePath SchemeScriptPath)])

    ;; lib
    (I "-m" "444" PetiteBoot (build-path* LibBin "petite.boot"))
    (guard* InstallPetiteName "!=" "petite"
            (lambda ()
              (rm-f (build-path* LibBin (~a InstallPetiteName ".boot"))))
            (lambda ()
              (ln-f (build-path* LibBin "petite.boot") (build-path* LibBin (~a InstallPetiteName ".boot")))))
    (I "-m" "444" SchemeBoot (build-path* LibBin "scheme.boot"))
    (guard* InstallSchemeName "!=" "scheme"
            (lambda ()
              (rm-f (build-path* LibBin (~a InstallSchemeName ".boot"))))
            (lambda ()
              (ln-f (build-path* LibBin "scheme.boot") (build-path* LibBin (~a InstallSchemeName ".boot")))))
    (ln-f (build-path* LibBin "scheme.boot") (build-path* LibBin (~a InstallScriptName ".boot")))
    (I "-m" "444" (build-path* Include "main.o") LibBin)
    (I "-m" "444" (build-path* Include "scheme.h") LibBin)
    (I "-m" "444" Revision (build-path* LibBin "revision"))

    ;; man
    (shell/wait* "sed"
                 "-e" (quoted* (~a "s;{InstallBin};" InstallBin ";g"))
                 "-e" (quoted* (~a "s;{InstallLibExamples};" InstallLibExamples ";g"))
                 "-e" (quoted* (~a "s;{InstallLibBin};" InstallLibBin ";g"))
                 "-e" (quoted* (~a "s;{InstallPetiteName};" InstallPetiteName ";g"))
                 "-e" (quoted* (~a "s;{InstallSchemeName};" InstallSchemeName ";g"))
                 "-e" (quoted* (~a "s;{InstallScriptName};" InstallScriptName ";g"))
                 (at-source* "../scheme.1.in")
                 (literal ">")
                 (at-workarea* "scheme.1"))
    (for-each (lambda (manpage)
                (I "-m" "444" (at-workarea* "scheme.1") manpage)
                (guard* GzipManPages "=" "yes"
                        (lambda () (shell/wait* "gzip" "-f" manpage))))
              (list (build-path* Man (~a InstallSchemeName ".1"))
                    (build-path* Man (~a InstallPetiteName ".1"))))

    (let ([kernel (if (string=? Kernel "KernelO") "kernel.o" "libkernel.a")])
      (I "-m" "444" (build-path* Include kernel) LibBin))

    (when (string=? Kernel "KernelLib")
      (when (string=? zlibLib "")
        (I "-m" "444" (at-workarea* "zlib/libz.a") LibBin))
      (when (string=? LZ4Lib "")
        (I "-m" "444" (at-workarea* "lz4/lib/liblz4.a") LibBin)))

    (apply I (list* "-m" "444" (append
                                (map (lambda (n) (at-source* "../examples" n))
                                     (ls (at-source "../examples")))
                                (list LibExamples)))))

  (when (or uninstall? script-to)
    (when script-to (out "\nuninstall:"))
    (rm-rf Lib)
    (rm-f PetitePath)
    (rm-f SchemePath)
    (rm-f SchemeScriptPath)
    (rm-f (build-path* Man (~a InstallPetiteName ".1")))
    (rm-f (build-path* Man (~a InstallPetiteName ".1.gz")))
    (rm-f (build-path* Man (~a InstallSchemeName ".1")))
    (rm-f (build-path* Man (~a InstallSchemeName ".1.gz"))))

  (when script-to
    (out "")))