Commit | Line | Data |
---|---|---|
42090217 AW |
1 | ;;; Compilation targets |
2 | ||
3 | ;; Copyright (C) 2011 Free Software Foundation, Inc. | |
4 | ||
5 | ;; This library is free software; you can redistribute it and/or | |
6 | ;; modify it under the terms of the GNU Lesser General Public | |
7 | ;; License as published by the Free Software Foundation; either | |
8 | ;; version 3 of the License, or (at your option) any later version. | |
9 | ;; | |
10 | ;; This library is distributed in the hope that it will be useful, | |
11 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | ;; Lesser General Public License for more details. | |
14 | ;; | |
15 | ;; You should have received a copy of the GNU Lesser General Public | |
16 | ;; License along with this library; if not, write to the Free Software | |
17 | ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
18 | ;; 02110-1301 USA | |
19 | ||
20 | ;;; Code: | |
21 | ||
22 | (define-module (system base target) | |
23 | #:use-module (rnrs bytevectors) | |
24 | #:export (target-type with-target | |
25 | ||
26 | target-cpu target-vendor target-os | |
27 | ||
28 | target-endianness target-word-size)) | |
29 | ||
30 | ||
31 | \f | |
32 | ;;; | |
33 | ;;; Target types | |
34 | ;;; | |
35 | ||
36 | (define %target-type (make-fluid)) | |
37 | ||
38 | (define (target-type) | |
39 | (or (fluid-ref %target-type) | |
40 | %host-type)) | |
41 | ||
42 | (define (validate-target target) | |
43 | (if (or (not (string? target)) | |
44 | (let ((parts (string-split target #\-))) | |
45 | (or (< 3 (length parts)) | |
46 | (or-map string-null? parts)))) | |
47 | (error "invalid target" target))) | |
48 | ||
49 | (define (with-target target thunk) | |
50 | (validate-target target) | |
51 | (with-fluids ((%target-type target)) | |
52 | (thunk))) | |
53 | ||
54 | (define (target-cpu) | |
55 | (let ((t (target-type))) | |
56 | (substring t 0 (string-index t #\-)))) | |
57 | ||
58 | (define (target-vendor) | |
59 | (let* ((t (target-type)) | |
60 | (start (1+ (string-index t #\-)))) | |
61 | (substring t start (string-index t #\- start)))) | |
62 | ||
63 | (define (target-os) | |
64 | (let* ((t (target-type)) | |
65 | (start (1+ (string-index t #\- (1+ (string-index t #\-)))))) | |
66 | (substring t start))) | |
67 | ||
68 | (define (target-endianness) | |
69 | (if (equal? (target-type) %host-type) | |
70 | (native-endianness) | |
71 | (error "cross-compilation not yet handled" %host-type (target-type)))) | |
72 | ||
73 | (define (target-word-size) | |
74 | (if (equal? (target-type) %host-type) | |
75 | ((@ (system foreign) sizeof) '*) | |
76 | (error "cross-compilation not yet handled" %host-type (target-type)))) |