0.8.3.22:
[sbcl.git] / contrib / sb-bsd-sockets / sb-bsd-sockets.asd
1 ;;; -*-  Lisp -*-
2 (eval-when (:compile-toplevel :load-toplevel :execute)
3   (require :sb-grovel))
4 (defpackage #:sb-bsd-sockets-system (:use #:asdf #:sb-grovel #:cl))
5 (in-package #:sb-bsd-sockets-system)
6
7 ;;; we also have a shared library with some .o files in it
8
9 (defclass unix-dso (module) ())
10 (defun unix-name (pathname)
11   (namestring 
12    (typecase pathname
13      (logical-pathname (translate-logical-pathname pathname))
14      (t pathname))))
15
16 (defmethod asdf::input-files ((operation compile-op) (dso unix-dso))
17   (mapcar #'component-pathname (module-components dso)))
18
19 (defmethod output-files ((operation compile-op) (dso unix-dso))
20   (let ((dir (component-pathname dso)))
21     (list
22      (make-pathname :type "so"
23                     :name (car (last (pathname-directory dir)))
24                     :directory (butlast (pathname-directory dir))
25                     :defaults dir))))
26
27
28 (defmethod perform :after ((operation compile-op) (dso unix-dso))
29   (let ((dso-name (unix-name (car (output-files operation dso)))))
30     (unless (zerop
31              (run-shell-command
32               #+sunos "gcc -shared -lresolv -lsocket -lnsl -o ~S ~{~S ~}"
33               #+darwin "gcc -bundle -o ~S ~{~S ~}"
34               #-(or darwin sunos) "gcc -shared -o ~S ~{~S ~} "
35               dso-name
36               (mapcar #'unix-name
37                       (mapcan (lambda (c)
38                                 (output-files operation c))
39                               (module-components dso)))))
40       (error 'operation-error :operation operation :component dso))))
41
42 ;;; if this goes into the standard asdf, it could reasonably be extended
43 ;;; to allow cflags to be set somehow
44 (defmethod output-files ((op compile-op) (c c-source-file))
45   (list 
46    (make-pathname :type "o" :defaults
47                   (component-pathname c))))
48 (defmethod perform ((op compile-op) (c c-source-file))
49   (unless
50       (= 0 (run-shell-command "gcc -fPIC -o ~S -c ~S"
51                               (unix-name (car (output-files op c)))
52                               (unix-name (component-pathname c))))
53     (error 'operation-error :operation op :component c)))
54
55 (defmethod perform ((operation load-op) (c c-source-file))
56   t)
57   
58 (defmethod perform ((o load-op) (c unix-dso))
59   (let ((co (make-instance 'compile-op)))
60     (let ((filename (car (output-files co c))))
61       #+cmu (ext:load-foreign filename)
62       #+sbcl (sb-alien:load-1-foreign filename))))
63
64 (defsystem sb-bsd-sockets
65     :version "0.58"
66     :depends-on (sb-grovel)
67     :components ((:file "defpackage")
68                  (:file "split" :depends-on ("defpackage"))
69                  (:file "array-data" :depends-on ("defpackage"))
70                  (:unix-dso "alien"
71                             :components ((:c-source-file "undefs")
72                                          (:c-source-file "get-h-errno")))
73                  (:file "malloc" :depends-on ("defpackage"))
74                  (:file "foreign-glue" :depends-on ("defpackage" "malloc"))
75                  (sb-grovel:grovel-constants-file
76                   "constants"
77                   :package :sockint  :pathname "constants.lisp"
78                   :depends-on  ("def-to-lisp" "defpackage" "foreign-glue"))
79                  (:file "sockets"
80                         :depends-on ("constants" "array-data"))
81                  
82                  (:file "sockopt" :depends-on ("sockets"))
83                  (:file "inet" :depends-on ("sockets" "split"  "constants" ))
84                  (:file "local" :depends-on ("sockets" "split" "constants" ))
85                  (:file "name-service" :depends-on ("sockets" "constants" "alien"))
86                  (:file "misc" :depends-on ("sockets" "constants"))
87
88                  (:file "def-to-lisp")
89
90                  (:static-file "NEWS")
91                  ;; (:static-file "INSTALL")
92                  (:static-file "README")
93                  (:static-file "index" :pathname "index.html")
94                  (:static-file "doc" :pathname "doc.lisp")
95                  (:static-file "TODO")))
96
97 (defmethod perform :after ((o load-op) (c (eql (find-system :sb-bsd-sockets))))
98   (provide 'sb-bsd-sockets))
99
100 (defmethod perform ((o test-op) (c (eql (find-system :sb-bsd-sockets))))
101   (operate 'load-op 'sb-bsd-sockets-tests)
102   (operate 'test-op 'sb-bsd-sockets-tests))
103
104 (defsystem sb-bsd-sockets-tests
105   :depends-on (sb-rt sb-bsd-sockets)
106   :components ((:file "tests")))
107
108 (defmethod perform ((o test-op) (c (eql (find-system :sb-bsd-sockets-tests))))
109   (or (funcall (intern "DO-TESTS" (find-package "SB-RT")))
110       (error "test-op failed")))