0.8.6.14:
[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               "gcc ~A -o ~S ~{~S ~}"
33               (concatenate 'string
34                            (sb-ext:posix-getenv "EXTRA_LDFLAGS")
35                            " "
36                            #+sunos "-shared -lresolv -lsocket -lnsl"
37                            #+darwin "-bundle"
38                            #-(or darwin sunos) "-shared")
39               dso-name
40               (mapcar #'unix-name
41                       (mapcan (lambda (c)
42                                 (output-files operation c))
43                               (module-components dso)))))
44       (error 'operation-error :operation operation :component dso))))
45
46 ;;; if this goes into the standard asdf, it could reasonably be extended
47 ;;; to allow cflags to be set somehow
48 (defmethod output-files ((op compile-op) (c c-source-file))
49   (list 
50    (make-pathname :type "o" :defaults
51                   (component-pathname c))))
52 (defmethod perform ((op compile-op) (c c-source-file))
53   (unless
54       (= 0 (run-shell-command "gcc ~A -o ~S -c ~S"
55                               (concatenate 'string
56                                            (sb-ext:posix-getenv "EXTRA_CFLAGS")
57                                            " "
58                                            "-fPIC")
59                               (unix-name (car (output-files op c)))
60                               (unix-name (component-pathname c))))
61     (error 'operation-error :operation op :component c)))
62
63 (defmethod perform ((operation load-op) (c c-source-file))
64   t)
65   
66 (defmethod perform ((o load-op) (c unix-dso))
67   (let ((co (make-instance 'compile-op)))
68     (let ((filename (car (output-files co c))))
69       #+cmu (ext:load-foreign filename)
70       #+sbcl (sb-alien:load-1-foreign filename))))
71
72 (defsystem sb-bsd-sockets
73     :version "0.58"
74     :depends-on (sb-grovel)
75     #+sb-building-contrib :pathname
76     #+sb-building-contrib "SYS:CONTRIB;SB-BSD-SOCKETS;"
77     :components ((:file "defpackage")
78                  (:file "split" :depends-on ("defpackage"))
79                  (:file "array-data" :depends-on ("defpackage"))
80                  (:unix-dso "alien"
81                             :components ((:c-source-file "undefs")
82                                          (:c-source-file "get-h-errno")))
83                  (:file "malloc" :depends-on ("defpackage"))
84                  (:file "foreign-glue" :depends-on ("defpackage" "malloc"))
85                  (sb-grovel:grovel-constants-file
86                   "constants"
87                   :package :sockint
88                   :depends-on  ("def-to-lisp" "defpackage" "foreign-glue"))
89                  (:file "sockets"
90                         :depends-on ("constants" "array-data"))
91                  
92                  (:file "sockopt" :depends-on ("sockets"))
93                  (:file "inet" :depends-on ("sockets" "split"  "constants" ))
94                  (:file "local" :depends-on ("sockets" "split" "constants" ))
95                  (:file "name-service" :depends-on ("sockets" "constants" "alien"))
96                  (:file "misc" :depends-on ("sockets" "constants"))
97
98                  (:file "def-to-lisp")
99
100                  (:static-file "NEWS")
101                  ;; (:static-file "INSTALL")
102                  (:static-file "README")
103                  (:static-file "index" :pathname "index.html")
104                  (:static-file "doc" :pathname "doc.lisp")
105                  (:static-file "TODO")))
106
107 (defmethod perform :after ((o load-op) (c (eql (find-system :sb-bsd-sockets))))
108   (provide 'sb-bsd-sockets))
109
110 (defmethod perform ((o test-op) (c (eql (find-system :sb-bsd-sockets))))
111   (operate 'load-op 'sb-bsd-sockets-tests)
112   (operate 'test-op 'sb-bsd-sockets-tests))
113
114 (defsystem sb-bsd-sockets-tests
115   :depends-on (sb-rt sb-bsd-sockets sb-posix)
116   :components ((:file "tests")))
117
118 (defmethod perform ((o test-op) (c (eql (find-system :sb-bsd-sockets-tests))))
119   (or (funcall (intern "DO-TESTS" (find-package "SB-RT")))
120       (error "test-op failed")))