0.9.8.40:
[sbcl.git] / contrib / sb-posix / sb-posix.asd
1 ;;; -*-  Lisp -*-
2 (cl:eval-when (:compile-toplevel :load-toplevel :execute)
3   (asdf:oos 'asdf:load-op :sb-grovel))
4 (defpackage #:sb-posix-system (:use #:asdf #:cl #:sb-grovel))
5 (in-package #:sb-posix-system)
6
7
8 ;;; we also have a shared library with some .o files in it
9 ;;;
10 ;;; FIXME: we share this with SB-BSD-SOCKETS.  This should either (a)
11 ;;; be part of ASDF itself, or (b) be in a shared file that we can
12 ;;; LOAD at this point.
13 (defclass unix-dso (module) ())
14 (defun unix-name (pathname)
15   (namestring 
16    (typecase pathname
17      (logical-pathname (translate-logical-pathname pathname))
18      (t pathname))))
19
20 (defmethod asdf::input-files ((operation compile-op) (dso unix-dso))
21   (mapcar #'component-pathname (module-components dso)))
22
23 (defmethod output-files ((operation compile-op) (dso unix-dso))
24   (let ((dir (component-pathname dso)))
25     (list
26      (make-pathname :type "so"
27                     :name (car (last (pathname-directory dir)))
28                     :directory (butlast (pathname-directory dir))
29                     :defaults dir))))
30
31
32 (defmethod perform :after ((operation compile-op) (dso unix-dso))
33   (let ((dso-name (unix-name (car (output-files operation dso)))))
34     (unless (zerop
35              (run-shell-command
36               "gcc ~A -o ~S ~{~S ~}"
37               (concatenate 'string
38                            (sb-ext:posix-getenv "EXTRA_LDFLAGS")
39                            " "
40                            #+sunos "-shared -lresolv -lsocket -lnsl"
41                            #+darwin "-bundle"
42                            #-(or darwin sunos) "-shared")
43               dso-name
44               (mapcar #'unix-name
45                       (mapcan (lambda (c)
46                                 (output-files operation c))
47                               (module-components dso)))))
48       (error 'operation-error :operation operation :component dso))))
49
50 ;;; if this goes into the standard asdf, it could reasonably be extended
51 ;;; to allow cflags to be set somehow
52 (defmethod output-files ((op compile-op) (c c-source-file))
53   (list 
54    (make-pathname :type "o" :defaults
55                   (component-pathname c))))
56 (defmethod perform ((op compile-op) (c c-source-file))
57   (unless
58       (= 0 (run-shell-command "gcc ~A -o ~S -c ~S"
59                               (concatenate
60                                'string
61                                (sb-ext:posix-getenv "EXTRA_CFLAGS")
62                                " "
63                                "-fPIC")
64                               (unix-name (car (output-files op c)))
65                               (unix-name (component-pathname c))))
66     (error 'operation-error :operation op :component c)))
67
68 (defmethod perform ((operation load-op) (c c-source-file))
69   t)
70   
71 (defmethod perform ((o load-op) (c unix-dso))
72   (let ((co (make-instance 'compile-op)))
73     (let ((filename (car (output-files co c))))
74       #+cmu (ext:load-foreign filename)
75       #+sbcl (sb-alien:load-shared-object filename))))
76
77 (defsystem sb-posix
78     :depends-on (sb-grovel)
79     #+sb-building-contrib :pathname
80     #+sb-building-contrib "SYS:CONTRIB;SB-POSIX;"
81     :components ((:file "defpackage")
82                  (:file "designator" :depends-on ("defpackage"))
83                  (:unix-dso "alien"
84                             :components ((:c-source-file "stat-macros")
85                                          (:c-source-file "waitpid-macros")))
86                  (:file "macros" :depends-on ("designator"))
87                  (sb-grovel:grovel-constants-file
88                   "constants"
89                   :package :sb-posix :depends-on  ("defpackage"))
90                  (:file "interface" :depends-on ("constants" "macros" "designator" "alien"))))
91
92 (defsystem sb-posix-tests
93     :depends-on (sb-rt)
94     :components ((:file "posix-tests")))
95
96 (defmethod perform :after ((o load-op) (c (eql (find-system :sb-posix))))
97   (provide 'sb-posix))
98
99 (defmethod perform ((o test-op) (c (eql (find-system :sb-posix))))
100   (operate 'load-op 'sb-posix-tests)
101   (operate 'test-op 'sb-posix-tests))
102
103 (defmethod perform ((o test-op) (c (eql (find-system :sb-posix-tests))))
104   (funcall (intern "DO-TESTS" (find-package "SB-RT")))
105   (let ((failures (funcall (intern "PENDING-TESTS" "SB-RT")))
106         (ignored-failures (loop for sym being the symbols of :sb-posix-tests
107                                 if (search ".ERROR" (symbol-name sym))
108                                 collect sym)))
109     (cond
110       ((null failures)
111        t)            
112       ((null (set-difference failures ignored-failures))
113        (warn "~@<some POSIX implementations return incorrect error values for ~
114               failing calls, but there is legitimate variation between ~
115               implementations too.  If you think the errno ~
116               from your platform is valid, please contact the sbcl ~
117               developers; otherwise, please submit a bug report to your ~
118               kernel distributor~@:>")
119        t)
120       (t
121        (error "non-errno tests failed!")))))