0.7.12.57
[sbcl.git] / contrib / sb-bsd-sockets / sb-bsd-sockets.asd
1 ;;; -*-  Lisp -*-
2
3 (defpackage #:sb-bsd-sockets-system (:use #:asdf #:cl))
4 (in-package #:sb-bsd-sockets-system)
5
6 ;;; constants.lisp requires special treatment
7
8 (defclass constants-file (cl-source-file) ())
9
10 (defmethod perform ((op compile-op) (component constants-file))
11   ;; we want to generate all our temporary files in the fasl directory
12   ;; because that's where we have write permission.  Can't use /tmp;
13   ;; it's insecure (these files will later be owned by root)
14   (let* ((output-file (car (output-files op component)))
15          (filename (component-pathname component))
16          (real-output-file
17           (if (typep output-file 'logical-pathname)
18               (translate-logical-pathname output-file)
19               (pathname output-file)))
20          (tmp-c-source (merge-pathnames #p"foo.c" real-output-file))
21          (tmp-a-dot-out (merge-pathnames #p"a.out" real-output-file))
22          (tmp-constants (merge-pathnames #p"constants.lisp-temp"
23                                          real-output-file)))
24     (princ (list filename output-file real-output-file
25                  tmp-c-source tmp-a-dot-out tmp-constants))
26     (terpri)
27     (funcall (intern "C-CONSTANTS-EXTRACT"
28                      (find-package "SB-BSD-SOCKETS-SYSTEM"))
29              filename tmp-c-source :sb-bsd-sockets-internal)
30     (and
31      (= (run-shell-command "gcc -o ~S ~S" (namestring tmp-a-dot-out)
32          (namestring tmp-c-source)) 0)
33      (= (run-shell-command "~A >~A"
34                            (namestring tmp-a-dot-out)
35                            (namestring tmp-constants)) 0)
36      (compile-file tmp-constants :output-file output-file))))
37
38
39 ;;; we also have a shared library with some .o files in it
40
41 (defclass unix-dso (module) ())
42 (defun unix-name (pathname)
43   (namestring 
44    (typecase pathname
45      (logical-pathname (translate-logical-pathname pathname))
46      (t pathname))))
47
48 (defmethod asdf::input-files ((operation compile-op) (dso unix-dso))
49   (mapcar #'component-pathname (module-components dso)))
50
51 (defmethod output-files ((operation compile-op) (dso unix-dso))
52   (let ((dir (component-pathname dso)))
53     (list
54      (make-pathname :type "so"
55                     :name (car (last (pathname-directory dir)))
56                     :directory (butlast (pathname-directory dir))
57                     :defaults dir))))
58
59
60 (defmethod perform :after ((operation compile-op) (dso unix-dso))
61   (let ((dso-name (unix-name (car (output-files operation dso)))))
62     (unless (zerop
63              (run-shell-command
64               #+sunos "gcc -shared -o ~S ~{~S ~} -lresolv"
65               #-sunos "gcc -shared -o ~S ~{~S ~} "
66               dso-name
67               (mapcar #'unix-name
68                       (mapcan (lambda (c)
69                                 (output-files operation c))
70                               (module-components dso)))))
71       (error 'operation-error :operation operation :component dso))))
72
73 ;;; if this goes into the standard asdf, it could reasonably be extended
74 ;;; to allow cflags to be set somehow
75 (defmethod output-files ((op compile-op) (c c-source-file))
76   (list 
77    (make-pathname :type "o" :defaults
78                   (component-pathname c))))
79 (defmethod perform ((op compile-op) (c c-source-file))
80   (unless
81       (= 0 (run-shell-command "gcc -fPIC -o ~S -c ~S"
82                               (unix-name (car (output-files op c)))
83                               (unix-name (component-pathname c))))
84     (error 'operation-error :operation op :component c)))
85
86 (defmethod perform ((operation load-op) (c c-source-file))
87   t)
88   
89 (defmethod perform ((o load-op) (c unix-dso))
90   (let ((co (make-instance 'compile-op)))
91     (let ((filename (car (output-files co c))))
92       #+cmu (ext:load-foreign filename)
93       #+sbcl (sb-alien:load-1-foreign filename))))
94
95 (defsystem sb-bsd-sockets
96     :version "0.58"
97     :components ((:file "defpackage" :depends-on ("rt"))
98                  (:file "split" :depends-on ("defpackage"))
99                  (:file "array-data" :depends-on ("defpackage"))
100                  (:unix-dso "alien"
101                             :components ((:c-source-file "undefs")
102                                          (:c-source-file "get-h-errno")))
103                  (:file "malloc" :depends-on ("defpackage"))
104                  (:file "foreign-glue" :depends-on ("defpackage" "malloc"))
105                  (:constants-file "constants"
106                                   :pathname "constants.lisp"
107                                   :depends-on
108                                   ("def-to-lisp" "defpackage" "foreign-glue"))
109                  (:file "sockets"
110                         :depends-on ("constants" "array-data"))
111                  
112                  (:file "sockopt" :depends-on ("sockets"))
113                  (:file "inet" :depends-on ("sockets" "split"  "constants" ))
114                  (:file "local" :depends-on ("sockets" "split" "constants" ))
115                  (:file "name-service" :depends-on ("sockets" "constants" "alien"))
116                  (:file "misc" :depends-on ("sockets" "constants"))
117
118                  (:file "rt")
119                  (:file "def-to-lisp")
120                  (:file "tests" :depends-on ("inet" "sockopt" "rt"))
121
122                  (:static-file "NEWS")
123                  ;; (:static-file "INSTALL")
124                  (:static-file "README")
125                  (:static-file "index" :pathname "index.html")
126                  (:static-file "doc" :pathname "doc.lisp")
127                  (:static-file "TODO")))
128