all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 30a35a153a1cd442dfadbae6f7c3ae9358641406 8873 bytes (raw)
name: guix/build/build-flags.scm 	 # note: path name is non-authoritative(*)

  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
264
265
266
267
268
269
270
271
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015 Alex Vong <alexvong1995@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guix build build-flags)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-9)
  #:export (flag-list
            flag-list+
            flag-list-
            flag-list->string-list
            default-flag-list
            format-flag-list
            fortify-flag-list
            stackprotector-flag-list
            stackprotectorstrong-flag-list
            relro-flag-list
            bindnow-flag-list
            pie-flag-list
            all-flag-list))

;;; Commentary:
;;;
;;; Module to manipulate build flags, similar to dpkg-buildflags.
;;;
;;; Data structure <flag-list> is constructed by flag-list.
;;; The constructor flag-list does something to its arguments,
;;; such as trimming white-spaces, to ensure no two arguments mean the same.
;;;
;;; Here is an example:
;;; (define default-flag-list
;;;   (flag-list
;;;    #:CFLAGS '("-O2" "-g")
;;;    #:LDFLAGS '("-lm" "-lpthread")))
;;;
;;; flag-list+ and flag-list- are analogous to
;;; numeric + and - but operate on <flag-list>.
;;;
;;; flag-list->string-list converts <flag-list> into
;;; configure-flags-compatible string-list.
;;;
;;; Code:


;;; Pair up a symbol with a procedure so that we know
;;; what identifier is bound to the procedure at macro-expand time.
(define-record-type <identifier-procedure-pair>
  (cons-identifier-procedure id proc)
  identifier-procedure-pair?
  (id identifier)
  (proc procedure))

(define-syntax define-record-type-with-accessor-list
  (syntax-rules ()
    "Macro to define a srfi-9 record
with accessor list bound to accessor-list-name.
"
    ((_ record-name
        (constructor-name field-name* ...)
        predicate-name
        accessor-list-name
        (field-name accessor-name) ...)
     (begin
       (define-record-type record-name
         (constructor-name field-name* ...)
         predicate-name
         (field-name accessor-name) ...)
       (define accessor-list-name
         `(,(cons-identifier-procedure 'accessor-name
                                       accessor-name) ...))))))

;;; define <flag-list> using define-record-type-with-accessor-list macro
(define-record-type-with-accessor-list <flag-list>
  (make-flag-list c-flags
                  cpp-flags
                  c++-flags
                  fc-flags
                  f-flags
                  gcj-flags
                  ld-flags
                  objc-flags
                  objc++-flags)
  flag-list?
  flag-list-accessor-list
  (c-flags CFLAGS)
  (cpp-flags CPPFLAGS)
  (c++-flags CXXFLAGS)
  (fc-flags FCFLAGS)
  (f-flags FFLAGS)
  (gcj-flags GCJFLAGS)
  (ld-flags LDFLAGS)
  (objc-flags OBJCFLAGS)
  (objc++-flags OBJCXXFLAGS))


(define-syntax define*-with-keyword-list
  (syntax-rules ()
    "Macro to define a procedure with keyword and default arguments
only with keyword list bound to keyword-list-name.
"
    ((_ (proc-name keyword-list-name
                   (keyword default-val) ...)
        body)
     (begin
       (define* (proc-name #:key
                           (keyword default-val) ...)
         body)
       (define keyword-list-name
         (map symbol->keyword
              '(keyword ...)))))))

;;; Constructor for <flag-list>
;;; with keyword list bound to flag-list-keyword-list.
(define*-with-keyword-list (flag-list flag-list-keyword-list
                                      (CFLAGS '())
                                      (CPPFLAGS '())
                                      (CXXFLAGS '())
                                      (FCFLAGS '())
                                      (FFLAGS '())
                                      (GCJFLAGS '())
                                      (LDFLAGS '())
                                      (OBJCFLAGS '())
                                      (OBJCXXFLAGS '()))
  (apply make-flag-list
         (map (lambda (string-list)
                (map string-trim-both string-list))
              (list CFLAGS
                    CPPFLAGS
                    CXXFLAGS
                    FCFLAGS
                    FFLAGS
                    GCJFLAGS
                    LDFLAGS
                    OBJCFLAGS
                    OBJCXXFLAGS))))

(define (keyword-apply proc kw-list kw-arg-list by-position-arg-list)
  "keyword-apply is inspired by the same-name procedure in Racket.
It applies a procedure using keyword list and keyword argument list.
"
  (apply proc
         (append (concatenate (zip kw-list
                                   kw-arg-list))
                 by-position-arg-list)))


(define (flag-list-operation lset-operation)
  "Take a lset operation.
Return a procedure that takes any number of <flag-list>
and does the set operation on them for each flags respectively
"
  (define (list-of-string-list-operation list-of-string-list)
    (apply lset-operation
           `(,string=? ,@list-of-string-list)))
  (lambda list-of-flag-list
    (let ((flag-list-proc-list (map procedure
                                    flag-list-accessor-list)))
      (keyword-apply flag-list
                     flag-list-keyword-list
                     (map (lambda (proc)
                            (list-of-string-list-operation
                             (map proc list-of-flag-list)))
                          flag-list-proc-list)
                   '()))))

;;; union any number of <flag-list> for each flags
(define flag-list+
  (flag-list-operation lset-union))

;;; take the first <flag-list> and minus the union of the rest for each flags
(define flag-list-
  (flag-list-operation lset-difference))

(define (flag-list->string-list flag-lst)
  "Convert <flag-list> into configure-flags-compatible string list.
"
  (map (lambda (accessor)
         (let ((id (identifier accessor))
               (proc (procedure accessor)))
           (string-append (symbol->string id)
                          "="
                          (string-join (proc flag-lst)))))
       flag-list-accessor-list))


;;; build flags used in dpkg-buildflags

(define default-flag-list
  (flag-list
   #:CFLAGS '("-g" "-O2")
   #:CXXFLAGS '("-g" "-O2")
   #:FCFLAGS '("-g" "-O2")
   #:FFLAGS '("-g" "-O2")
   #:GCJFLAGS '("-g" "-O2")
   #:OBJCFLAGS '("-g" "-O2")
   #:OBJCXXFLAGS '("-g" "-O2")))

(define format-flag-list
  (flag-list
   #:CFLAGS '("-Wformat" "-Werror=format-security")
   #:CXXFLAGS '("-Wformat" "-Werror=format-security")
   #:OBJCFLAGS '("-Wformat" "-Werror=format-security")
   #:OBJCXXFLAGS '("-Wformat" "-Werror=format-security")))

(define fortify-flag-list
  (flag-list
   #:CPPFLAGS '("-D_FORTIFY_SOURCE=2")))

(define stackprotector-flag-list
  (flag-list
   #:CFLAGS '("-fstack-protector" "--param=ssp-buffer-size=4")
   #:CXXFLAGS '("-fstack-protector" "--param=ssp-buffer-size=4")
   #:FCFLAGS '("-fstack-protector" "--param=ssp-buffer-size=4")
   #:FFLAGS '("-fstack-protector" "--param=ssp-buffer-size=4")
   #:GCJFLAGS '("-fstack-protector" "--param=ssp-buffer-size=4")
   #:OBJCFLAGS '("-fstack-protector" "--param=ssp-buffer-size=4")
   #:OBJCXXFLAGS '("-fstack-protector" "--param=ssp-buffer-size=4")))

(define stackprotectorstrong-flag-list
  (flag-list
   #:CFLAGS '("-fstack-protector-strong")
   #:CXXFLAGS '("-fstack-protector-strong")
   #:FCFLAGS '("-fstack-protector-strong")
   #:FFLAGS '("-fstack-protector-strong")
   #:GCJFLAGS '("-fstack-protector-strong")
   #:OBJCFLAGS '("-fstack-protector-strong")
   #:OBJCXXFLAGS '("-fstack-protector-strong")))

(define relro-flag-list
  (flag-list
   #:LDFLAGS '("-Wl,-z,relro")))

(define bindnow-flag-list
  (flag-list
   #:LDFLAGS '("-Wl,-z,now")))

(define pie-flag-list
  (flag-list
   #:CFLAGS '("-fPIE")
   #:CXXFLAGS '("-fPIE")
   #:FCFLAGS '("-fPIE")
   #:FFLAGS '("-fPIE")
   #:GCJFLAGS '("-fPIE")
   #:LDFLAGS '("-fPIE" "-pie")
   #:OBJCFLAGS '("-fPIE")
   #:OBJCXXFLAGS '("-fPIE")))

(define all-flag-list
  (flag-list+ default-flag-list
              format-flag-list
              fortify-flag-list
              stackprotectorstrong-flag-list
              relro-flag-list
              bindnow-flag-list
              pie-flag-list))

;;; build-flags.scm ends here

debug log:

solving 30a35a1 ...
found 30a35a1 in https://yhetil.org/guix/20151031215617.4df7ce04@debian/ ||
	https://yhetil.org/guix/20151025141115.76144454@debian/

applying [1/1] https://yhetil.org/guix/20151031215617.4df7ce04@debian/
diff --git a/guix/build/build-flags.scm b/guix/build/build-flags.scm
new file mode 100644
index 0000000..30a35a1

Checking patch guix/build/build-flags.scm...
Applied patch guix/build/build-flags.scm cleanly.

skipping https://yhetil.org/guix/20151025141115.76144454@debian/ for 30a35a1
index at:
100644 30a35a153a1cd442dfadbae6f7c3ae9358641406	guix/build/build-flags.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.