0.8.5.15:
[sbcl.git] / contrib / sb-posix / sb-posix.asd
1 ;;; -*-  Lisp -*-
2 (require :sb-grovel)
3 (defpackage #:sb-posix-system (:use #:asdf #:cl #:sb-grovel))
4 (in-package #:sb-posix-system)
5
6
7 ;;; we also have a shared library with some .o files in it
8 ;;;
9 ;;; FIXME: we share this with SB-BSD-SOCKETS.  This should either (a)
10 ;;; be part of ASDF itself, or (b) be in a shared file that we can
11 ;;; LOAD at this point.
12 (defclass unix-dso (module) ())
13 (defun unix-name (pathname)
14   (namestring 
15    (typecase pathname
16      (logical-pathname (translate-logical-pathname pathname))
17      (t pathname))))
18
19 (defmethod asdf::input-files ((operation compile-op) (dso unix-dso))
20   (mapcar #'component-pathname (module-components dso)))
21
22 (defmethod output-files ((operation compile-op) (dso unix-dso))
23   (let ((dir (component-pathname dso)))
24     (list
25      (make-pathname :type "so"
26                     :name (car (last (pathname-directory dir)))
27                     :directory (butlast (pathname-directory dir))
28                     :defaults dir))))
29
30
31 (defmethod perform :after ((operation compile-op) (dso unix-dso))
32   (let ((dso-name (unix-name (car (output-files operation dso)))))
33     (unless (zerop
34              (run-shell-command
35               "gcc ~A -o ~S ~{~S ~}"
36               (if (sb-ext:posix-getenv "LDFLAGS")
37                   (sb-ext:posix-getenv "LDFLAGS")
38                 #+sunos "-shared -lresolv -lsocket -lnsl"
39                 #+darwin "-bundle"
40                 #-(or darwin sunos) "-shared")
41               dso-name
42               (mapcar #'unix-name
43                       (mapcan (lambda (c)
44                                 (output-files operation c))
45                               (module-components dso)))))
46       (error 'operation-error :operation operation :component dso))))
47
48 ;;; if this goes into the standard asdf, it could reasonably be extended
49 ;;; to allow cflags to be set somehow
50 (defmethod output-files ((op compile-op) (c c-source-file))
51   (list 
52    (make-pathname :type "o" :defaults
53                   (component-pathname c))))
54 (defmethod perform ((op compile-op) (c c-source-file))
55   (unless
56       (= 0 (run-shell-command "gcc ~A -o ~S -c ~S"
57                               (if (sb-ext:posix-getenv "CFLAGS")
58                                   (sb-ext:posix-getenv "CFLAGS")
59                                 "-fPIC")
60                               (unix-name (car (output-files op c)))
61                               (unix-name (component-pathname c))))
62     (error 'operation-error :operation op :component c)))
63
64 (defmethod perform ((operation load-op) (c c-source-file))
65   t)
66   
67 (defmethod perform ((o load-op) (c unix-dso))
68   (let ((co (make-instance 'compile-op)))
69     (let ((filename (car (output-files co c))))
70       #+cmu (ext:load-foreign filename)
71       #+sbcl (sb-alien:load-1-foreign filename))))
72
73
74 (defsystem sb-posix
75     :depends-on (sb-grovel)
76     :components ((:file "defpackage")
77                  (:file "designator" :depends-on ("defpackage"))
78                  (:unix-dso "alien"
79                             :components ((:c-source-file "stat-macros")))
80                  (:file "macros" :depends-on ("designator"))
81                  (sb-grovel:grovel-constants-file
82                   "constants"
83                   :package :sb-posix :depends-on  ("defpackage"))
84                  (:file "interface" :depends-on ("constants" "macros" "designator" "alien"))))
85
86 (defsystem sb-posix-tests
87     :depends-on (sb-rt)
88     :components ((:file "posix-tests")))
89
90 (defmethod perform :after ((o load-op) (c (eql (find-system :sb-posix))))
91   (provide 'sb-posix))
92
93 (defmethod perform ((o test-op) (c (eql (find-system :sb-posix))))
94   (operate 'load-op 'sb-posix-tests)
95   (operate 'test-op 'sb-posix-tests))
96
97 (defmethod perform ((o test-op) (c (eql (find-system :sb-posix-tests))))
98   (or (funcall (intern "DO-TESTS" (find-package "SB-RT")))
99       (error "test-op failed")))