1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 12:20:26 +02:00
guile/module/system/base/target.scm
Andy Wingo 42090217cf add (system base target)
* module/Makefile.am:
* module/system/base/target.scm: Add a minimal module to parameterize
  the target system type and inspect properties on it like cpu, vendor,
  os, endianness, and word size.
2011-05-31 11:18:28 +02:00

76 lines
2.2 KiB
Scheme
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; Compilation targets
;; Copyright (C) 2011 Free Software Foundation, Inc.
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
;; License as published by the Free Software Foundation; either
;; version 3 of the License, or (at your option) any later version.
;;
;; This library 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
;; Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with this library; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
;; 02110-1301 USA
;;; Code:
(define-module (system base target)
#:use-module (rnrs bytevectors)
#:export (target-type with-target
target-cpu target-vendor target-os
target-endianness target-word-size))
;;;
;;; Target types
;;;
(define %target-type (make-fluid))
(define (target-type)
(or (fluid-ref %target-type)
%host-type))
(define (validate-target target)
(if (or (not (string? target))
(let ((parts (string-split target #\-)))
(or (< 3 (length parts))
(or-map string-null? parts))))
(error "invalid target" target)))
(define (with-target target thunk)
(validate-target target)
(with-fluids ((%target-type target))
(thunk)))
(define (target-cpu)
(let ((t (target-type)))
(substring t 0 (string-index t #\-))))
(define (target-vendor)
(let* ((t (target-type))
(start (1+ (string-index t #\-))))
(substring t start (string-index t #\- start))))
(define (target-os)
(let* ((t (target-type))
(start (1+ (string-index t #\- (1+ (string-index t #\-))))))
(substring t start)))
(define (target-endianness)
(if (equal? (target-type) %host-type)
(native-endianness)
(error "cross-compilation not yet handled" %host-type (target-type))))
(define (target-word-size)
(if (equal? (target-type) %host-type)
((@ (system foreign) sizeof) '*)
(error "cross-compilation not yet handled" %host-type (target-type))))